* Search the relation 'rel' for tuple using the index. * * If a matching tuple is found, lock it with lockmode, fill the slot with its * contents, and return true. Return false otherwise. */
| 117 | * contents, and return true. Return false otherwise. |
| 118 | */ |
| 119 | bool |
| 120 | RelationFindReplTupleByIndex(Relation rel, Oid idxoid, |
| 121 | LockTupleMode lockmode, |
| 122 | TupleTableSlot *searchslot, |
| 123 | TupleTableSlot *outslot) |
| 124 | { |
| 125 | ScanKeyData skey[INDEX_MAX_KEYS]; |
| 126 | IndexScanDesc scan; |
| 127 | SnapshotData snap; |
| 128 | TransactionId xwait; |
| 129 | Relation idxrel; |
| 130 | bool found; |
| 131 | |
| 132 | /* Open the index. */ |
| 133 | idxrel = index_open(idxoid, RowExclusiveLock); |
| 134 | |
| 135 | /* Start an index scan. */ |
| 136 | InitDirtySnapshot(snap); |
| 137 | scan = index_beginscan(rel, idxrel, &snap, |
| 138 | IndexRelationGetNumberOfKeyAttributes(idxrel), |
| 139 | 0); |
| 140 | |
| 141 | /* Build scan key. */ |
| 142 | build_replindex_scan_key(skey, rel, idxrel, searchslot); |
| 143 | |
| 144 | retry: |
| 145 | found = false; |
| 146 | |
| 147 | index_rescan(scan, skey, IndexRelationGetNumberOfKeyAttributes(idxrel), NULL, 0); |
| 148 | |
| 149 | /* Try to find the tuple */ |
| 150 | if (index_getnext_slot(scan, ForwardScanDirection, outslot)) |
| 151 | { |
| 152 | found = true; |
| 153 | ExecMaterializeSlot(outslot); |
| 154 | |
| 155 | xwait = TransactionIdIsValid(snap.xmin) ? |
| 156 | snap.xmin : snap.xmax; |
| 157 | |
| 158 | /* |
| 159 | * If the tuple is locked, wait for locking transaction to finish and |
| 160 | * retry. |
| 161 | */ |
| 162 | if (TransactionIdIsValid(xwait)) |
| 163 | { |
| 164 | XactLockTableWait(xwait, NULL, NULL, XLTW_None); |
| 165 | goto retry; |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | /* Found tuple, try to lock it in the lockmode. */ |
| 170 | if (found) |
| 171 | { |
| 172 | TM_FailureData tmfd; |
| 173 | TM_Result res; |
| 174 | |
| 175 | PushActiveSnapshot(GetLatestSnapshot()); |
| 176 |
no test coverage detected