Files
greptimedb/tests/cases/standalone/common/aggregate/distinct.result
Yingwen 95d0c650ec feat: pushdown select distinct in some cases (#5847)
* feat: pushdown select distinct

* test: add sqlness test

* test: fix analyzer test
2025-04-09 02:39:04 +00:00

111 lines
2.6 KiB
Plaintext

CREATE TABLE test (a INTEGER, b INTEGER, t TIMESTAMP TIME INDEX);
Affected Rows: 0
INSERT INTO test VALUES (11, 22, 1), (13, 22, 2), (11, 21, 3), (11, 22, 4);
Affected Rows: 4
SELECT DISTINCT a, b FROM test ORDER BY a, b;
+----+----+
| a | b |
+----+----+
| 11 | 21 |
| 11 | 22 |
| 13 | 22 |
+----+----+
SELECT DISTINCT test.a, b FROM test ORDER BY a, b;
+----+----+
| a | b |
+----+----+
| 11 | 21 |
| 11 | 22 |
| 13 | 22 |
+----+----+
SELECT DISTINCT a FROM test ORDER BY a;
+----+
| a |
+----+
| 11 |
| 13 |
+----+
SELECT DISTINCT b FROM test ORDER BY b;
+----+
| b |
+----+
| 21 |
| 22 |
+----+
SELECT DISTINCT a, SUM(B) FROM test GROUP BY a ORDER BY a;
+----+-------------+
| a | sum(test.b) |
+----+-------------+
| 11 | 65 |
| 13 | 22 |
+----+-------------+
SELECT DISTINCT MAX(b) FROM test GROUP BY a;
+-------------+
| max(test.b) |
+-------------+
| 22 |
+-------------+
SELECT DISTINCT CASE WHEN a > 11 THEN 11 ELSE a END FROM test;
+-------------------------------------------------------------+
| CASE WHEN test.a > Int64(11) THEN Int64(11) ELSE test.a END |
+-------------------------------------------------------------+
| 11 |
+-------------------------------------------------------------+
SELECT DISTINCT ON (a) * FROM test ORDER BY a, t DESC;
+----+----+-------------------------+
| a | b | t |
+----+----+-------------------------+
| 11 | 22 | 1970-01-01T00:00:00.004 |
| 13 | 22 | 1970-01-01T00:00:00.002 |
+----+----+-------------------------+
-- SQLNESS REPLACE (metrics.*) REDACTED
-- SQLNESS REPLACE (RoundRobinBatch.*) REDACTED
-- SQLNESS REPLACE (Hash.*) REDACTED
-- SQLNESS REPLACE (-+) -
-- SQLNESS REPLACE (\s\s+) _
-- SQLNESS REPLACE (peers.*) REDACTED
-- SQLNESS REPLACE region=\d+\(\d+,\s+\d+\) region=REDACTED
EXPLAIN ANALYZE SELECT DISTINCT a FROM test ORDER BY a;
+-+-+-+
| stage | node | plan_|
+-+-+-+
| 0_| 0_|_MergeScanExec: REDACTED
|_|_|_|
| 1_| 0_|_SortPreservingMergeExec: [a@0 ASC NULLS LAST] REDACTED
|_|_|_SortExec: expr=[a@0 ASC NULLS LAST], preserve_partitioning=[true] REDACTED
|_|_|_AggregateExec: mode=FinalPartitioned, gby=[a@0 as a], aggr=[] REDACTED
|_|_|_CoalesceBatchesExec: target_batch_size=8192 REDACTED
|_|_|_RepartitionExec: partitioning=REDACTED
|_|_|_AggregateExec: mode=Partial, gby=[a@0 as a], aggr=[] REDACTED
|_|_|_RepartitionExec: partitioning=REDACTED
|_|_|_SeqScan: region=REDACTED, partition_count=1 (1 memtable ranges, 0 file 0 ranges) REDACTED
|_|_|_|
|_|_| Total rows: 2_|
+-+-+-+
DROP TABLE test;
Affected Rows: 0