|
30 | 30 | import java.util.Map.Entry; |
31 | 31 | import java.util.Optional; |
32 | 32 | import java.util.function.Function; |
| 33 | +import java.util.function.Predicate; |
33 | 34 | import java.util.regex.Pattern; |
34 | 35 | import org.antlr.runtime.ClassicToken; |
35 | 36 | import org.antlr.runtime.CommonToken; |
@@ -1700,6 +1701,11 @@ public RelNode apply(RelOptCluster cluster, RelOptSchema relOptSchema, SchemaPlu |
1700 | 1701 | materializationValidator.getAutomaticRewritingValidationResult()); |
1701 | 1702 | perfLogger.perfLogEnd(this.getClass().getName(), PerfLogger.VALIDATE_QUERY_MATERIALIZATION); |
1702 | 1703 |
|
| 1704 | + // this step primes the cache containing the validTxnWriteIdList. It will fetch |
| 1705 | + // all the tables into the MetaStore Client cache with one HMS call. These are |
| 1706 | + // uses within the partition prune rule. |
| 1707 | + callAndCacheValidTxnWriteIdList(calcitePlan); |
| 1708 | + |
1703 | 1709 | // 2. Apply pre-join order optimizations |
1704 | 1710 | perfLogger.perfLogBegin(this.getClass().getName(), PerfLogger.PREJOIN_ORDERING); |
1705 | 1711 | calcitePlan = applyPreJoinOrderingTransforms(calcitePlan, mdProvider.getMetadataProvider(), executorProvider); |
@@ -2454,15 +2460,20 @@ private RelNode applyPostJoinOrderingTransform(RelNode basePlan, RelMetadataProv |
2454 | 2460 | } |
2455 | 2461 |
|
2456 | 2462 | protected Set<TableName> getTablesUsed(RelNode plan) { |
| 2463 | + Predicate<Table> tableFilter = table -> AcidUtils.isTransactionalTable(table) || |
| 2464 | + table.isNonNative() && table.getStorageHandler().areSnapshotsSupported(); |
| 2465 | + return getTablesUsed(plan, tableFilter); |
| 2466 | + } |
| 2467 | + |
| 2468 | + private Set<TableName> getTablesUsed(RelNode plan, Predicate<Table> tableFilter) { |
2457 | 2469 | Set<TableName> tablesUsed = new HashSet<>(); |
2458 | 2470 | new RelVisitor() { |
2459 | 2471 | @Override |
2460 | 2472 | public void visit(RelNode node, int ordinal, RelNode parent) { |
2461 | 2473 | if (node instanceof TableScan) { |
2462 | 2474 | TableScan ts = (TableScan) node; |
2463 | 2475 | Table table = ((RelOptHiveTable) ts.getTable()).getHiveTableMD(); |
2464 | | - if (AcidUtils.isTransactionalTable(table) || |
2465 | | - table.isNonNative() && table.getStorageHandler().areSnapshotsSupported()) { |
| 2476 | + if (tableFilter.test(table)) { |
2466 | 2477 | tablesUsed.add(table.getFullTableName()); |
2467 | 2478 | } |
2468 | 2479 | } |
@@ -5112,9 +5123,21 @@ private ImmutableMap<String, Integer> buildHiveColNameToInputPosMap( |
5112 | 5123 | return hiveColNameToInputPosMapBuilder.build(); |
5113 | 5124 | } |
5114 | 5125 |
|
5115 | | - private QBParseInfo getQBParseInfo(QB qb) throws CalciteSemanticException { |
| 5126 | + private QBParseInfo getQBParseInfo(QB qb) { |
5116 | 5127 | return qb.getParseInfo(); |
5117 | 5128 | } |
| 5129 | + |
| 5130 | + private void callAndCacheValidTxnWriteIdList(RelNode relNode) { |
| 5131 | + var transactionalTables = getTablesUsed(relNode, AcidUtils::isTransactionalTable) |
| 5132 | + .stream() |
| 5133 | + .map(TableName::getNotEmptyDbTable) |
| 5134 | + .toList(); |
| 5135 | + try { |
| 5136 | + getValidTxnWriteIdList(transactionalTables); |
| 5137 | + } catch (SemanticException e) { |
| 5138 | + throw new RuntimeException(e.getMessage(), e); |
| 5139 | + } |
| 5140 | + } |
5118 | 5141 | } |
5119 | 5142 |
|
5120 | 5143 | @Override |
|
0 commit comments