You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by jo...@apache.org on 2018/12/10 23:44:00 UTC

[3/8] impala git commit: IMPALA-7659: Populate NULL count while computing column stats

IMPALA-7659: Populate NULL count while computing column stats

It was disabled for performance reasons (IMPALA-1003) and this patch
re-enables it since a lot of codegen improvements have happened since
then.

This patch switches the aggregation to use the CASE conditional instead
of IF since the former has proper codegen support (IMPALA-7655).

Tests:
=====

- Updated the affected tests to include the null counts.
- Added unit tests that verify IS [NOT] NULL predicates' cardinality
  estimation.

Perf note:
=========

I reran the compute stats child query with null counts included on the
store_sales table from 1000 SF (1TB) tpcds dataset. The table had 22
non-partitioned columns (on which null counts were computed) and ~2.8B
rows. This experiment showed around 7-8% perf drop compared to the same
child query without null counts for these columns.

Change-Id: Ic68f8b4c3756eb1980ce299a602a7d56db1e507a
Reviewed-on: http://gerrit.cloudera.org:8080/11565
Reviewed-by: Impala Public Jenkins <im...@cloudera.com>
Tested-by: Impala Public Jenkins <im...@cloudera.com>


Project: http://git-wip-us.apache.org/repos/asf/impala/repo
Commit: http://git-wip-us.apache.org/repos/asf/impala/commit/04d027df
Tree: http://git-wip-us.apache.org/repos/asf/impala/tree/04d027df
Diff: http://git-wip-us.apache.org/repos/asf/impala/diff/04d027df

Branch: refs/heads/master
Commit: 04d027df13e1c3c5c654b5a0bc965b670483b535
Parents: d8792c2
Author: Bharath Vissapragada <bh...@cloudera.com>
Authored: Tue Oct 2 22:48:56 2018 +0200
Committer: Impala Public Jenkins <im...@cloudera.com>
Committed: Sat Dec 8 00:21:55 2018 +0000

----------------------------------------------------------------------
 .../impala/analysis/ComputeStatsStmt.java       |   18 +-
 .../impala/catalog/PartialCatalogInfoTest.java  |    2 +-
 .../impala/catalog/local/LocalCatalogTest.java  |    2 +-
 .../apache/impala/planner/CardinalityTest.java  |    6 +
 .../queries/PlannerTest/subquery-rewrite.test   |   30 +-
 .../QueryTest/alter-table-set-column-stats.test |   18 +-
 .../queries/QueryTest/alter-table.test          |    6 +-
 .../QueryTest/compute-stats-decimal.test        |   16 +-
 .../QueryTest/compute-stats-incremental.test    |   11 +-
 .../QueryTest/compute-stats-keywords.test       |    2 +-
 .../queries/QueryTest/compute-stats.test        | 2375 +++++++++---------
 .../hbase-compute-stats-incremental.test        |   28 +-
 .../queries/QueryTest/hbase-compute-stats.test  |   60 +-
 .../queries/QueryTest/show-stats.test           |   25 +-
 14 files changed, 1295 insertions(+), 1304 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/impala/blob/04d027df/fe/src/main/java/org/apache/impala/analysis/ComputeStatsStmt.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/analysis/ComputeStatsStmt.java b/fe/src/main/java/org/apache/impala/analysis/ComputeStatsStmt.java
index 24e9d27..32f6f55 100644
--- a/fe/src/main/java/org/apache/impala/analysis/ComputeStatsStmt.java
+++ b/fe/src/main/java/org/apache/impala/analysis/ComputeStatsStmt.java
@@ -141,10 +141,6 @@ public class ComputeStatsStmt extends StatementBase {
   // We run the regular COMPUTE STATS for 0.0 and 1.0 where sampling has no benefit.
   protected double effectiveSamplePerc_ = -1;
 
-  // The Null count is not currently being used in optimization or run-time,
-  // and compute stats runs 2x faster in many cases when not counting NULLs.
-  private static final boolean COUNT_NULLS = false;
-
   // Query for getting the per-partition row count and the total row count.
   // Set during analysis.
   protected String tableStatsQueryStr_;
@@ -266,17 +262,9 @@ public class ComputeStatsStmt extends StatementBase {
         columnStatsSelectList.add("NDV(" + colRefSql + ") AS " + colRefSql);
       }
 
-      if (COUNT_NULLS) {
-        // Count the number of NULL values.
-        columnStatsSelectList.add("COUNT(IF(" + colRefSql + " IS NULL, 1, NULL))");
-      } else {
-        // Using -1 to indicate "unknown". We need cast to BIGINT because backend expects
-        // an i64Val as the number of NULLs returned by the COMPUTE STATS column stats
-        // child query. See CatalogOpExecutor::SetColumnStats(). If we do not cast, then
-        // the -1 will be treated as TINYINT resulting a 0 to be placed in the #NULLs
-        // column (see IMPALA-1068).
-        columnStatsSelectList.add("CAST(-1 as BIGINT)");
-      }
+      // Count the number of NULL values.
+      columnStatsSelectList.add("COUNT(CASE WHEN " + colRefSql +
+          " IS NULL THEN 1 ELSE NULL END)");
 
       // For STRING columns also compute the max and avg string length.
       Type type = c.getType();

http://git-wip-us.apache.org/repos/asf/impala/blob/04d027df/fe/src/test/java/org/apache/impala/catalog/PartialCatalogInfoTest.java
----------------------------------------------------------------------
diff --git a/fe/src/test/java/org/apache/impala/catalog/PartialCatalogInfoTest.java b/fe/src/test/java/org/apache/impala/catalog/PartialCatalogInfoTest.java
index 92fff65..6241523 100644
--- a/fe/src/test/java/org/apache/impala/catalog/PartialCatalogInfoTest.java
+++ b/fe/src/test/java/org/apache/impala/catalog/PartialCatalogInfoTest.java
@@ -197,7 +197,7 @@ public class PartialCatalogInfoTest {
     assertEquals(11, stats.size());
     assertEquals("ColumnStatisticsObj(colName:id, colType:INT, " +
         "statsData:<ColumnStatisticsData longStats:LongColumnStatsData(" +
-        "numNulls:-1, numDVs:7300)>)", stats.get(0).toString());
+        "numNulls:0, numDVs:7300)>)", stats.get(0).toString());
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/impala/blob/04d027df/fe/src/test/java/org/apache/impala/catalog/local/LocalCatalogTest.java
----------------------------------------------------------------------
diff --git a/fe/src/test/java/org/apache/impala/catalog/local/LocalCatalogTest.java b/fe/src/test/java/org/apache/impala/catalog/local/LocalCatalogTest.java
index acef882..a07d354 100644
--- a/fe/src/test/java/org/apache/impala/catalog/local/LocalCatalogTest.java
+++ b/fe/src/test/java/org/apache/impala/catalog/local/LocalCatalogTest.java
@@ -192,7 +192,7 @@ public class LocalCatalogTest {
     // Verify expected stats for timestamp.
     stats = t.getColumn("timestamp_col").getStats();
     assertEquals(10210, stats.getNumDistinctValues());
-    assertEquals(-1, stats.getNumNulls());
+    assertEquals(0, stats.getNumNulls());
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/impala/blob/04d027df/fe/src/test/java/org/apache/impala/planner/CardinalityTest.java
----------------------------------------------------------------------
diff --git a/fe/src/test/java/org/apache/impala/planner/CardinalityTest.java b/fe/src/test/java/org/apache/impala/planner/CardinalityTest.java
index d6ccfb6..da59860 100644
--- a/fe/src/test/java/org/apache/impala/planner/CardinalityTest.java
+++ b/fe/src/test/java/org/apache/impala/planner/CardinalityTest.java
@@ -78,6 +78,12 @@ public class CardinalityTest extends PlannerTestBase {
     verifyCardinality(
         "SELECT id FROM functional.alltypes WHERE nullvalue(int_col)", 730);
 
+    // IMPALA-7695: IS [NOT] NULL predicates should factor in null count.
+    verifyCardinality(
+        "select id from functional.alltypesagg where tinyint_col IS NULL", 2000);
+    verifyCardinality(
+        "select id from functional.alltypesagg where tinyint_col IS NOT NULL", 9000);
+
     // Grouping should reduce cardinality
     verifyCardinality(
         "SELECT COUNT(*) FROM functional.alltypes GROUP BY int_col", 10);

http://git-wip-us.apache.org/repos/asf/impala/blob/04d027df/testdata/workloads/functional-planner/queries/PlannerTest/subquery-rewrite.test
----------------------------------------------------------------------
diff --git a/testdata/workloads/functional-planner/queries/PlannerTest/subquery-rewrite.test b/testdata/workloads/functional-planner/queries/PlannerTest/subquery-rewrite.test
index 7404491..1e59828 100644
--- a/testdata/workloads/functional-planner/queries/PlannerTest/subquery-rewrite.test
+++ b/testdata/workloads/functional-planner/queries/PlannerTest/subquery-rewrite.test
@@ -1331,23 +1331,23 @@ and t.bool_col = false
 ---- PLAN
 PLAN-ROOT SINK
 |
-03:HASH JOIN [RIGHT SEMI JOIN]
-|  hash predicates: g.id = t.id
-|  runtime filters: RF000 <- t.id
-|
-|--00:SCAN HDFS [functional.alltypestiny t]
-|     partitions=4/4 files=4 size=460B
-|     predicates: t.bool_col = FALSE
+03:HASH JOIN [LEFT SEMI JOIN]
+|  hash predicates: t.id = g.id
+|  runtime filters: RF000 <- g.id
 |
-02:AGGREGATE [FINALIZE]
-|  output: max(int_col)
-|  group by: g.id
-|  having: max(int_col) IS NULL
+|--02:AGGREGATE [FINALIZE]
+|  |  output: max(int_col)
+|  |  group by: g.id
+|  |  having: max(int_col) IS NULL
+|  |
+|  01:SCAN HDFS [functional.alltypesagg g]
+|     partitions=11/11 files=11 size=814.73KB
+|     predicates: g.int_col IS NULL
 |
-01:SCAN HDFS [functional.alltypesagg g]
-   partitions=11/11 files=11 size=814.73KB
-   predicates: g.int_col IS NULL
-   runtime filters: RF000 -> g.id
+00:SCAN HDFS [functional.alltypestiny t]
+   partitions=4/4 files=4 size=460B
+   predicates: t.bool_col = FALSE
+   runtime filters: RF000 -> t.id
 ====
 # Complex expr with a scalar subquery
 select *

http://git-wip-us.apache.org/repos/asf/impala/blob/04d027df/testdata/workloads/functional-query/queries/QueryTest/alter-table-set-column-stats.test
----------------------------------------------------------------------
diff --git a/testdata/workloads/functional-query/queries/QueryTest/alter-table-set-column-stats.test b/testdata/workloads/functional-query/queries/QueryTest/alter-table-set-column-stats.test
index cd6593d..c18e56a 100644
--- a/testdata/workloads/functional-query/queries/QueryTest/alter-table-set-column-stats.test
+++ b/testdata/workloads/functional-query/queries/QueryTest/alter-table-set-column-stats.test
@@ -52,16 +52,16 @@ show column stats alltypes_clone
 ---- LABELS
 COLUMN, TYPE, #DISTINCT VALUES, #NULLS, MAX SIZE, AVG SIZE
 ---- RESULTS
-'id','INT',7300,-1,4,4
-'bool_col','BOOLEAN',2,-1,1,1
-'tinyint_col','TINYINT',10,-1,1,1
-'smallint_col','SMALLINT',10,-1,2,2
+'id','INT',7300,0,4,4
+'bool_col','BOOLEAN',2,0,1,1
+'tinyint_col','TINYINT',10,0,1,1
+'smallint_col','SMALLINT',10,0,2,2
 'int_col','INT',-1,-1,4,4
-'bigint_col','BIGINT',10,-1,8,8
-'float_col','FLOAT',10,-1,4,4
-'double_col','DOUBLE',-1,-1,8,8
-'date_string_col','STRING',736,-1,8,8
-'string_col','STRING',10,-1,-1,-1
+'bigint_col','BIGINT',10,0,8,8
+'float_col','FLOAT',10,0,4,4
+'double_col','DOUBLE',-1,0,8,8
+'date_string_col','STRING',736,0,8,8
+'string_col','STRING',10,0,-1,-1
 'timestamp_col','TIMESTAMP',7300,-1,16,16
 'year','INT',2,0,4,4
 'month','INT',12,0,4,4

http://git-wip-us.apache.org/repos/asf/impala/blob/04d027df/testdata/workloads/functional-query/queries/QueryTest/alter-table.test
----------------------------------------------------------------------
diff --git a/testdata/workloads/functional-query/queries/QueryTest/alter-table.test b/testdata/workloads/functional-query/queries/QueryTest/alter-table.test
index 013b8a9..e6332d6 100644
--- a/testdata/workloads/functional-query/queries/QueryTest/alter-table.test
+++ b/testdata/workloads/functional-query/queries/QueryTest/alter-table.test
@@ -820,8 +820,8 @@ BIGINT, BIGINT, STRING, STRING, STRING, STRING, STRING, STRING
 ---- QUERY
 show column stats $DATABASE2.mv2
 ---- RESULTS
-'x','INT',2,-1,4,4
-'y','STRING',2,-1,1,1
+'x','INT',2,1,4,4
+'y','STRING',2,1,1,1
 ---- TYPES
 STRING, STRING, BIGINT, BIGINT, BIGINT, DOUBLE
 ====
@@ -875,7 +875,7 @@ STRING, BIGINT, BIGINT, STRING, STRING, STRING, STRING, STRING, STRING
 ---- QUERY
 show column stats $DATABASE2.mv2
 ---- RESULTS: VERIFY_IS_EQUAL_SORTED
-'x','INT',2,-1,4,4
+'x','INT',2,1,4,4
 'y','STRING',3,1,-1,-1
 ---- TYPES
 STRING, STRING, BIGINT, BIGINT, BIGINT, DOUBLE

http://git-wip-us.apache.org/repos/asf/impala/blob/04d027df/testdata/workloads/functional-query/queries/QueryTest/compute-stats-decimal.test
----------------------------------------------------------------------
diff --git a/testdata/workloads/functional-query/queries/QueryTest/compute-stats-decimal.test b/testdata/workloads/functional-query/queries/QueryTest/compute-stats-decimal.test
index a302601..e43ffea 100644
--- a/testdata/workloads/functional-query/queries/QueryTest/compute-stats-decimal.test
+++ b/testdata/workloads/functional-query/queries/QueryTest/compute-stats-decimal.test
@@ -25,11 +25,11 @@ show column stats decimal_tbl
 ---- LABELS
 COLUMN, TYPE, #DISTINCT VALUES, #NULLS, MAX SIZE, AVG SIZE
 ---- RESULTS
-'d1','DECIMAL(9,0)',4,-1,4,4
-'d2','DECIMAL(10,0)',3,-1,8,8
-'d3','DECIMAL(20,10)',5,-1,16,16
-'d4','DECIMAL(38,38)',1,-1,16,16
-'d5','DECIMAL(10,5)',5,-1,8,8
+'d1','DECIMAL(9,0)',4,0,4,4
+'d2','DECIMAL(10,0)',3,0,8,8
+'d3','DECIMAL(20,10)',5,0,16,16
+'d4','DECIMAL(38,38)',1,0,16,16
+'d5','DECIMAL(10,5)',5,0,8,8
 'd6','DECIMAL(9,0)',1,0,4,4
 ---- TYPES
 STRING, STRING, BIGINT, BIGINT, BIGINT, DOUBLE
@@ -58,8 +58,8 @@ show column stats mixed_types
 ---- LABELS
 COLUMN, TYPE, #DISTINCT VALUES, #NULLS, MAX SIZE, AVG SIZE
 ---- RESULTS
-'a','INT',2,-1,4,4
-'b','DECIMAL(10,0)',2,-1,8,8
+'a','INT',2,0,4,4
+'b','DECIMAL(10,0)',2,0,8,8
 ---- TYPES
 STRING, STRING, BIGINT, BIGINT, BIGINT, DOUBLE
-====
+====
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/impala/blob/04d027df/testdata/workloads/functional-query/queries/QueryTest/compute-stats-incremental.test
----------------------------------------------------------------------
diff --git a/testdata/workloads/functional-query/queries/QueryTest/compute-stats-incremental.test b/testdata/workloads/functional-query/queries/QueryTest/compute-stats-incremental.test
index 50eb24d..064c23a 100644
--- a/testdata/workloads/functional-query/queries/QueryTest/compute-stats-incremental.test
+++ b/testdata/workloads/functional-query/queries/QueryTest/compute-stats-incremental.test
@@ -495,7 +495,6 @@ show table stats incremental_not_partitioned;
 ---- TYPES
 BIGINT, BIGINT, STRING, STRING, STRING, STRING, STRING, STRING
 ====
-====
 ---- QUERY
 # IMPALA-1629: Verify that the column stats for CHAR/VARCHAR columns are populated.
 # The values of date_string_col always have exactly 8 characters. The CHAR/VARCHAR
@@ -577,11 +576,11 @@ show column stats chars_tbl
 ---- LABELS
 COLUMN, TYPE, #DISTINCT VALUES, #NULLS, MAX SIZE, AVG SIZE
 ---- RESULTS
-'id','INT',2915,-1,4,4
+'id','INT',2915,0,4,4
 'ch1','CHAR(1)',2,-1,1,1
 'ch2','CHAR(8)',11,-1,8,7.99766731262207
 'ch3','CHAR(20)',11,-1,8,7.99766731262207
-'ts','TIMESTAMP',2871,-1,16,16
+'ts','TIMESTAMP',2871,0,16,16
 'vc1','VARCHAR(1)',2,-1,1,1
 'vc2','VARCHAR(8)',11,-1,8,7.99766731262207
 'vc3','VARCHAR(20)',11,-1,8,7.99766731262207
@@ -608,10 +607,10 @@ STRING
 ---- QUERY
 # The table was not changed. Validate that the next compute incremental stats is a no-op.
 compute incremental stats complextypestbl_part;
----- RESULTS
-'No partitions selected for incremental stats update.'
 ---- ERRORS
 No partitions selected for incremental stats update
+---- RESULTS
+'No partitions selected for incremental stats update.'
 ====
 ---- QUERY
 # Add a new partition and check that only stats for the new partition are computed.
@@ -622,4 +621,4 @@ compute incremental stats complextypestbl_part;
 'Updated 1 partition(s) and 1 column(s).'
 ---- TYPES
 STRING
-====
+====
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/impala/blob/04d027df/testdata/workloads/functional-query/queries/QueryTest/compute-stats-keywords.test
----------------------------------------------------------------------
diff --git a/testdata/workloads/functional-query/queries/QueryTest/compute-stats-keywords.test b/testdata/workloads/functional-query/queries/QueryTest/compute-stats-keywords.test
index a58e7c5..eef249c 100644
--- a/testdata/workloads/functional-query/queries/QueryTest/compute-stats-keywords.test
+++ b/testdata/workloads/functional-query/queries/QueryTest/compute-stats-keywords.test
@@ -12,4 +12,4 @@ COMPUTE STATS `parquet`.`parquet`
 'Updated 1 partition(s) and 1 column(s).'
 ---- TYPES
 STRING
-====
+====
\ No newline at end of file