Skip to content

Commit 9d6db8b

Browse files
committed
Allow non-btree unique indexes for matviews
We were rejecting non-btree indexes in some cases owing to the inability to determine the equality operators for other index AMs; that problem no longer exists, because we can look up the equality operator using COMPARE_EQ. Stop rejecting these indexes, but instead rely on all unique indexes having equality operators. Unique indexes must have equality operators. Author: Mark Dilger <mark.dilger@enterprisedb.com> Discussion: https://www.postgresql.org/message-id/flat/E72EAA49-354D-4C2E-8EB9-255197F55330@enterprisedb.com
1 parent f278e1f commit 9d6db8b

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

src/backend/commands/matview.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -774,16 +774,14 @@ refresh_by_match_merge(Oid matviewOid, Oid tempOid, Oid relowner,
774774
if (!HeapTupleIsValid(cla_ht))
775775
elog(ERROR, "cache lookup failed for opclass %u", opclass);
776776
cla_tup = (Form_pg_opclass) GETSTRUCT(cla_ht);
777-
Assert(cla_tup->opcmethod == BTREE_AM_OID);
778777
opfamily = cla_tup->opcfamily;
779778
opcintype = cla_tup->opcintype;
780779
ReleaseSysCache(cla_ht);
781780

782-
op = get_opfamily_member(opfamily, opcintype, opcintype,
783-
BTEqualStrategyNumber);
781+
op = get_opfamily_member_for_cmptype(opfamily, opcintype, opcintype, COMPARE_EQ);
784782
if (!OidIsValid(op))
785-
elog(ERROR, "missing operator %d(%u,%u) in opfamily %u",
786-
BTEqualStrategyNumber, opcintype, opcintype, opfamily);
783+
elog(ERROR, "missing equality operator for (%u,%u) in opfamily %u",
784+
opcintype, opcintype, opfamily);
787785

788786
/*
789787
* If we find the same column with the same equality semantics
@@ -920,15 +918,10 @@ is_usable_unique_index(Relation indexRel)
920918

921919
/*
922920
* Must be unique, valid, immediate, non-partial, and be defined over
923-
* plain user columns (not expressions). We also require it to be a
924-
* btree. Even if we had any other unique index kinds, we'd not know how
925-
* to identify the corresponding equality operator, nor could we be sure
926-
* that the planner could implement the required FULL JOIN with non-btree
927-
* operators.
921+
* plain user columns (not expressions).
928922
*/
929923
if (indexStruct->indisunique &&
930924
indexStruct->indimmediate &&
931-
indexRel->rd_rel->relam == BTREE_AM_OID &&
932925
indexStruct->indisvalid &&
933926
RelationGetIndexPredicate(indexRel) == NIL &&
934927
indexStruct->indnatts > 0)

0 commit comments

Comments
 (0)