Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: append table stats #4561

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/table/src/table/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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 |
+-------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

21 changes: 21 additions & 0 deletions tests/cases/distributed/explain/analyze_append_table_count.sql
Original file line number Diff line number Diff line change
@@ -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;