Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
Signed-off-by: Lloyd-Pottiger <yan1579196623@gmail.com>
  • Loading branch information
Lloyd-Pottiger committed Oct 26, 2022
1 parent 452969a commit f68b3d1
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 11 deletions.
6 changes: 3 additions & 3 deletions dbms/src/Flash/Planner/optimize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
3 changes: 3 additions & 0 deletions dbms/src/Flash/Planner/plans/PhysicalTableScan.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
59 changes: 51 additions & 8 deletions tests/fullstack-test/expr/count_const_not_null.test
Original file line number Diff line number Diff line change
Expand Up @@ -18,63 +18,106 @@ 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
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 |
+----------+

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 |
+----------+

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

0 comments on commit f68b3d1

Please sign in to comment.