MCPcopy Create free account
hub / github.com/apache/cloudberry / ExecCheckIndexConstraints

Function ExecCheckIndexConstraints

src/backend/executor/execIndexing.c:508–626  ·  view source on GitHub ↗

---------------------------------------------------------------- * ExecCheckIndexConstraints * * This routine checks if a tuple violates any unique or * exclusion constraints. Returns true if there is no conflict. * Otherwise returns false, and the TID of the conflicting * tuple is returned in *conflictTid. * * If 'arbiterIndexes' is given, only those indexes are checked. * NIL me

Source from the content-addressed store, hash-verified

506 * ----------------------------------------------------------------
507 */
508bool
509ExecCheckIndexConstraints(ResultRelInfo *resultRelInfo, TupleTableSlot *slot,
510 EState *estate, ItemPointer conflictTid,
511 List *arbiterIndexes)
512{
513 int i;
514 int numIndices;
515 RelationPtr relationDescs;
516 Relation heapRelation;
517 IndexInfo **indexInfoArray;
518 ExprContext *econtext;
519 Datum values[INDEX_MAX_KEYS];
520 bool isnull[INDEX_MAX_KEYS];
521 ItemPointerData invalidItemPtr;
522 bool checkedIndex = false;
523
524 ItemPointerSetInvalid(conflictTid);
525 ItemPointerSetInvalid(&invalidItemPtr);
526
527 /*
528 * Get information from the result relation info structure.
529 */
530 numIndices = resultRelInfo->ri_NumIndices;
531 relationDescs = resultRelInfo->ri_IndexRelationDescs;
532 indexInfoArray = resultRelInfo->ri_IndexRelationInfo;
533 heapRelation = resultRelInfo->ri_RelationDesc;
534
535 /*
536 * We will use the EState's per-tuple context for evaluating predicates
537 * and index expressions (creating it if it's not already there).
538 */
539 econtext = GetPerTupleExprContext(estate);
540
541 /* Arrange for econtext's scan tuple to be the tuple under test */
542 econtext->ecxt_scantuple = slot;
543
544 /*
545 * For each index, form index tuple and check if it satisfies the
546 * constraint.
547 */
548 for (i = 0; i < numIndices; i++)
549 {
550 Relation indexRelation = relationDescs[i];
551 IndexInfo *indexInfo;
552 bool satisfiesConstraint;
553
554 if (indexRelation == NULL)
555 continue;
556
557 indexInfo = indexInfoArray[i];
558
559 if (!indexInfo->ii_Unique && !indexInfo->ii_ExclusionOps)
560 continue;
561
562 /* If the index is marked as read-only, ignore it */
563 if (!indexInfo->ii_ReadyForInserts)
564 continue;
565

Callers 1

ExecInsertFunction · 0.85

Calls 8

list_member_oidFunction · 0.85
errtableconstraintFunction · 0.85
ExecPrepareQualFunction · 0.85
ExecQualFunction · 0.85
FormIndexDatumFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected