Files
greptimedb/tests/cases/standalone/common/aggregate/empty_region_stats.sql
T
dennis zhuang ef1298ce02 fix(query): accept narrowed nullability in MergeScan remote schema check (#9592)
On append-mode tables a region reports an exact row count. When it is
zero, DataFusion's AggregateStatistics replaces the region-side
__min_state/__max_state aggregate with a non-null struct literal, so the
remote stream advertises the state column as non-nullable. The MergeScan
schema check required equal nullability and failed the query.

Accept a remote field that is non-nullable where the expected field is
nullable, matching DataFusion's own physical-plan schema invariant.
Batches are already rebuilt with the expected schema. Widening is still
rejected, and nested field nullability is still compared exactly as part
of the data type.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-10-15 03:28:25 +00:00

43 lines
1.1 KiB
SQL

-- Append-mode regions report exact row counts, so the datanode can answer
-- count/min/max over a region from statistics. This only happens when every
-- aggregate in the query can be answered that way.
CREATE TABLE a1 (ts TIMESTAMP(9) TIME INDEX, k STRING, v BIGINT)
PARTITION ON COLUMNS (k) (k < 'b', k >= 'b' AND k < 'c', k >= 'c')
WITH (append_mode = 'true');
-- All regions are empty.
SELECT min(v), max(v) FROM a1;
SELECT count(*), count(v) FROM a1;
INSERT INTO a1 VALUES (1000, 'a', 1), (2000, 'a', 2);
-- Two of three regions are empty.
SELECT min(v) FROM a1;
SELECT max(v) FROM a1;
SELECT min(ts), max(k) FROM a1;
SELECT count(*), count(v) FROM a1;
SELECT min(v), count(*) FROM a1;
SELECT sum(v), avg(v) FROM a1;
SELECT k, min(v), max(v), count(*) FROM a1 GROUP BY k ORDER BY k;
INSERT INTO a1 VALUES (3000, 'b', 3);
-- One of three regions is empty.
SELECT min(v), max(v) FROM a1;
SELECT k, min(v), max(v), count(*) FROM a1 GROUP BY k ORDER BY k;
INSERT INTO a1 VALUES (4000, 'c', 4);
-- No region is empty.
SELECT min(v), max(v), count(*) FROM a1;
DROP TABLE a1;