mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-09-10 21:03:21 +02:00
The conventions specified by the GiST SGML documentation were widely ignored. For example, the strategy-number argument for "consistent" and "distance" functions is specified to be a smallint, but most of the built-in support functions declared it as an integer, and for that matter the core code passed it using Int32GetDatum not Int16GetDatum. None of that makes any real difference at runtime, but it's quite confusing for newcomers to the code, and it makes it very hard to write an amvalidate() function that checks support function signatures. So let's try to instill some consistency here. Another similar issue is that the "query" argument is not of a single well-defined type, but could have different types depending on the strategy (corresponding to search operators with different righthand-side argument types). Some of the functions threw up their hands and declared the query argument as being of "internal" type, which surely isn't right ("any" would have been more appropriate); but the majority position seemed to be to declare it as being of the indexed data type, corresponding to a search operator with both input types the same. So I've specified a convention that that's what to do always. Also, the result of the "union" support function actually must be of the index's storage type, but the documentation suggested declaring it to return "internal", and some of the functions followed that. Standardize on telling the truth, instead. Similarly, standardize on declaring the "same" function's inputs as being of the storage type, not "internal". Also, somebody had forgotten to add the "recheck" argument to both the documentation of the "distance" support function and all of their SQL declarations, even though the C code was happily using that argument. Clean that up too. Fix up some other omissions in the docs too, such as documenting that union's second input argument is vestigial. So far as the errors in core function declarations go, we can just fix pg_proc.h and bump catversion. Adjusting the erroneous declarations in contrib modules is more debatable: in principle any change in those scripts should involve an extension version bump, which is a pain. However, since these changes are purely cosmetic and make no functional difference, I think we can get away without doing that.
396 lines
7.6 KiB
SQL
396 lines
7.6 KiB
SQL
/* contrib/seg/seg--1.0.sql */
|
|
|
|
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
|
|
\echo Use "CREATE EXTENSION seg" to load this file. \quit
|
|
|
|
-- Create the user-defined type for 1-D floating point intervals (seg)
|
|
|
|
CREATE FUNCTION seg_in(cstring)
|
|
RETURNS seg
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
CREATE FUNCTION seg_out(seg)
|
|
RETURNS cstring
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
CREATE TYPE seg (
|
|
INTERNALLENGTH = 12,
|
|
INPUT = seg_in,
|
|
OUTPUT = seg_out
|
|
);
|
|
|
|
COMMENT ON TYPE seg IS
|
|
'floating point interval ''FLOAT .. FLOAT'', ''.. FLOAT'', ''FLOAT ..'' or ''FLOAT''';
|
|
|
|
--
|
|
-- External C-functions for R-tree methods
|
|
--
|
|
|
|
-- Left/Right methods
|
|
|
|
CREATE FUNCTION seg_over_left(seg, seg)
|
|
RETURNS bool
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
COMMENT ON FUNCTION seg_over_left(seg, seg) IS
|
|
'overlaps or is left of';
|
|
|
|
CREATE FUNCTION seg_over_right(seg, seg)
|
|
RETURNS bool
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
COMMENT ON FUNCTION seg_over_right(seg, seg) IS
|
|
'overlaps or is right of';
|
|
|
|
CREATE FUNCTION seg_left(seg, seg)
|
|
RETURNS bool
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
COMMENT ON FUNCTION seg_left(seg, seg) IS
|
|
'is left of';
|
|
|
|
CREATE FUNCTION seg_right(seg, seg)
|
|
RETURNS bool
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
COMMENT ON FUNCTION seg_right(seg, seg) IS
|
|
'is right of';
|
|
|
|
|
|
-- Scalar comparison methods
|
|
|
|
CREATE FUNCTION seg_lt(seg, seg)
|
|
RETURNS bool
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
COMMENT ON FUNCTION seg_lt(seg, seg) IS
|
|
'less than';
|
|
|
|
CREATE FUNCTION seg_le(seg, seg)
|
|
RETURNS bool
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
COMMENT ON FUNCTION seg_le(seg, seg) IS
|
|
'less than or equal';
|
|
|
|
CREATE FUNCTION seg_gt(seg, seg)
|
|
RETURNS bool
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
COMMENT ON FUNCTION seg_gt(seg, seg) IS
|
|
'greater than';
|
|
|
|
CREATE FUNCTION seg_ge(seg, seg)
|
|
RETURNS bool
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
COMMENT ON FUNCTION seg_ge(seg, seg) IS
|
|
'greater than or equal';
|
|
|
|
CREATE FUNCTION seg_contains(seg, seg)
|
|
RETURNS bool
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
COMMENT ON FUNCTION seg_contains(seg, seg) IS
|
|
'contains';
|
|
|
|
CREATE FUNCTION seg_contained(seg, seg)
|
|
RETURNS bool
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
COMMENT ON FUNCTION seg_contained(seg, seg) IS
|
|
'contained in';
|
|
|
|
CREATE FUNCTION seg_overlap(seg, seg)
|
|
RETURNS bool
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
COMMENT ON FUNCTION seg_overlap(seg, seg) IS
|
|
'overlaps';
|
|
|
|
CREATE FUNCTION seg_same(seg, seg)
|
|
RETURNS bool
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
COMMENT ON FUNCTION seg_same(seg, seg) IS
|
|
'same as';
|
|
|
|
CREATE FUNCTION seg_different(seg, seg)
|
|
RETURNS bool
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
COMMENT ON FUNCTION seg_different(seg, seg) IS
|
|
'different';
|
|
|
|
-- support routines for indexing
|
|
|
|
CREATE FUNCTION seg_cmp(seg, seg)
|
|
RETURNS int4
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
COMMENT ON FUNCTION seg_cmp(seg, seg) IS 'btree comparison function';
|
|
|
|
CREATE FUNCTION seg_union(seg, seg)
|
|
RETURNS seg
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
CREATE FUNCTION seg_inter(seg, seg)
|
|
RETURNS seg
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
CREATE FUNCTION seg_size(seg)
|
|
RETURNS float4
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
-- miscellaneous
|
|
|
|
CREATE FUNCTION seg_center(seg)
|
|
RETURNS float4
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
CREATE FUNCTION seg_upper(seg)
|
|
RETURNS float4
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
CREATE FUNCTION seg_lower(seg)
|
|
RETURNS float4
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
|
|
--
|
|
-- OPERATORS
|
|
--
|
|
|
|
CREATE OPERATOR < (
|
|
LEFTARG = seg,
|
|
RIGHTARG = seg,
|
|
PROCEDURE = seg_lt,
|
|
COMMUTATOR = '>',
|
|
NEGATOR = '>=',
|
|
RESTRICT = scalarltsel,
|
|
JOIN = scalarltjoinsel
|
|
);
|
|
|
|
CREATE OPERATOR <= (
|
|
LEFTARG = seg,
|
|
RIGHTARG = seg,
|
|
PROCEDURE = seg_le,
|
|
COMMUTATOR = '>=',
|
|
NEGATOR = '>',
|
|
RESTRICT = scalarltsel,
|
|
JOIN = scalarltjoinsel
|
|
);
|
|
|
|
CREATE OPERATOR > (
|
|
LEFTARG = seg,
|
|
RIGHTARG = seg,
|
|
PROCEDURE = seg_gt,
|
|
COMMUTATOR = '<',
|
|
NEGATOR = '<=',
|
|
RESTRICT = scalargtsel,
|
|
JOIN = scalargtjoinsel
|
|
);
|
|
|
|
CREATE OPERATOR >= (
|
|
LEFTARG = seg,
|
|
RIGHTARG = seg,
|
|
PROCEDURE = seg_ge,
|
|
COMMUTATOR = '<=',
|
|
NEGATOR = '<',
|
|
RESTRICT = scalargtsel,
|
|
JOIN = scalargtjoinsel
|
|
);
|
|
|
|
CREATE OPERATOR << (
|
|
LEFTARG = seg,
|
|
RIGHTARG = seg,
|
|
PROCEDURE = seg_left,
|
|
COMMUTATOR = '>>',
|
|
RESTRICT = positionsel,
|
|
JOIN = positionjoinsel
|
|
);
|
|
|
|
CREATE OPERATOR &< (
|
|
LEFTARG = seg,
|
|
RIGHTARG = seg,
|
|
PROCEDURE = seg_over_left,
|
|
RESTRICT = positionsel,
|
|
JOIN = positionjoinsel
|
|
);
|
|
|
|
CREATE OPERATOR && (
|
|
LEFTARG = seg,
|
|
RIGHTARG = seg,
|
|
PROCEDURE = seg_overlap,
|
|
COMMUTATOR = '&&',
|
|
RESTRICT = areasel,
|
|
JOIN = areajoinsel
|
|
);
|
|
|
|
CREATE OPERATOR &> (
|
|
LEFTARG = seg,
|
|
RIGHTARG = seg,
|
|
PROCEDURE = seg_over_right,
|
|
RESTRICT = positionsel,
|
|
JOIN = positionjoinsel
|
|
);
|
|
|
|
CREATE OPERATOR >> (
|
|
LEFTARG = seg,
|
|
RIGHTARG = seg,
|
|
PROCEDURE = seg_right,
|
|
COMMUTATOR = '<<',
|
|
RESTRICT = positionsel,
|
|
JOIN = positionjoinsel
|
|
);
|
|
|
|
CREATE OPERATOR = (
|
|
LEFTARG = seg,
|
|
RIGHTARG = seg,
|
|
PROCEDURE = seg_same,
|
|
COMMUTATOR = '=',
|
|
NEGATOR = '<>',
|
|
RESTRICT = eqsel,
|
|
JOIN = eqjoinsel,
|
|
MERGES
|
|
);
|
|
|
|
CREATE OPERATOR <> (
|
|
LEFTARG = seg,
|
|
RIGHTARG = seg,
|
|
PROCEDURE = seg_different,
|
|
COMMUTATOR = '<>',
|
|
NEGATOR = '=',
|
|
RESTRICT = neqsel,
|
|
JOIN = neqjoinsel
|
|
);
|
|
|
|
CREATE OPERATOR @> (
|
|
LEFTARG = seg,
|
|
RIGHTARG = seg,
|
|
PROCEDURE = seg_contains,
|
|
COMMUTATOR = '<@',
|
|
RESTRICT = contsel,
|
|
JOIN = contjoinsel
|
|
);
|
|
|
|
CREATE OPERATOR <@ (
|
|
LEFTARG = seg,
|
|
RIGHTARG = seg,
|
|
PROCEDURE = seg_contained,
|
|
COMMUTATOR = '@>',
|
|
RESTRICT = contsel,
|
|
JOIN = contjoinsel
|
|
);
|
|
|
|
-- obsolete:
|
|
CREATE OPERATOR @ (
|
|
LEFTARG = seg,
|
|
RIGHTARG = seg,
|
|
PROCEDURE = seg_contains,
|
|
COMMUTATOR = '~',
|
|
RESTRICT = contsel,
|
|
JOIN = contjoinsel
|
|
);
|
|
|
|
CREATE OPERATOR ~ (
|
|
LEFTARG = seg,
|
|
RIGHTARG = seg,
|
|
PROCEDURE = seg_contained,
|
|
COMMUTATOR = '@',
|
|
RESTRICT = contsel,
|
|
JOIN = contjoinsel
|
|
);
|
|
|
|
|
|
-- define the GiST support methods
|
|
CREATE FUNCTION gseg_consistent(internal,seg,smallint,oid,internal)
|
|
RETURNS bool
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C IMMUTABLE STRICT;
|
|
|
|
CREATE FUNCTION gseg_compress(internal)
|
|
RETURNS internal
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C IMMUTABLE STRICT;
|
|
|
|
CREATE FUNCTION gseg_decompress(internal)
|
|
RETURNS internal
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C IMMUTABLE STRICT;
|
|
|
|
CREATE FUNCTION gseg_penalty(internal,internal,internal)
|
|
RETURNS internal
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C IMMUTABLE STRICT;
|
|
|
|
CREATE FUNCTION gseg_picksplit(internal, internal)
|
|
RETURNS internal
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C IMMUTABLE STRICT;
|
|
|
|
CREATE FUNCTION gseg_union(internal, internal)
|
|
RETURNS seg
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C IMMUTABLE STRICT;
|
|
|
|
CREATE FUNCTION gseg_same(seg, seg, internal)
|
|
RETURNS internal
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C IMMUTABLE STRICT;
|
|
|
|
|
|
-- Create the operator classes for indexing
|
|
|
|
CREATE OPERATOR CLASS seg_ops
|
|
DEFAULT FOR TYPE seg USING btree AS
|
|
OPERATOR 1 < ,
|
|
OPERATOR 2 <= ,
|
|
OPERATOR 3 = ,
|
|
OPERATOR 4 >= ,
|
|
OPERATOR 5 > ,
|
|
FUNCTION 1 seg_cmp(seg, seg);
|
|
|
|
CREATE OPERATOR CLASS gist_seg_ops
|
|
DEFAULT FOR TYPE seg USING gist
|
|
AS
|
|
OPERATOR 1 << ,
|
|
OPERATOR 2 &< ,
|
|
OPERATOR 3 && ,
|
|
OPERATOR 4 &> ,
|
|
OPERATOR 5 >> ,
|
|
OPERATOR 6 = ,
|
|
OPERATOR 7 @> ,
|
|
OPERATOR 8 <@ ,
|
|
OPERATOR 13 @ ,
|
|
OPERATOR 14 ~ ,
|
|
FUNCTION 1 gseg_consistent (internal, seg, smallint, oid, internal),
|
|
FUNCTION 2 gseg_union (internal, internal),
|
|
FUNCTION 3 gseg_compress (internal),
|
|
FUNCTION 4 gseg_decompress (internal),
|
|
FUNCTION 5 gseg_penalty (internal, internal, internal),
|
|
FUNCTION 6 gseg_picksplit (internal, internal),
|
|
FUNCTION 7 gseg_same (seg, seg, internal);
|