You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by mb...@apache.org on 2020/03/11 22:20:37 UTC
[asterixdb] 01/03: [NO ISSUE][COMP] Eliminate listify in some
window function cases
This is an automated email from the ASF dual-hosted git repository.
mblow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git
commit d17798fadeb990acc4faac82dbae288f9d410ed1
Author: Dmitry Lychagin <dm...@couchbase.com>
AuthorDate: Tue Mar 3 13:27:35 2020 -0800
[NO ISSUE][COMP] Eliminate listify in some window function cases
- user model changes: no
- storage format changes: no
- interface changes: no
Details:
- Eliminate listify when a window function call
operates on the output of an aggregate function
Change-Id: I714fd4210a615963480e22c38ed3bcd3c98f5463
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/5223
Integration-Tests: Jenkins <je...@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
Reviewed-by: Dmitry Lychagin <dm...@couchbase.com>
Reviewed-by: Ali Alsuliman <al...@gmail.com>
---
.../rules/PushAggregateIntoNestedSubplanRule.java | 29 ++++++++------------
.../queries/window/win_opt_01/win_opt_01_12.sqlpp | 31 ++++++++++++++++++++++
.../results/window/win_opt_01/win_opt_01_12.plan | 24 +++++++++++++++++
.../window/win_opt_01/win_opt_01.12.query.sqlpp | 31 ++++++++++++++++++++++
.../results/window/win_opt_01/win_opt_01.12.adm | 4 +++
5 files changed, 101 insertions(+), 18 deletions(-)
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/PushAggregateIntoNestedSubplanRule.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/PushAggregateIntoNestedSubplanRule.java
index 6497b88..f8457cc 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/PushAggregateIntoNestedSubplanRule.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/PushAggregateIntoNestedSubplanRule.java
@@ -45,13 +45,12 @@ import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
import org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator;
import org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractOperatorWithNestedPlans;
import org.apache.hyracks.algebricks.core.algebra.operators.logical.AggregateOperator;
-import org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator;
-import org.apache.hyracks.algebricks.core.algebra.operators.logical.SelectOperator;
import org.apache.hyracks.algebricks.core.algebra.operators.logical.SubplanOperator;
import org.apache.hyracks.algebricks.core.algebra.operators.logical.UnnestOperator;
import org.apache.hyracks.algebricks.core.algebra.operators.logical.visitors.VariableUtilities;
import org.apache.hyracks.algebricks.core.algebra.util.OperatorManipulationUtil;
import org.apache.hyracks.algebricks.core.algebra.util.OperatorPropertiesUtil;
+import org.apache.hyracks.algebricks.core.algebra.visitors.ILogicalExpressionReferenceTransform;
import org.apache.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
public class PushAggregateIntoNestedSubplanRule implements IAlgebraicRewriteRule {
@@ -133,8 +132,9 @@ public class PushAggregateIntoNestedSubplanRule implements IAlgebraicRewriteRule
switch (op1.getOperatorTag()) {
case ASSIGN:
case SELECT:
+ case WINDOW:
boolean found = false;
- // Do some prefiltering: check if the Assign uses any nsp vars.
+ // Do some pre-filtering: check if the operator uses any nsp vars.
for (LogicalVariable v : used) {
if (nspListifyVarsCount.get(v) != null) {
found = true;
@@ -144,26 +144,19 @@ public class PushAggregateIntoNestedSubplanRule implements IAlgebraicRewriteRule
if (!found) {
break;
}
- if (op1.getOperatorTag() == LogicalOperatorTag.ASSIGN) {
- AssignOperator assign = (AssignOperator) op1;
- for (Mutable<ILogicalExpression> exprRef : assign.getExpressions()) {
- Pair<Boolean, ILogicalExpression> p =
- extractAggFunctionsFromExpression(exprRef, nspWithAgg, aggregateExprToVarExpr, context);
- if (p.first) {
- change = true;
- exprRef.setValue(p.second);
- }
- }
- }
- if (op1.getOperatorTag() == LogicalOperatorTag.SELECT) {
- SelectOperator select = (SelectOperator) op1;
- Mutable<ILogicalExpression> exprRef = select.getCondition();
+
+ ILogicalExpressionReferenceTransform exprTransform = exprRef -> {
Pair<Boolean, ILogicalExpression> p =
extractAggFunctionsFromExpression(exprRef, nspWithAgg, aggregateExprToVarExpr, context);
if (p.first) {
- change = true;
exprRef.setValue(p.second);
+ return true;
+ } else {
+ return false;
}
+ };
+ if (op1.acceptExpressionTransform(exprTransform)) {
+ change = true;
}
used.clear();
VariableUtilities.getUsedVariables(op1, used);
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/window/win_opt_01/win_opt_01_12.sqlpp b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/window/win_opt_01/win_opt_01_12.sqlpp
new file mode 100644
index 0000000..757fed4
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/window/win_opt_01/win_opt_01_12.sqlpp
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description : Test listify removal for window functions over aggregates
+ * Expected Res : SUCCESS (no listify in the final plan)
+ */
+
+from (
+ from range(1, 10) r
+ select r % 2 as x, r % 4 as y, r as z
+) t
+group by x, y
+select x, y, count(z) as cnt,
+ rank() over(partition by x order by count(z)) as rnk
+order by x, cnt;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_12.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_12.plan
new file mode 100644
index 0000000..77572d4
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_12.plan
@@ -0,0 +1,24 @@
+-- DISTRIBUTE_RESULT |LOCAL|
+ -- ONE_TO_ONE_EXCHANGE |LOCAL|
+ -- STREAM_PROJECT |LOCAL|
+ -- ASSIGN |LOCAL|
+ -- ONE_TO_ONE_EXCHANGE |LOCAL|
+ -- STABLE_SORT [$$x(ASC), $$93(ASC)] |LOCAL|
+ -- ONE_TO_ONE_EXCHANGE |LOCAL|
+ -- STREAM_PROJECT |LOCAL|
+ -- WINDOW_STREAM |LOCAL|
+ -- ONE_TO_ONE_EXCHANGE |LOCAL|
+ -- STABLE_SORT [$$x(ASC), $$94(ASC)] |LOCAL|
+ -- ONE_TO_ONE_EXCHANGE |LOCAL|
+ -- PRE_CLUSTERED_GROUP_BY[$$96, $$97] |LOCAL|
+ {
+ -- AGGREGATE |LOCAL|
+ -- AGGREGATE |LOCAL|
+ -- NESTED_TUPLE_SOURCE |LOCAL|
+ }
+ -- ONE_TO_ONE_EXCHANGE |LOCAL|
+ -- STABLE_SORT [$$96(ASC), $$97(ASC)] |LOCAL|
+ -- ONE_TO_ONE_EXCHANGE |UNPARTITIONED|
+ -- ASSIGN |UNPARTITIONED|
+ -- UNNEST |UNPARTITIONED|
+ -- EMPTY_TUPLE_SOURCE |UNPARTITIONED|
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/win_opt_01/win_opt_01.12.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/win_opt_01/win_opt_01.12.query.sqlpp
new file mode 100644
index 0000000..757fed4
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/win_opt_01/win_opt_01.12.query.sqlpp
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description : Test listify removal for window functions over aggregates
+ * Expected Res : SUCCESS (no listify in the final plan)
+ */
+
+from (
+ from range(1, 10) r
+ select r % 2 as x, r % 4 as y, r as z
+) t
+group by x, y
+select x, y, count(z) as cnt,
+ rank() over(partition by x order by count(z)) as rnk
+order by x, cnt;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/window/win_opt_01/win_opt_01.12.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/win_opt_01/win_opt_01.12.adm
new file mode 100644
index 0000000..f3be989
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/win_opt_01/win_opt_01.12.adm
@@ -0,0 +1,4 @@
+{ "x": 0, "y": 0, "cnt": 2, "rnk": 1 }
+{ "x": 0, "y": 2, "cnt": 3, "rnk": 2 }
+{ "x": 1, "y": 3, "cnt": 2, "rnk": 1 }
+{ "x": 1, "y": 1, "cnt": 3, "rnk": 2 }
\ No newline at end of file