From f68b3d163f2aff914104e0d4a31e34b1113380b2 Mon Sep 17 00:00:00 2001 From: Lloyd-Pottiger Date: Wed, 26 Oct 2022 20:11:22 +0800 Subject: [PATCH] add more tests Signed-off-by: Lloyd-Pottiger --- dbms/src/Flash/Planner/optimize.cpp | 6 +- .../Flash/Planner/plans/PhysicalTableScan.h | 3 + .../expr/count_const_not_null.test | 59 ++++++++++++++++--- 3 files changed, 57 insertions(+), 11 deletions(-) diff --git a/dbms/src/Flash/Planner/optimize.cpp b/dbms/src/Flash/Planner/optimize.cpp index fb1e797c971..3c4bde3705c 100644 --- a/dbms/src/Flash/Planner/optimize.cpp +++ b/dbms/src/Flash/Planner/optimize.cpp @@ -63,9 +63,9 @@ class RewriteCountStarRule : public Rule if (aggr_descs[0].function->getName() != "count" && aggr_descs[0].argument_names.empty()) return plan; } - // if all the aggregators are `count()`, then the columns to read must be the handle_column - // so we do not need to do any check here - // just rewrite the table scan to read the delmark_column instead of handle_column + // if table scan will read handle_column + // rewrite the table scan by handle_column with replace delmark_column + // else do nothing auto table_scan_nodes = DB::PhysicalPlanVisitor::getTableScanNodes(plan); for (auto & table_scan_node : table_scan_nodes) { diff --git a/dbms/src/Flash/Planner/plans/PhysicalTableScan.h b/dbms/src/Flash/Planner/plans/PhysicalTableScan.h index b4ca4cb74b8..3ecbbf8a267 100644 --- a/dbms/src/Flash/Planner/plans/PhysicalTableScan.h +++ b/dbms/src/Flash/Planner/plans/PhysicalTableScan.h @@ -42,6 +42,9 @@ class PhysicalTableScan : public PhysicalLeaf void replaceColumnToRead(const String & src_name, const String & dst_name, const DataTypePtr & dst_type) { + // Actually, we should rewirte the `tidb_table_scan`, and then re-generate the schema and block. + // But the `columns` in `tidb_table_scan` come from TiDB where may does not aware of the `dst_name`, like `delmark_column`. + // so we just replace the name and type in the schema and block. for (auto & item : schema) { if (item.name == src_name) diff --git a/tests/fullstack-test/expr/count_const_not_null.test b/tests/fullstack-test/expr/count_const_not_null.test index f6fd7bdb986..e8a60ebc154 100644 --- a/tests/fullstack-test/expr/count_const_not_null.test +++ b/tests/fullstack-test/expr/count_const_not_null.test @@ -18,11 +18,11 @@ mysql> drop table if exists test.t3 # is_common_handle == true -mysql> CREATE TABLE t1 (a VARCHAR(255) NOT NULL PRIMARY KEY CLUSTERED) +mysql> CREATE TABLE t1 (a VARCHAR(255) NOT NULL PRIMARY KEY CLUSTERED, b INT) # is_common_handle == false && pk_is_handle == true -mysql> CREATE TABLE t2 (a BIGINT NOT NULL PRIMARY KEY) +mysql> CREATE TABLE t2 (a BIGINT NOT NULL PRIMARY KEY, b INT) # is_common_handle == false && pk_is_handle == false -mysql> CREATE TABLE t3 (a INT NOT NULL PRIMARY KEY NONCLUSTERED) +mysql> CREATE TABLE t3 (a INT NOT NULL PRIMARY KEY NONCLUSTERED, b INT) mysql> alter table test.t1 set tiflash replica 1 @@ -30,24 +30,41 @@ mysql> alter table test.t2 set tiflash replica 1 mysql> alter table test.t3 set tiflash replica 1 -mysql> insert into test.t1 values('-123') -mysql> insert into test.t2 values(123) -mysql> insert into test.t3 values(123) +mysql> insert into test.t1 values('-123', 0) +mysql> insert into test.t1 values('-124', 1) +mysql> insert into test.t2 values(123, 0) +mysql> insert into test.t2 values(124, 1) +mysql> insert into test.t3 values(123, 0) +mysql> insert into test.t3 values(124, 1) -func> wait_table test t +func> wait_table test t1 +func> wait_table test t2 +func> wait_table test t3 mysql> set @@tidb_isolation_read_engines='tiflash'; select count(*) from test.t1 +----------+ | count(*) | +----------+ +| 2 | ++----------+ +mysql> set @@tidb_isolation_read_engines='tiflash'; select count(*) from test.t1 where b = 1; ++----------+ +| count(*) | ++----------+ | 1 | +----------+ mysql> set @@tidb_isolation_read_engines='tiflash'; select count(a) from test.t1 +----------+ | count(a) | +----------+ +| 2 | ++----------+ +mysql> set @@tidb_isolation_read_engines='tiflash'; select count(a) from test.t1 where b = 1; ++----------+ +| count(a) | ++----------+ | 1 | +----------+ @@ -55,12 +72,24 @@ mysql> set @@tidb_isolation_read_engines='tiflash'; select count(*) from test.t2 +----------+ | count(*) | +----------+ +| 2 | ++----------+ +mysql> set @@tidb_isolation_read_engines='tiflash'; select count(*) from test.t2 where b = 1; ++----------+ +| count(*) | ++----------+ | 1 | +----------+ mysql> set @@tidb_isolation_read_engines='tiflash'; select count(a) from test.t2 +----------+ | count(a) | +----------+ +| 2 | ++----------+ +mysql> set @@tidb_isolation_read_engines='tiflash'; select count(a) from test.t2 where b = 1; ++----------+ +| count(*) | ++----------+ | 1 | +----------+ @@ -68,13 +97,27 @@ mysql> set @@tidb_isolation_read_engines='tiflash'; select count(*) from test.t3 +----------+ | count(*) | +----------+ +| 2 | ++----------+ +mysql> set @@tidb_isolation_read_engines='tiflash'; select count(*) from test.t3 where b = 1; ++----------+ +| count(*) | ++----------+ | 1 | +----------+ mysql> set @@tidb_isolation_read_engines='tiflash'; select count(a) from test.t3 +----------+ | count(a) | +----------+ +| 2 | ++----------+ +mysql> set @@tidb_isolation_read_engines='tiflash'; select count(*) from test.t3 where b = 1; ++----------+ +| count(*) | ++----------+ | 1 | +----------+ -mysql> drop table if exists test.t +mysql> drop table if exists test.t1 +mysql> drop table if exists test.t2 +mysql> drop table if exists test.t3