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

Function initNextTableToScan

src/backend/executor/nodeDynamicBitmapHeapscan.c:123–192  ·  view source on GitHub ↗

* initNextTableToScan * Find the next table to scan and initiate the scan if the previous table * is finished. * * If scanning on the current table is not finished, or a new table is found, * this function returns true. * If no more table is found, this function returns false. */

Source from the content-addressed store, hash-verified

121 * If no more table is found, this function returns false.
122 */
123static bool
124initNextTableToScan(DynamicBitmapHeapScanState *node)
125{
126 ScanState *scanState = (ScanState *)node;
127 DynamicBitmapHeapScan *plan = (DynamicBitmapHeapScan *) scanState->ps.plan;
128 EState *estate = scanState->ps.state;
129 Relation lastScannedRel;
130 TupleDesc partTupDesc;
131 TupleDesc lastTupDesc;
132 AttrMap *attMap;
133 Oid pid;
134 Relation currentRelation;
135
136 if (++node->whichPart < node->nOids)
137 pid = node->partOids[node->whichPart];
138 else
139 return false;
140
141 estate->partitionOid = pid;
142
143 /* Collect number of partitions scanned in EXPLAIN ANALYZE */
144 if (NULL != scanState->ps.instrument)
145 {
146 Instrumentation *instr = scanState->ps.instrument;
147 instr->numPartScanned++;
148 }
149
150 currentRelation = scanState->ss_currentRelation =
151 table_open(node->partOids[node->whichPart], AccessShareLock);
152
153 if (currentRelation->rd_rel->relkind != RELKIND_RELATION)
154 {
155 /* shouldn't happen */
156 elog(ERROR, "unexpected relkind in Dynamic Scan: %c", currentRelation->rd_rel->relkind);
157 }
158 lastScannedRel = table_open(node->lastRelOid, AccessShareLock);
159 lastTupDesc = RelationGetDescr(lastScannedRel);
160 partTupDesc = RelationGetDescr(scanState->ss_currentRelation);
161 /*
162 * FIXME: should we use execute_attr_map_tuple instead? Seems like a
163 * higher level abstraction that fits the bill
164 */
165 attMap = build_attrmap_by_name_if_req(partTupDesc, lastTupDesc);
166 table_close(lastScannedRel, AccessShareLock);
167
168 /* If attribute remapping is not necessary, then do not change the varattno */
169 if (attMap)
170 {
171 change_varattnos_of_a_varno((Node*)scanState->ps.plan->qual, attMap->attnums, node->scanrelid);
172 change_varattnos_of_a_varno((Node*)scanState->ps.plan->targetlist, attMap->attnums, node->scanrelid);
173
174 /*
175 * Now that the varattno mapping has been changed, change the relation that
176 * the new varnos correspond to
177 */
178 node->lastRelOid = pid;
179 free_attrmap(attMap);
180 }

Callers 1

Calls 7

table_openFunction · 0.85
table_closeFunction · 0.85
free_attrmapFunction · 0.85
ExecReScanFunction · 0.85

Tested by

no test coverage detected