This is an automated email from the ASF dual-hosted git repository.
vsarathy1 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git
The following commit(s) were added to refs/heads/master by this push:
new 290d5374a8 [ASTERIXDB-3208][COMP] Fix for array predicate selectivity
290d5374a8 is described below
commit 290d5374a80b9e62bfe01f87ed689a0513d603e7
Author: Vijay Sarathy <[email protected]>
AuthorDate: Fri Jun 30 12:38:51 2023 -0700
[ASTERIXDB-3208][COMP] Fix for array predicate selectivity
Change-Id: I890b5c2a32b583a8d6e1f23c5f27d2c912ce3ef9
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/17626
Integration-Tests: Jenkins <[email protected]>
Reviewed-by: Vijay Sarathy <[email protected]>
Reviewed-by: Ali Alsuliman <[email protected]>
Tested-by: Jenkins <[email protected]>
---
.../asterix/optimizer/rules/cbo/JoinNode.java | 3 ++-
.../apache/asterix/optimizer/rules/cbo/Stats.java | 28 +++++++++++++++++++---
2 files changed, 27 insertions(+), 4 deletions(-)
diff --git
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/cbo/JoinNode.java
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/cbo/JoinNode.java
index 7f0a74932a..6c5b2ca12b 100644
---
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/cbo/JoinNode.java
+++
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/cbo/JoinNode.java
@@ -471,7 +471,8 @@ public class JoinNode {
selOp = new SelectOperator(new MutableObject<>(afce));
selOp.getInputs().add(new MutableObject<>(leafInput));
}
- sel =
joinEnum.getStatsHandle().findSelectivityForThisPredicate(selOp, afce,
this.origCardinality);
+ sel =
joinEnum.getStatsHandle().findSelectivityForThisPredicate(selOp, afce,
+
chosenIndex.getIndexType().equals(DatasetConfig.IndexType.ARRAY),
this.origCardinality);
}
IndexCostInfo.add(new Triple<>(chosenIndex, sel, afce));
}
diff --git
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/cbo/Stats.java
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/cbo/Stats.java
index 785d56b49c..b285de280b 100644
---
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/cbo/Stats.java
+++
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/cbo/Stats.java
@@ -372,7 +372,7 @@ public class Stats {
}
protected double findSelectivityForThisPredicate(SelectOperator selOp,
AbstractFunctionCallExpression exp,
- double datasetCard) throws AlgebricksException {
+ boolean arrayIndex, double datasetCard) throws AlgebricksException
{
// replace the SelOp.condition with the new exp and replace it at the
end
// The Selop here is the start of the leafInput.
@@ -442,13 +442,35 @@ public class Stats {
}
}
}
- // switch the scanOp back
- parent.getInputs().get(0).setValue(scanOp);
double predicateCardinality = (double) ((AInt64)
result.get(0).get(0)).getLongValue();
if (predicateCardinality == 0.0) {
predicateCardinality = 0.0001 *
idxDetails.getSampleCardinalityTarget();
}
+
+ if (arrayIndex) {
+ // In case of array predicates, the sample cardinality should be
computed as
+ // the number of unnested array elements. Run a second sampling
query to compute this.
+ // The query should already have the unnest operation, so simply
replace the select clause with TRUE
+ // to get the unnested cardinality from the sample.
+ // Example query: SELECT count(*) as revenue
+ // FROM orders o, o.o_orderline ol
+ // WHERE ol.ol_delivery_d >= '2016-01-01
00:00:00.000000'
+ // AND ol.ol_delivery_d < '2017-01-01
00:00:00.000000';
+ // ol_delivery_d is part of the array o_orderline
+ // To get the unnested cardinality,we run the following query on
the sample:
+ // SELECT count(*) as revenue
+ // FROM orders o, o.o_orderline ol
+ // WHERE TRUE;
+ ILogicalExpression saveExprs = selOp.getCondition().getValue();
+ selOp.getCondition().setValue(ConstantExpression.TRUE);
+ result = runSamplingQuery(optCtx, selOp);
+ selOp.getCondition().setValue(saveExprs);
+ sampleCard = (double) ((AInt64)
result.get(0).get(0)).getLongValue();
+ }
+ // switch the scanOp back
+ parent.getInputs().get(0).setValue(scanOp);
+
double sel = (double) predicateCardinality / sampleCard;
return sel;
}