>From Vijay Sarathy <[email protected]>: Vijay Sarathy has submitted this change. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/17626 )
Change subject: [ASTERIXDB-3208][COMP] Fix for array predicate selectivity ...................................................................... [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]> --- M asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/cbo/Stats.java M asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/cbo/JoinNode.java 2 files changed, 41 insertions(+), 4 deletions(-) Approvals: Ali Alsuliman: Looks good to me, approved Vijay Sarathy: Looks good to me, but someone else must approve Jenkins: Verified; Verified Objections: Anon. E. Moose #1000171: Violations found 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 7f0a749..6c5b2ca 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 @@ 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 785d56b..b285de2 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 @@ } 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 @@ } } } - // 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; } -- To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/17626 To unsubscribe, or for help writing mail filters, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Change-Id: I890b5c2a32b583a8d6e1f23c5f27d2c912ce3ef9 Gerrit-Change-Number: 17626 Gerrit-PatchSet: 2 Gerrit-Owner: Vijay Sarathy <[email protected]> Gerrit-Reviewer: Ali Alsuliman <[email protected]> Gerrit-Reviewer: Anon. E. Moose #1000171 Gerrit-Reviewer: Jenkins <[email protected]> Gerrit-Reviewer: Vijay Sarathy <[email protected]> Gerrit-MessageType: merged
