diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 35d0165..f5c0b24 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -8433,10 +8433,9 @@ CREATE TYPE rainbow AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'purple shows the operators available for the cidr and inet types. - The operators <<, - <<=, >>, - >>= and && - test for subnet inclusion. They + The operators <@, <@=, + @>, @>= and + && test for subnet inclusion. They consider only the network parts of the two addresses (ignoring any host part) and determine whether one network is identical to or a subnet of the other. @@ -8484,24 +8483,24 @@ CREATE TYPE rainbow AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'purple inet '192.168.1.5' <> inet '192.168.1.4' - << + <@ is contained within - inet '192.168.1.5' << inet '192.168.1/24' + inet '192.168.1.5' <@ inet '192.168.1/24' - <<= + <@= is contained within or equals - inet '192.168.1/24' <<= inet '192.168.1/24' + inet '192.168.1/24' <@= inet '192.168.1/24' - >> + @> contains - inet '192.168.1/24' >> inet '192.168.1.5' + inet '192.168.1/24' @> inet '192.168.1.5' - >>= + @>= contains or equals - inet '192.168.1/24' >>= inet '192.168.1/24' + inet '192.168.1/24' @>= inet '192.168.1/24' && @@ -8542,14 +8541,26 @@ CREATE TYPE rainbow AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'purple + + + Prior to PostgreSQL 9.4, the inclusion operators <@, + <@=, @> and + @>= were called <<, + <<=, >> and + >>= respectively. These names are still + available but are deprecated. They will eventually be removed and + may be used for other purposes in the future releases. + + + GiST operator class is included for the cidr and inet types, which support indexed queries using <, <=, =, >=, >, - <>, <<, - <<=, >>, - >>= and && + <>, <@, + <@=, @>, + @>= and && operators. The operator class considers only the network parts of the addresses while creating and using the tree. diff --git a/src/include/catalog/pg_amop.h b/src/include/catalog/pg_amop.h index 7dbd015..f4abe05 100644 --- a/src/include/catalog/pg_amop.h +++ b/src/include/catalog/pg_amop.h @@ -794,16 +794,16 @@ DATA(insert ( 3474 3831 3831 18 s 3882 4000 0 )); /* * GiST inet_ops */ -DATA(insert ( 4049 869 869 3 s 4041 783 0 )); -DATA(insert ( 4049 869 869 7 s 933 783 0 )); -DATA(insert ( 4049 869 869 8 s 931 783 0 )); -DATA(insert ( 4049 869 869 9 s 934 783 0 )); -DATA(insert ( 4049 869 869 10 s 932 783 0 )); -DATA(insert ( 4049 869 869 11 s 1203 783 0 )); -DATA(insert ( 4049 869 869 12 s 1204 783 0 )); -DATA(insert ( 4049 869 869 14 s 1206 783 0 )); -DATA(insert ( 4049 869 869 15 s 1205 783 0 )); -DATA(insert ( 4049 869 869 18 s 1201 783 0 )); -DATA(insert ( 4049 869 869 19 s 1202 783 0 )); +DATA(insert ( 4045 869 869 3 s 4046 783 0 )); +DATA(insert ( 4045 869 869 7 s 4047 783 0 )); +DATA(insert ( 4045 869 869 8 s 4048 783 0 )); +DATA(insert ( 4045 869 869 9 s 4049 783 0 )); +DATA(insert ( 4045 869 869 10 s 4050 783 0 )); +DATA(insert ( 4045 869 869 11 s 1203 783 0 )); +DATA(insert ( 4045 869 869 12 s 1204 783 0 )); +DATA(insert ( 4045 869 869 14 s 1206 783 0 )); +DATA(insert ( 4045 869 869 15 s 1205 783 0 )); +DATA(insert ( 4045 869 869 18 s 1201 783 0 )); +DATA(insert ( 4045 869 869 19 s 1202 783 0 )); #endif /* PG_AMOP_H */ diff --git a/src/include/catalog/pg_amproc.h b/src/include/catalog/pg_amproc.h index 32b59a1..2a112cd 100644 --- a/src/include/catalog/pg_amproc.h +++ b/src/include/catalog/pg_amproc.h @@ -356,13 +356,13 @@ DATA(insert ( 3659 3614 3614 2 3656 )); DATA(insert ( 3659 3614 3614 3 3657 )); DATA(insert ( 3659 3614 3614 4 3658 )); DATA(insert ( 3659 3614 3614 5 2700 )); -DATA(insert ( 4049 869 869 1 4042 )); -DATA(insert ( 4049 869 869 2 4043 )); -DATA(insert ( 4049 869 869 3 4044 )); -DATA(insert ( 4049 869 869 4 4045 )); -DATA(insert ( 4049 869 869 5 4046 )); -DATA(insert ( 4049 869 869 6 4047 )); -DATA(insert ( 4049 869 869 7 4048 )); +DATA(insert ( 4045 869 869 1 4051 )); +DATA(insert ( 4045 869 869 2 4052 )); +DATA(insert ( 4045 869 869 3 4053 )); +DATA(insert ( 4045 869 869 4 4054 )); +DATA(insert ( 4045 869 869 5 4055 )); +DATA(insert ( 4045 869 869 6 4056 )); +DATA(insert ( 4045 869 869 7 4057 )); /* sp-gist */ diff --git a/src/include/catalog/pg_opclass.h b/src/include/catalog/pg_opclass.h index 081459f..d3bca92 100644 --- a/src/include/catalog/pg_opclass.h +++ b/src/include/catalog/pg_opclass.h @@ -112,7 +112,7 @@ DATA(insert OID = 3123 ( 403 float8_ops PGNSP PGUID 1970 701 t 0 )); DATA(insert ( 405 float8_ops PGNSP PGUID 1971 701 t 0 )); DATA(insert ( 403 inet_ops PGNSP PGUID 1974 869 t 0 )); DATA(insert ( 405 inet_ops PGNSP PGUID 1975 869 t 0 )); -DATA(insert ( 783 inet_ops PGNSP PGUID 4049 869 f 869 )); +DATA(insert ( 783 inet_ops PGNSP PGUID 4045 869 f 869 )); DATA(insert OID = 1979 ( 403 int2_ops PGNSP PGUID 1976 21 t 0 )); #define INT2_BTREE_OPS_OID 1979 DATA(insert ( 405 int2_ops PGNSP PGUID 1977 21 t 0 )); diff --git a/src/include/catalog/pg_operator.h b/src/include/catalog/pg_operator.h index 8b2628a..8203089 100644 --- a/src/include/catalog/pg_operator.h +++ b/src/include/catalog/pg_operator.h @@ -1140,21 +1140,33 @@ DATA(insert OID = 1205 ( ">" PGNSP PGUID b f f 869 869 16 1203 1204 network DESCR("greater than"); DATA(insert OID = 1206 ( ">=" PGNSP PGUID b f f 869 869 16 1204 1203 network_ge scalargtsel scalargtjoinsel )); DESCR("greater than or equal"); -DATA(insert OID = 931 ( "<<" PGNSP PGUID b f f 869 869 16 933 0 network_sub contsel contjoinsel )); +DATA(insert OID = 931 ( "<<" PGNSP PGUID b f f 869 869 16 933 0 network_sub - - )); DESCR("is subnet"); #define OID_INET_SUB_OP 931 -DATA(insert OID = 932 ( "<<=" PGNSP PGUID b f f 869 869 16 934 0 network_subeq contsel contjoinsel )); +DATA(insert OID = 932 ( "<<=" PGNSP PGUID b f f 869 869 16 934 0 network_subeq - - )); DESCR("is subnet or equal"); #define OID_INET_SUBEQ_OP 932 -DATA(insert OID = 933 ( ">>" PGNSP PGUID b f f 869 869 16 931 0 network_sup contsel contjoinsel )); +DATA(insert OID = 933 ( ">>" PGNSP PGUID b f f 869 869 16 931 0 network_sup - - )); DESCR("is supernet"); #define OID_INET_SUP_OP 933 -DATA(insert OID = 934 ( ">>=" PGNSP PGUID b f f 869 869 16 932 0 network_supeq contsel contjoinsel )); +DATA(insert OID = 934 ( ">>=" PGNSP PGUID b f f 869 869 16 932 0 network_supeq - - )); DESCR("is supernet or equal"); #define OID_INET_SUPEQ_OP 94 -DATA(insert OID = 4041 ( "&&" PGNSP PGUID b f f 869 869 16 4041 0 network_overlap areasel areajoinsel)); +DATA(insert OID = 4046 ( "&&" PGNSP PGUID b f f 869 869 16 4046 0 inet_overlap areasel areajoinsel)); DESCR("overlaps (is subnet or supernet)"); -#define OID_INET_OVERLAP_OP 4041 +#define OID_INET_OVERLAP_OP 4046 +DATA(insert OID = 4047 ( "@>" PGNSP PGUID b f f 869 869 16 4048 0 inet_contain contsel contjoinsel )); +DESCR("contains"); +#define OID_INET_CONTAINS_OP 4047 +DATA(insert OID = 4048 ( "<@" PGNSP PGUID b f f 869 869 16 4047 0 inet_contained contsel contjoinsel )); +DESCR("is contained within"); +#define OID_INET_CONTAINED_OP 4048 +DATA(insert OID = 4049 ( "@>=" PGNSP PGUID b f f 869 869 16 4050 0 inet_containeq contsel contjoinsel )); +DESCR("contains or equals"); +#define OID_INET_CONTAINSEQ_OP 4049 +DATA(insert OID = 4050 ( "<@=" PGNSP PGUID b f f 869 869 16 4049 0 inet_containedeq contsel contjoinsel )); +DESCR("is contained within or equals"); +#define OID_INET_CONTAINEDEQ_OP 4050 DATA(insert OID = 2634 ( "~" PGNSP PGUID l f f 0 869 869 0 0 inetnot - - )); DESCR("bitwise not"); diff --git a/src/include/catalog/pg_opfamily.h b/src/include/catalog/pg_opfamily.h index b84cb05..6dc6782 100644 --- a/src/include/catalog/pg_opfamily.h +++ b/src/include/catalog/pg_opfamily.h @@ -78,7 +78,7 @@ DATA(insert OID = 1971 ( 405 float_ops PGNSP PGUID )); DATA(insert OID = 1974 ( 403 network_ops PGNSP PGUID )); #define NETWORK_BTREE_FAM_OID 1974 DATA(insert OID = 1975 ( 405 network_ops PGNSP PGUID )); -DATA(insert OID = 4049 ( 783 network_ops PGNSP PGUID )); +DATA(insert OID = 4045 ( 783 network_ops PGNSP PGUID )); DATA(insert OID = 1976 ( 403 integer_ops PGNSP PGUID )); #define INTEGER_BTREE_FAM_OID 1976 DATA(insert OID = 1977 ( 405 integer_ops PGNSP PGUID )); diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h index 393f43d..1908dd3 100644 --- a/src/include/catalog/pg_proc.h +++ b/src/include/catalog/pg_proc.h @@ -2118,22 +2118,26 @@ DATA(insert OID = 927 ( network_sub PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1 DATA(insert OID = 928 ( network_subeq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "869 869" _null_ _null_ _null_ _null_ network_subeq _null_ _null_ _null_ )); DATA(insert OID = 929 ( network_sup PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "869 869" _null_ _null_ _null_ _null_ network_sup _null_ _null_ _null_ )); DATA(insert OID = 930 ( network_supeq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "869 869" _null_ _null_ _null_ _null_ network_supeq _null_ _null_ _null_ )); -DATA(insert OID = 4040 ( network_overlap PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "869 869" _null_ _null_ _null_ _null_ network_overlap _null_ _null_ _null_ )); +DATA(insert OID = 4040 ( inet_overlap PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "869 869" _null_ _null_ _null_ _null_ network_overlap _null_ _null_ _null_ )); +DATA(insert OID = 4041 ( inet_contain PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "869 869" _null_ _null_ _null_ _null_ network_sup _null_ _null_ _null_ )); +DATA(insert OID = 4042 ( inet_contained PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "869 869" _null_ _null_ _null_ _null_ network_sub _null_ _null_ _null_ )); +DATA(insert OID = 4043 ( inet_containeq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "869 869" _null_ _null_ _null_ _null_ network_supeq _null_ _null_ _null_ )); +DATA(insert OID = 4044 ( inet_containedeq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "869 869" _null_ _null_ _null_ _null_ network_subeq _null_ _null_ _null_ )); /* GiST support for inet and cidr */ -DATA(insert OID = 4042 ( inet_gist_consistent PGNSP PGUID 12 1 0 0 0 f f f f t f i 5 0 16 "2281 869 23 26 2281" _null_ _null_ _null_ _null_ inet_gist_consistent _null_ _null_ _null_ )); +DATA(insert OID = 4051 ( inet_gist_consistent PGNSP PGUID 12 1 0 0 0 f f f f t f i 5 0 16 "2281 869 23 26 2281" _null_ _null_ _null_ _null_ inet_gist_consistent _null_ _null_ _null_ )); DESCR("GiST support"); -DATA(insert OID = 4043 ( inet_gist_union PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2281 "2281 2281" _null_ _null_ _null_ _null_ inet_gist_union _null_ _null_ _null_ )); +DATA(insert OID = 4052 ( inet_gist_union PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2281 "2281 2281" _null_ _null_ _null_ _null_ inet_gist_union _null_ _null_ _null_ )); DESCR("GiST support"); -DATA(insert OID = 4044 ( inet_gist_compress PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ inet_gist_compress _null_ _null_ _null_ )); +DATA(insert OID = 4053 ( inet_gist_compress PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ inet_gist_compress _null_ _null_ _null_ )); DESCR("GiST support"); -DATA(insert OID = 4045 ( inet_gist_decompress PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ inet_gist_decompress _null_ _null_ _null_ )); +DATA(insert OID = 4054 ( inet_gist_decompress PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ inet_gist_decompress _null_ _null_ _null_ )); DESCR("GiST support"); -DATA(insert OID = 4046 ( inet_gist_penalty PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ inet_gist_penalty _null_ _null_ _null_ )); +DATA(insert OID = 4055 ( inet_gist_penalty PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ inet_gist_penalty _null_ _null_ _null_ )); DESCR("GiST support"); -DATA(insert OID = 4047 ( inet_gist_picksplit PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2281 "2281 2281" _null_ _null_ _null_ _null_ inet_gist_picksplit _null_ _null_ _null_ )); +DATA(insert OID = 4056 ( inet_gist_picksplit PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2281 "2281 2281" _null_ _null_ _null_ _null_ inet_gist_picksplit _null_ _null_ _null_ )); DESCR("GiST support"); -DATA(insert OID = 4048 ( inet_gist_same PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "869 869 2281" _null_ _null_ _null_ _null_ inet_gist_same _null_ _null_ _null_ )); +DATA(insert OID = 4057 ( inet_gist_same PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "869 869 2281" _null_ _null_ _null_ _null_ inet_gist_same _null_ _null_ _null_ )); DESCR("GiST support"); /* inet/cidr functions */ diff --git a/src/test/regress/expected/inet.out b/src/test/regress/expected/inet.out index d8a6232..3844d37 100644 --- a/src/test/regress/expected/inet.out +++ b/src/test/regress/expected/inet.out @@ -179,8 +179,8 @@ SELECT '' AS six, c AS cidr, i AS inet FROM INET_TBL SELECT '' AS ten, i, c, i < c AS lt, i <= c AS le, i = c AS eq, i >= c AS ge, i > c AS gt, i <> c AS ne, - i << c AS sb, i <<= c AS sbe, i >> c AS sup, - i >>= c AS spe, i && c AS ovr + i <@ c AS sb, i <@= c AS sbe, i @> c AS sup, + i @>= c AS spe, i && c AS ovr FROM INET_TBL; ten | i | c | lt | le | eq | ge | gt | ne | sb | sbe | sup | spe | ovr -----+------------------+--------------------+----+----+----+----+----+----+----+-----+-----+-----+----- @@ -253,7 +253,7 @@ DROP INDEX inet_idx1; -- check that gist index works correctly CREATE INDEX inet_idx2 ON inet_tbl using gist (i inet_ops); SET enable_seqscan TO off; -SELECT * FROM inet_tbl WHERE i << '192.168.1.0/24'::cidr ORDER BY i; +SELECT * FROM inet_tbl WHERE i <@ '192.168.1.0/24'::cidr ORDER BY i; c | i ----------------+------------------ 192.168.1.0/24 | 192.168.1.0/25 @@ -261,7 +261,7 @@ SELECT * FROM inet_tbl WHERE i << '192.168.1.0/24'::cidr ORDER BY i; 192.168.1.0/26 | 192.168.1.226 (3 rows) -SELECT * FROM inet_tbl WHERE i <<= '192.168.1.0/24'::cidr ORDER BY i; +SELECT * FROM inet_tbl WHERE i <@= '192.168.1.0/24'::cidr ORDER BY i; c | i ----------------+------------------ 192.168.1.0/24 | 192.168.1.0/24 @@ -283,7 +283,7 @@ SELECT * FROM inet_tbl WHERE i && '192.168.1.0/24'::cidr ORDER BY i; 192.168.1.0/26 | 192.168.1.226 (6 rows) -SELECT * FROM inet_tbl WHERE i >>= '192.168.1.0/24'::cidr ORDER BY i; +SELECT * FROM inet_tbl WHERE i @>= '192.168.1.0/24'::cidr ORDER BY i; c | i ----------------+------------------ 192.168.1.0/24 | 192.168.1.0/24 @@ -291,7 +291,7 @@ SELECT * FROM inet_tbl WHERE i >>= '192.168.1.0/24'::cidr ORDER BY i; 192.168.1.0/24 | 192.168.1.255/24 (3 rows) -SELECT * FROM inet_tbl WHERE i >> '192.168.1.0/24'::cidr ORDER BY i; +SELECT * FROM inet_tbl WHERE i @> '192.168.1.0/24'::cidr ORDER BY i; c | i ---+--- (0 rows) diff --git a/src/test/regress/expected/opr_sanity.out b/src/test/regress/expected/opr_sanity.out index 108fcff..adc0969 100644 --- a/src/test/regress/expected/opr_sanity.out +++ b/src/test/regress/expected/opr_sanity.out @@ -1105,14 +1105,12 @@ ORDER BY 1, 2, 3; 783 | 5 | >> 783 | 6 | -|- 783 | 6 | ~= - 783 | 7 | >> 783 | 7 | @> - 783 | 8 | << 783 | 8 | <@ 783 | 9 | &<| - 783 | 9 | >>= - 783 | 10 | <<= + 783 | 9 | @>= 783 | 10 | <<| + 783 | 10 | <@= 783 | 10 | <^ 783 | 11 | < 783 | 11 | >^ @@ -1158,7 +1156,7 @@ ORDER BY 1, 2, 3; 4000 | 15 | > 4000 | 16 | @> 4000 | 18 | = -(76 rows) +(74 rows) -- Check that all opclass search operators have selectivity estimators. -- This is not absolutely required, but it seems a reasonable thing diff --git a/src/test/regress/sql/inet.sql b/src/test/regress/sql/inet.sql index 850a319..9aa1af3 100644 --- a/src/test/regress/sql/inet.sql +++ b/src/test/regress/sql/inet.sql @@ -51,8 +51,8 @@ SELECT '' AS six, c AS cidr, i AS inet FROM INET_TBL SELECT '' AS ten, i, c, i < c AS lt, i <= c AS le, i = c AS eq, i >= c AS ge, i > c AS gt, i <> c AS ne, - i << c AS sb, i <<= c AS sbe, i >> c AS sup, - i >>= c AS spe, i && c AS ovr + i <@ c AS sb, i <@= c AS sbe, i @> c AS sup, + i @>= c AS spe, i && c AS ovr FROM INET_TBL; -- check the conversion to/from text and set_netmask @@ -69,11 +69,11 @@ DROP INDEX inet_idx1; -- check that gist index works correctly CREATE INDEX inet_idx2 ON inet_tbl using gist (i inet_ops); SET enable_seqscan TO off; -SELECT * FROM inet_tbl WHERE i << '192.168.1.0/24'::cidr ORDER BY i; -SELECT * FROM inet_tbl WHERE i <<= '192.168.1.0/24'::cidr ORDER BY i; +SELECT * FROM inet_tbl WHERE i <@ '192.168.1.0/24'::cidr ORDER BY i; +SELECT * FROM inet_tbl WHERE i <@= '192.168.1.0/24'::cidr ORDER BY i; SELECT * FROM inet_tbl WHERE i && '192.168.1.0/24'::cidr ORDER BY i; -SELECT * FROM inet_tbl WHERE i >>= '192.168.1.0/24'::cidr ORDER BY i; -SELECT * FROM inet_tbl WHERE i >> '192.168.1.0/24'::cidr ORDER BY i; +SELECT * FROM inet_tbl WHERE i @>= '192.168.1.0/24'::cidr ORDER BY i; +SELECT * FROM inet_tbl WHERE i @> '192.168.1.0/24'::cidr ORDER BY i; SELECT * FROM inet_tbl WHERE i < '192.168.1.0/24'::cidr ORDER BY i; SELECT * FROM inet_tbl WHERE i <= '192.168.1.0/24'::cidr ORDER BY i; SELECT * FROM inet_tbl WHERE i = '192.168.1.0/24'::cidr ORDER BY i;