>From Rithwik Koul <[email protected]>:

Rithwik Koul has uploaded this change for review. ( 
https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21293?usp=email )


Change subject: [NO ISSUE][COMP] Drop constant ORDER BY sort keys
......................................................................

[NO ISSUE][COMP] Drop constant ORDER BY sort keys

- user model changes: no
- storage format changes: no
- interface changes: no

Details:
Adds RemoveConstantOrderByExpressionsRule, which strips entries from
OrderOperator.getOrderExpressions() whose value is a compile-time
constant. The OrderOperator is unwrapped entirely if every key
becomes constant.

Ext-ref: No ref
Change-Id: I1156355d55b0f4cdde0044fb94e9c1b3ed15a3f2
---
M 
asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/base/RuleCollections.java
A 
asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/RemoveConstantOrderByExpressionsRule.java
A 
asterixdb/asterix-app/src/test/resources/optimizerts/queries/group-by/grouping-sets-empty-branch.sqlpp
A 
asterixdb/asterix-app/src/test/resources/optimizerts/queries/order-by/order-by-const-folded.sqlpp
A 
asterixdb/asterix-app/src/test/resources/optimizerts/queries/order-by/order-by-const-mixed.sqlpp
A 
asterixdb/asterix-app/src/test/resources/optimizerts/queries/order-by/order-by-const-single.sqlpp
A 
asterixdb/asterix-app/src/test/resources/optimizerts/queries/order-by/order-by-real-var.sqlpp
A 
asterixdb/asterix-app/src/test/resources/optimizerts/results/group-by/grouping-sets-empty-branch.plan
A 
asterixdb/asterix-app/src/test/resources/optimizerts/results/order-by/order-by-const-folded.plan
A 
asterixdb/asterix-app/src/test/resources/optimizerts/results/order-by/order-by-const-mixed.plan
A 
asterixdb/asterix-app/src/test/resources/optimizerts/results/order-by/order-by-const-single.plan
A 
asterixdb/asterix-app/src/test/resources/optimizerts/results/order-by/order-by-real-var.plan
12 files changed, 443 insertions(+), 0 deletions(-)



  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb 
refs/changes/93/21293/1

diff --git 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/base/RuleCollections.java
 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/base/RuleCollections.java
index 5defe14..5f2be32 100644
--- 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/base/RuleCollections.java
+++ 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/base/RuleCollections.java
@@ -83,6 +83,7 @@
 import org.apache.asterix.optimizer.rules.PushProperJoinThroughProduct;
 import org.apache.asterix.optimizer.rules.PushSimilarityFunctionsBelowJoin;
 import org.apache.asterix.optimizer.rules.PushValueAccessAndFilterDownRule;
+import org.apache.asterix.optimizer.rules.RemoveConstantOrderByExpressionsRule;
 import org.apache.asterix.optimizer.rules.RemoveDuplicateFieldsRule;
 import 
org.apache.asterix.optimizer.rules.RemoveLeftOuterUnnestForLeftOuterJoinRule;
 import org.apache.asterix.optimizer.rules.RemoveOrReplaceDefaultNullCastRule;
@@ -222,6 +223,10 @@
         normalization.add(new IntroduceEnforcedListTypeRule());
         // Perform constant folding before common expression extraction
         normalization.add(new ConstantFoldingRule(appCtx));
+        // Drop ORDER BY entries that fold to constants (e.g. `order by 4`, 
`order by 1+1`,
+        // `order by abs(-5)`). Must run AFTER ConstantFoldingRule so 
arithmetic / function
+        // calls on constants have been collapsed to ConstantExpressions.
+        normalization.add(new RemoveConstantOrderByExpressionsRule());
         normalization.add(new ExtractCommonExpressionsRule());

         // Let PushAggFuncIntoStandaloneAggregateRule run after 
ExtractCommonExpressionsRule
@@ -409,6 +414,9 @@
         physicalRewritesAllLevels.add(new 
AddEquivalenceClassForRecordConstructorRule());
         physicalRewritesAllLevels.add(new 
EnforceStructuralPropertiesRule(BuiltinFunctions.RANGE_MAP,
                 BuiltinFunctions.LOCAL_SAMPLING, 
BuiltinFunctions.NULL_WRITER));
+        // Strip sorts whose keys all fold to constants, including those just 
injected by
+        // EnforceStructuralPropertiesRule for GROUPING SETS branches with 
constant grouping keys.
+        physicalRewritesAllLevels.add(new 
RemoveConstantOrderByExpressionsRule());
         physicalRewritesAllLevels.add(new RemoveSortInFeedIngestionRule());
         physicalRewritesAllLevels.add(new 
RemoveUnnecessarySortMergeExchange());
         physicalRewritesAllLevels.add(new PushProjectDownRule());
diff --git 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/RemoveConstantOrderByExpressionsRule.java
 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/RemoveConstantOrderByExpressionsRule.java
new file mode 100644
index 0000000..ef1d13d
--- /dev/null
+++ 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/RemoveConstantOrderByExpressionsRule.java
@@ -0,0 +1,124 @@
+/*
+ * 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.
+ */
+package org.apache.asterix.optimizer.rules;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.commons.lang3.mutable.Mutable;
+import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
+import org.apache.hyracks.algebricks.common.utils.Pair;
+import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression;
+import org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator;
+import org.apache.hyracks.algebricks.core.algebra.base.IOptimizationContext;
+import org.apache.hyracks.algebricks.core.algebra.base.LogicalExpressionTag;
+import org.apache.hyracks.algebricks.core.algebra.base.LogicalOperatorTag;
+import org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable;
+import 
org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression;
+import 
org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator;
+import 
org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator;
+import 
org.apache.hyracks.algebricks.core.algebra.operators.logical.OrderOperator;
+import 
org.apache.hyracks.algebricks.core.algebra.operators.logical.OrderOperator.IOrder;
+import org.apache.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
+
+/**
+ * Drops ORDER BY expressions whose value is a compile-time constant
+ * (e.g. {@code order by 4}), since sorting on a constant never reorders
+ * tuples. If every sort key in an OrderOperator is constant the operator
+ * itself is removed.
+ *
+ * Runs after ConstantFoldingRule so folded expressions like {@code 1+3}
+ * are picked up as well.
+ */
+public class RemoveConstantOrderByExpressionsRule implements 
IAlgebraicRewriteRule {
+
+    @Override
+    public boolean rewritePre(Mutable<ILogicalOperator> opRef, 
IOptimizationContext context) {
+        return false;
+    }
+
+    @Override
+    public boolean rewritePost(Mutable<ILogicalOperator> opRef, 
IOptimizationContext context)
+            throws AlgebricksException {
+        AbstractLogicalOperator op = (AbstractLogicalOperator) 
opRef.getValue();
+        if (op.getOperatorTag() != LogicalOperatorTag.ORDER) {
+            return false;
+        }
+        if (context.checkIfInDontApplySet(this, op)) {
+            return false;
+        }
+        context.addToDontApplySet(this, op);
+
+        OrderOperator orderOp = (OrderOperator) op;
+        List<Pair<IOrder, Mutable<ILogicalExpression>>> orderExprs = 
orderOp.getOrderExpressions();
+
+        boolean changed = false;
+        Iterator<Pair<IOrder, Mutable<ILogicalExpression>>> it = 
orderExprs.iterator();
+        while (it.hasNext()) {
+            ILogicalExpression e = it.next().getSecond().getValue();
+            if (resolvesToConstant(e, orderOp)) {
+                it.remove();
+                changed = true;
+            }
+        }
+
+        if (!changed) {
+            return false;
+        }
+
+        if (orderExprs.isEmpty()) {
+            opRef.setValue(orderOp.getInputs().get(0).getValue());
+        }
+        return true;
+    }
+
+    /**
+     * Returns true if {@code expr} is a compile-time constant, either directly
+     * (CONSTANT tag) or as a VARIABLE bound to a CONSTANT by an upstream
+     * AssignOperator. ExtractOrderExpressionsRule extracts non-variable sort
+     * keys into assigns before this rule runs, so the var case is common.
+     */
+    private static boolean resolvesToConstant(ILogicalExpression expr, 
ILogicalOperator orderOp) {
+        if (expr.getExpressionTag() == LogicalExpressionTag.CONSTANT) {
+            return true;
+        }
+        if (expr.getExpressionTag() != LogicalExpressionTag.VARIABLE) {
+            return false;
+        }
+        LogicalVariable var = ((VariableReferenceExpression) 
expr).getVariableReference();
+        ILogicalOperator cur = orderOp.getInputs().get(0).getValue();
+        while (cur != null) {
+            if (cur.getOperatorTag() == LogicalOperatorTag.ASSIGN) {
+                AssignOperator assign = (AssignOperator) cur;
+                List<LogicalVariable> vars = assign.getVariables();
+                for (int i = 0; i < vars.size(); i++) {
+                    if (vars.get(i).equals(var)) {
+                        ILogicalExpression bound = 
assign.getExpressions().get(i).getValue();
+                        return bound.getExpressionTag() == 
LogicalExpressionTag.CONSTANT;
+                    }
+                }
+            }
+            if (cur.getInputs().isEmpty()) {
+                return false;
+            }
+            cur = cur.getInputs().get(0).getValue();
+        }
+        return false;
+    }
+}
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/group-by/grouping-sets-empty-branch.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/group-by/grouping-sets-empty-branch.sqlpp
new file mode 100644
index 0000000..ce39394
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/group-by/grouping-sets-empty-branch.sqlpp
@@ -0,0 +1,39 @@
+/*
+ * 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: GROUPING SETS with an empty grouping branch `()` expands into
+ *              a UNION ALL of GroupBy branches. 
EnforceStructuralPropertiesRule
+ *              injects a STABLE_SORT above the PRE_CLUSTERED_GROUP_BY for each
+ *              branch to satisfy local-order properties. In the `()` branch
+ *              the grouping key is constant, so the injected sort is wasted
+ *              work. RemoveConstantOrderByExpressionsRule, registered in
+ *              physicalRewritesAllLevels after ESPRule, must strip the
+ *              constant sort from the `()` branch while leaving the sort
+ *              on the `(id)` branch intact.
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use test;
+
+create type col1Type as { id: int };
+create dataset col1(col1Type) primary key id;
+
+select id from col1 group by grouping sets ((id), ());
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/order-by/order-by-const-folded.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/order-by/order-by-const-folded.sqlpp
new file mode 100644
index 0000000..2bed898
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/order-by/order-by-const-folded.sqlpp
@@ -0,0 +1,36 @@
+/*
+ * 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: An arithmetic expression that folds to a constant must also
+ *              be dropped from ORDER BY. Verifies that
+ *              RemoveConstantOrderByExpressionsRule runs after
+ *              ConstantFoldingRule so that `2 + 2` has already collapsed to
+ *              a ConstantExpression by the time this rule inspects the
+ *              OrderOperator.
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use test;
+
+create type col1Type as { id: int };
+create dataset col1(col1Type) primary key id;
+
+select * from col1 order by 2 + 2;
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/order-by/order-by-const-mixed.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/order-by/order-by-const-mixed.sqlpp
new file mode 100644
index 0000000..c0f9eed
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/order-by/order-by-const-mixed.sqlpp
@@ -0,0 +1,35 @@
+/*
+ * 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: When ORDER BY mixes a real variable with a constant, the
+ *              constant key must be dropped while the variable key is kept.
+ *              The OrderOperator stays in the plan but loses the constant
+ *              entry, so the resulting STABLE_SORT / SORT_MERGE_EXCHANGE
+ *              should reference only the `id` field.
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use test;
+
+create type col1Type as { id: int };
+create dataset col1(col1Type) primary key id;
+
+select * from col1 order by id, 4;
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/order-by/order-by-const-single.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/order-by/order-by-const-single.sqlpp
new file mode 100644
index 0000000..04fbb57
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/order-by/order-by-const-single.sqlpp
@@ -0,0 +1,35 @@
+/*
+ * 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: A constant ORDER BY key cannot reorder tuples, so the rule
+ *              RemoveConstantOrderByExpressionsRule must drop the sort key
+ *              entirely. The OrderOperator is unwrapped and no STABLE_SORT
+ *              or SORT_MERGE_EXCHANGE survives in the optimized plan.
+ *              Exercises the normalization-phase registration of the rule.
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use test;
+
+create type col1Type as { id: int };
+create dataset col1(col1Type) primary key id;
+
+select * from col1 order by 4;
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/order-by/order-by-real-var.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/order-by/order-by-real-var.sqlpp
new file mode 100644
index 0000000..a95d398
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/order-by/order-by-real-var.sqlpp
@@ -0,0 +1,34 @@
+/*
+ * 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: Guardrail - a real variable in ORDER BY must NOT be touched
+ *              by RemoveConstantOrderByExpressionsRule. The optimized plan
+ *              must still contain a STABLE_SORT and SORT_MERGE_EXCHANGE on
+ *              `id`.
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use test;
+
+create type col1Type as { id: int };
+create dataset col1(col1Type) primary key id;
+
+select * from col1 order by id;
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/results/group-by/grouping-sets-empty-branch.plan
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/results/group-by/grouping-sets-empty-branch.plan
new file mode 100644
index 0000000..e7f36de
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/optimizerts/results/group-by/grouping-sets-empty-branch.plan
@@ -0,0 +1,60 @@
+distribute result [$#2]
+-- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
+  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    union ($$129, $$130, $#2)
+    -- UNION_ALL  |PARTITIONED|
+      exchange
+      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        assign [$$129] <- [cast({"id": $$id})] project: [$$129]
+        -- ASSIGN  |PARTITIONED|
+          exchange
+          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            group by ([$$id := $$89]) decor ([]) {
+                      aggregate [] <- [] [cardinality: 0.0, doc-size: 0.0, 
op-cost: 0.0, total-cost: 0.0]
+                      -- AGGREGATE  |LOCAL|
+                        nested tuple source [cardinality: 0.0, doc-size: 0.0, 
op-cost: 0.0, total-cost: 0.0]
+                        -- NESTED_TUPLE_SOURCE  |LOCAL|
+                   }
+            -- SORT_GROUP_BY[$$89]  |PARTITIONED|
+              exchange
+              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$89])
+                -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
+                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    data-scan []<-[$$89, $$col1] <- test.col1
+                    -- DATASOURCE_SCAN  |PARTITIONED|
+                      exchange
+                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        empty-tuple-source
+                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+      exchange
+      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        assign [$$130] <- [cast({"id": $$id})] project: [$$130]
+        -- ASSIGN  |PARTITIONED|
+          project ([$$id])
+          -- STREAM_PROJECT  |PARTITIONED|
+            exchange
+            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              group by ([$$78 := $$88]) decor ([$$id := $$86]) {
+                        aggregate [] <- [] [cardinality: 0.0, doc-size: 0.0, 
op-cost: 0.0, total-cost: 0.0]
+                        -- AGGREGATE  |LOCAL|
+                          nested tuple source [cardinality: 0.0, doc-size: 
0.0, op-cost: 0.0, total-cost: 0.0]
+                          -- NESTED_TUPLE_SOURCE  |LOCAL|
+                     }
+              -- PRE_CLUSTERED_GROUP_BY[$$88]  |PARTITIONED|
+                exchange
+                -- HASH_PARTITION_EXCHANGE [$$88]  |PARTITIONED|
+                  assign [$$88, $$86] <- [true, null]
+                  -- ASSIGN  |PARTITIONED|
+                    project ([])
+                    -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
+                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        data-scan []<-[$$90, $$col1] <- test.col1
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
+                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
+                            -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/results/order-by/order-by-const-folded.plan
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/results/order-by/order-by-const-folded.plan
new file mode 100644
index 0000000..fda97ab
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/optimizerts/results/order-by/order-by-const-folded.plan
@@ -0,0 +1,16 @@
+distribute result [$$16]
+-- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
+  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    assign [$$16] <- [{"col1": $$col1}] project: [$$16]
+    -- ASSIGN  |PARTITIONED|
+      project ([$$col1])
+      -- STREAM_PROJECT  |PARTITIONED|
+        exchange
+        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          data-scan []<-[$$19, $$col1] <- test.col1
+          -- DATASOURCE_SCAN  |PARTITIONED|
+            exchange
+            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              empty-tuple-source
+              -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/results/order-by/order-by-const-mixed.plan
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/results/order-by/order-by-const-mixed.plan
new file mode 100644
index 0000000..07f45af
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/optimizerts/results/order-by/order-by-const-mixed.plan
@@ -0,0 +1,20 @@
+distribute result [$$16]
+-- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
+  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    assign [$$16] <- [{"col1": $$col1}] project: [$$16]
+    -- ASSIGN  |PARTITIONED|
+      project ([$$col1])
+      -- STREAM_PROJECT  |PARTITIONED|
+        exchange
+        -- SORT_MERGE_EXCHANGE [$$19(ASC) ]  |PARTITIONED|
+          order (ASC, $$19)
+          -- STABLE_SORT [$$19(ASC)]  |PARTITIONED|
+            exchange
+            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              data-scan []<-[$$19, $$col1] <- test.col1
+              -- DATASOURCE_SCAN  |PARTITIONED|
+                exchange
+                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  empty-tuple-source
+                  -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/results/order-by/order-by-const-single.plan
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/results/order-by/order-by-const-single.plan
new file mode 100644
index 0000000..9ec0d62
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/optimizerts/results/order-by/order-by-const-single.plan
@@ -0,0 +1,16 @@
+distribute result [$$16]
+-- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
+  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    assign [$$16] <- [{"col1": $$col1}] project: [$$16]
+    -- ASSIGN  |PARTITIONED|
+      project ([$$col1])
+      -- STREAM_PROJECT  |PARTITIONED|
+        exchange
+        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          data-scan []<-[$$18, $$col1] <- test.col1
+          -- DATASOURCE_SCAN  |PARTITIONED|
+            exchange
+            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              empty-tuple-source
+              -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/results/order-by/order-by-real-var.plan
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/results/order-by/order-by-real-var.plan
new file mode 100644
index 0000000..81ded83
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/optimizerts/results/order-by/order-by-real-var.plan
@@ -0,0 +1,20 @@
+distribute result [$$16]
+-- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
+  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    assign [$$16] <- [{"col1": $$col1}] project: [$$16]
+    -- ASSIGN  |PARTITIONED|
+      project ([$$col1])
+      -- STREAM_PROJECT  |PARTITIONED|
+        exchange
+        -- SORT_MERGE_EXCHANGE [$$18(ASC) ]  |PARTITIONED|
+          order (ASC, $$18)
+          -- STABLE_SORT [$$18(ASC)]  |PARTITIONED|
+            exchange
+            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              data-scan []<-[$$18, $$col1] <- test.col1
+              -- DATASOURCE_SCAN  |PARTITIONED|
+                exchange
+                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  empty-tuple-source
+                  -- EMPTY_TUPLE_SOURCE  |PARTITIONED|

--
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21293?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: I1156355d55b0f4cdde0044fb94e9c1b3ed15a3f2
Gerrit-Change-Number: 21293
Gerrit-PatchSet: 1
Gerrit-Owner: Rithwik Koul <[email protected]>

Reply via email to