>From <[email protected]>:
[email protected] has uploaded this change for review. (
https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/20546?usp=email )
Change subject: [ASTERIXDB-3635][COMP] Tune single dataset index costing (ARRAY)
......................................................................
[ASTERIXDB-3635][COMP] Tune single dataset index costing (ARRAY)
Change-Id: If2e62a6e0748f27474837faf7d74a184b2c62c03
---
M
asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/cbo/Stats.java
1 file changed, 35 insertions(+), 23 deletions(-)
git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb
refs/changes/46/20546/1
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 72ec179..e27193c 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
@@ -649,10 +649,12 @@
}
}
- protected double findSelectivityForThisPredicate(SelectOperator selOp,
AbstractFunctionCallExpression exp,
+ protected double findSelectivityForThisPredicate(SelectOperator leafInput,
AbstractFunctionCallExpression exp,
boolean arrayIndex) 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.
+ SelectOperator selOp = (SelectOperator)
OperatorManipulationUtil.bottomUpCopyOperators(leafInput); // make a copy
+ // replace the selOp.condition with the new exp and replace it at the
end
+ // The selop here is the start of the leafInput.
+ convertAllInAndAnySubplansToInAnySubplans(selOp); // This will make
the rest of the code simpler
ILogicalOperator parent =
joinEnum.findDataSourceScanOperatorParent(selOp);
DataSourceScanOperator scanOp = (DataSourceScanOperator)
parent.getInputs().get(0).getValue();
@@ -693,26 +695,7 @@
selOp.getCondition().setValue(saveExprs);
} else {
if (numSubplans == 1 && nonSubplanSelects == 0) {
- AggregateOperator aggOp = findAggOp(selOp, exp);
- if (aggOp.getExpressions().size() > 1) {
- // ANY and EVERY IN query; for selectivity purposes, we
need to transform this into a ANY IN query
- SelectOperator newSelOp = (SelectOperator)
OperatorManipulationUtil.bottomUpCopyOperators(selOp);
- aggOp = findAggOp(newSelOp, exp);
- ILogicalOperator input =
aggOp.getInputs().get(0).getValue();
- SelectOperator condition = (SelectOperator)
OperatorManipulationUtil
-
.bottomUpCopyOperators(AbstractOperatorFromSubplanRewrite.getSelectFromPlan(aggOp));
- //push this condition below aggOp.
- aggOp.getInputs().get(0).setValue(condition);
- condition.getInputs().get(0).setValue(input);
- ILogicalExpression newExp2 =
newSelOp.getCondition().getValue();
- if (newExp2.getExpressionTag() ==
LogicalExpressionTag.FUNCTION_CALL) {
- AbstractFunctionCallExpression afce =
(AbstractFunctionCallExpression) newExp2;
-
afce.getArguments().get(1).setValue(ConstantExpression.TRUE);
- }
- result = runSamplingQuery(optCtx, newSelOp); // no need to
switch anything
- } else {
- result = runSamplingQuery(optCtx, selOp);
- }
+ result = runSamplingQuery(optCtx, selOp);
} else {
SelectOperator selOp2 = findSelectOpWithExpr(selOp, exp);
List<ILogicalExpression> selExprs;
@@ -754,6 +737,35 @@
return sel;
}
+ private void convertAllInAndAnySubplansToInAnySubplans(SelectOperator
selOp) throws AlgebricksException {
+ SubplanOperator subOp;
+ AggregateOperator aggOp;
+ ILogicalOperator op = selOp;
+ while (op != null && op.getOperatorTag() !=
LogicalOperatorTag.EMPTYTUPLESOURCE) {
+ if (op.getOperatorTag().equals(LogicalOperatorTag.SUBPLAN)) {
+ subOp = (SubplanOperator) op;
+ ILogicalOperator nextOp =
subOp.getNestedPlans().get(0).getRoots().get(0).getValue();
+ if (nextOp.getOperatorTag() == LogicalOperatorTag.AGGREGATE) {
+ aggOp = (AggregateOperator) nextOp;
+ if (aggOp.getExpressions().size() > 1) { //IN And EVERY
subplan
+ ILogicalOperator input =
aggOp.getInputs().get(0).getValue();
+ SelectOperator condition = (SelectOperator)
OperatorManipulationUtil
+
.bottomUpCopyOperators(AbstractOperatorFromSubplanRewrite.getSelectFromPlan(aggOp));
+ //push this condition below aggOp.
+ aggOp.getInputs().get(0).setValue(condition);
+ condition.getInputs().get(0).setValue(input);
+ ILogicalExpression newExp2 =
selOp.getCondition().getValue(); // was newSelOp before
+ if (newExp2.getExpressionTag() ==
LogicalExpressionTag.FUNCTION_CALL) {
+ AbstractFunctionCallExpression afce =
(AbstractFunctionCallExpression) newExp2;
+
afce.getArguments().get(1).setValue(ConstantExpression.TRUE);
+ }
+ }
+ }
+ }
+ op = op.getInputs().get(0).getValue();
+ }
+ }
+
public double findPredicateCardinality(List<List<IAObject>> result,
boolean project) {
if (project) {
ARecord record = (ARecord) (((IAObject) ((List<IAObject>)
(result.get(0))).get(0)));
--
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/20546?usp=email
To unsubscribe, or for help writing mail filters, visit
https://asterix-gerrit.ics.uci.edu/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Change-Id: If2e62a6e0748f27474837faf7d74a184b2c62c03
Gerrit-Change-Number: 20546
Gerrit-PatchSet: 1
Gerrit-Owner: [email protected]