131 EState *estate,
bool newIndex,
137 Datum *existing_values,
bool *existing_isnull,
198 foreach(l, indexoidlist)
216 relationDescs[
i] = indexDesc;
217 indexInfoArray[
i] = ii;
240 for (
i = 0;
i < numIndices;
i++)
242 if (indexDescs[
i] == NULL)
290 List *arbiterIndexes)
328 for (
i = 0;
i < numIndices;
i++)
330 Relation indexRelation = relationDescs[
i];
335 bool satisfiesConstraint;
337 if (indexRelation == NULL)
340 indexInfo = indexInfoArray[
i];
356 if (predicate == NULL)
378 applyNoDupErr = noDupErr &&
379 (arbiterIndexes ==
NIL ||
381 indexRelation->
rd_index->indexrelid));
396 if (!indexRelation->
rd_index->indisunique)
398 else if (applyNoDupErr)
400 else if (indexRelation->
rd_index->indimmediate)
415 satisfiesConstraint =
449 else if (!indexRelation->
rd_index->indimmediate)
460 satisfiesConstraint =
462 indexRelation, indexInfo,
465 waitMode, violationOK, NULL);
470 !satisfiesConstraint)
479 if (indexRelation->
rd_index->indimmediate && specConflict)
480 *specConflict =
true;
507 List *arbiterIndexes)
518 bool checkedIndex =
false;
544 for (
i = 0;
i < numIndices;
i++)
546 Relation indexRelation = relationDescs[
i];
548 bool satisfiesConstraint;
550 if (indexRelation == NULL)
553 indexInfo = indexInfoArray[
i];
563 if (arbiterIndexes !=
NIL &&
565 indexRelation->
rd_index->indexrelid))
568 if (!indexRelation->
rd_index->indimmediate)
570 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
571 errmsg(
"ON CONFLICT does not support deferrable unique constraints/exclusion constraints as arbiters"),
587 if (predicate == NULL)
608 satisfiesConstraint =
610 indexInfo, &invalidItemPtr,
611 values, isnull, estate,
false,
614 if (!satisfiesConstraint)
618 if (arbiterIndexes !=
NIL && !checkedIndex)
619 elog(
ERROR,
"unexpected failure to find arbiter index");
671 EState *estate,
bool newIndex,
678 Oid *index_collations =
index->rd_indcollation;
705 for (
i = 0;
i < indnkeyatts;
i++)
717 for (
i = 0;
i < indnkeyatts;
i++)
750 index_rescan(index_scan, scankeys, indnkeyatts, NULL, 0);
759 char *error_existing;
768 elog(
ERROR,
"found self tuple multiple times in index \"%s\"",
779 existing_values, existing_isnull);
804 DirtySnapshot.
xmin : DirtySnapshot.
xmax;
820 &existing_slot->
tts_tid, reason_wait);
832 *conflictTid = existing_slot->
tts_tid;
841 (
errcode(ERRCODE_EXCLUSION_VIOLATION),
842 errmsg(
"could not create exclusion constraint \"%s\"",
844 error_new && error_existing ?
845 errdetail(
"Key %s conflicts with key %s.",
846 error_new, error_existing) :
852 (
errcode(ERRCODE_EXCLUSION_VIOLATION),
853 errmsg(
"conflicting key value violates exclusion constraint \"%s\"",
855 error_new && error_existing ?
856 errdetail(
"Key %s conflicts with existing key %s.",
857 error_new, error_existing) :
858 errdetail(
"Key conflicts with existing key."),
891 EState *estate,
bool newIndex)
905 Datum *existing_values,
bool *existing_isnull,
911 for (
i = 0;
i < indnkeyatts;
i++)
914 if (existing_isnull[
i])
918 index->rd_indcollation[
i],
941 bool hasexpression =
false;
974 hasexpression =
true;
1007 if (!extraUpdatedCols)
1008 allUpdatedCols = updatedCols;
1010 allUpdatedCols =
bms_union(updatedCols, extraUpdatedCols);
1024 if (extraUpdatedCols)
1070 (
void *) allUpdatedCols);
void bms_free(Bitmapset *a)
bool bms_is_member(int x, const Bitmapset *a)
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
static Datum values[MAXATTR]
int errdetail(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
ExprState * ExecPrepareQual(List *qual, EState *estate)
static bool index_unchanged_by_update(ResultRelInfo *resultRelInfo, EState *estate, IndexInfo *indexInfo, Relation indexRelation)
bool ExecCheckIndexConstraints(ResultRelInfo *resultRelInfo, TupleTableSlot *slot, EState *estate, ItemPointer conflictTid, List *arbiterIndexes)
void check_exclusion_constraint(Relation heap, Relation index, IndexInfo *indexInfo, ItemPointer tupleid, Datum *values, bool *isnull, EState *estate, bool newIndex)
static bool index_recheck_constraint(Relation index, Oid *constr_procs, Datum *existing_values, bool *existing_isnull, Datum *new_values)
List * ExecInsertIndexTuples(ResultRelInfo *resultRelInfo, TupleTableSlot *slot, EState *estate, bool update, bool noDupErr, bool *specConflict, List *arbiterIndexes)
void ExecCloseIndices(ResultRelInfo *resultRelInfo)
void ExecOpenIndices(ResultRelInfo *resultRelInfo, bool speculative)
@ CEOUC_LIVELOCK_PREVENTING_WAIT
static bool index_expression_changed_walker(Node *node, Bitmapset *allUpdatedCols)
static bool check_exclusion_or_unique_constraint(Relation heap, Relation index, IndexInfo *indexInfo, ItemPointer tupleid, Datum *values, bool *isnull, EState *estate, bool newIndex, CEOUC_WAIT_MODE waitMode, bool errorOK, ItemPointer conflictTid)
void ExecDropSingleTupleTableSlot(TupleTableSlot *slot)
Bitmapset * ExecGetUpdatedCols(ResultRelInfo *relinfo, EState *estate)
Bitmapset * ExecGetExtraUpdatedCols(ResultRelInfo *relinfo, EState *estate)
#define GetPerTupleExprContext(estate)
static bool ExecQual(ExprState *state, ExprContext *econtext)
Datum OidFunctionCall2Coll(Oid functionId, Oid collation, Datum arg1, Datum arg2)
char * BuildIndexValueDescription(Relation indexRelation, Datum *values, bool *isnull)
void BuildSpeculativeIndexInfo(Relation index, IndexInfo *ii)
void FormIndexDatum(IndexInfo *indexInfo, TupleTableSlot *slot, EState *estate, Datum *values, bool *isnull)
IndexInfo * BuildIndexInfo(Relation index)
bool index_getnext_slot(IndexScanDesc scan, ScanDirection direction, TupleTableSlot *slot)
bool index_insert(Relation indexRelation, Datum *values, bool *isnull, ItemPointer heap_t_ctid, Relation heapRelation, IndexUniqueCheck checkUnique, bool indexUnchanged, IndexInfo *indexInfo)
void index_close(Relation relation, LOCKMODE lockmode)
IndexScanDesc index_beginscan(Relation heapRelation, Relation indexRelation, Snapshot snapshot, int nkeys, int norderbys)
void index_endscan(IndexScanDesc scan)
Relation index_open(Oid relationId, LOCKMODE lockmode)
void index_rescan(IndexScanDesc scan, ScanKey keys, int nkeys, ScanKey orderbys, int norderbys)
bool ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2)
#define ItemPointerIsValid(pointer)
#define ItemPointerSetInvalid(pointer)
Assert(fmt[strlen(fmt) - 1] !='\n')
List * lappend_oid(List *list, Oid datum)
void list_free(List *list)
bool list_member_oid(const List *list, Oid datum)
void XactLockTableWait(TransactionId xid, Relation rel, ItemPointer ctid, XLTW_Oper oper)
void SpeculativeInsertionWait(TransactionId xid, uint32 token)
@ XLTW_RecheckExclusionConstr
bool expression_tree_walker(Node *node, bool(*walker)(), void *context)
#define IsA(nodeptr, _type_)
static int list_length(const List *l)
#define RelationGetForm(relation)
#define RelationGetRelid(relation)
#define RelationGetRelationName(relation)
#define IndexRelationGetNumberOfKeyAttributes(relation)
List * RelationGetIndexList(Relation relation)
int errtableconstraint(Relation rel, const char *conname)
List * RelationGetIndexExpressions(Relation relation)
void ScanKeyEntryInitialize(ScanKey entry, int flags, AttrNumber attributeNumber, StrategyNumber strategy, Oid subtype, Oid collation, RegProcedure procedure, Datum argument)
#define InitDirtySnapshot(snapshotdata)
TupleTableSlot * ecxt_scantuple
uint16 * ii_ExclusionStrats
ExprState * ii_PredicateState
AttrNumber ii_IndexAttrNumbers[INDEX_MAX_KEYS]
RelationPtr ri_IndexRelationDescs
IndexInfo ** ri_IndexRelationInfo
#define FirstLowInvalidHeapAttributeNumber
TupleTableSlot * table_slot_create(Relation relation, List **reglist)
bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
#define TransactionIdIsValid(xid)
TransactionId GetCurrentTransactionId(void)