---------------------------------------------------------------- * 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
| 506 | * ---------------------------------------------------------------- |
| 507 | */ |
| 508 | bool |
| 509 | ExecCheckIndexConstraints(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 |
no test coverage detected