Bitmapset *inferAttrs = NULL;
List *inferElems = NIL;
- /* Result */
- List *candidates = NIL;
+ /* Results */
+ List *results = NIL;
/*
* Quickly return NIL for ON CONFLICT DO NOTHING without an inference
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("ON CONFLICT DO UPDATE not supported with exclusion constraints")));
- candidates = lappend_oid(candidates, idxForm->indexrelid);
+ results = lappend_oid(results, idxForm->indexrelid);
list_free(indexList);
index_close(idxRel, NoLock);
heap_close(relation, NoLock);
- return candidates;
+ return results;
}
else if (indexOidFromConstraint != InvalidOid)
{
* index definition.
*/
if (elem->infercollid != InvalidOid ||
- elem->inferopfamily != InvalidOid ||
+ elem->inferopclass != InvalidOid ||
list_member(idxExprs, elem->expr))
continue;
if (!predicate_implied_by(predExprs, whereExplicit))
goto next;
- candidates = lappend_oid(candidates, idxForm->indexrelid);
+ results = lappend_oid(results, idxForm->indexrelid);
next:
index_close(idxRel, NoLock);
}
list_free(indexList);
heap_close(relation, NoLock);
- if (candidates == NIL)
+ if (results == NIL)
ereport(ERROR,
(errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
errmsg("there is no unique or exclusion constraint matching the ON CONFLICT specification")));
- return candidates;
+ return results;
}
/*
Bitmapset *inferAttrs, List *idxExprs)
{
AttrNumber natt;
+ Oid inferopfamily = InvalidOid; /* OID of att opfamily */
+ Oid inferopcinputtype = InvalidOid; /* OID of att opfamily */
/*
* If inference specification element lacks collation/opclass, then no
* need to check for exact match.
*/
- if (elem->infercollid == InvalidOid && elem->inferopfamily == InvalidOid)
+ if (elem->infercollid == InvalidOid && elem->inferopclass == InvalidOid)
return true;
+ /*
+ * Lookup opfamily and input type, for matching indexes
+ */
+ if (elem->inferopclass)
+ {
+ inferopfamily = get_opclass_family(elem->inferopclass);
+ inferopcinputtype = get_opclass_input_type(elem->inferopclass);
+ }
+
for (natt = 1; natt <= idxRel->rd_att->natts; natt++)
{
Oid opfamily = idxRel->rd_opfamily[natt - 1];
Oid opcinputtype = idxRel->rd_opcintype[natt - 1];
Oid collation = idxRel->rd_indcollation[natt - 1];
- if (elem->inferopfamily != InvalidOid &&
- (elem->inferopfamily != opfamily ||
- elem->inferopcinputtype != opcinputtype))
+ if (elem->inferopclass != InvalidOid &&
+ (inferopfamily != opfamily || inferopcinputtype != opcinputtype))
{
/* Attribute needed to match opclass, but didn't */
continue;
exprLocation(pInfer->expr));
if (!ielem->opclass)
- {
- pInfer->inferopfamily = InvalidOid;
- pInfer->inferopcinputtype = InvalidOid;
- }
+ pInfer->inferopclass = InvalidOid;
else
- {
- Oid opclass = get_opclass_oid(BTREE_AM_OID, ielem->opclass,
- false);
-
- pInfer->inferopfamily = get_opclass_family(opclass);
- pInfer->inferopcinputtype = get_opclass_input_type(opclass);
- }
+ pInfer->inferopclass = get_opclass_oid(BTREE_AM_OID,
+ ielem->opclass, false);
result = lappend(result, pInfer);
}