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)
299 List *arbiterIndexes,
300 bool onlySummarizing)
338 for (
i = 0;
i < numIndices;
i++)
340 Relation indexRelation = relationDescs[
i];
345 bool satisfiesConstraint;
347 if (indexRelation == NULL)
350 indexInfo = indexInfoArray[
i];
373 if (predicate == NULL)
395 applyNoDupErr = noDupErr &&
396 (arbiterIndexes ==
NIL ||
398 indexRelation->
rd_index->indexrelid));
413 if (!indexRelation->
rd_index->indisunique)
415 else if (applyNoDupErr)
417 else if (indexRelation->
rd_index->indimmediate)
432 satisfiesConstraint =
466 else if (!indexRelation->
rd_index->indimmediate)
477 satisfiesConstraint =
479 indexRelation, indexInfo,
482 waitMode, violationOK, NULL);
487 !satisfiesConstraint)
496 if (indexRelation->
rd_index->indimmediate && specConflict)
497 *specConflict =
true;
524 List *arbiterIndexes)
535 bool checkedIndex =
false;
561 for (
i = 0;
i < numIndices;
i++)
563 Relation indexRelation = relationDescs[
i];
565 bool satisfiesConstraint;
567 if (indexRelation == NULL)
570 indexInfo = indexInfoArray[
i];
580 if (arbiterIndexes !=
NIL &&
582 indexRelation->
rd_index->indexrelid))
585 if (!indexRelation->
rd_index->indimmediate)
587 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
588 errmsg(
"ON CONFLICT does not support deferrable unique constraints/exclusion constraints as arbiters"),
604 if (predicate == NULL)
625 satisfiesConstraint =
627 indexInfo, &invalidItemPtr,
628 values, isnull, estate,
false,
631 if (!satisfiesConstraint)
635 if (arbiterIndexes !=
NIL && !checkedIndex)
636 elog(
ERROR,
"unexpected failure to find arbiter index");
688 EState *estate,
bool newIndex,
695 Oid *index_collations =
index->rd_indcollation;
727 for (
i = 0;
i < indnkeyatts;
i++)
740 for (
i = 0;
i < indnkeyatts;
i++)
773 index_rescan(index_scan, scankeys, indnkeyatts, NULL, 0);
782 char *error_existing;
791 elog(
ERROR,
"found self tuple multiple times in index \"%s\"",
802 existing_values, existing_isnull);
827 DirtySnapshot.
xmin : DirtySnapshot.
xmax;
843 &existing_slot->
tts_tid, reason_wait);
855 *conflictTid = existing_slot->
tts_tid;
864 (
errcode(ERRCODE_EXCLUSION_VIOLATION),
865 errmsg(
"could not create exclusion constraint \"%s\"",
867 error_new && error_existing ?
868 errdetail(
"Key %s conflicts with key %s.",
869 error_new, error_existing) :
875 (
errcode(ERRCODE_EXCLUSION_VIOLATION),
876 errmsg(
"conflicting key value violates exclusion constraint \"%s\"",
878 error_new && error_existing ?
879 errdetail(
"Key %s conflicts with existing key %s.",
880 error_new, error_existing) :
881 errdetail(
"Key conflicts with existing key."),
914 EState *estate,
bool newIndex)
928 Datum *existing_values,
bool *existing_isnull,
934 for (
i = 0;
i < indnkeyatts;
i++)
937 if (existing_isnull[
i])
941 index->rd_indcollation[
i],
964 bool hasexpression =
false;
997 hasexpression =
true;
1030 if (!extraUpdatedCols)
1031 allUpdatedCols = updatedCols;
1033 allUpdatedCols =
bms_union(updatedCols, extraUpdatedCols);
1047 if (extraUpdatedCols)
1093 (
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]
elog(ERROR, "%s: %s", p2, msg)
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)
void ExecCloseIndices(ResultRelInfo *resultRelInfo)
List * ExecInsertIndexTuples(ResultRelInfo *resultRelInfo, TupleTableSlot *slot, EState *estate, bool update, bool noDupErr, bool *specConflict, List *arbiterIndexes, bool onlySummarizing)
void ExecOpenIndices(ResultRelInfo *resultRelInfo, bool speculative)
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 violationOK, ItemPointer conflictTid)
@ CEOUC_LIVELOCK_PREVENTING_WAIT
static bool index_expression_changed_walker(Node *node, Bitmapset *allUpdatedCols)
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)
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)