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

Function RelationFindReplTupleByIndex

src/backend/executor/execReplication.c:119–223  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

117 * contents, and return true. Return false otherwise.
118 */
119bool
120RelationFindReplTupleByIndex(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
144retry:
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

Callers 1

FindReplTupleInLocalRelFunction · 0.85

Calls 15

index_openFunction · 0.85
index_beginscanFunction · 0.85
build_replindex_scan_keyFunction · 0.85
index_rescanFunction · 0.85
index_getnext_slotFunction · 0.85
ExecMaterializeSlotFunction · 0.85
XactLockTableWaitFunction · 0.85
PushActiveSnapshotFunction · 0.85
GetLatestSnapshotFunction · 0.85
table_tuple_lockFunction · 0.85
GetCurrentCommandIdFunction · 0.85
PopActiveSnapshotFunction · 0.85

Tested by

no test coverage detected