* Find the correct index in the given partition, and create a IndexScan executor * node to scan it. */
| 120 | * node to scan it. |
| 121 | */ |
| 122 | static void |
| 123 | beginCurrentIndexScan(DynamicIndexScanState *node, EState *estate, |
| 124 | Oid tableOid) |
| 125 | { |
| 126 | bool is_indexonly_scan = nodeTag(node->ss.ps.plan) == T_DynamicIndexOnlyScan; |
| 127 | Relation currentRelation; |
| 128 | Oid indexOid; |
| 129 | List *save_tupletable; |
| 130 | MemoryContext oldCxt; |
| 131 | |
| 132 | /* |
| 133 | * open the base relation and acquire appropriate lock on it. |
| 134 | */ |
| 135 | currentRelation = table_open(tableOid, AccessShareLock); |
| 136 | node->ss.ss_currentRelation = currentRelation; |
| 137 | |
| 138 | save_tupletable = estate->es_tupleTable; |
| 139 | estate->es_tupleTable = NIL; |
| 140 | oldCxt = MemoryContextSwitchTo(node->partitionMemoryContext); |
| 141 | |
| 142 | /* |
| 143 | * Re-map the index columns, per the new partition, and find the correct |
| 144 | * index. |
| 145 | */ |
| 146 | if (!OidIsValid(node->columnLayoutOid)) |
| 147 | { |
| 148 | /* Very first partition */ |
| 149 | /* |
| 150 | * Just get the direct parent, we don't support multi-level |
| 151 | * partitioning |
| 152 | */ |
| 153 | node->columnLayoutOid = get_partition_parent(tableOid, true /* even_if_detached */); |
| 154 | } |
| 155 | if (is_indexonly_scan) |
| 156 | { |
| 157 | DynamicIndexOnlyScan *dynamicIndexOnlyScan = (DynamicIndexOnlyScan *) node->ss.ps.plan; |
| 158 | |
| 159 | DynamicIndexOnlyScan_ReMapColumns(dynamicIndexOnlyScan, |
| 160 | tableOid, node->columnLayoutOid); |
| 161 | node->columnLayoutOid = tableOid; |
| 162 | |
| 163 | indexOid = index_get_partition(currentRelation, dynamicIndexOnlyScan->indexscan.indexid); |
| 164 | if (!OidIsValid(indexOid)) |
| 165 | elog(ERROR, "failed to find index for partition \"%s\" in dynamic index scan", |
| 166 | RelationGetRelationName(currentRelation)); |
| 167 | |
| 168 | node->indexOnlyScanState = ExecInitIndexOnlyScanForPartition(&dynamicIndexOnlyScan->indexscan, estate, |
| 169 | node->eflags, |
| 170 | currentRelation, indexOid); |
| 171 | node->indexScanState = NULL; |
| 172 | } |
| 173 | else |
| 174 | { |
| 175 | DynamicIndexScan *dynamicIndexScan = (DynamicIndexScan *) node->ss.ps.plan; |
| 176 | |
| 177 | DynamicIndexScan_ReMapColumns(dynamicIndexScan, |
| 178 | tableOid, node->columnLayoutOid); |
| 179 | node->columnLayoutOid = tableOid; |
no test coverage detected