Repository: calcite Updated Branches: refs/heads/master 83fedf32f -> 352aaeade
[CALCITE-1019] RelMdUtil.checkInputForCollationAndLimit() was wrong with alreadySorted check Project: http://git-wip-us.apache.org/repos/asf/calcite/repo Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/352aaead Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/352aaead Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/352aaead Branch: refs/heads/master Commit: 352aaeade9c9b1d99710009e0509cfe8ddfdb698 Parents: 83fedf3 Author: maryannxue <[email protected]> Authored: Fri Dec 11 15:09:51 2015 -0500 Committer: maryannxue <[email protected]> Committed: Fri Dec 11 15:09:51 2015 -0500 ---------------------------------------------------------------------- .../java/org/apache/calcite/rel/metadata/RelMdUtil.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/calcite/blob/352aaead/core/src/main/java/org/apache/calcite/rel/metadata/RelMdUtil.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdUtil.java b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdUtil.java index d9ea2a2..dc1ea3e 100644 --- a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdUtil.java +++ b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdUtil.java @@ -18,7 +18,6 @@ package org.apache.calcite.rel.metadata; import org.apache.calcite.plan.RelOptUtil; import org.apache.calcite.rel.RelCollation; -import org.apache.calcite.rel.RelCollations; import org.apache.calcite.rel.RelNode; import org.apache.calcite.rel.core.Aggregate; import org.apache.calcite.rel.core.AggregateCall; @@ -809,10 +808,15 @@ public class RelMdUtil { public static boolean checkInputForCollationAndLimit(RelNode input, RelCollation collation, RexNode offset, RexNode fetch) { // Check if the input is already sorted - ImmutableList<RelCollation> inputCollation = + ImmutableList<RelCollation> inputCollations = RelMetadataQuery.collations(input); - final boolean alreadySorted = RelCollations.equal( - ImmutableList.of(collation), inputCollation); + boolean alreadySorted = false; + for (RelCollation inputCollation : inputCollations) { + if (inputCollation.satisfies(collation)) { + alreadySorted = true; + break; + } + } // Check if we are not reducing the number of tuples boolean alreadySmaller = true; final Double rowCount = RelMetadataQuery.getMaxRowCount(input);
