131 EState *estate,
bool newIndex,
137 const Datum *existing_values,
const bool *existing_isnull,
138 const Datum *new_values);
198 foreach(l, indexoidlist)
216 relationDescs[
i] = indexDesc;
217 indexInfoArray[
i] = ii;
242 for (
i = 0;
i < numIndices;
i++)
244 if (indexDescs[
i] == NULL)
304 List *arbiterIndexes,
305 bool onlySummarizing)
343 for (
i = 0;
i < numIndices;
i++)
345 Relation indexRelation = relationDescs[
i];
350 bool satisfiesConstraint;
352 if (indexRelation == NULL)
355 indexInfo = indexInfoArray[
i];
378 if (predicate == NULL)
400 applyNoDupErr = noDupErr &&
401 (arbiterIndexes ==
NIL ||
403 indexRelation->
rd_index->indexrelid));
418 if (!indexRelation->
rd_index->indisunique)
420 else if (applyNoDupErr)
422 else if (indexRelation->
rd_index->indimmediate)
437 satisfiesConstraint =
471 else if (!indexRelation->
rd_index->indimmediate)
482 satisfiesConstraint =
484 indexRelation, indexInfo,
487 waitMode, violationOK, NULL);
492 !satisfiesConstraint)
501 if (indexRelation->
rd_index->indimmediate && specConflict)
502 *specConflict =
true;
529 List *arbiterIndexes)
540 bool checkedIndex =
false;
566 for (
i = 0;
i < numIndices;
i++)
568 Relation indexRelation = relationDescs[
i];
570 bool satisfiesConstraint;
572 if (indexRelation == NULL)
575 indexInfo = indexInfoArray[
i];
585 if (arbiterIndexes !=
NIL &&
587 indexRelation->
rd_index->indexrelid))
590 if (!indexRelation->
rd_index->indimmediate)
592 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
593 errmsg(
"ON CONFLICT does not support deferrable unique constraints/exclusion constraints as arbiters"),
609 if (predicate == NULL)
630 satisfiesConstraint =
632 indexInfo, &invalidItemPtr,
633 values, isnull, estate,
false,
636 if (!satisfiesConstraint)
640 if (arbiterIndexes !=
NIL && !checkedIndex)
641 elog(
ERROR,
"unexpected failure to find arbiter index");
693 EState *estate,
bool newIndex,
700 Oid *index_collations =
index->rd_indcollation;
732 for (
i = 0;
i < indnkeyatts;
i++)
745 for (
i = 0;
i < indnkeyatts;
i++)
778 index_rescan(index_scan, scankeys, indnkeyatts, NULL, 0);
787 char *error_existing;
796 elog(
ERROR,
"found self tuple multiple times in index \"%s\"",
807 existing_values, existing_isnull);
832 DirtySnapshot.
xmin : DirtySnapshot.
xmax;
848 &existing_slot->
tts_tid, reason_wait);
860 *conflictTid = existing_slot->
tts_tid;
869 (
errcode(ERRCODE_EXCLUSION_VIOLATION),
870 errmsg(
"could not create exclusion constraint \"%s\"",
872 error_new && error_existing ?
873 errdetail(
"Key %s conflicts with key %s.",
874 error_new, error_existing) :
880 (
errcode(ERRCODE_EXCLUSION_VIOLATION),
881 errmsg(
"conflicting key value violates exclusion constraint \"%s\"",
883 error_new && error_existing ?
884 errdetail(
"Key %s conflicts with existing key %s.",
885 error_new, error_existing) :
886 errdetail(
"Key conflicts with existing key."),
919 EState *estate,
bool newIndex)
933 const Datum *existing_values,
const bool *existing_isnull,
934 const Datum *new_values)
939 for (
i = 0;
i < indnkeyatts;
i++)
942 if (existing_isnull[
i])
946 index->rd_indcollation[
i],
969 bool hasexpression =
false;
1002 hasexpression =
true;
1035 if (!extraUpdatedCols)
1036 allUpdatedCols = updatedCols;
1038 allUpdatedCols =
bms_union(updatedCols, extraUpdatedCols);
1052 if (extraUpdatedCols)
1098 (
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)
static bool check_exclusion_or_unique_constraint(Relation heap, Relation index, IndexInfo *indexInfo, ItemPointer tupleid, const Datum *values, const bool *isnull, EState *estate, bool newIndex, CEOUC_WAIT_MODE waitMode, bool violationOK, ItemPointer conflictTid)
void ExecCloseIndices(ResultRelInfo *resultRelInfo)
List * ExecInsertIndexTuples(ResultRelInfo *resultRelInfo, TupleTableSlot *slot, EState *estate, bool update, bool noDupErr, bool *specConflict, List *arbiterIndexes, bool onlySummarizing)
static bool index_recheck_constraint(Relation index, const Oid *constr_procs, const Datum *existing_values, const bool *existing_isnull, const Datum *new_values)
void ExecOpenIndices(ResultRelInfo *resultRelInfo, bool speculative)
@ CEOUC_LIVELOCK_PREVENTING_WAIT
static bool index_expression_changed_walker(Node *node, Bitmapset *allUpdatedCols)
void check_exclusion_constraint(Relation heap, Relation index, IndexInfo *indexInfo, ItemPointer tupleid, const Datum *values, const bool *isnull, EState *estate, bool newIndex)
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, const Datum *values, const 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_insert_cleanup(Relation indexRelation, 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)
static void ItemPointerSetInvalid(ItemPointerData *pointer)
static bool ItemPointerIsValid(const ItemPointerData *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
#define expression_tree_walker(n, w, c)
#define IsA(nodeptr, _type_)
static int list_length(const List *l)
static bool DatumGetBool(Datum X)
#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)