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

Function IndexNextWithReorder

src/backend/executor/nodeIndexscan.c:171–358  ·  view source on GitHub ↗

---------------------------------------------------------------- * IndexNextWithReorder * * Like IndexNext, but this version can also re-check ORDER BY * expressions, and reorder the tuples as necessary. * ---------------------------------------------------------------- */

Source from the content-addressed store, hash-verified

169 * ----------------------------------------------------------------
170 */
171static TupleTableSlot *
172IndexNextWithReorder(IndexScanState *node)
173{
174 EState *estate;
175 ExprContext *econtext;
176 IndexScanDesc scandesc;
177 TupleTableSlot *slot;
178 ReorderTuple *topmost = NULL;
179 bool was_exact;
180 Datum *lastfetched_vals;
181 bool *lastfetched_nulls;
182 int cmp;
183
184 estate = node->ss.ps.state;
185
186 /*
187 * Only forward scan is supported with reordering. Note: we can get away
188 * with just Asserting here because the system will not try to run the
189 * plan backwards if ExecSupportsBackwardScan() says it won't work.
190 * Currently, that is guaranteed because no index AMs support both
191 * amcanorderbyop and amcanbackward; if any ever do,
192 * ExecSupportsBackwardScan() will need to consider indexorderbys
193 * explicitly.
194 */
195 Assert(!ScanDirectionIsBackward(((IndexScan *) node->ss.ps.plan)->indexorderdir));
196 Assert(ScanDirectionIsForward(estate->es_direction));
197
198 scandesc = node->iss_ScanDesc;
199 econtext = node->ss.ps.ps_ExprContext;
200 slot = node->ss.ss_ScanTupleSlot;
201
202 if (scandesc == NULL)
203 {
204 /*
205 * We reach here if the index scan is not parallel, or if we're
206 * serially executing an index scan that was planned to be parallel.
207 */
208 scandesc = index_beginscan(node->ss.ss_currentRelation,
209 node->iss_RelationDesc,
210 estate->es_snapshot,
211 node->iss_NumScanKeys,
212 node->iss_NumOrderByKeys);
213
214 node->iss_ScanDesc = scandesc;
215
216 /*
217 * If no run-time keys to calculate or they are ready, go ahead and
218 * pass the scankeys to the index AM.
219 */
220 if (node->iss_NumRuntimeKeys == 0 || node->iss_RuntimeKeysReady)
221 index_rescan(scandesc,
222 node->iss_ScanKeys, node->iss_NumScanKeys,
223 node->iss_OrderByKeys, node->iss_NumOrderByKeys);
224 }
225
226 for (;;)
227 {
228 CHECK_FOR_INTERRUPTS();

Callers

nothing calls this directly

Calls 11

index_beginscanFunction · 0.85
index_rescanFunction · 0.85
pairingheap_firstFunction · 0.85
cmp_orderbyvalsFunction · 0.85
reorderqueue_popFunction · 0.85
ExecForceStoreHeapTupleFunction · 0.85
ExecClearTupleFunction · 0.85
index_getnext_slotFunction · 0.85
ExecQualAndResetFunction · 0.85
EvalOrderByExpressionsFunction · 0.85
reorderqueue_pushFunction · 0.85

Tested by

no test coverage detected