Rename amcancrosscompare
authorPeter Eisentraut <peter@eisentraut.org>
Fri, 7 Mar 2025 09:51:53 +0000 (10:51 +0100)
committerPeter Eisentraut <peter@eisentraut.org>
Fri, 7 Mar 2025 10:46:33 +0000 (11:46 +0100)
After more discussion about commit ce62f2f2a0a, rename the index AM
property amcancrosscompare to two separate properties
amconsistentequality and amconsistentordering.  Also improve the
documentation and update some comments that were previously missed.

Reported-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/E1tngY6-0000UL-2n%40gemulon.postgresql.org

12 files changed:
contrib/bloom/blutils.c
doc/src/sgml/indexam.sgml
src/backend/access/brin/brin.c
src/backend/access/gin/ginutil.c
src/backend/access/gist/gist.c
src/backend/access/hash/hash.c
src/backend/access/nbtree/nbtree.c
src/backend/access/spgist/spgutils.c
src/backend/optimizer/plan/analyzejoins.c
src/backend/utils/cache/lsyscache.c
src/include/access/amapi.h
src/test/modules/dummy_index_am/dummy_index_am.c

index c901e9427204515862834de06997bfbfb8b8f714..2c0e71eedc654e4829db62909e4249f60cebbae7 100644 (file)
@@ -110,7 +110,8 @@ blhandler(PG_FUNCTION_ARGS)
    amroutine->amcanorder = false;
    amroutine->amcanorderbyop = false;
    amroutine->amcanhash = false;
-   amroutine->amcancrosscompare = false;
+   amroutine->amconsistentequality = false;
+   amroutine->amconsistentordering = false;
    amroutine->amcanbackward = false;
    amroutine->amcanunique = false;
    amroutine->amcanmulticol = true;
index c50ba60e21c1c211dae55d5a9ffe356cb508da47..768b77aa0d2ba1cb046c61672041999b9174872a 100644 (file)
@@ -105,8 +105,10 @@ typedef struct IndexAmRoutine
     bool        amcanorderbyop;
     /* does AM support hashing using API consistent with the hash AM? */
     bool        amcanhash;
-    /* does AM support cross-type comparisons? */
-    bool        amcancrosscompare;
+    /* do operators within an opfamily have consistent equality semantics? */
+    bool        amconsistentequality;
+    /* do operators within an opfamily have consistent ordering semantics? */
+    bool        amconsistentordering;
     /* does AM support backward scanning? */
     bool        amcanbackward;
     /* does AM support UNIQUE indexes? */
index 75a65ec9c75a949d8a7fa90304fdabe069334587..b01009c5d85ed7dbefc3f8551e690e8f59fc9a53 100644 (file)
@@ -257,7 +257,8 @@ brinhandler(PG_FUNCTION_ARGS)
    amroutine->amcanorder = false;
    amroutine->amcanorderbyop = false;
    amroutine->amcanhash = false;
-   amroutine->amcancrosscompare = false;
+   amroutine->amconsistentequality = false;
+   amroutine->amconsistentordering = false;
    amroutine->amcanbackward = false;
    amroutine->amcanunique = false;
    amroutine->amcanmulticol = true;
index 0b67108bc3431fb9c9d51c66184324c4411b038d..78f7b7a2495cf8ab9429ef4b6934080ce74c09dd 100644 (file)
@@ -45,7 +45,8 @@ ginhandler(PG_FUNCTION_ARGS)
    amroutine->amcanorder = false;
    amroutine->amcanorderbyop = false;
    amroutine->amcanhash = false;
-   amroutine->amcancrosscompare = false;
+   amroutine->amconsistentequality = false;
+   amroutine->amconsistentordering = false;
    amroutine->amcanbackward = false;
    amroutine->amcanunique = false;
    amroutine->amcanmulticol = true;
index 5482925a0f39db9b5e3ec15e36e47a01eb0b9c90..1840f04bfbf533be43424df75be0d15e2fe1417f 100644 (file)
@@ -66,7 +66,8 @@ gisthandler(PG_FUNCTION_ARGS)
    amroutine->amcanorder = false;
    amroutine->amcanorderbyop = true;
    amroutine->amcanhash = false;
-   amroutine->amcancrosscompare = false;
+   amroutine->amconsistentequality = false;
+   amroutine->amconsistentordering = false;
    amroutine->amcanbackward = false;
    amroutine->amcanunique = false;
    amroutine->amcanmulticol = true;
index 4c83b09eddea7cf05c1f94ddf6fb1f15e76f1796..874558849a292e9d9b07de6d2a0c33e2352ec3b2 100644 (file)
@@ -65,7 +65,8 @@ hashhandler(PG_FUNCTION_ARGS)
    amroutine->amcanorder = false;
    amroutine->amcanorderbyop = false;
    amroutine->amcanhash = true;
-   amroutine->amcancrosscompare = true;
+   amroutine->amconsistentequality = true;
+   amroutine->amconsistentequality = false;
    amroutine->amcanbackward = true;
    amroutine->amcanunique = false;
    amroutine->amcanmulticol = false;
index 45ea6afba1db57e845c8de561cb24b25f7b10798..136e9408ae5fd024167b0546d66064b5e32e21d8 100644 (file)
@@ -108,7 +108,8 @@ bthandler(PG_FUNCTION_ARGS)
    amroutine->amcanorder = true;
    amroutine->amcanorderbyop = false;
    amroutine->amcanhash = false;
-   amroutine->amcancrosscompare = true;
+   amroutine->amconsistentequality = true;
+   amroutine->amconsistentordering = true;
    amroutine->amcanbackward = true;
    amroutine->amcanunique = true;
    amroutine->amcanmulticol = true;
index 7e56b1e6b95de95d04c36f8737db98dc10a398a7..95fea74e296f8500c54404acd1349f525039d7e7 100644 (file)
@@ -51,7 +51,8 @@ spghandler(PG_FUNCTION_ARGS)
    amroutine->amcanorder = false;
    amroutine->amcanorderbyop = true;
    amroutine->amcanhash = false;
-   amroutine->amcancrosscompare = false;
+   amroutine->amconsistentequality = false;
+   amroutine->amconsistentordering = false;
    amroutine->amcanbackward = false;
    amroutine->amcanunique = false;
    amroutine->amcanmulticol = false;
index b1e173c63bcb34dac5c979d95e8c38fab217e801..8a8d4a2af33323df2d7efd2ca98c3eec9c84a51f 100644 (file)
@@ -1083,9 +1083,10 @@ query_supports_distinctness(Query *query)
  * the values are distinct.  (Note: the opids entries could be cross-type
  * operators, and thus not exactly the equality operators that the subquery
  * would use itself.  We use equality_ops_are_compatible() to check
- * compatibility.  That looks at btree or hash opfamily membership, and so
- * should give trustworthy answers for all operators that we might need
- * to deal with here.)
+ * compatibility.  That looks at opfamily membership for index AMs that have
+ * declared that they support consistent equality semantics within an
+ * opfamily, and so should give trustworthy answers for all operators that we
+ * might need to deal with here.)
  */
 bool
 query_is_distinct_for(Query *query, List *colnos, List *opids)
index 7bd476f3de70c10395574e6716f2881e117ad37f..97ad36a031b05b35070c7fc52490a4518caae23f 100644 (file)
@@ -690,10 +690,11 @@ get_op_btree_interpretation(Oid opno)
  *     semantics.
  *
  * This is trivially true if they are the same operator.  Otherwise,
- * we look to see if they can be found in the same btree or hash opfamily.
- * Either finding allows us to assume that they have compatible notions
- * of equality.  (The reason we need to do these pushups is that one might
- * be a cross-type operator; for instance int24eq vs int4eq.)
+ * Otherwise, we look to see if they both belong to an opfamily that
+ * guarantees compatible semantics for equality.  Either finding allows us to
+ * assume that they have compatible notions of equality.  (The reason we need
+ * to do these pushups is that one might be a cross-type operator; for
+ * instance int24eq vs int4eq.)
  */
 bool
 equality_ops_are_compatible(Oid opno1, Oid opno2)
@@ -718,7 +719,7 @@ equality_ops_are_compatible(Oid opno1, Oid opno2)
        Form_pg_amop op_form = (Form_pg_amop) GETSTRUCT(op_tuple);
        IndexAmRoutine *amroutine = GetIndexAmRoutineByAmId(op_form->amopmethod, false);
 
-       if (amroutine->amcancrosscompare)
+       if (amroutine->amconsistentequality)
        {
            if (op_in_opfamily(opno2, op_form->amopfamily))
            {
@@ -738,12 +739,13 @@ equality_ops_are_compatible(Oid opno1, Oid opno2)
  *     Return true if the two given comparison operators have compatible
  *     semantics.
  *
- * This is trivially true if they are the same operator.  Otherwise,
- * we look to see if they can be found in the same btree opfamily.
- * For example, '<' and '>=' ops match if they belong to the same family.
+ * This is trivially true if they are the same operator.  Otherwise, we look
+ * to see if they both belong to an opfamily that guarantees compatible
+ * semantics for ordering.  (For example, for btree, '<' and '>=' ops match if
+ * they belong to the same family.)
  *
- * (This is identical to equality_ops_are_compatible(), except that we
- * don't bother to examine hash opclasses.)
+ * (This is identical to equality_ops_are_compatible(), except that we check
+ * amcanorder plus amconsistentordering instead of amconsistentequality.)
  */
 bool
 comparison_ops_are_compatible(Oid opno1, Oid opno2)
@@ -768,7 +770,7 @@ comparison_ops_are_compatible(Oid opno1, Oid opno2)
        Form_pg_amop op_form = (Form_pg_amop) GETSTRUCT(op_tuple);
        IndexAmRoutine *amroutine = GetIndexAmRoutineByAmId(op_form->amopmethod, false);
 
-       if (amroutine->amcanorder && amroutine->amcancrosscompare)
+       if (amroutine->amcanorder && amroutine->amconsistentordering)
        {
            if (op_in_opfamily(opno2, op_form->amopfamily))
            {
index bf729a1e4ae845a01175f013fff39d76947897f0..c4a0737731f2d1fc4b2a9442029655fab8edca1e 100644 (file)
@@ -245,8 +245,10 @@ typedef struct IndexAmRoutine
    bool        amcanorderbyop;
    /* does AM support hashing using API consistent with the hash AM? */
    bool        amcanhash;
-   /* does AM support cross-type comparisons? */
-   bool        amcancrosscompare;
+   /* do operators within an opfamily have consistent equality semantics? */
+   bool        amconsistentequality;
+   /* do operators within an opfamily have consistent ordering semantics? */
+   bool        amconsistentordering;
    /* does AM support backward scanning? */
    bool        amcanbackward;
    /* does AM support UNIQUE indexes? */
index c83954ad11da0abd4cf2ce2dcef6e2ae1d2b559f..94ef639b6fcdb6573d3ae373545496b5d4a3863f 100644 (file)
@@ -283,7 +283,8 @@ dihandler(PG_FUNCTION_ARGS)
    amroutine->amcanorder = false;
    amroutine->amcanorderbyop = false;
    amroutine->amcanhash = false;
-   amroutine->amcancrosscompare = false;
+   amroutine->amconsistentequality = false;
+   amroutine->amconsistentordering = false;
    amroutine->amcanbackward = false;
    amroutine->amcanunique = false;
    amroutine->amcanmulticol = false;