Tom Lane wrote: > Alvaro Herrera <alvhe...@2ndquadrant.com> writes:
> > I can, of course, just leave these files well enough alone and just rely > > on the numbers not changing (which surely they won't anyway) and > > remaining consistent with numbers used in new opclasses (which surely > > they will lest they be born inconsistent with existing ones). > > Yeah, we do have checks in opr_sanity which will complain if inconsistent > strategy numbers are used for similarly-named operators. That's a pretty > weak test though, and operator names aren't exactly the right thing to > check anyway. I'd be good with pushing all of that stuff to a new central > header. So here's a patch for this. -- Álvaro Herrera http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
commit 912acf2a0e622fec0837ff6773fc95621e216fa5 Author: Alvaro Herrera <alvhe...@alvh.no-ip.org> Date: Fri May 15 01:26:12 2015 -0300 Move strategy number definitions to their own file diff --git a/contrib/btree_gin/btree_gin.c b/contrib/btree_gin/btree_gin.c index 1a5bb3c..6e3bf17 100644 --- a/contrib/btree_gin/btree_gin.c +++ b/contrib/btree_gin/btree_gin.c @@ -5,7 +5,7 @@ #include <limits.h> -#include "access/skey.h" +#include "access/stratnum.h" #include "utils/builtins.h" #include "utils/bytea.h" #include "utils/cash.h" diff --git a/contrib/cube/cube.c b/contrib/cube/cube.c index b9ccad9..113c663 100644 --- a/contrib/cube/cube.c +++ b/contrib/cube/cube.c @@ -12,7 +12,7 @@ #include <math.h> #include "access/gist.h" -#include "access/skey.h" +#include "access/stratnum.h" #include "utils/array.h" #include "utils/builtins.h" diff --git a/contrib/hstore/hstore_gin.c b/contrib/hstore/hstore_gin.c index 68f9061..919181d 100644 --- a/contrib/hstore/hstore_gin.c +++ b/contrib/hstore/hstore_gin.c @@ -4,7 +4,7 @@ #include "postgres.h" #include "access/gin.h" -#include "access/skey.h" +#include "access/stratnum.h" #include "catalog/pg_type.h" #include "hstore.h" diff --git a/contrib/hstore/hstore_gist.c b/contrib/hstore/hstore_gist.c index 06f3c93..dde37fb 100644 --- a/contrib/hstore/hstore_gist.c +++ b/contrib/hstore/hstore_gist.c @@ -4,7 +4,7 @@ #include "postgres.h" #include "access/gist.h" -#include "access/skey.h" +#include "access/stratnum.h" #include "catalog/pg_type.h" #include "utils/pg_crc.h" diff --git a/contrib/intarray/_int_gin.c b/contrib/intarray/_int_gin.c index 58352ca..fb16b66 100644 --- a/contrib/intarray/_int_gin.c +++ b/contrib/intarray/_int_gin.c @@ -4,8 +4,7 @@ #include "postgres.h" #include "access/gin.h" -#include "access/gist.h" -#include "access/skey.h" +#include "access/stratnum.h" #include "_int.h" diff --git a/contrib/intarray/_intbig_gist.c b/contrib/intarray/_intbig_gist.c index 235db38..6dae7c91 100644 --- a/contrib/intarray/_intbig_gist.c +++ b/contrib/intarray/_intbig_gist.c @@ -4,7 +4,7 @@ #include "postgres.h" #include "access/gist.h" -#include "access/skey.h" +#include "access/stratnum.h" #include "_int.h" diff --git a/contrib/ltree/_ltree_gist.c b/contrib/ltree/_ltree_gist.c index 41be68d..37cd991 100644 --- a/contrib/ltree/_ltree_gist.c +++ b/contrib/ltree/_ltree_gist.c @@ -8,7 +8,7 @@ #include "postgres.h" #include "access/gist.h" -#include "access/skey.h" +#include "access/stratnum.h" #include "crc32.h" #include "ltree.h" diff --git a/contrib/ltree/ltree_gist.c b/contrib/ltree/ltree_gist.c index 2d89f1a..83da620 100644 --- a/contrib/ltree/ltree_gist.c +++ b/contrib/ltree/ltree_gist.c @@ -6,7 +6,7 @@ #include "postgres.h" #include "access/gist.h" -#include "access/skey.h" +#include "access/stratnum.h" #include "crc32.h" #include "ltree.h" diff --git a/contrib/pg_trgm/trgm_gin.c b/contrib/pg_trgm/trgm_gin.c index c59925c..d524cea 100644 --- a/contrib/pg_trgm/trgm_gin.c +++ b/contrib/pg_trgm/trgm_gin.c @@ -6,7 +6,8 @@ #include "trgm.h" #include "access/gin.h" -#include "access/skey.h" +#include "access/stratnum.h" +#include "fmgr.h" PG_FUNCTION_INFO_V1(gin_extract_trgm); diff --git a/contrib/pg_trgm/trgm_gist.c b/contrib/pg_trgm/trgm_gist.c index 69dc7f7..07d1dc3 100644 --- a/contrib/pg_trgm/trgm_gist.c +++ b/contrib/pg_trgm/trgm_gist.c @@ -5,7 +5,8 @@ #include "trgm.h" -#include "access/skey.h" +#include "access/stratnum.h" +#include "fmgr.h" typedef struct diff --git a/contrib/seg/seg.c b/contrib/seg/seg.c index 8e2d534..1e6c37d 100644 --- a/contrib/seg/seg.c +++ b/contrib/seg/seg.c @@ -12,7 +12,8 @@ #include <float.h> #include "access/gist.h" -#include "access/skey.h" +#include "access/stratnum.h" +#include "fmgr.h" #include "segdata.h" diff --git a/src/backend/access/gin/ginarrayproc.c b/src/backend/access/gin/ginarrayproc.c index 9c26e77..9220b5f 100644 --- a/src/backend/access/gin/ginarrayproc.c +++ b/src/backend/access/gin/ginarrayproc.c @@ -14,7 +14,7 @@ #include "postgres.h" #include "access/gin.h" -#include "access/skey.h" +#include "access/stratnum.h" #include "utils/array.h" #include "utils/builtins.h" #include "utils/lsyscache.h" diff --git a/src/backend/access/gist/gistproc.c b/src/backend/access/gist/gistproc.c index 9d21e3f..c5aaeab 100644 --- a/src/backend/access/gist/gistproc.c +++ b/src/backend/access/gist/gistproc.c @@ -18,7 +18,7 @@ #include "postgres.h" #include "access/gist.h" -#include "access/skey.h" +#include "access/stratnum.h" #include "utils/geo_decls.h" diff --git a/src/backend/bootstrap/bootparse.y b/src/backend/bootstrap/bootparse.y index 6e563b6..d8d1b06 100644 --- a/src/backend/bootstrap/bootparse.y +++ b/src/backend/bootstrap/bootparse.y @@ -21,7 +21,6 @@ #include "access/attnum.h" #include "access/htup.h" #include "access/itup.h" -#include "access/skey.h" #include "access/tupdesc.h" #include "access/xact.h" #include "bootstrap/bootstrap.h" diff --git a/src/backend/bootstrap/bootscanner.l b/src/backend/bootstrap/bootscanner.l index 72714f4..e60d377 100644 --- a/src/backend/bootstrap/bootscanner.l +++ b/src/backend/bootstrap/bootscanner.l @@ -18,7 +18,6 @@ #include "access/attnum.h" #include "access/htup.h" #include "access/itup.h" -#include "access/skey.h" #include "access/tupdesc.h" #include "bootstrap/bootstrap.h" #include "catalog/pg_am.h" diff --git a/src/backend/optimizer/path/equivclass.c b/src/backend/optimizer/path/equivclass.c index eb65c97..80021d5 100644 --- a/src/backend/optimizer/path/equivclass.c +++ b/src/backend/optimizer/path/equivclass.c @@ -16,7 +16,7 @@ */ #include "postgres.h" -#include "access/skey.h" +#include "access/stratnum.h" #include "catalog/pg_type.h" #include "nodes/makefuncs.h" #include "nodes/nodeFuncs.h" diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c index fdd6bab..26e6e1b 100644 --- a/src/backend/optimizer/path/indxpath.c +++ b/src/backend/optimizer/path/indxpath.c @@ -17,7 +17,7 @@ #include <math.h> -#include "access/skey.h" +#include "access/stratnum.h" #include "access/sysattr.h" #include "catalog/pg_am.h" #include "catalog/pg_collation.h" diff --git a/src/backend/optimizer/path/pathkeys.c b/src/backend/optimizer/path/pathkeys.c index 42183df..8b25222 100644 --- a/src/backend/optimizer/path/pathkeys.c +++ b/src/backend/optimizer/path/pathkeys.c @@ -17,7 +17,7 @@ */ #include "postgres.h" -#include "access/skey.h" +#include "access/stratnum.h" #include "nodes/makefuncs.h" #include "nodes/nodeFuncs.h" #include "nodes/plannodes.h" diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c index c809237..454d9a0 100644 --- a/src/backend/optimizer/plan/createplan.c +++ b/src/backend/optimizer/plan/createplan.c @@ -19,7 +19,7 @@ #include <limits.h> #include <math.h> -#include "access/skey.h" +#include "access/stratnum.h" #include "access/sysattr.h" #include "catalog/pg_class.h" #include "foreign/fdwapi.h" diff --git a/src/backend/utils/adt/jsonb_gin.c b/src/backend/utils/adt/jsonb_gin.c index bc521ed..2591c81 100644 --- a/src/backend/utils/adt/jsonb_gin.c +++ b/src/backend/utils/adt/jsonb_gin.c @@ -15,7 +15,7 @@ #include "access/gin.h" #include "access/hash.h" -#include "access/skey.h" +#include "access/stratnum.h" #include "catalog/pg_collation.h" #include "catalog/pg_type.h" #include "utils/builtins.h" diff --git a/src/backend/utils/adt/network_gist.c b/src/backend/utils/adt/network_gist.c index cd2b8b1..958e1e2 100644 --- a/src/backend/utils/adt/network_gist.c +++ b/src/backend/utils/adt/network_gist.c @@ -48,23 +48,23 @@ #include <sys/socket.h> #include "access/gist.h" -#include "access/skey.h" +#include "access/stratnum.h" #include "utils/inet.h" /* * Operator strategy numbers used in the GiST inet_ops opclass */ -#define INETSTRAT_OVERLAPS 3 -#define INETSTRAT_EQ 18 -#define INETSTRAT_NE 19 -#define INETSTRAT_LT 20 -#define INETSTRAT_LE 21 -#define INETSTRAT_GT 22 -#define INETSTRAT_GE 23 -#define INETSTRAT_SUB 24 -#define INETSTRAT_SUBEQ 25 -#define INETSTRAT_SUP 26 -#define INETSTRAT_SUPEQ 27 +#define INETSTRAT_OVERLAPS RTOverlapStrategyNumber +#define INETSTRAT_EQ RTEqualStrategyNumber +#define INETSTRAT_NE RTNotEqualStrategyNumber +#define INETSTRAT_LT RTLessStrategyNumber +#define INETSTRAT_LE RTLessEqualStrategyNumber +#define INETSTRAT_GT RTGreaterStrategyNumber +#define INETSTRAT_GE RTGreaterEqualStrategyNumber +#define INETSTRAT_SUB RTContainsNotEqualStrategyNumber +#define INETSTRAT_SUBEQ RTSubOrEqualStrategyNumber +#define INETSTRAT_SUP RTContainedByNotEqualStrategyNumber +#define INETSTRAT_SUPEQ RTSuperOrEqualStrategyNumber /* diff --git a/src/backend/utils/adt/rangetypes_gist.c b/src/backend/utils/adt/rangetypes_gist.c index ef84121..ddeb18b 100644 --- a/src/backend/utils/adt/rangetypes_gist.c +++ b/src/backend/utils/adt/rangetypes_gist.c @@ -15,7 +15,7 @@ #include "postgres.h" #include "access/gist.h" -#include "access/skey.h" +#include "access/stratnum.h" #include "utils/builtins.h" #include "utils/datum.h" #include "utils/rangetypes.h" diff --git a/src/backend/utils/adt/rangetypes_spgist.c b/src/backend/utils/adt/rangetypes_spgist.c index d7b2081..9281529 100644 --- a/src/backend/utils/adt/rangetypes_spgist.c +++ b/src/backend/utils/adt/rangetypes_spgist.c @@ -37,7 +37,7 @@ #include "postgres.h" #include "access/spgist.h" -#include "access/skey.h" +#include "access/stratnum.h" #include "catalog/pg_type.h" #include "utils/builtins.h" #include "utils/datum.h" diff --git a/src/backend/utils/adt/tsginidx.c b/src/backend/utils/adt/tsginidx.c index 828175b..da90ca8 100644 --- a/src/backend/utils/adt/tsginidx.c +++ b/src/backend/utils/adt/tsginidx.c @@ -14,7 +14,7 @@ #include "postgres.h" #include "access/gin.h" -#include "access/skey.h" +#include "access/stratnum.h" #include "miscadmin.h" #include "tsearch/ts_type.h" #include "tsearch/ts_utils.h" diff --git a/src/backend/utils/adt/tsquery_gist.c b/src/backend/utils/adt/tsquery_gist.c index d610bbc..232715c 100644 --- a/src/backend/utils/adt/tsquery_gist.c +++ b/src/backend/utils/adt/tsquery_gist.c @@ -14,7 +14,7 @@ #include "postgres.h" -#include "access/skey.h" +#include "access/stratnum.h" #include "access/gist.h" #include "tsearch/ts_utils.h" diff --git a/src/include/access/skey.h b/src/include/access/skey.h index eeee1f4..76c33bc 100644 --- a/src/include/access/skey.h +++ b/src/include/access/skey.h @@ -15,32 +15,11 @@ #define SKEY_H #include "access/attnum.h" +#include "access/stratnum.h" #include "fmgr.h" /* - * Strategy numbers identify the semantics that particular operators have - * with respect to particular operator classes. In some cases a strategy - * subtype (an OID) is used as further information. - */ -typedef uint16 StrategyNumber; - -#define InvalidStrategy ((StrategyNumber) 0) - -/* - * We define the strategy numbers for B-tree indexes here, to avoid having - * to import access/nbtree.h into a lot of places that shouldn't need it. - */ -#define BTLessStrategyNumber 1 -#define BTLessEqualStrategyNumber 2 -#define BTEqualStrategyNumber 3 -#define BTGreaterEqualStrategyNumber 4 -#define BTGreaterStrategyNumber 5 - -#define BTMaxStrategyNumber 5 - - -/* * A ScanKey represents the application of a comparison operator between * a table or index column and a constant. When it's part of an array of * ScanKeys, the comparison conditions are implicitly ANDed. The index diff --git a/src/include/access/stratnum.h b/src/include/access/stratnum.h new file mode 100644 index 0000000..ac0d2e7 --- /dev/null +++ b/src/include/access/stratnum.h @@ -0,0 +1,74 @@ +/*------------------------------------------------------------------------- + * + * stratnum.h + * POSTGRES strategy number definitions. + * + * + * Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/stratnum.h + * + *------------------------------------------------------------------------- + */ +#ifndef STRATNUM_H +#define STRATNUM_H + +/* + * Strategy numbers identify the semantics that particular operators have + * with respect to particular operator classes. In some cases a strategy + * subtype (an OID) is used as further information. + */ +typedef uint16 StrategyNumber; + +#define InvalidStrategy ((StrategyNumber) 0) + +/* + * Strategy numbers for B-tree indexes. + */ +#define BTLessStrategyNumber 1 +#define BTLessEqualStrategyNumber 2 +#define BTEqualStrategyNumber 3 +#define BTGreaterEqualStrategyNumber 4 +#define BTGreaterStrategyNumber 5 + +#define BTMaxStrategyNumber 5 + + +/* + * Strategy numbers common to (some) GiST, SP-GiST, GIN and BRIN opclasses. + * The first few of these come from the R-Tree indexing method (hence the + * names); the others have been added over time as they have been needed. + */ +#define RTLeftStrategyNumber 1 /* for << */ +#define RTOverLeftStrategyNumber 2 /* for &< */ +#define RTOverlapStrategyNumber 3 /* for && */ +#define RTOverRightStrategyNumber 4 /* for &> */ +#define RTRightStrategyNumber 5 /* for >> */ +#define RTSameStrategyNumber 6 /* for ~= */ +#define RTContainsStrategyNumber 7 /* for @> */ +#define RTContainedByStrategyNumber 8 /* for <@ */ +#define RTOverBelowStrategyNumber 9 /* for &<| */ +#define RTBelowStrategyNumber 10 /* for <<| */ +#define RTAboveStrategyNumber 11 /* for |>> */ +#define RTOverAboveStrategyNumber 12 /* for |&> */ +#define RTOldContainsStrategyNumber 13 /* for old spelling of @> */ +#define RTOldContainedByStrategyNumber 14 /* for old spelling of <@ */ +#define RTKNNSearchStrategyNumber 15 /* for <-> (distance) */ +#define RTContainsElemStrategyNumber 16 /* for range types @> elem */ +#define RTAdjacentStrategyNumber 17 /* for -|- */ +#define RTEqualStrategyNumber 18 /* for = */ +#define RTNotEqualStrategyNumber 19 /* for != */ +#define RTLessStrategyNumber 20 /* for < */ +#define RTLessEqualStrategyNumber 21 /* for <= */ +#define RTGreaterStrategyNumber 22 /* for > */ +#define RTGreaterEqualStrategyNumber 23 /* for >= */ +#define RTContainsNotEqualStrategyNumber 24 /* for inet >> */ +#define RTSubOrEqualStrategyNumber 25 /* for inet <<= */ +#define RTContainedByNotEqualStrategyNumber 26 /* for inet << */ +#define RTSuperOrEqualStrategyNumber 27 /* for inet >>= */ + +#define RTMaxStrategyNumber 27 + + +#endif /* STRATNUM_H */ diff --git a/src/include/utils/rangetypes.h b/src/include/utils/rangetypes.h index 00a3efe..487b2b3 100644 --- a/src/include/utils/rangetypes.h +++ b/src/include/utils/rangetypes.h @@ -77,16 +77,16 @@ typedef struct /* Operator strategy numbers used in the GiST and SP-GiST range opclasses */ /* Numbers are chosen to match up operator names with existing usages */ -#define RANGESTRAT_BEFORE 1 -#define RANGESTRAT_OVERLEFT 2 -#define RANGESTRAT_OVERLAPS 3 -#define RANGESTRAT_OVERRIGHT 4 -#define RANGESTRAT_AFTER 5 -#define RANGESTRAT_ADJACENT 6 -#define RANGESTRAT_CONTAINS 7 -#define RANGESTRAT_CONTAINED_BY 8 -#define RANGESTRAT_CONTAINS_ELEM 16 -#define RANGESTRAT_EQ 18 +#define RANGESTRAT_BEFORE RTLeftStrategyNumber +#define RANGESTRAT_OVERLEFT RTOverLeftStrategyNumber +#define RANGESTRAT_OVERLAPS RTOverlapStrategyNumber +#define RANGESTRAT_OVERRIGHT RTOverRightStrategyNumber +#define RANGESTRAT_AFTER RTRightStrategyNumber +#define RANGESTRAT_ADJACENT RTSameStrategyNumber +#define RANGESTRAT_CONTAINS RTContainsStrategyNumber +#define RANGESTRAT_CONTAINED_BY RTContainedByStrategyNumber +#define RANGESTRAT_CONTAINS_ELEM RTContainsElemStrategyNumber +#define RANGESTRAT_EQ RTEqualStrategyNumber /* * prototypes for functions defined in rangetypes.c
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers