mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-01-13 16:52:56 +00:00
* fix: use alias expr to check commutativity * chore: debug sort * feat: consider alias in window sort optimizer * test: sqlness test * test: update sqlness result
136 lines
12 KiB
Plaintext
136 lines
12 KiB
Plaintext
explain select * from numbers;
|
|
|
|
+---------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| plan_type | plan |
|
|
+---------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| logical_plan | MergeScan [is_placeholder=false] |
|
|
| physical_plan | StreamScanAdapter: [<SendableRecordBatchStream>], schema: [Schema { fields: [Field { name: "number", data_type: UInt32, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }], metadata: {"greptime:version": "0"} }] |
|
|
| | |
|
|
+---------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
|
|
explain select * from numbers order by number desc;
|
|
|
|
+---------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| plan_type | plan |
|
|
+---------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| logical_plan | MergeScan [is_placeholder=false] |
|
|
| physical_plan | SortExec: expr=[number@0 DESC], preserve_partitioning=[false] |
|
|
| | StreamScanAdapter: [<SendableRecordBatchStream>], schema: [Schema { fields: [Field { name: "number", data_type: UInt32, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }], metadata: {"greptime:version": "0"} }] |
|
|
| | |
|
|
+---------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
|
|
explain select * from numbers order by number asc;
|
|
|
|
+---------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| plan_type | plan |
|
|
+---------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| logical_plan | MergeScan [is_placeholder=false] |
|
|
| physical_plan | SortExec: expr=[number@0 ASC NULLS LAST], preserve_partitioning=[false] |
|
|
| | StreamScanAdapter: [<SendableRecordBatchStream>], schema: [Schema { fields: [Field { name: "number", data_type: UInt32, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }], metadata: {"greptime:version": "0"} }] |
|
|
| | |
|
|
+---------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
|
|
explain select * from numbers order by number desc limit 10;
|
|
|
|
+---------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| plan_type | plan |
|
|
+---------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| logical_plan | MergeScan [is_placeholder=false] |
|
|
| physical_plan | SortExec: TopK(fetch=10), expr=[number@0 DESC], preserve_partitioning=[false] |
|
|
| | StreamScanAdapter: [<SendableRecordBatchStream>], schema: [Schema { fields: [Field { name: "number", data_type: UInt32, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }], metadata: {"greptime:version": "0"} }] |
|
|
| | |
|
|
+---------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
|
|
explain select * from numbers order by number asc limit 10;
|
|
|
|
+---------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| plan_type | plan |
|
|
+---------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| logical_plan | MergeScan [is_placeholder=false] |
|
|
| physical_plan | SortExec: TopK(fetch=10), expr=[number@0 ASC NULLS LAST], preserve_partitioning=[false] |
|
|
| | StreamScanAdapter: [<SendableRecordBatchStream>], schema: [Schema { fields: [Field { name: "number", data_type: UInt32, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }], metadata: {"greptime:version": "0"} }] |
|
|
| | |
|
|
+---------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
|
|
CREATE TABLE test_pk(pk INTEGER PRIMARY KEY, i INTEGER, t TIMESTAMP TIME INDEX) WITH('compaction.type'='twcs', 'compaction.twcs.max_inactive_window_files'='4');
|
|
|
|
Affected Rows: 0
|
|
|
|
INSERT INTO test_pk VALUES (1, 1, 1), (2, NULL, 2), (3, 1, 3), (4, 2, 4), (5, 2, 5), (6, NULL, 6);
|
|
|
|
Affected Rows: 6
|
|
|
|
-- Test aliasing.
|
|
SELECT i, t AS alias_ts FROM test_pk ORDER BY t DESC LIMIT 5;
|
|
|
|
+---+-------------------------+
|
|
| i | alias_ts |
|
|
+---+-------------------------+
|
|
| | 1970-01-01T00:00:00.006 |
|
|
| 2 | 1970-01-01T00:00:00.005 |
|
|
| 2 | 1970-01-01T00:00:00.004 |
|
|
| 1 | 1970-01-01T00:00:00.003 |
|
|
| | 1970-01-01T00:00:00.002 |
|
|
+---+-------------------------+
|
|
|
|
-- Test aliasing.
|
|
SELECT i, t AS alias_ts FROM test_pk ORDER BY alias_ts DESC LIMIT 5;
|
|
|
|
+---+-------------------------+
|
|
| i | alias_ts |
|
|
+---+-------------------------+
|
|
| | 1970-01-01T00:00:00.006 |
|
|
| 2 | 1970-01-01T00:00:00.005 |
|
|
| 2 | 1970-01-01T00:00:00.004 |
|
|
| 1 | 1970-01-01T00:00:00.003 |
|
|
| | 1970-01-01T00:00:00.002 |
|
|
+---+-------------------------+
|
|
|
|
-- SQLNESS REPLACE (-+) -
|
|
-- SQLNESS REPLACE (\s\s+) _
|
|
-- SQLNESS REPLACE (peers.*) REDACTED
|
|
-- SQLNESS REPLACE (metrics.*) REDACTED
|
|
-- SQLNESS REPLACE region=\d+\(\d+,\s+\d+\) region=REDACTED
|
|
EXPLAIN ANALYZE SELECT i, t AS alias_ts FROM test_pk ORDER BY t DESC LIMIT 5;
|
|
|
|
+-+-+-+
|
|
| stage | node | plan_|
|
|
+-+-+-+
|
|
| 0_| 0_|_MergeScanExec: REDACTED
|
|
|_|_|_|
|
|
| 1_| 0_|_ProjectionExec: expr=[i@0 as i, alias_ts@1 as alias_ts] REDACTED
|
|
|_|_|_SortPreservingMergeExec: [t@2 DESC] REDACTED
|
|
|_|_|_WindowedSortExec: expr=t@2 DESC num_ranges=1 fetch=5 REDACTED
|
|
|_|_|_PartSortExec: expr=t@2 DESC num_ranges=1 limit=5 REDACTED
|
|
|_|_|_ProjectionExec: expr=[i@0 as i, t@1 as alias_ts, t@1 as t] REDACTED
|
|
|_|_|_SeqScan: region=REDACTED, partition_count=1 (1 memtable ranges, 0 file 0 ranges) REDACTED
|
|
|_|_|_|
|
|
|_|_| Total rows: 5_|
|
|
+-+-+-+
|
|
|
|
-- SQLNESS REPLACE (-+) -
|
|
-- SQLNESS REPLACE (\s\s+) _
|
|
-- SQLNESS REPLACE (peers.*) REDACTED
|
|
-- SQLNESS REPLACE (metrics.*) REDACTED
|
|
-- SQLNESS REPLACE region=\d+\(\d+,\s+\d+\) region=REDACTED
|
|
EXPLAIN ANALYZE SELECT i, t AS alias_ts FROM test_pk ORDER BY alias_ts DESC LIMIT 5;
|
|
|
|
+-+-+-+
|
|
| stage | node | plan_|
|
|
+-+-+-+
|
|
| 0_| 0_|_MergeScanExec: REDACTED
|
|
|_|_|_|
|
|
| 1_| 0_|_SortPreservingMergeExec: [alias_ts@1 DESC] REDACTED
|
|
|_|_|_WindowedSortExec: expr=alias_ts@1 DESC num_ranges=1 fetch=5 REDACTED
|
|
|_|_|_PartSortExec: expr=alias_ts@1 DESC num_ranges=1 limit=5 REDACTED
|
|
|_|_|_ProjectionExec: expr=[i@0 as i, t@1 as alias_ts] REDACTED
|
|
|_|_|_SeqScan: region=REDACTED, partition_count=1 (1 memtable ranges, 0 file 0 ranges) REDACTED
|
|
|_|_|_|
|
|
|_|_| Total rows: 5_|
|
|
+-+-+-+
|
|
|
|
DROP TABLE test_pk;
|
|
|
|
Affected Rows: 0
|
|
|