Files
greptimedb/tests/cases/distributed/information_schema/ssts_limit.result
T
Weny Xu d750d25965 perf: push down COUNT and SUM for SST manifest queries (#9949)
* feat: execute logical plans through distributed inspection

Signed-off-by: WenyXu <wenymedia@gmail.com>

* perf: push down SST manifest scalar aggregates

Signed-off-by: WenyXu <wenymedia@gmail.com>

* docs: remove redundant SST manifest inspection guide

Signed-off-by: WenyXu <wenymedia@gmail.com>

* perf: generalize SST manifest aggregate pushdown

Signed-off-by: WenyXu <wenymedia@gmail.com>

* fix: retain frontend aggregation for unsupported inspection states

Signed-off-by: WenyXu <wenymedia@gmail.com>

* fix: expose remote SST aggregate plans in EXPLAIN

Signed-off-by: WenyXu <wenymedia@gmail.com>

* test: normalize SST analyzer in TQL explain snapshots

Signed-off-by: WenyXu <wenymedia@gmail.com>

* fix: guard SST predicate types before remote inspection

Signed-off-by: WenyXu <wenymedia@gmail.com>

---------

Signed-off-by: WenyXu <wenymedia@gmail.com>
2026-11-05 02:37:00 +00:00

479 lines
85 KiB
Plaintext

CREATE TABLE ssts_limit_case (
a INT PRIMARY KEY INVERTED INDEX,
b STRING SKIPPING INDEX,
c STRING FULLTEXT INDEX,
ts TIMESTAMP TIME INDEX,
)
PARTITION ON COLUMNS (a) (
a < 1000,
a >= 1000 AND a < 2000,
a >= 2000
);
Affected Rows: 0
INSERT INTO ssts_limit_case VALUES
(500, 'a', 'a', 1),
(1500, 'b', 'b', 2),
(2500, 'c', 'c', 3);
Affected Rows: 3
ADMIN FLUSH_TABLE('ssts_limit_case');
+--------------------------------------+
| ADMIN FLUSH_TABLE('ssts_limit_case') |
+--------------------------------------+
| 0 |
+--------------------------------------+
SELECT COUNT(DISTINCT node_id) > 1 AS has_multi_datanodes
FROM information_schema.ssts_manifest;
+---------------------+
| has_multi_datanodes |
+---------------------+
| true |
+---------------------+
SELECT COUNT(*) AS limited_rows
FROM (
SELECT region_id
FROM information_schema.ssts_manifest
LIMIT 1
);
+--------------+
| limited_rows |
+--------------+
| 1 |
+--------------+
SELECT COUNT(*) AS filtered_limited_rows
FROM (
SELECT region_id
FROM information_schema.ssts_manifest
WHERE region_id > 0
LIMIT 1
);
+-----------------------+
| filtered_limited_rows |
+-----------------------+
| 1 |
+-----------------------+
-- SQLNESS REPLACE (RepartitionExec:.*) RepartitionExec: REDACTED
EXPLAIN SELECT COUNT(*) AS filtered_limited_rows
FROM (
SELECT region_id
FROM information_schema.ssts_manifest
WHERE table_id > 0
LIMIT 1
);
+---------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| plan_type | plan |
+---------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| logical_plan | MergeScan [is_placeholder=false, remote_input=[ |
| | Projection: count(Int64(1)) AS count(*) AS filtered_limited_rows |
| | Aggregate: groupBy=[[]], aggr=[[count(Int64(1))]] |
| | Limit: skip=0, fetch=1 |
| | Projection: information_schema.ssts_manifest.region_id |
| | Filter: information_schema.ssts_manifest.table_id > UInt32(0) |
| | TableScan: information_schema.ssts_manifest, partial_filters=[information_schema.ssts_manifest.table_id > UInt32(0)] |
| | ]] |
| physical_plan | ProjectionExec: expr=[count(Int64(1))@0 as filtered_limited_rows] |
| | AggregateExec: mode=Final, gby=[], aggr=[count(Int64(1))] |
| | CoalescePartitionsExec |
| | AggregateExec: mode=Partial, gby=[], aggr=[count(Int64(1))] |
| | RepartitionExec: REDACTED
| | CoalescePartitionsExec: fetch=1 |
| | FilterExec: table_id@0 > 0, projection=[], fetch=1 |
| | RepartitionExec: REDACTED
| | DistributedInspectExec: kind=SstManifest, scan=ScanRequest { projection: [2], filters: [table_id > UInt32(0)] }, schema=Schema { fields: [Field { name: "table_id", data_type: UInt32 }], metadata: {"greptime:version": "0"} } |
| | |
+---------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
-- The frontend orders results from all datanodes before applying the global offset.
SELECT min_ts, max_ts
FROM information_schema.ssts_manifest
WHERE region_id > 0
ORDER BY min_ts DESC
LIMIT 2 OFFSET 1;
+-------------------------+-------------------------+
| min_ts | max_ts |
+-------------------------+-------------------------+
| 1970-01-01T00:00:00.002 | 1970-01-01T00:00:00.002 |
| 1970-01-01T00:00:00.001 | 1970-01-01T00:00:00.001 |
+-------------------------+-------------------------+
-- SQLNESS REPLACE (RepartitionExec:.*) RepartitionExec: REDACTED
EXPLAIN SELECT min_ts
FROM information_schema.ssts_manifest
WHERE region_id > 0
ORDER BY min_ts DESC
LIMIT 1;
+---------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| plan_type | plan |
+---------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| logical_plan | MergeScan [is_placeholder=false, remote_input=[ |
| | Limit: skip=0, fetch=1 |
| | Sort: information_schema.ssts_manifest.min_ts DESC NULLS FIRST |
| | Projection: information_schema.ssts_manifest.min_ts |
| | Filter: information_schema.ssts_manifest.region_id > UInt64(0) |
| | TableScan: information_schema.ssts_manifest, partial_filters=[information_schema.ssts_manifest.region_id > UInt64(0)] |
| | ]] |
| physical_plan | SortPreservingMergeExec: [min_ts@0 DESC], fetch=1 |
| | SortExec: TopK(fetch=1), expr=[min_ts@0 DESC], preserve_partitioning=[true] |
| | FilterExec: region_id@0 > 0, projection=[min_ts@1] |
| | RepartitionExec: REDACTED
| | DistributedInspectExec: kind=SstManifest, scan=ScanRequest { projection: [1, 16], filters: [region_id > UInt64(0)] }, schema=Schema { fields: [Field { name: "region_id", data_type: UInt64 }, Field { name: "min_ts", data_type: Timestamp(Nanosecond, None), nullable: true }], metadata: {"greptime:version": "0"} } |
| | |
+---------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
-- Timestamp filtering happens before global ordering and offset. The sort key
-- must remain available even when it is absent from the output projection.
SELECT max_ts
FROM information_schema.ssts_manifest
WHERE region_id > 0 AND min_ts >= '1970-01-01T00:00:00.002Z'::TIMESTAMP_NS
ORDER BY min_ts DESC
LIMIT 1 OFFSET 1;
+-------------------------+
| max_ts |
+-------------------------+
| 1970-01-01T00:00:00.002 |
+-------------------------+
-- Each datanode contributes aggregate states; the frontend merges them.
-- SQLNESS REPLACE (RepartitionExec:.*) RepartitionExec: REDACTED
EXPLAIN SELECT COUNT(*) AS files, COUNT(1) AS files_one, SUM(file_size) AS bytes,
COUNT(*) FILTER (WHERE file_size >= 1) AS nonempty_files,
SUM(file_size) FILTER (WHERE file_size = 0) AS zero_bytes
FROM information_schema.ssts_manifest
WHERE table_id > 0 AND region_id > 0
AND min_ts >= '1970-01-01T00:00:00.002Z'::TIMESTAMP_NS
AND max_ts < '1970-01-01T00:00:00.004Z'::TIMESTAMP_NS;
+---------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| plan_type | plan |
+---------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| logical_plan | Projection: count(Int64(1)) AS count(*) AS files, count(Int64(1)) AS files_one, sum(information_schema.ssts_manifest.file_size) AS bytes, count(Int64(1)) FILTER (WHERE information_schema.ssts_manifest.file_size >= Int64(1)) AS count(*) FILTER (WHERE information_schema.ssts_manifest.file_size >= Int64(1)) AS nonempty_files, sum(information_schema.ssts_manifest.file_size) FILTER (WHERE information_schema.ssts_manifest.file_size = Int64(0)) AS zero_bytes |
| | Aggregate: groupBy=[[]], aggr=[[__count_merge(__count_state(Int64(1))) AS count(Int64(1)), __sum_merge(__sum_state(information_schema.ssts_manifest.file_size)) AS sum(information_schema.ssts_manifest.file_size), __count_merge(__count_state(Int64(1)) FILTER (WHERE CAST(information_schema.ssts_manifest.file_size AS Decimal128(20, 0)) >= CAST(Int64(1) AS Decimal128(20, 0)))) AS count(Int64(1)) FILTER (WHERE information_schema.ssts_manifest.file_size >= Int64(1)), __sum_merge(__sum_state(information_schema.ssts_manifest.file_size) FILTER (WHERE CAST(information_schema.ssts_manifest.file_size AS Decimal128(20, 0)) = CAST(Int64(0) AS Decimal128(20, 0)))) AS sum(information_schema.ssts_manifest.file_size) FILTER (WHERE information_schema.ssts_manifest.file_size = Int64(0))]] |
| | SstManifestAggregate: Aggregate: groupBy=[[]], aggr=[[__count_state(Int64(1)), __sum_state(information_schema.ssts_manifest.file_size), __count_state(Int64(1)) FILTER (WHERE CAST(information_schema.ssts_manifest.file_size AS Decimal128(20, 0)) >= CAST(Int64(1) AS Decimal128(20, 0))), __sum_state(information_schema.ssts_manifest.file_size) FILTER (WHERE CAST(information_schema.ssts_manifest.file_size AS Decimal128(20, 0)) = CAST(Int64(0) AS Decimal128(20, 0)))]] |
| | Filter: information_schema.ssts_manifest.table_id > UInt32(0) AND CAST(information_schema.ssts_manifest.region_id AS Decimal128(20, 0)) > CAST(Int64(0) AS Decimal128(20, 0)) AND information_schema.ssts_manifest.min_ts >= arrow_cast(Utf8("1970-01-01T00:00:00.002Z"), Utf8("Timestamp(ns)")) AND information_schema.ssts_manifest.max_ts < arrow_cast(Utf8("1970-01-01T00:00:00.004Z"), Utf8("Timestamp(ns)")) |
| | SubqueryAlias: information_schema.ssts_manifest |
| | TableScan: __inspect/__mito/__sst_manifest |
| physical_plan | ProjectionExec: expr=[count(Int64(1))@0 as files, count(Int64(1))@0 as files_one, sum(information_schema.ssts_manifest.file_size)@1 as bytes, count(Int64(1)) FILTER (WHERE information_schema.ssts_manifest.file_size >= Int64(1))@2 as nonempty_files, sum(information_schema.ssts_manifest.file_size) FILTER (WHERE information_schema.ssts_manifest.file_size = Int64(0))@3 as zero_bytes] |
| | AggregateExec: mode=Final, gby=[], aggr=[__count_merge(__count_state(Int64(1))) as count(Int64(1)), __sum_merge(__sum_state(information_schema.ssts_manifest.file_size)) as sum(information_schema.ssts_manifest.file_size), __count_merge(__count_state(Int64(1)) FILTER (WHERE CAST(information_schema.ssts_manifest.file_size AS Decimal128(20, 0)) >= CAST(Int64(1) AS Decimal128(20, 0)))) as count(Int64(1)) FILTER (WHERE information_schema.ssts_manifest.file_size >= Int64(1)), __sum_merge(__sum_state(information_schema.ssts_manifest.file_size) FILTER (WHERE CAST(information_schema.ssts_manifest.file_size AS Decimal128(20, 0)) = CAST(Int64(0) AS Decimal128(20, 0)))) as sum(information_schema.ssts_manifest.file_size) FILTER (WHERE information_schema.ssts_manifest.file_size = Int64(0))] |
| | CoalescePartitionsExec |
| | AggregateExec: mode=Partial, gby=[], aggr=[__count_merge(__count_state(Int64(1))) as count(Int64(1)), __sum_merge(__sum_state(information_schema.ssts_manifest.file_size)) as sum(information_schema.ssts_manifest.file_size), __count_merge(__count_state(Int64(1)) FILTER (WHERE CAST(information_schema.ssts_manifest.file_size AS Decimal128(20, 0)) >= CAST(Int64(1) AS Decimal128(20, 0)))) as count(Int64(1)) FILTER (WHERE information_schema.ssts_manifest.file_size >= Int64(1)), __sum_merge(__sum_state(information_schema.ssts_manifest.file_size) FILTER (WHERE CAST(information_schema.ssts_manifest.file_size AS Decimal128(20, 0)) = CAST(Int64(0) AS Decimal128(20, 0)))) as sum(information_schema.ssts_manifest.file_size) FILTER (WHERE information_schema.ssts_manifest.file_size = Int64(0))] |
| | RepartitionExec: REDACTED
| | DistributedInspectExec: query=Aggregate: groupBy=[[]], aggr=[[__count_state(Int64(1)), __sum_state(information_schema.ssts_manifest.file_size), __count_state(Int64(1)) FILTER (WHERE CAST(information_schema.ssts_manifest.file_size AS Decimal128(20, 0)) >= CAST(Int64(1) AS Decimal128(20, 0))), __sum_state(information_schema.ssts_manifest.file_size) FILTER (WHERE CAST(information_schema.ssts_manifest.file_size AS Decimal128(20, 0)) = CAST(Int64(0) AS Decimal128(20, 0)))]] |
| | Filter: information_schema.ssts_manifest.table_id > UInt32(0) AND CAST(information_schema.ssts_manifest.region_id AS Decimal128(20, 0)) > CAST(Int64(0) AS Decimal128(20, 0)) AND information_schema.ssts_manifest.min_ts >= arrow_cast(Utf8("1970-01-01T00:00:00.002Z"), Utf8("Timestamp(ns)")) AND information_schema.ssts_manifest.max_ts < arrow_cast(Utf8("1970-01-01T00:00:00.004Z"), Utf8("Timestamp(ns)")) |
| | SubqueryAlias: information_schema.ssts_manifest |
| | TableScan: __inspect/__mito/__sst_manifest, schema=Schema { fields: [Field { name: "__count_state(Int64(1))", data_type: Struct([Field { name: "count[count]", data_type: Int64, nullable: true }]) }, Field { name: "__sum_state(information_schema.ssts_manifest.file_size)", data_type: Struct([Field { name: "sum[sum]", data_type: UInt64, nullable: true }]), nullable: true }, Field { name: "__count_state(Int64(1)) FILTER (WHERE CAST(information_schema.ssts_manifest.file_size AS Decimal128(20, 0)) >= CAST(Int64(1) AS Decimal128(20, 0)))", data_type: Struct([Field { name: "count[count]", data_type: Int64, nullable: true }]) }, Field { name: "__sum_state(information_schema.ssts_manifest.file_size) FILTER (WHERE CAST(information_schema.ssts_manifest.file_size AS Decimal128(20, 0)) = CAST(Int64(0) AS Decimal128(20, 0)))", data_type: Struct([Field { name: "sum[sum]", data_type: UInt64, nullable: true }]), nullable: true }], metadata: {"greptime:version": "0"} } |
| | |
+---------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
-- Compare exact byte totals with a limited-input query that must not push
-- aggregation through its global limit. The limit exceeds this fixture's size.
WITH pushed AS (
SELECT COUNT(*) AS files, COUNT(1) AS files_one, SUM(file_size) AS bytes,
COUNT(*) FILTER (WHERE file_size >= 1) AS nonempty_files,
SUM(file_size) FILTER (WHERE file_size >= 1) AS nonempty_bytes,
COUNT(*) FILTER (WHERE file_size = 0) AS zero_files,
SUM(file_size) FILTER (WHERE file_size = 0) AS zero_bytes
FROM information_schema.ssts_manifest
WHERE table_id > 0 AND region_id > 0
AND min_ts >= '1970-01-01T00:00:00.002Z'::TIMESTAMP_NS
AND max_ts < '1970-01-01T00:00:00.004Z'::TIMESTAMP_NS
), fallback AS (
SELECT COUNT(*) AS files, SUM(file_size) AS bytes
FROM (
SELECT file_size FROM information_schema.ssts_manifest
WHERE table_id > 0 AND region_id > 0
AND min_ts >= '1970-01-01T00:00:00.002Z'::TIMESTAMP_NS
AND max_ts < '1970-01-01T00:00:00.004Z'::TIMESTAMP_NS
LIMIT 1000
)
)
SELECT pushed.files, pushed.files_one, pushed.nonempty_files, pushed.zero_files,
pushed.files = fallback.files AS same_count,
pushed.bytes = fallback.bytes AS same_bytes,
pushed.nonempty_bytes = fallback.bytes AS same_filtered_bytes,
pushed.zero_bytes IS NULL AS empty_filtered_sum
FROM pushed CROSS JOIN fallback;
+-------+-----------+----------------+------------+------------+------------+---------------------+--------------------+
| files | files_one | nonempty_files | zero_files | same_count | same_bytes | same_filtered_bytes | empty_filtered_sum |
+-------+-----------+----------------+------------+------------+------------+---------------------+--------------------+
| 2 | 2 | 2 | 0 | true | true | true | true |
+-------+-----------+----------------+------------+------------+------------+---------------------+--------------------+
-- All nodes have empty input: COUNT returns zero, while SUM remains NULL.
SELECT COUNT(*) AS files, COUNT(1) AS files_one, SUM(file_size) AS bytes,
COUNT(*) FILTER (WHERE file_size >= 1) AS nonempty_files,
SUM(file_size) FILTER (WHERE file_size >= 1) AS nonempty_bytes
FROM information_schema.ssts_manifest WHERE region_id = 0;
+-------+-----------+-------+----------------+----------------+
| files | files_one | bytes | nonempty_files | nonempty_bytes |
+-------+-----------+-------+----------------+----------------+
| 0 | 0 | | 0 | |
+-------+-----------+-------+----------------+----------------+
-- SQLNESS REPLACE (RepartitionExec:.*) RepartitionExec: REDACTED
EXPLAIN SELECT COUNT(*), SUM(file_size)
FROM (SELECT file_size FROM information_schema.ssts_manifest LIMIT 1);
+---------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| plan_type | plan |
+---------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| logical_plan | MergeScan [is_placeholder=false, remote_input=[ |
| | Projection: count(Int64(1)) AS count(*), sum(information_schema.ssts_manifest.file_size) |
| | Aggregate: groupBy=[[]], aggr=[[count(Int64(1)), sum(information_schema.ssts_manifest.file_size)]] |
| | Limit: skip=0, fetch=1 |
| | Projection: information_schema.ssts_manifest.file_size |
| | TableScan: information_schema.ssts_manifest |
| | ]] |
| physical_plan | ProjectionExec: expr=[count(Int64(1))@0 as count(*), sum(information_schema.ssts_manifest.file_size)@1 as sum(information_schema.ssts_manifest.file_size)] |
| | AggregateExec: mode=Final, gby=[], aggr=[count(Int64(1)), sum(information_schema.ssts_manifest.file_size)] |
| | CoalescePartitionsExec |
| | AggregateExec: mode=Partial, gby=[], aggr=[count(Int64(1)), sum(information_schema.ssts_manifest.file_size)] |
| | RepartitionExec: REDACTED
| | GlobalLimitExec: skip=0, fetch=1 |
| | DistributedInspectExec: kind=SstManifest, scan=ScanRequest { projection: [10], limit: 1 }, schema=Schema { fields: [Field { name: "file_size", data_type: UInt64 }], metadata: {"greptime:version": "0"} } |
| | |
+---------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
SELECT COUNT(*) AS files, SUM(file_size) > 0 AS has_bytes
FROM (SELECT file_size FROM information_schema.ssts_manifest LIMIT 1);
+-------+-----------+
| files | has_bytes |
+-------+-----------+
| 1 | true |
+-------+-----------+
-- Other aggregate shapes retain ordinary query execution.
SELECT level, COUNT(*) AS files, SUM(file_size) > 0 AS has_bytes
FROM information_schema.ssts_manifest GROUP BY level ORDER BY level;
+-------+-------+-----------+
| level | files | has_bytes |
+-------+-------+-----------+
| 0 | 3 | true |
+-------+-------+-----------+
SELECT COUNT(DISTINCT region_id) AS distinct_regions,
SUM(file_size + 1) = SUM(file_size) + COUNT(*) AS complex_input_matches
FROM information_schema.ssts_manifest;
+------------------+-----------------------+
| distinct_regions | complex_input_matches |
+------------------+-----------------------+
| 3 | true |
+------------------+-----------------------+
-- Non-file-size columns and general aggregate filters use the same state merge.
-- SQLNESS REPLACE (RepartitionExec:.*) RepartitionExec: REDACTED
EXPLAIN SELECT COUNT(file_id), SUM(num_rows), SUM(level), SUM(table_id),
SUM(CAST(num_row_groups AS DOUBLE)), SUM(CAST(max_row_group_uncompressed_size AS DECIMAL(20, 0))),
COUNT(index_file_size), SUM(index_file_size),
COUNT(*) FILTER (WHERE visible AND level = 0)
FROM information_schema.ssts_manifest WHERE region_id > 0;
+---------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| plan_type | plan |
+---------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| logical_plan | Projection: count(information_schema.ssts_manifest.file_id), sum(information_schema.ssts_manifest.num_rows), sum(information_schema.ssts_manifest.level), sum(information_schema.ssts_manifest.table_id), sum(information_schema.ssts_manifest.num_row_groups), sum(information_schema.ssts_manifest.max_row_group_uncompressed_size), count(information_schema.ssts_manifest.index_file_size), sum(information_schema.ssts_manifest.index_file_size), count(Int64(1)) FILTER (WHERE information_schema.ssts_manifest.visible AND information_schema.ssts_manifest.level = Int64(0)) AS count(*) FILTER (WHERE information_schema.ssts_manifest.visible AND information_schema.ssts_manifest.level = Int64(0)) |
| | Aggregate: groupBy=[[]], aggr=[[__count_merge(__count_state(information_schema.ssts_manifest.file_id)) AS count(information_schema.ssts_manifest.file_id), __sum_merge(__sum_state(information_schema.ssts_manifest.num_rows)) AS sum(information_schema.ssts_manifest.num_rows), __sum_merge(__sum_state(information_schema.ssts_manifest.level)) AS sum(information_schema.ssts_manifest.level), __sum_merge(__sum_state(information_schema.ssts_manifest.table_id)) AS sum(information_schema.ssts_manifest.table_id), __sum_merge(__sum_state(information_schema.ssts_manifest.num_row_groups)) AS sum(information_schema.ssts_manifest.num_row_groups), __sum_merge(__sum_state(information_schema.ssts_manifest.max_row_group_uncompressed_size)) AS sum(information_schema.ssts_manifest.max_row_group_uncompressed_size), __count_merge(__count_state(information_schema.ssts_manifest.index_file_size)) AS count(information_schema.ssts_manifest.index_file_size), __sum_merge(__sum_state(information_schema.ssts_manifest.index_file_size)) AS sum(information_schema.ssts_manifest.index_file_size), __count_merge(__count_state(Int64(1)) FILTER (WHERE information_schema.ssts_manifest.visible AND CAST(information_schema.ssts_manifest.level AS Int64) = Int64(0))) AS count(Int64(1)) FILTER (WHERE information_schema.ssts_manifest.visible AND information_schema.ssts_manifest.level = Int64(0))]] |
| | SstManifestAggregate: Aggregate: groupBy=[[]], aggr=[[__count_state(information_schema.ssts_manifest.file_id), __sum_state(information_schema.ssts_manifest.num_rows), __sum_state(CAST(information_schema.ssts_manifest.level AS UInt64)), __sum_state(CAST(information_schema.ssts_manifest.table_id AS UInt64)), __sum_state(CAST(information_schema.ssts_manifest.num_row_groups AS Float64)), __sum_state(CAST(information_schema.ssts_manifest.max_row_group_uncompressed_size AS Decimal128(20, 0))), __count_state(information_schema.ssts_manifest.index_file_size), __sum_state(information_schema.ssts_manifest.index_file_size), __count_state(Int64(1)) FILTER (WHERE information_schema.ssts_manifest.visible AND CAST(information_schema.ssts_manifest.level AS Int64) = Int64(0))]] |
| | Filter: CAST(information_schema.ssts_manifest.region_id AS Decimal128(20, 0)) > CAST(Int64(0) AS Decimal128(20, 0)) |
| | SubqueryAlias: information_schema.ssts_manifest |
| | TableScan: __inspect/__mito/__sst_manifest |
| physical_plan | ProjectionExec: expr=[count(information_schema.ssts_manifest.file_id)@0 as count(information_schema.ssts_manifest.file_id), sum(information_schema.ssts_manifest.num_rows)@1 as sum(information_schema.ssts_manifest.num_rows), sum(information_schema.ssts_manifest.level)@2 as sum(information_schema.ssts_manifest.level), sum(information_schema.ssts_manifest.table_id)@3 as sum(information_schema.ssts_manifest.table_id), sum(information_schema.ssts_manifest.num_row_groups)@4 as sum(information_schema.ssts_manifest.num_row_groups), sum(information_schema.ssts_manifest.max_row_group_uncompressed_size)@5 as sum(information_schema.ssts_manifest.max_row_group_uncompressed_size), count(information_schema.ssts_manifest.index_file_size)@6 as count(information_schema.ssts_manifest.index_file_size), sum(information_schema.ssts_manifest.index_file_size)@7 as sum(information_schema.ssts_manifest.index_file_size), count(Int64(1)) FILTER (WHERE information_schema.ssts_manifest.visible AND information_schema.ssts_manifest.level = Int64(0))@8 as count(*) FILTER (WHERE information_schema.ssts_manifest.visible AND information_schema.ssts_manifest.level = Int64(0))] |
| | AggregateExec: mode=Final, gby=[], aggr=[__count_merge(__count_state(information_schema.ssts_manifest.file_id)) as count(information_schema.ssts_manifest.file_id), __sum_merge(__sum_state(information_schema.ssts_manifest.num_rows)) as sum(information_schema.ssts_manifest.num_rows), __sum_merge(__sum_state(information_schema.ssts_manifest.level)) as sum(information_schema.ssts_manifest.level), __sum_merge(__sum_state(information_schema.ssts_manifest.table_id)) as sum(information_schema.ssts_manifest.table_id), __sum_merge(__sum_state(information_schema.ssts_manifest.num_row_groups)) as sum(information_schema.ssts_manifest.num_row_groups), __sum_merge(__sum_state(information_schema.ssts_manifest.max_row_group_uncompressed_size)) as sum(information_schema.ssts_manifest.max_row_group_uncompressed_size), __count_merge(__count_state(information_schema.ssts_manifest.index_file_size)) as count(information_schema.ssts_manifest.index_file_size), __sum_merge(__sum_state(information_schema.ssts_manifest.index_file_size)) as sum(information_schema.ssts_manifest.index_file_size), __count_merge(__count_state(Int64(1)) FILTER (WHERE information_schema.ssts_manifest.visible AND CAST(information_schema.ssts_manifest.level AS Int64) = Int64(0))) as count(Int64(1)) FILTER (WHERE information_schema.ssts_manifest.visible AND information_schema.ssts_manifest.level = Int64(0))] |
| | CoalescePartitionsExec |
| | AggregateExec: mode=Partial, gby=[], aggr=[__count_merge(__count_state(information_schema.ssts_manifest.file_id)) as count(information_schema.ssts_manifest.file_id), __sum_merge(__sum_state(information_schema.ssts_manifest.num_rows)) as sum(information_schema.ssts_manifest.num_rows), __sum_merge(__sum_state(information_schema.ssts_manifest.level)) as sum(information_schema.ssts_manifest.level), __sum_merge(__sum_state(information_schema.ssts_manifest.table_id)) as sum(information_schema.ssts_manifest.table_id), __sum_merge(__sum_state(information_schema.ssts_manifest.num_row_groups)) as sum(information_schema.ssts_manifest.num_row_groups), __sum_merge(__sum_state(information_schema.ssts_manifest.max_row_group_uncompressed_size)) as sum(information_schema.ssts_manifest.max_row_group_uncompressed_size), __count_merge(__count_state(information_schema.ssts_manifest.index_file_size)) as count(information_schema.ssts_manifest.index_file_size), __sum_merge(__sum_state(information_schema.ssts_manifest.index_file_size)) as sum(information_schema.ssts_manifest.index_file_size), __count_merge(__count_state(Int64(1)) FILTER (WHERE information_schema.ssts_manifest.visible AND CAST(information_schema.ssts_manifest.level AS Int64) = Int64(0))) as count(Int64(1)) FILTER (WHERE information_schema.ssts_manifest.visible AND information_schema.ssts_manifest.level = Int64(0))] |
| | RepartitionExec: REDACTED
| | DistributedInspectExec: query=Aggregate: groupBy=[[]], aggr=[[__count_state(information_schema.ssts_manifest.file_id), __sum_state(information_schema.ssts_manifest.num_rows), __sum_state(CAST(information_schema.ssts_manifest.level AS UInt64)), __sum_state(CAST(information_schema.ssts_manifest.table_id AS UInt64)), __sum_state(CAST(information_schema.ssts_manifest.num_row_groups AS Float64)), __sum_state(CAST(information_schema.ssts_manifest.max_row_group_uncompressed_size AS Decimal128(20, 0))), __count_state(information_schema.ssts_manifest.index_file_size), __sum_state(information_schema.ssts_manifest.index_file_size), __count_state(Int64(1)) FILTER (WHERE information_schema.ssts_manifest.visible AND CAST(information_schema.ssts_manifest.level AS Int64) = Int64(0))]] |
| | Filter: CAST(information_schema.ssts_manifest.region_id AS Decimal128(20, 0)) > CAST(Int64(0) AS Decimal128(20, 0)) |
| | SubqueryAlias: information_schema.ssts_manifest |
| | TableScan: __inspect/__mito/__sst_manifest, schema=Schema { fields: [Field { name: "__count_state(information_schema.ssts_manifest.file_id)", data_type: Struct([Field { name: "count[count]", data_type: Int64, nullable: true }]) }, Field { name: "__sum_state(information_schema.ssts_manifest.num_rows)", data_type: Struct([Field { name: "sum[sum]", data_type: UInt64, nullable: true }]), nullable: true }, Field { name: "__sum_state(information_schema.ssts_manifest.level)", data_type: Struct([Field { name: "sum[sum]", data_type: UInt64, nullable: true }]), nullable: true }, Field { name: "__sum_state(information_schema.ssts_manifest.table_id)", data_type: Struct([Field { name: "sum[sum]", data_type: UInt64, nullable: true }]), nullable: true }, Field { name: "__sum_state(information_schema.ssts_manifest.num_row_groups)", data_type: Struct([Field { name: "sum[sum]", data_type: Float64, nullable: true }]), nullable: true }, Field { name: "__sum_state(information_schema.ssts_manifest.max_row_group_uncompressed_size)", data_type: Struct([Field { name: "sum[sum]", data_type: Decimal128(30, 0), nullable: true }]), nullable: true }, Field { name: "__count_state(information_schema.ssts_manifest.index_file_size)", data_type: Struct([Field { name: "count[count]", data_type: Int64, nullable: true }]) }, Field { name: "__sum_state(information_schema.ssts_manifest.index_file_size)", data_type: Struct([Field { name: "sum[sum]", data_type: UInt64, nullable: true }]), nullable: true }, Field { name: "__count_state(Int64(1)) FILTER (WHERE information_schema.ssts_manifest.visible AND CAST(information_schema.ssts_manifest.level AS Int64) = Int64(0))", data_type: Struct([Field { name: "count[count]", data_type: Int64, nullable: true }]) }], metadata: {"greptime:version": "0"} } |
| | |
+---------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
WITH pushed AS (
SELECT COUNT(file_id) AS files, COUNT(index_file_size) AS indexes,
SUM(num_rows) AS rows, SUM(level) AS levels, SUM(table_id) AS tables,
SUM(index_file_size) AS index_bytes,
SUM(CAST(num_row_groups AS DOUBLE)) AS float_groups,
SUM(CAST(max_row_group_uncompressed_size AS DECIMAL(20, 0))) AS decimal_bytes,
COUNT(*) FILTER (WHERE visible AND level = 0) AS visible_files,
SUM(num_rows) FILTER (WHERE min_ts >= '1970-01-01T00:00:00.002Z'::TIMESTAMP_NS) AS recent_rows
FROM information_schema.ssts_manifest WHERE region_id > 0
), fallback AS (
SELECT COUNT(file_id) AS files, COUNT(index_file_size) AS indexes,
SUM(num_rows) AS rows, SUM(level) AS levels, SUM(table_id) AS tables,
SUM(index_file_size) AS index_bytes,
SUM(CAST(num_row_groups AS DOUBLE)) AS float_groups,
SUM(CAST(max_row_group_uncompressed_size AS DECIMAL(20, 0))) AS decimal_bytes,
COUNT(*) FILTER (WHERE visible AND level = 0) AS visible_files,
SUM(num_rows) FILTER (WHERE min_ts >= '1970-01-01T00:00:00.002Z'::TIMESTAMP_NS) AS recent_rows
FROM (SELECT * FROM information_schema.ssts_manifest WHERE region_id > 0 LIMIT 1000)
)
SELECT pushed.files = fallback.files AS same_count,
pushed.indexes = fallback.indexes AS same_nullable_count,
pushed.rows = fallback.rows AS same_rows,
pushed.float_groups = fallback.float_groups AS same_float_groups,
pushed.decimal_bytes = fallback.decimal_bytes AS same_decimal_bytes,
pushed.levels = fallback.levels AS same_levels,
pushed.tables = fallback.tables AS same_tables,
pushed.index_bytes IS NOT DISTINCT FROM fallback.index_bytes AS same_index_bytes,
pushed.visible_files = fallback.visible_files AS same_visible_count,
pushed.recent_rows IS NOT DISTINCT FROM fallback.recent_rows AS same_recent_rows
FROM pushed CROSS JOIN fallback;
+------------+---------------------+-----------+-------------------+--------------------+-------------+-------------+------------------+--------------------+------------------+
| same_count | same_nullable_count | same_rows | same_float_groups | same_decimal_bytes | same_levels | same_tables | same_index_bytes | same_visible_count | same_recent_rows |
+------------+---------------------+-----------+-------------------+--------------------+-------------+-------------+------------------+--------------------+------------------+
| true | true | true | true | true | true | true | true | true | true |
+------------+---------------------+-----------+-------------------+--------------------+-------------+-------------+------------------+--------------------+------------------+
-- Unsupported aggregate state types stay on the frontend, including mixed aggregates.
-- SQLNESS REPLACE (RepartitionExec:.*) RepartitionExec: REDACTED
EXPLAIN SELECT COUNT(*), CAST(SUM(CAST(file_size AS DECIMAL(39, 0))) AS DOUBLE)
FROM information_schema.ssts_manifest;
+---------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| plan_type | plan |
+---------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| logical_plan | MergeScan [is_placeholder=false, remote_input=[ |
| | Projection: count(Int64(1)) AS count(*), CAST(sum(information_schema.ssts_manifest.file_size) AS Float64) |
| | Aggregate: groupBy=[[]], aggr=[[count(Int64(1)), sum(CAST(information_schema.ssts_manifest.file_size AS Decimal256(39, 0)))]] |
| | TableScan: information_schema.ssts_manifest |
| | ]] |
| physical_plan | ProjectionExec: expr=[count(Int64(1))@0 as count(*), CAST(sum(information_schema.ssts_manifest.file_size)@1 AS Float64) as sum(information_schema.ssts_manifest.file_size)] |
| | AggregateExec: mode=Final, gby=[], aggr=[count(Int64(1)), sum(information_schema.ssts_manifest.file_size)] |
| | CoalescePartitionsExec |
| | AggregateExec: mode=Partial, gby=[], aggr=[count(Int64(1)), sum(information_schema.ssts_manifest.file_size)] |
| | RepartitionExec: REDACTED
| | DistributedInspectExec: kind=SstManifest, scan=ScanRequest { projection: [10] }, schema=Schema { fields: [Field { name: "file_size", data_type: UInt64 }], metadata: {"greptime:version": "0"} } |
| | |
+---------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
WITH candidate AS (
SELECT COUNT(*) AS files,
CAST(SUM(CAST(file_size AS DECIMAL(39, 0))) AS DOUBLE) AS bytes
FROM information_schema.ssts_manifest
), baseline AS (
SELECT COUNT(*) AS files,
CAST(SUM(CAST(file_size AS DECIMAL(39, 0))) AS DOUBLE) AS bytes
FROM (SELECT file_size FROM information_schema.ssts_manifest LIMIT 1000)
)
SELECT candidate.files = baseline.files AS same_count,
candidate.bytes = baseline.bytes AS same_bytes
FROM candidate CROSS JOIN baseline;
+------------+------------+
| same_count | same_bytes |
+------------+------------+
| true | true |
+------------+------------+
-- Timezone-bearing implicit casts must remain on the frontend.
-- The inner LIMIT blocks aggregate pushdown without truncating the fixture.
WITH candidate AS (
SELECT COUNT(*) FILTER (WHERE min_ts < arrow_cast('1970-01-01T04:00:00', 'Timestamp(Nanosecond, Some("+08:00"))')) AS files,
SUM(file_size) FILTER (WHERE min_ts < arrow_cast('1970-01-01T04:00:00', 'Timestamp(Nanosecond, Some("+08:00"))')) AS bytes
FROM information_schema.ssts_manifest
), fallback AS (
SELECT COUNT(*) FILTER (WHERE min_ts < arrow_cast('1970-01-01T04:00:00', 'Timestamp(Nanosecond, Some("+08:00"))')) AS files,
SUM(file_size) FILTER (WHERE min_ts < arrow_cast('1970-01-01T04:00:00', 'Timestamp(Nanosecond, Some("+08:00"))')) AS bytes
FROM (SELECT * FROM information_schema.ssts_manifest LIMIT 1000)
)
SELECT candidate.files, fallback.files AS expected_files,
candidate.files = fallback.files AS same_count,
candidate.bytes = fallback.bytes AS same_bytes
FROM candidate CROSS JOIN fallback;
+-------+----------------+------------+------------+
| files | expected_files | same_count | same_bytes |
+-------+----------------+------------+------------+
| 3 | 3 | true | true |
+-------+----------------+------------+------------+
-- Apply the same transport boundary to a WHERE predicate below the aggregate.
WITH candidate AS (
SELECT COUNT(*) AS files, SUM(file_size) AS bytes
FROM information_schema.ssts_manifest
WHERE min_ts < arrow_cast('1970-01-01T04:00:00', 'Timestamp(Nanosecond, Some("+08:00"))')
), fallback AS (
SELECT COUNT(*) AS files, SUM(file_size) AS bytes
FROM (SELECT * FROM information_schema.ssts_manifest LIMIT 1000)
WHERE min_ts < arrow_cast('1970-01-01T04:00:00', 'Timestamp(Nanosecond, Some("+08:00"))')
)
SELECT candidate.files, fallback.files AS expected_files,
candidate.files = fallback.files AS same_count,
candidate.bytes = fallback.bytes AS same_bytes
FROM candidate CROSS JOIN fallback;
+-------+----------------+------------+------------+
| files | expected_files | same_count | same_bytes |
+-------+----------------+------------+------------+
| 3 | 3 | true | true |
+-------+----------------+------------+------------+
-- Unsupported intermediate types must not enter the remote plan.
-- The inner LIMIT blocks aggregate pushdown without truncating the fixture.
WITH candidate AS (
SELECT COUNT(*) FILTER (WHERE arrow_cast(1, 'Decimal32(9, 0)') > arrow_cast(0, 'Decimal32(9, 0)')) AS files,
SUM(file_size) FILTER (WHERE arrow_cast(1, 'Decimal32(9, 0)') > arrow_cast(0, 'Decimal32(9, 0)')) AS bytes
FROM information_schema.ssts_manifest
), fallback AS (
SELECT COUNT(*) FILTER (WHERE arrow_cast(1, 'Decimal32(9, 0)') > arrow_cast(0, 'Decimal32(9, 0)')) AS files,
SUM(file_size) FILTER (WHERE arrow_cast(1, 'Decimal32(9, 0)') > arrow_cast(0, 'Decimal32(9, 0)')) AS bytes
FROM (SELECT * FROM information_schema.ssts_manifest LIMIT 1000)
)
SELECT candidate.files, fallback.files AS expected_files,
candidate.files = fallback.files AS same_count,
candidate.bytes = fallback.bytes AS same_bytes
FROM candidate CROSS JOIN fallback;
+-------+----------------+------------+------------+
| files | expected_files | same_count | same_bytes |
+-------+----------------+------------+------------+
| 3 | 3 | true | true |
+-------+----------------+------------+------------+
-- Apply the same transport boundary to a WHERE predicate below the aggregate.
WITH candidate AS (
SELECT COUNT(*) AS files, SUM(file_size) AS bytes
FROM information_schema.ssts_manifest
WHERE arrow_cast(1, 'Decimal32(9, 0)') > arrow_cast(0, 'Decimal32(9, 0)')
), fallback AS (
SELECT COUNT(*) AS files, SUM(file_size) AS bytes
FROM (SELECT * FROM information_schema.ssts_manifest LIMIT 1000)
WHERE arrow_cast(1, 'Decimal32(9, 0)') > arrow_cast(0, 'Decimal32(9, 0)')
)
SELECT candidate.files, fallback.files AS expected_files,
candidate.files = fallback.files AS same_count,
candidate.bytes = fallback.bytes AS same_bytes
FROM candidate CROSS JOIN fallback;
+-------+----------------+------------+------------+
| files | expected_files | same_count | same_bytes |
+-------+----------------+------------+------------+
| 3 | 3 | true | true |
+-------+----------------+------------+------------+
DROP TABLE ssts_limit_case;
Affected Rows: 0