fix last row cache

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
This commit is contained in:
Ruihang Xia
2026-03-20 01:53:03 +08:00
parent 733f406e42
commit b3ba1c5914
3 changed files with 87 additions and 0 deletions

View File

@@ -515,6 +515,13 @@ impl FlatRowGroupLastRowReader {
if self.yielded_batches.is_empty() {
return;
}
// Filtered flat last-row scans only contain the subset of series that matched the
// encoded primary-key prefilter, so they cannot be published under the shared
// selector cache key.
if self.primary_key_filter.is_some() {
return;
}
let batches = std::mem::take(&mut self.yielded_batches);
let value = Arc::new(SelectorResultValue::new_flat(
batches,

View File

@@ -0,0 +1,53 @@
CREATE TABLE last_row_selector_cache_filter (
host STRING,
cpu DOUBLE,
ts TIMESTAMP TIME INDEX,
PRIMARY KEY (host)
) WITH ('sst_format' = 'flat');
Affected Rows: 0
INSERT INTO last_row_selector_cache_filter VALUES
('a', 1.0, 1000),
('a', 2.0, 2000),
('b', 3.0, 1000),
('b', 4.0, 2000);
Affected Rows: 4
ADMIN FLUSH_TABLE('last_row_selector_cache_filter');
+-----------------------------------------------------+
| ADMIN FLUSH_TABLE('last_row_selector_cache_filter') |
+-----------------------------------------------------+
| 0 |
+-----------------------------------------------------+
SELECT host, last_value(cpu ORDER BY ts) AS last_cpu
FROM last_row_selector_cache_filter
WHERE host = 'a'
GROUP BY host
ORDER BY host;
+------+----------+
| host | last_cpu |
+------+----------+
| a | 2.0 |
+------+----------+
SELECT host, last_value(cpu ORDER BY ts) AS last_cpu
FROM last_row_selector_cache_filter
GROUP BY host
ORDER BY host;
+------+----------+
| host | last_cpu |
+------+----------+
| a | 2.0 |
| b | 4.0 |
+------+----------+
DROP TABLE last_row_selector_cache_filter;
Affected Rows: 0

View File

@@ -0,0 +1,27 @@
CREATE TABLE last_row_selector_cache_filter (
host STRING,
cpu DOUBLE,
ts TIMESTAMP TIME INDEX,
PRIMARY KEY (host)
) WITH ('sst_format' = 'flat');
INSERT INTO last_row_selector_cache_filter VALUES
('a', 1.0, 1000),
('a', 2.0, 2000),
('b', 3.0, 1000),
('b', 4.0, 2000);
ADMIN FLUSH_TABLE('last_row_selector_cache_filter');
SELECT host, last_value(cpu ORDER BY ts) AS last_cpu
FROM last_row_selector_cache_filter
WHERE host = 'a'
GROUP BY host
ORDER BY host;
SELECT host, last_value(cpu ORDER BY ts) AS last_cpu
FROM last_row_selector_cache_filter
GROUP BY host
ORDER BY host;
DROP TABLE last_row_selector_cache_filter;