mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-11-26 12:44:10 +00:00
perf(mito2): prune files by their primary key range before reading footers (#10564)
* perf(mito2): prune files by their primary key range before reading footers File-level pruning used only the manifest time range, so a scan read the footer of every file in the time range even when the file's primary key range excludes the predicate. The file-level pruning statistics now include the min and max of the first primary key column, decoded from FileMeta's primary key range, so such files are skipped without a footer read. For metric engine physical regions the first column is the table id. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * test(mito2): cover file pruning by primary key range end to end Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * perf(mito2): decode the file primary key range only when pruning uses it Predicates on the time index or fields never ask for the first primary key column, so they no longer build a codec and two arrays per file. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * fix(mito2): prune files by primary key ranges loaded from footers Region open can fill a file handle's key range from the SST footer when the manifest has none. Let the handle decide whether bounds are known, so those files are pruned too. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * test: check file pruning by primary key range with EXPLAIN ANALYZE Signed-off-by: Dennis Zhuang <killme2008@gmail.com> --------- Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
This commit is contained in:
@@ -65,3 +65,52 @@ SELECT host FROM test_time_filter WHERE greptime_timestamp > '2026-01-07 00:00:0
|
||||
SELECT host, greptime_timestamp FROM test_time_filter WHERE greptime_timestamp > '2026-01-07 00:00:00';
|
||||
|
||||
DROP TABLE test_time_filter;
|
||||
|
||||
-- Files whose primary key range excludes the predicate are pruned before reading them.
|
||||
CREATE TABLE pk_range_prune(ts TIMESTAMP TIME INDEX, val DOUBLE, host STRING, idc STRING, PRIMARY KEY(host, idc));
|
||||
|
||||
INSERT INTO pk_range_prune VALUES (1, 1, 'a', 'idc1'), (2, 2, 'b', 'idc2');
|
||||
|
||||
ADMIN flush_table('pk_range_prune');
|
||||
|
||||
INSERT INTO pk_range_prune VALUES (1, 3, 'c', 'idc1'), (2, 4, 'd', 'idc2');
|
||||
|
||||
ADMIN flush_table('pk_range_prune');
|
||||
|
||||
-- SQLNESS REPLACE (?s)^.*("files_time_range_pruned":\d+).*$ $1
|
||||
EXPLAIN ANALYZE VERBOSE SELECT * FROM pk_range_prune WHERE host = 'c';
|
||||
|
||||
SELECT * FROM pk_range_prune WHERE host = 'c';
|
||||
|
||||
SELECT * FROM pk_range_prune WHERE host >= 'b' ORDER BY host;
|
||||
|
||||
SELECT * FROM pk_range_prune WHERE host < 'b';
|
||||
|
||||
DROP TABLE pk_range_prune;
|
||||
|
||||
CREATE TABLE pk_range_phy (ts TIMESTAMP TIME INDEX, val DOUBLE) ENGINE = metric WITH ("physical_metric_table" = "");
|
||||
|
||||
CREATE TABLE pk_range_t1 (ts TIMESTAMP TIME INDEX, val DOUBLE, host STRING PRIMARY KEY) ENGINE = metric WITH ("on_physical_table" = "pk_range_phy");
|
||||
|
||||
CREATE TABLE pk_range_t2 (ts TIMESTAMP TIME INDEX, val DOUBLE, job STRING PRIMARY KEY) ENGINE = metric WITH ("on_physical_table" = "pk_range_phy");
|
||||
|
||||
INSERT INTO pk_range_t1 VALUES ('host1', 0, 1), ('host2', 1, 2);
|
||||
|
||||
ADMIN flush_table('pk_range_phy');
|
||||
|
||||
INSERT INTO pk_range_t2 VALUES ('job1', 0, 3), ('job2', 1, 4);
|
||||
|
||||
ADMIN flush_table('pk_range_phy');
|
||||
|
||||
-- SQLNESS REPLACE (?s)^.*("files_time_range_pruned":\d+).*$ $1
|
||||
EXPLAIN ANALYZE VERBOSE SELECT * FROM pk_range_t1;
|
||||
|
||||
SELECT * FROM pk_range_t1 ORDER BY host;
|
||||
|
||||
SELECT * FROM pk_range_t2 ORDER BY job;
|
||||
|
||||
DROP TABLE pk_range_t1;
|
||||
|
||||
DROP TABLE pk_range_t2;
|
||||
|
||||
DROP TABLE pk_range_phy;
|
||||
|
||||
Reference in New Issue
Block a user