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

Function initNextTableToScan

src/backend/executor/nodeDynamicSeqscan.c:114–174  ·  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

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

Callers 1

ExecDynamicSeqScanFunction · 0.70

Calls 6

table_openFunction · 0.85
table_closeFunction · 0.85
free_attrmapFunction · 0.85

Tested by

no test coverage detected