diff --git ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/stats/FilterSelectivityEstimator.java ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/stats/FilterSelectivityEstimator.java index 6f26d7d..1345709 100644 --- ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/stats/FilterSelectivityEstimator.java +++ ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/stats/FilterSelectivityEstimator.java @@ -43,6 +43,7 @@ public class FilterSelectivityEstimator extends RexVisitorImpl { private final RelNode childRel; private final double childCardinality; + private boolean colStatsComputed; protected FilterSelectivityEstimator(RelNode childRel) { super(true); @@ -72,6 +73,15 @@ public Double visitCall(RexCall call) { switch (op) { case AND: { + if ((childRel instanceof HiveTableScan) && !colStatsComputed) { + Set iRefSet = HiveCalciteUtil.getInputRefs(call); + // Club all required cols together and get the stats. + // Meta/Object store caches the results and next call to fetch col stats for + // individual cols (e.g getMaxNulls) would be much faster + // than fetching every column. + ((HiveTableScan) childRel).getColStat(new ArrayList(iRefSet)); + colStatsComputed = true; + } selectivity = computeConjunctionSelectivity(call); break; }