calcite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jcama...@apache.org
Subject [22/50] [abbrv] calcite git commit: [CALCITE-938] More accurate rowCount for Aggregate applied to already unique keys (Maryann Xue)
Date Wed, 11 Nov 2015 12:25:28 GMT
[CALCITE-938] More accurate rowCount for Aggregate applied to already unique keys (Maryann
Xue)


Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/52b06213
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/52b06213
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/52b06213

Branch: refs/heads/branch-release
Commit: 52b06213d02ff3fce981b1c23ab545029b5d4767
Parents: 6f326d0
Author: maryannxue <wei.xue@intel.com>
Authored: Mon Oct 26 12:56:41 2015 -0700
Committer: Julian Hyde <jhyde@apache.org>
Committed: Mon Oct 26 12:56:41 2015 -0700

----------------------------------------------------------------------
 .../rel/metadata/RelMdColumnUniqueness.java     | 41 +++-----------------
 .../calcite/rel/metadata/RelMdRowCount.java     |  2 +-
 core/src/test/resources/sql/agg.oq              | 34 ++++++++++++++++
 3 files changed, 40 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/52b06213/core/src/main/java/org/apache/calcite/rel/metadata/RelMdColumnUniqueness.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdColumnUniqueness.java
b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdColumnUniqueness.java
index f627774..2a6431d 100644
--- a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdColumnUniqueness.java
+++ b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdColumnUniqueness.java
@@ -366,46 +366,15 @@ public class RelMdColumnUniqueness {
   }
 
   public Boolean areColumnsUnique(
-      boolean dummy, // prevent method from being used
       RelSubset rel,
       ImmutableBitSet columns,
       boolean ignoreNulls) {
-    int nullCount = 0;
-    for (RelNode rel2 : rel.getRels()) {
-      if (rel2 instanceof Aggregate || simplyProjects(rel2, columns)) {
-        final Boolean unique =
-            RelMetadataQuery.areColumnsUnique(rel2, columns, ignoreNulls);
-        if (unique != null) {
-          if (unique) {
-            return true;
-          }
-        } else {
-          ++nullCount;
-        }
-      }
-    }
-    return nullCount == 0 ? false : null;
-  }
-
-  private boolean simplyProjects(RelNode rel, ImmutableBitSet columns) {
-    if (!(rel instanceof Project)) {
-      return false;
-    }
-    Project project = (Project) rel;
-    final List<RexNode> projects = project.getProjects();
-    for (int column : columns) {
-      if (column >= projects.size()) {
-        return false;
-      }
-      if (!(projects.get(column) instanceof RexInputRef)) {
-        return false;
-      }
-      final RexInputRef ref = (RexInputRef) projects.get(column);
-      if (ref.getIndex() != column) {
-        return false;
-      }
+    final RelNode best = rel.getBest();
+    if (best == null) {
+      return null;
+    } else {
+      return RelMetadataQuery.areColumnsUnique(best, columns, ignoreNulls);
     }
-    return true;
   }
 
   /** Aggregate and Calc are "safe" children of a RelSubset to delve into. */

http://git-wip-us.apache.org/repos/asf/calcite/blob/52b06213/core/src/main/java/org/apache/calcite/rel/metadata/RelMdRowCount.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdRowCount.java b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdRowCount.java
index cc90395..2d7beaf 100644
--- a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdRowCount.java
+++ b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdRowCount.java
@@ -94,7 +94,7 @@ public class RelMdRowCount {
   }
 
   public Double getRowCount(Aggregate rel) {
-    ImmutableBitSet groupKey = ImmutableBitSet.range(rel.getGroupCount());
+    ImmutableBitSet groupKey = rel.getGroupSet();
 
     // rowcount is the cardinality of the group by columns
     Double distinctRowCount =

http://git-wip-us.apache.org/repos/asf/calcite/blob/52b06213/core/src/test/resources/sql/agg.oq
----------------------------------------------------------------------
diff --git a/core/src/test/resources/sql/agg.oq b/core/src/test/resources/sql/agg.oq
index 3787ac2..e92f08d 100644
--- a/core/src/test/resources/sql/agg.oq
+++ b/core/src/test/resources/sql/agg.oq
@@ -1209,6 +1209,40 @@ order by sum_cnt;
 
 !ok
 
+# [CALCITE-938] Aggregate row count
+select empno, d.deptno
+from "scott".emp
+join (select distinct deptno from "scott".dept) d
+using (deptno);
++-------+--------+
+| EMPNO | DEPTNO |
++-------+--------+
+|  7369 |     20 |
+|  7499 |     30 |
+|  7521 |     30 |
+|  7566 |     20 |
+|  7654 |     30 |
+|  7698 |     30 |
+|  7782 |     10 |
+|  7788 |     20 |
+|  7839 |     10 |
+|  7844 |     30 |
+|  7876 |     20 |
+|  7900 |     30 |
+|  7902 |     20 |
+|  7934 |     10 |
++-------+--------+
+(14 rows)
+
+!ok
+EnumerableCalc(expr#0..2=[{inputs}], EMPNO=[$t1], DEPTNO=[$t0])
+  EnumerableJoin(condition=[=($0, $2)], joinType=[inner])
+    EnumerableCalc(expr#0..2=[{inputs}], DEPTNO=[$t0])
+      EnumerableTableScan(table=[[scott, DEPT]])
+    EnumerableCalc(expr#0..7=[{inputs}], EMPNO=[$t0], DEPTNO=[$t7])
+      EnumerableTableScan(table=[[scott, EMP]])
+!plan
+
 # [CALCITE-729] IndexOutOfBoundsException in ROLLUP query on JDBC data source
 !use jdbc_scott
 select deptno, job, count(*) as c


Mime
View raw message