amansinha100 commented on a change in pull request #1699: DRILL-7108: Improve
selectivity estimates for (NOT)LIKE, NOT_EQUALS, IS NOT NULL predicates
URL: https://github.com/apache/drill/pull/1699#discussion_r267158524
##########
File path:
exec/java-exec/src/main/java/org/apache/drill/exec/planner/cost/DrillRelMdSelectivity.java
##########
@@ -137,34 +138,33 @@ private double getScanSelectivityInternal(DrillTable
table, RexNode predicate, L
for (RexNode pred : RelOptUtil.conjunctions(predicate)) {
double orSel = 0;
for (RexNode orPred : RelOptUtil.disjunctions(pred)) {
- //CALCITE guess
- Double guess = RelMdUtil.guessSelectivity(pred);
+
if (orPred.isA(SqlKind.EQUALS)) {
+ orSel += computeEqualsSelectivity(table, orPred, fieldNames);
+ } else if (orPred.isA(SqlKind.NOT_EQUALS)) {
+ orSel += 1.0 - computeEqualsSelectivity(table, orPred, fieldNames);
+ } else if (orPred.isA(SqlKind.LIKE)) {
+ // LIKE selectivity is 5% more than a similar equality predicate,
capped at CALCITE guess
+ orSel += Math.min(computeEqualsSelectivity(table, orPred,
fieldNames) + LIKE_PREDICATE_SELECTIVITY,
+ RelMdUtil.guessSelectivity(orPred));
+ } else if (orPred.isA(SqlKind.NOT)) {
if (orPred instanceof RexCall) {
- int colIdx = -1;
- RexInputRef op = findRexInputRef(orPred);
- if (op != null) {
- colIdx = op.hashCode();
- }
- if (colIdx != -1 && colIdx < fieldNames.size()) {
- String col = fieldNames.get(colIdx);
- if (table.getStatsTable() != null
- && table.getStatsTable().getNdv(col) != null) {
- orSel += 1.00 / table.getStatsTable().getNdv(col);
- } else {
- orSel += guess;
- }
+ // LIKE selectivity is 5% more than a similar equality predicate,
capped at CALCITE guess
+ RexNode childOp = ((RexCall) orPred).getOperands().get(0);
+ if (childOp.isA(SqlKind.LIKE)) {
+ orSel += 1.0 - Math.min(computeEqualsSelectivity(table, childOp,
fieldNames) + LIKE_PREDICATE_SELECTIVITY,
+ RelMdUtil.guessSelectivity(childOp));
} else {
- orSel += guess;
- if (logger.isDebugEnabled()) {
- logger.warn(String.format("No input reference $[%s] found for
predicate [%s]",
- Integer.toString(colIdx), orPred.toString()));
- }
+ orSel += 1.0 - RelMdUtil.guessSelectivity(orPred);
}
}
+ } else if (orPred.isA(SqlKind.IS_NULL)) {
+ orSel += computeNullSelectivity(table, orPred, fieldNames);
+ } else if (orPred.isA(SqlKind.IS_NOT_NULL)) {
+ orSel += 1.0 - computeNullSelectivity(table, orPred, fieldNames);
Review comment:
Why not have a computeIsNotNullSelectivity() function ? Sorry for the
nit-pick but since we already have the exact NNRowCount to begin with, the
clean formula without the subtraction would be preferred.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services