2023-01-26 22:15:02 +00:00
|
|
|
-- Disabled query_plan_remove_redundant_distinct
|
2023-02-14 20:36:12 +00:00
|
|
|
Expression (Projection)
|
|
|
|
Distinct
|
2023-01-25 17:09:26 +00:00
|
|
|
Distinct (Preliminary DISTINCT)
|
2023-02-14 20:36:12 +00:00
|
|
|
Expression ((Before ORDER BY + Projection))
|
|
|
|
Distinct
|
2022-12-12 22:04:53 +00:00
|
|
|
Distinct (Preliminary DISTINCT)
|
2023-02-14 20:36:12 +00:00
|
|
|
Expression ((Before ORDER BY + Projection))
|
|
|
|
Distinct
|
2023-01-25 17:09:26 +00:00
|
|
|
Distinct (Preliminary DISTINCT)
|
2023-02-14 20:36:12 +00:00
|
|
|
Expression (Before ORDER BY)
|
2023-12-01 18:59:25 +00:00
|
|
|
ReadFromSystemNumbers
|
2023-01-26 22:15:02 +00:00
|
|
|
-- Enabled query_plan_remove_redundant_distinct
|
|
|
|
-- DISTINCT is only in most inner subquery
|
|
|
|
-- query
|
|
|
|
SELECT DISTINCT *
|
|
|
|
FROM
|
|
|
|
(
|
|
|
|
SELECT DISTINCT *
|
|
|
|
FROM
|
|
|
|
(
|
|
|
|
SELECT DISTINCT *
|
|
|
|
FROM numbers(3)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
-- explain
|
2023-02-14 20:36:12 +00:00
|
|
|
Expression ((Projection + (Before ORDER BY + (Projection + (Before ORDER BY + Projection)))))
|
|
|
|
Distinct
|
2023-01-25 17:09:26 +00:00
|
|
|
Distinct (Preliminary DISTINCT)
|
2023-02-14 20:36:12 +00:00
|
|
|
Expression (Before ORDER BY)
|
2023-12-01 18:59:25 +00:00
|
|
|
ReadFromSystemNumbers
|
2023-01-26 22:15:02 +00:00
|
|
|
-- execute
|
|
|
|
0
|
|
|
|
1
|
|
|
|
2
|
|
|
|
-- do _not_ remove DISTINCT after UNION
|
|
|
|
-- query
|
|
|
|
SELECT DISTINCT number FROM
|
|
|
|
(
|
|
|
|
(SELECT DISTINCT number FROM numbers(1))
|
|
|
|
UNION ALL
|
|
|
|
(SELECT DISTINCT number FROM numbers(2))
|
|
|
|
)
|
|
|
|
ORDER BY number
|
|
|
|
-- explain
|
2023-02-14 20:36:12 +00:00
|
|
|
Expression (Projection)
|
|
|
|
Distinct
|
2023-01-26 22:15:02 +00:00
|
|
|
Sorting (Sorting for ORDER BY)
|
2023-02-14 20:36:12 +00:00
|
|
|
Distinct (Preliminary DISTINCT)
|
|
|
|
Union
|
|
|
|
Expression ((Before ORDER BY + Projection))
|
|
|
|
Distinct
|
|
|
|
Distinct (Preliminary DISTINCT)
|
|
|
|
Expression (Before ORDER BY)
|
2023-12-01 18:59:25 +00:00
|
|
|
ReadFromSystemNumbers
|
2023-02-14 20:36:12 +00:00
|
|
|
Expression (( + Projection))
|
|
|
|
Distinct
|
|
|
|
Distinct (Preliminary DISTINCT)
|
|
|
|
Expression (Before ORDER BY)
|
2023-12-01 18:59:25 +00:00
|
|
|
ReadFromSystemNumbers
|
2023-01-26 22:15:02 +00:00
|
|
|
-- execute
|
|
|
|
0
|
|
|
|
1
|
|
|
|
-- do _not_ remove DISTINCT after JOIN
|
|
|
|
-- query
|
|
|
|
SELECT DISTINCT *
|
|
|
|
FROM
|
|
|
|
(
|
|
|
|
SELECT DISTINCT number AS n
|
|
|
|
FROM numbers(2)
|
2023-02-14 20:36:12 +00:00
|
|
|
) as x,
|
2023-01-26 22:15:02 +00:00
|
|
|
(
|
|
|
|
SELECT DISTINCT number AS n
|
|
|
|
FROM numbers(2)
|
2023-02-14 20:36:12 +00:00
|
|
|
) as y
|
2023-12-11 12:15:42 +00:00
|
|
|
ORDER BY x.n, y.n
|
2023-01-26 22:15:02 +00:00
|
|
|
-- explain
|
2023-02-14 20:36:12 +00:00
|
|
|
Expression (Projection)
|
|
|
|
Distinct
|
2023-12-07 16:17:10 +00:00
|
|
|
Sorting (Sorting for ORDER BY)
|
|
|
|
Distinct (Preliminary DISTINCT)
|
|
|
|
Expression (Before ORDER BY)
|
|
|
|
Join (JOIN FillRightFirst)
|
|
|
|
Expression ((Before JOIN + Projection))
|
|
|
|
Distinct
|
|
|
|
Distinct (Preliminary DISTINCT)
|
|
|
|
Expression (Before ORDER BY)
|
|
|
|
ReadFromSystemNumbers
|
|
|
|
Expression ((Joined actions + (Rename joined columns + Projection)))
|
|
|
|
Distinct
|
|
|
|
Distinct (Preliminary DISTINCT)
|
|
|
|
Expression (Before ORDER BY)
|
|
|
|
ReadFromSystemNumbers
|
2023-01-26 22:15:02 +00:00
|
|
|
-- execute
|
|
|
|
0 0
|
2023-01-30 23:08:26 +00:00
|
|
|
0 1
|
|
|
|
1 0
|
2023-01-26 22:15:02 +00:00
|
|
|
1 1
|
2023-01-30 23:08:26 +00:00
|
|
|
-- DISTINCT duplicates with several columns
|
|
|
|
-- query
|
|
|
|
SELECT DISTINCT *
|
|
|
|
FROM
|
|
|
|
(
|
|
|
|
SELECT DISTINCT *
|
|
|
|
FROM
|
|
|
|
(
|
|
|
|
SELECT DISTINCT number as a, 2*number as b
|
|
|
|
FROM numbers(3)
|
|
|
|
)
|
|
|
|
)
|
2023-12-07 16:17:10 +00:00
|
|
|
ORDER BY a, b
|
2023-01-30 23:08:26 +00:00
|
|
|
-- explain
|
2023-12-07 16:17:10 +00:00
|
|
|
Expression (Projection)
|
|
|
|
Sorting (Sorting for ORDER BY)
|
|
|
|
Expression ((Before ORDER BY + (Projection + (Before ORDER BY + Projection))))
|
|
|
|
Distinct
|
|
|
|
Distinct (Preliminary DISTINCT)
|
|
|
|
Expression (Before ORDER BY)
|
|
|
|
ReadFromSystemNumbers
|
2023-01-30 23:08:26 +00:00
|
|
|
-- execute
|
|
|
|
0 0
|
|
|
|
1 2
|
|
|
|
2 4
|
2023-02-01 21:13:44 +00:00
|
|
|
-- DISTINCT duplicates with constant columns
|
|
|
|
-- query
|
|
|
|
SELECT DISTINCT 2, a, b
|
|
|
|
FROM
|
|
|
|
(
|
|
|
|
SELECT DISTINCT a, b
|
|
|
|
FROM
|
|
|
|
(
|
|
|
|
SELECT DISTINCT 1, number as a, 2*number as b
|
|
|
|
FROM numbers(3)
|
|
|
|
)
|
|
|
|
)
|
2023-12-07 16:17:10 +00:00
|
|
|
ORDER BY a, b
|
2023-02-01 21:13:44 +00:00
|
|
|
-- explain
|
2023-12-07 16:17:10 +00:00
|
|
|
Expression (Projection)
|
|
|
|
Sorting (Sorting for ORDER BY)
|
|
|
|
Expression ((Before ORDER BY + (Projection + (Before ORDER BY + Projection))))
|
|
|
|
Distinct
|
|
|
|
Distinct (Preliminary DISTINCT)
|
|
|
|
Expression (Before ORDER BY)
|
|
|
|
ReadFromSystemNumbers
|
2023-02-01 21:13:44 +00:00
|
|
|
-- execute
|
|
|
|
2 0 0
|
|
|
|
2 1 2
|
|
|
|
2 2 4
|
2023-02-07 11:48:23 +00:00
|
|
|
-- ARRAY JOIN: do _not_ remove outer DISTINCT because new rows are generated between inner and outer DISTINCTs
|
|
|
|
-- query
|
|
|
|
SELECT DISTINCT *
|
|
|
|
FROM
|
|
|
|
(
|
|
|
|
SELECT DISTINCT *
|
|
|
|
FROM VALUES('Hello', 'World', 'Goodbye')
|
|
|
|
) AS words
|
|
|
|
ARRAY JOIN [0, 1] AS arr
|
2023-12-11 12:15:42 +00:00
|
|
|
ORDER BY c1, arr
|
2023-02-07 11:48:23 +00:00
|
|
|
-- explain
|
2023-02-14 20:36:12 +00:00
|
|
|
Expression (Projection)
|
|
|
|
Distinct
|
2023-12-07 16:17:10 +00:00
|
|
|
Sorting (Sorting for ORDER BY)
|
|
|
|
Distinct (Preliminary DISTINCT)
|
|
|
|
Expression (Before ORDER BY)
|
|
|
|
ArrayJoin (ARRAY JOIN)
|
|
|
|
Expression ((Before ARRAY JOIN + Projection))
|
|
|
|
Distinct
|
|
|
|
Distinct (Preliminary DISTINCT)
|
|
|
|
Expression (Before ORDER BY)
|
|
|
|
ReadFromStorage (Values)
|
2023-02-07 11:48:23 +00:00
|
|
|
-- execute
|
2023-12-11 12:15:42 +00:00
|
|
|
Goodbye
|
2023-02-07 11:48:23 +00:00
|
|
|
Hello
|
|
|
|
World
|
|
|
|
-- WITH FILL: do _not_ remove outer DISTINCT because new rows are generated between inner and outer DISTINCTs
|
|
|
|
-- query
|
|
|
|
SELECT DISTINCT *
|
|
|
|
FROM
|
|
|
|
(
|
|
|
|
SELECT DISTINCT *
|
|
|
|
FROM values('id UInt8', 0, 2)
|
|
|
|
ORDER BY id ASC WITH FILL
|
|
|
|
)
|
|
|
|
-- explain
|
2023-02-14 20:36:12 +00:00
|
|
|
Expression (Projection)
|
|
|
|
Distinct
|
2023-02-07 11:48:23 +00:00
|
|
|
Distinct (Preliminary DISTINCT)
|
2023-02-14 20:36:12 +00:00
|
|
|
Expression ((Before ORDER BY + Projection))
|
2023-02-07 11:48:23 +00:00
|
|
|
Filling
|
2023-02-14 20:36:12 +00:00
|
|
|
Distinct
|
2023-02-07 11:48:23 +00:00
|
|
|
Sorting (Sorting for ORDER BY)
|
2023-02-14 20:36:12 +00:00
|
|
|
Distinct (Preliminary DISTINCT)
|
|
|
|
Expression (Before ORDER BY)
|
|
|
|
ReadFromStorage (Values)
|
2023-02-07 11:48:23 +00:00
|
|
|
-- execute
|
|
|
|
0
|
|
|
|
1
|
|
|
|
2
|
|
|
|
-- WHERE with arrayJoin(): do _not_ remove outer DISTINCT because new rows are generated between inner and outer DISTINCTs
|
|
|
|
-- query
|
|
|
|
SELECT DISTINCT *
|
|
|
|
FROM
|
|
|
|
(
|
|
|
|
SELECT DISTINCT ['Istanbul', 'Berlin', 'Bensheim'] AS cities
|
|
|
|
)
|
|
|
|
WHERE arrayJoin(cities) IN ['Berlin', 'Bensheim']
|
2023-12-07 16:17:10 +00:00
|
|
|
ORDER BY cities
|
2023-02-07 11:48:23 +00:00
|
|
|
-- explain
|
2023-02-14 20:36:12 +00:00
|
|
|
Expression (( + Projection))
|
|
|
|
Distinct
|
2023-12-07 16:17:10 +00:00
|
|
|
Sorting (Sorting for ORDER BY)
|
|
|
|
Distinct (Preliminary DISTINCT)
|
|
|
|
Expression (Before ORDER BY)
|
|
|
|
Filter ((WHERE + Projection))
|
|
|
|
Distinct
|
|
|
|
Distinct (Preliminary DISTINCT)
|
|
|
|
Expression (Before ORDER BY)
|
|
|
|
ReadFromStorage (SystemOne)
|
2023-02-07 11:48:23 +00:00
|
|
|
-- execute
|
|
|
|
['Istanbul','Berlin','Bensheim']
|
2023-02-09 11:37:15 +00:00
|
|
|
-- GROUP BY before DISTINCT with on the same columns => remove DISTINCT
|
|
|
|
-- query
|
|
|
|
SELECT DISTINCT a
|
|
|
|
FROM
|
|
|
|
(
|
|
|
|
SELECT
|
|
|
|
a,
|
|
|
|
sum(b) AS c
|
|
|
|
FROM
|
|
|
|
(
|
|
|
|
SELECT
|
|
|
|
x.number AS a,
|
|
|
|
y.number AS b
|
|
|
|
FROM numbers(3) AS x, numbers(3, 3) AS y
|
|
|
|
)
|
|
|
|
GROUP BY a
|
2023-12-07 16:17:10 +00:00
|
|
|
ORDER BY a
|
2023-02-09 11:37:15 +00:00
|
|
|
)
|
|
|
|
-- explain
|
2023-12-07 16:17:10 +00:00
|
|
|
Expression ((Projection + (Before ORDER BY + Projection)))
|
|
|
|
Sorting (Sorting for ORDER BY)
|
|
|
|
Expression (Before ORDER BY)
|
|
|
|
Aggregating
|
|
|
|
Expression ((Before GROUP BY + (Projection + Before ORDER BY)))
|
|
|
|
Join (JOIN FillRightFirst)
|
|
|
|
Expression (Before JOIN)
|
|
|
|
ReadFromSystemNumbers
|
|
|
|
Expression ((Joined actions + (Rename joined columns + (Projection + Before ORDER BY))))
|
|
|
|
ReadFromSystemNumbers
|
2023-02-09 11:37:15 +00:00
|
|
|
-- execute
|
|
|
|
0
|
|
|
|
1
|
2023-12-07 16:17:10 +00:00
|
|
|
2
|
2023-02-09 11:37:15 +00:00
|
|
|
-- GROUP BY before DISTINCT with on different columns => do _not_ remove DISTINCT
|
|
|
|
-- query
|
|
|
|
SELECT DISTINCT c
|
|
|
|
FROM
|
|
|
|
(
|
|
|
|
SELECT
|
|
|
|
a,
|
|
|
|
sum(b) AS c
|
|
|
|
FROM
|
|
|
|
(
|
|
|
|
SELECT
|
|
|
|
x.number AS a,
|
|
|
|
y.number AS b
|
|
|
|
FROM numbers(3) AS x, numbers(3, 3) AS y
|
|
|
|
)
|
|
|
|
GROUP BY a
|
2023-12-07 16:17:10 +00:00
|
|
|
ORDER BY a
|
2023-02-09 11:37:15 +00:00
|
|
|
)
|
|
|
|
-- explain
|
2023-02-14 20:36:12 +00:00
|
|
|
Expression (Projection)
|
|
|
|
Distinct
|
2023-02-09 11:37:15 +00:00
|
|
|
Distinct (Preliminary DISTINCT)
|
2023-12-07 16:17:10 +00:00
|
|
|
Expression ((Before ORDER BY + Projection))
|
|
|
|
Sorting (Sorting for ORDER BY)
|
|
|
|
Expression (Before ORDER BY)
|
|
|
|
Aggregating
|
|
|
|
Expression ((Before GROUP BY + (Projection + Before ORDER BY)))
|
|
|
|
Join (JOIN FillRightFirst)
|
|
|
|
Expression (Before JOIN)
|
|
|
|
ReadFromSystemNumbers
|
|
|
|
Expression ((Joined actions + (Rename joined columns + (Projection + Before ORDER BY))))
|
|
|
|
ReadFromSystemNumbers
|
2023-02-09 11:37:15 +00:00
|
|
|
-- execute
|
|
|
|
12
|
2023-02-14 19:45:57 +00:00
|
|
|
-- GROUP BY WITH ROLLUP before DISTINCT with on different columns => do _not_ remove DISTINCT
|
|
|
|
-- query
|
|
|
|
SELECT DISTINCT c
|
|
|
|
FROM
|
|
|
|
(
|
|
|
|
SELECT
|
|
|
|
a,
|
|
|
|
sum(b) AS c
|
|
|
|
FROM
|
|
|
|
(
|
|
|
|
SELECT
|
|
|
|
x.number AS a,
|
|
|
|
y.number AS b
|
|
|
|
FROM numbers(3) AS x, numbers(3, 3) AS y
|
|
|
|
)
|
|
|
|
GROUP BY a WITH ROLLUP
|
2023-12-07 16:17:10 +00:00
|
|
|
ORDER BY a
|
2023-02-14 19:45:57 +00:00
|
|
|
)
|
|
|
|
-- explain
|
2023-02-14 20:36:12 +00:00
|
|
|
Expression (Projection)
|
|
|
|
Distinct
|
2023-02-14 19:45:57 +00:00
|
|
|
Distinct (Preliminary DISTINCT)
|
2023-12-07 16:17:10 +00:00
|
|
|
Expression ((Before ORDER BY + Projection))
|
|
|
|
Sorting (Sorting for ORDER BY)
|
|
|
|
Expression (Before ORDER BY)
|
|
|
|
Rollup
|
|
|
|
Aggregating
|
|
|
|
Expression ((Before GROUP BY + (Projection + Before ORDER BY)))
|
|
|
|
Join (JOIN FillRightFirst)
|
|
|
|
Expression (Before JOIN)
|
|
|
|
ReadFromSystemNumbers
|
|
|
|
Expression ((Joined actions + (Rename joined columns + (Projection + Before ORDER BY))))
|
|
|
|
ReadFromSystemNumbers
|
2023-02-14 19:45:57 +00:00
|
|
|
-- execute
|
|
|
|
12
|
|
|
|
36
|
|
|
|
-- GROUP BY WITH ROLLUP before DISTINCT with on the same columns => remove DISTINCT
|
|
|
|
-- query
|
|
|
|
SELECT DISTINCT a
|
|
|
|
FROM
|
|
|
|
(
|
|
|
|
SELECT
|
|
|
|
a,
|
|
|
|
sum(b) AS c
|
|
|
|
FROM
|
|
|
|
(
|
|
|
|
SELECT
|
|
|
|
x.number AS a,
|
|
|
|
y.number AS b
|
|
|
|
FROM numbers(3) AS x, numbers(3, 3) AS y
|
|
|
|
)
|
|
|
|
GROUP BY a WITH ROLLUP
|
2023-12-07 16:17:10 +00:00
|
|
|
ORDER BY a
|
2023-02-14 19:45:57 +00:00
|
|
|
)
|
|
|
|
-- explain
|
2023-12-07 16:17:10 +00:00
|
|
|
Expression ((Projection + (Before ORDER BY + Projection)))
|
|
|
|
Sorting (Sorting for ORDER BY)
|
|
|
|
Expression (Before ORDER BY)
|
|
|
|
Rollup
|
|
|
|
Aggregating
|
|
|
|
Expression ((Before GROUP BY + (Projection + Before ORDER BY)))
|
|
|
|
Join (JOIN FillRightFirst)
|
|
|
|
Expression (Before JOIN)
|
|
|
|
ReadFromSystemNumbers
|
|
|
|
Expression ((Joined actions + (Rename joined columns + (Projection + Before ORDER BY))))
|
|
|
|
ReadFromSystemNumbers
|
2023-02-14 19:45:57 +00:00
|
|
|
-- execute
|
|
|
|
0
|
|
|
|
0
|
2023-12-07 16:17:10 +00:00
|
|
|
1
|
|
|
|
2
|
2023-02-14 19:45:57 +00:00
|
|
|
-- GROUP BY WITH CUBE before DISTINCT with on different columns => do _not_ remove DISTINCT
|
|
|
|
-- query
|
|
|
|
SELECT DISTINCT c
|
|
|
|
FROM
|
|
|
|
(
|
|
|
|
SELECT
|
|
|
|
a,
|
|
|
|
sum(b) AS c
|
|
|
|
FROM
|
|
|
|
(
|
|
|
|
SELECT
|
|
|
|
x.number AS a,
|
|
|
|
y.number AS b
|
|
|
|
FROM numbers(3) AS x, numbers(3, 3) AS y
|
|
|
|
)
|
|
|
|
GROUP BY a WITH CUBE
|
2023-12-07 16:17:10 +00:00
|
|
|
ORDER BY a
|
2023-02-14 19:45:57 +00:00
|
|
|
)
|
|
|
|
-- explain
|
2023-02-14 20:36:12 +00:00
|
|
|
Expression (Projection)
|
|
|
|
Distinct
|
2023-02-14 19:45:57 +00:00
|
|
|
Distinct (Preliminary DISTINCT)
|
2023-12-07 16:17:10 +00:00
|
|
|
Expression ((Before ORDER BY + Projection))
|
|
|
|
Sorting (Sorting for ORDER BY)
|
|
|
|
Expression (Before ORDER BY)
|
|
|
|
Cube
|
|
|
|
Aggregating
|
|
|
|
Expression ((Before GROUP BY + (Projection + Before ORDER BY)))
|
|
|
|
Join (JOIN FillRightFirst)
|
|
|
|
Expression (Before JOIN)
|
|
|
|
ReadFromSystemNumbers
|
|
|
|
Expression ((Joined actions + (Rename joined columns + (Projection + Before ORDER BY))))
|
|
|
|
ReadFromSystemNumbers
|
2023-02-14 19:45:57 +00:00
|
|
|
-- execute
|
|
|
|
12
|
|
|
|
36
|
|
|
|
-- GROUP BY WITH CUBE before DISTINCT with on the same columns => remove DISTINCT
|
|
|
|
-- query
|
|
|
|
SELECT DISTINCT a
|
|
|
|
FROM
|
|
|
|
(
|
|
|
|
SELECT
|
|
|
|
a,
|
|
|
|
sum(b) AS c
|
|
|
|
FROM
|
|
|
|
(
|
|
|
|
SELECT
|
|
|
|
x.number AS a,
|
|
|
|
y.number AS b
|
|
|
|
FROM numbers(3) AS x, numbers(3, 3) AS y
|
|
|
|
)
|
|
|
|
GROUP BY a WITH CUBE
|
2023-12-07 16:17:10 +00:00
|
|
|
ORDER BY a
|
2023-02-14 19:45:57 +00:00
|
|
|
)
|
|
|
|
-- explain
|
2023-12-07 16:17:10 +00:00
|
|
|
Expression ((Projection + (Before ORDER BY + Projection)))
|
|
|
|
Sorting (Sorting for ORDER BY)
|
|
|
|
Expression (Before ORDER BY)
|
|
|
|
Cube
|
|
|
|
Aggregating
|
|
|
|
Expression ((Before GROUP BY + (Projection + Before ORDER BY)))
|
|
|
|
Join (JOIN FillRightFirst)
|
|
|
|
Expression (Before JOIN)
|
|
|
|
ReadFromSystemNumbers
|
|
|
|
Expression ((Joined actions + (Rename joined columns + (Projection + Before ORDER BY))))
|
|
|
|
ReadFromSystemNumbers
|
2023-02-14 19:45:57 +00:00
|
|
|
-- execute
|
|
|
|
0
|
|
|
|
0
|
2023-12-07 16:17:10 +00:00
|
|
|
1
|
|
|
|
2
|
2023-02-14 21:14:41 +00:00
|
|
|
-- GROUP BY WITH TOTALS before DISTINCT with on different columns => do _not_ remove DISTINCT
|
|
|
|
-- query
|
|
|
|
SELECT DISTINCT c
|
|
|
|
FROM
|
|
|
|
(
|
|
|
|
SELECT
|
|
|
|
a,
|
|
|
|
sum(b) AS c
|
|
|
|
FROM
|
|
|
|
(
|
|
|
|
SELECT
|
|
|
|
x.number AS a,
|
|
|
|
y.number AS b
|
|
|
|
FROM numbers(3) AS x, numbers(3, 3) AS y
|
|
|
|
)
|
|
|
|
GROUP BY a WITH TOTALS
|
2023-12-07 16:17:10 +00:00
|
|
|
ORDER BY a
|
2023-02-14 21:14:41 +00:00
|
|
|
)
|
|
|
|
-- explain
|
|
|
|
Expression (Projection)
|
|
|
|
Distinct
|
|
|
|
Distinct (Preliminary DISTINCT)
|
2023-12-07 16:17:10 +00:00
|
|
|
Expression ((Before ORDER BY + Projection))
|
|
|
|
Sorting (Sorting for ORDER BY)
|
|
|
|
Expression (Before ORDER BY)
|
|
|
|
TotalsHaving
|
|
|
|
Aggregating
|
|
|
|
Expression ((Before GROUP BY + (Projection + Before ORDER BY)))
|
|
|
|
Join (JOIN FillRightFirst)
|
|
|
|
Expression (Before JOIN)
|
|
|
|
ReadFromSystemNumbers
|
|
|
|
Expression ((Joined actions + (Rename joined columns + (Projection + Before ORDER BY))))
|
|
|
|
ReadFromSystemNumbers
|
2023-02-14 21:14:41 +00:00
|
|
|
-- execute
|
|
|
|
12
|
|
|
|
|
|
|
|
36
|
|
|
|
-- GROUP BY WITH TOTALS before DISTINCT with on the same columns => remove DISTINCT
|
|
|
|
-- query
|
|
|
|
SELECT DISTINCT a
|
|
|
|
FROM
|
|
|
|
(
|
|
|
|
SELECT
|
|
|
|
a,
|
|
|
|
sum(b) AS c
|
|
|
|
FROM
|
|
|
|
(
|
|
|
|
SELECT
|
|
|
|
x.number AS a,
|
|
|
|
y.number AS b
|
|
|
|
FROM numbers(3) AS x, numbers(3, 3) AS y
|
|
|
|
)
|
|
|
|
GROUP BY a WITH TOTALS
|
2023-12-07 16:17:10 +00:00
|
|
|
ORDER BY a
|
2023-02-14 21:14:41 +00:00
|
|
|
)
|
|
|
|
-- explain
|
2023-12-07 16:17:10 +00:00
|
|
|
Expression ((Projection + (Before ORDER BY + Projection)))
|
|
|
|
Sorting (Sorting for ORDER BY)
|
|
|
|
Expression (Before ORDER BY)
|
|
|
|
TotalsHaving
|
|
|
|
Aggregating
|
|
|
|
Expression ((Before GROUP BY + (Projection + Before ORDER BY)))
|
|
|
|
Join (JOIN FillRightFirst)
|
|
|
|
Expression (Before JOIN)
|
|
|
|
ReadFromSystemNumbers
|
|
|
|
Expression ((Joined actions + (Rename joined columns + (Projection + Before ORDER BY))))
|
|
|
|
ReadFromSystemNumbers
|
2023-02-14 21:14:41 +00:00
|
|
|
-- execute
|
|
|
|
0
|
|
|
|
1
|
2023-12-07 16:17:10 +00:00
|
|
|
2
|
2023-02-14 21:14:41 +00:00
|
|
|
|
|
|
|
0
|
2023-03-15 12:44:22 +00:00
|
|
|
-- DISTINCT COUNT() with GROUP BY => do _not_ remove DISTINCT
|
|
|
|
-- query
|
|
|
|
select distinct count() from numbers(10) group by number
|
|
|
|
-- explain
|
|
|
|
Expression (Projection)
|
|
|
|
Distinct
|
|
|
|
Distinct (Preliminary DISTINCT)
|
|
|
|
Expression (Before ORDER BY)
|
|
|
|
Aggregating
|
|
|
|
Expression (Before GROUP BY)
|
2023-12-01 18:59:25 +00:00
|
|
|
ReadFromSystemNumbers
|
2023-03-15 12:44:22 +00:00
|
|
|
-- execute
|
|
|
|
1
|
2023-07-19 19:34:49 +00:00
|
|
|
-- UNION ALL with DISTINCT => do _not_ remove DISTINCT
|
|
|
|
-- query
|
|
|
|
SELECT DISTINCT number
|
|
|
|
FROM
|
|
|
|
(
|
|
|
|
SELECT DISTINCT number
|
|
|
|
FROM numbers(1)
|
|
|
|
UNION ALL
|
|
|
|
SELECT DISTINCT number
|
|
|
|
FROM numbers(2)
|
|
|
|
)
|
2023-12-07 16:17:10 +00:00
|
|
|
ORDER BY number
|
2023-07-19 19:34:49 +00:00
|
|
|
-- explain
|
|
|
|
Expression (Projection)
|
|
|
|
Distinct
|
2023-12-07 16:17:10 +00:00
|
|
|
Sorting (Sorting for ORDER BY)
|
|
|
|
Distinct (Preliminary DISTINCT)
|
|
|
|
Union
|
|
|
|
Expression ((Before ORDER BY + Projection))
|
|
|
|
Distinct
|
|
|
|
Distinct (Preliminary DISTINCT)
|
|
|
|
Expression (Before ORDER BY)
|
|
|
|
ReadFromSystemNumbers
|
|
|
|
Expression (( + Projection))
|
|
|
|
Distinct
|
|
|
|
Distinct (Preliminary DISTINCT)
|
|
|
|
Expression (Before ORDER BY)
|
|
|
|
ReadFromSystemNumbers
|
2023-07-19 19:34:49 +00:00
|
|
|
-- execute
|
|
|
|
0
|
|
|
|
1
|