Allow non-btree speculative insertion indexes
authorPeter Eisentraut <peter@eisentraut.org>
Fri, 7 Feb 2025 10:17:25 +0000 (11:17 +0100)
committerPeter Eisentraut <peter@eisentraut.org>
Fri, 7 Feb 2025 10:23:34 +0000 (11:23 +0100)
Previously, only btrees were supported as the arbiter index for
speculative insertion because there was no way to get the equality
strategy number for other index methods.  We have this now (commit
c09e5a6a016), so we can support this.

At the moment, only btree supports unique indexes, so this does not
change anything in practice, but it would allow another index method
that has amcanunique to be supported.

Co-authored-by: Mark Dilger <mark.dilger@enterprisedb.com>
Discussion: https://www.postgresql.org/message-id/flat/E72EAA49-354D-4C2E-8EB9-255197F55330@enterprisedb.com

src/backend/catalog/index.c

index 7377912b41e0b862d4227fc5307ecfae70063ceb..cdabf78024490ee2400e7f0f8c16dabad943fb55 100644 (file)
@@ -2677,9 +2677,6 @@ BuildSpeculativeIndexInfo(Relation index, IndexInfo *ii)
     */
    Assert(ii->ii_Unique);
 
-   if (index->rd_rel->relam != BTREE_AM_OID)
-       elog(ERROR, "unexpected non-btree speculative unique index");
-
    ii->ii_UniqueOps = (Oid *) palloc(sizeof(Oid) * indnkeyatts);
    ii->ii_UniqueProcs = (Oid *) palloc(sizeof(Oid) * indnkeyatts);
    ii->ii_UniqueStrats = (uint16 *) palloc(sizeof(uint16) * indnkeyatts);
@@ -2691,7 +2688,12 @@ BuildSpeculativeIndexInfo(Relation index, IndexInfo *ii)
    /* We need the func OIDs and strategy numbers too */
    for (i = 0; i < indnkeyatts; i++)
    {
-       ii->ii_UniqueStrats[i] = BTEqualStrategyNumber;
+       ii->ii_UniqueStrats[i] =
+           IndexAmTranslateCompareType(COMPARE_EQ,
+                                       index->rd_rel->relam,
+                                       index->rd_opfamily[i],
+                                       index->rd_opcintype[i],
+                                       false);
        ii->ii_UniqueOps[i] =
            get_opfamily_member(index->rd_opfamily[i],
                                index->rd_opcintype[i],