From c1b1be47ba4a3b43a0d96141fb73f9cfb16ecc5e Mon Sep 17 00:00:00 2001 From: "Lei, HUANG" <6406592+v0y4g3r@users.noreply.github.com> Date: Wed, 14 Aug 2024 17:01:42 +0800 Subject: [PATCH] fix: append table stats (#4561) * fix: append table stats * fix: clippy --- src/table/src/table/scan.rs | 1 + .../explain/analyze_append_table_count.result | 34 +++++++++++++++++++ .../explain/analyze_append_table_count.sql | 21 ++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 tests/cases/distributed/explain/analyze_append_table_count.result create mode 100644 tests/cases/distributed/explain/analyze_append_table_count.sql diff --git a/src/table/src/table/scan.rs b/src/table/src/table/scan.rs index c7d4fe98a2..83c348d6d9 100644 --- a/src/table/src/table/scan.rs +++ b/src/table/src/table/scan.rs @@ -168,6 +168,7 @@ impl ExecutionPlan for RegionScanExec { .iter() .map(|_| ColumnStatistics { distinct_count: Precision::Exact(self.total_rows), + null_count: Precision::Exact(0), // all null rows are counted for append-only table ..Default::default() }) .collect(); diff --git a/tests/cases/distributed/explain/analyze_append_table_count.result b/tests/cases/distributed/explain/analyze_append_table_count.result new file mode 100644 index 0000000000..7a2a1603f2 --- /dev/null +++ b/tests/cases/distributed/explain/analyze_append_table_count.result @@ -0,0 +1,34 @@ +CREATE TABLE IF NOT EXISTS `test_table` ( + `bytes` BIGINT NULL, + `http_version` STRING NULL, + `ip` STRING NULL, + `method` STRING NULL, + `path` STRING NULL, + `status` SMALLINT UNSIGNED NULL, + `user` STRING NULL, + `timestamp` TIMESTAMP(3) NOT NULL, + TIME INDEX (`timestamp`), + PRIMARY KEY (`user`, `path`, `status`) +) +ENGINE=mito +WITH( + append_mode = 'true' +); + +Affected Rows: 0 + +-- SQLNESS REPLACE (metrics.*) REDACTED +-- SQLNESS REPLACE (peers.*) REDACTED +EXPLAIN ANALYZE SELECT count(*) FROM test_table; + ++-------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| stage | node | plan | ++-------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| 0 | 0 | MergeScanExec: REDACTED +| | | | +| 1 | 0 | ProjectionExec: expr=[0 as COUNT(test_table.timestamp)] REDACTED +| | | common_recordbatch::adapter::MetricCollector REDACTED +| | | | +| | | Total rows: 1 | ++-------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ + diff --git a/tests/cases/distributed/explain/analyze_append_table_count.sql b/tests/cases/distributed/explain/analyze_append_table_count.sql new file mode 100644 index 0000000000..fedf18dfa8 --- /dev/null +++ b/tests/cases/distributed/explain/analyze_append_table_count.sql @@ -0,0 +1,21 @@ +CREATE TABLE IF NOT EXISTS `test_table` ( + `bytes` BIGINT NULL, + `http_version` STRING NULL, + `ip` STRING NULL, + `method` STRING NULL, + `path` STRING NULL, + `status` SMALLINT UNSIGNED NULL, + `user` STRING NULL, + `timestamp` TIMESTAMP(3) NOT NULL, + TIME INDEX (`timestamp`), + PRIMARY KEY (`user`, `path`, `status`) +) + +ENGINE=mito +WITH( + append_mode = 'true' +); + +-- SQLNESS REPLACE (metrics.*) REDACTED +-- SQLNESS REPLACE (peers.*) REDACTED +EXPLAIN ANALYZE SELECT count(*) FROM test_table;