mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-18 21:51:57 +00:00
482 lines
14 KiB
Plaintext
482 lines
14 KiB
Plaintext
-- Disabled query_plan_remove_redundant_distinct
|
|
Expression (Project names)
|
|
Distinct (DISTINCT)
|
|
Distinct (Preliminary DISTINCT)
|
|
Expression ((Projection + (Change column names to column identifiers + Project names)))
|
|
Distinct (DISTINCT)
|
|
Distinct (Preliminary DISTINCT)
|
|
Expression ((Projection + (Change column names to column identifiers + Project names)))
|
|
Distinct (DISTINCT)
|
|
Distinct (Preliminary DISTINCT)
|
|
Expression ((Projection + Change column names to column identifiers))
|
|
ReadFromStorage (SystemNumbers)
|
|
-- 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
|
|
Expression ((Project names + (Projection + (Change column names to column identifiers + (Project names + (Projection + (Change column names to column identifiers + Project names)))))))
|
|
Distinct (DISTINCT)
|
|
Distinct (Preliminary DISTINCT)
|
|
Expression ((Projection + Change column names to column identifiers))
|
|
ReadFromStorage (SystemNumbers)
|
|
-- 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
|
|
Expression (Project names)
|
|
Distinct (DISTINCT)
|
|
Sorting (Sorting for ORDER BY)
|
|
Expression (Before ORDER BY)
|
|
Distinct (Preliminary DISTINCT)
|
|
Union
|
|
Expression ((Projection + (Change column names to column identifiers + Project names)))
|
|
Distinct (DISTINCT)
|
|
Distinct (Preliminary DISTINCT)
|
|
Expression ((Projection + Change column names to column identifiers))
|
|
ReadFromStorage (SystemNumbers)
|
|
Expression (( + ( + Project names)))
|
|
Distinct (DISTINCT)
|
|
Distinct (Preliminary DISTINCT)
|
|
Expression ((Projection + Change column names to column identifiers))
|
|
ReadFromStorage (SystemNumbers)
|
|
-- execute
|
|
0
|
|
1
|
|
-- do _not_ remove DISTINCT after JOIN
|
|
-- query
|
|
SELECT DISTINCT *
|
|
FROM
|
|
(
|
|
SELECT DISTINCT number AS n
|
|
FROM numbers(2)
|
|
) as x,
|
|
(
|
|
SELECT DISTINCT number AS n
|
|
FROM numbers(2)
|
|
) as y
|
|
-- explain
|
|
Expression (Project names)
|
|
Distinct (DISTINCT)
|
|
Distinct (Preliminary DISTINCT)
|
|
Expression ((Projection + DROP unused columns after JOIN))
|
|
Join (JOIN FillRightFirst)
|
|
Expression ((Change column names to column identifiers + Project names))
|
|
Distinct (DISTINCT)
|
|
Distinct (Preliminary DISTINCT)
|
|
Expression ((Projection + Change column names to column identifiers))
|
|
ReadFromStorage (SystemNumbers)
|
|
Expression ((Change column names to column identifiers + Project names))
|
|
Distinct (DISTINCT)
|
|
Distinct (Preliminary DISTINCT)
|
|
Expression ((Projection + Change column names to column identifiers))
|
|
ReadFromStorage (SystemNumbers)
|
|
-- execute
|
|
0 0
|
|
0 1
|
|
1 0
|
|
1 1
|
|
-- DISTINCT duplicates with several columns
|
|
-- query
|
|
SELECT DISTINCT *
|
|
FROM
|
|
(
|
|
SELECT DISTINCT *
|
|
FROM
|
|
(
|
|
SELECT DISTINCT number as a, 2*number as b
|
|
FROM numbers(3)
|
|
)
|
|
)
|
|
-- explain
|
|
Expression ((Project names + (Projection + (Change column names to column identifiers + (Project names + (Projection + (Change column names to column identifiers + Project names)))))))
|
|
Distinct (DISTINCT)
|
|
Distinct (Preliminary DISTINCT)
|
|
Expression ((Projection + Change column names to column identifiers))
|
|
ReadFromStorage (SystemNumbers)
|
|
-- execute
|
|
0 0
|
|
1 2
|
|
2 4
|
|
-- 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)
|
|
)
|
|
)
|
|
-- explain
|
|
Expression ((Project names + (Projection + (Change column names to column identifiers + (Project names + (Projection + (Change column names to column identifiers + Project names)))))))
|
|
Distinct (DISTINCT)
|
|
Distinct (Preliminary DISTINCT)
|
|
Expression ((Projection + Change column names to column identifiers))
|
|
ReadFromStorage (SystemNumbers)
|
|
-- execute
|
|
2 0 0
|
|
2 1 2
|
|
2 2 4
|
|
-- 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
|
|
-- explain
|
|
Expression (Project names)
|
|
Distinct (DISTINCT)
|
|
Distinct (Preliminary DISTINCT)
|
|
Expression (Projection)
|
|
ArrayJoin (ARRAY JOIN)
|
|
Expression ((DROP unused columns before ARRAY JOIN + (ARRAY JOIN actions + (Change column names to column identifiers + Project names))))
|
|
Distinct (DISTINCT)
|
|
Distinct (Preliminary DISTINCT)
|
|
Expression ((Projection + Change column names to column identifiers))
|
|
ReadFromStorage (Values)
|
|
-- execute
|
|
Hello
|
|
World
|
|
Goodbye
|
|
-- 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
|
|
Expression (Project names)
|
|
Distinct (DISTINCT)
|
|
Distinct (Preliminary DISTINCT)
|
|
Expression ((Projection + (Change column names to column identifiers + Project names)))
|
|
Filling
|
|
Distinct (DISTINCT)
|
|
Sorting (Sorting for ORDER BY)
|
|
Expression (Before ORDER BY)
|
|
Distinct (Preliminary DISTINCT)
|
|
Expression ((Projection + Change column names to column identifiers))
|
|
ReadFromStorage (Values)
|
|
-- 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']
|
|
-- explain
|
|
Expression (Project names)
|
|
Distinct (DISTINCT)
|
|
Distinct (Preliminary DISTINCT)
|
|
Expression (Projection)
|
|
Filter ((WHERE + (Change column names to column identifiers + Project names)))
|
|
Distinct (DISTINCT)
|
|
Distinct (Preliminary DISTINCT)
|
|
Expression ((Projection + Change column names to column identifiers))
|
|
ReadFromStorage (SystemOne)
|
|
-- execute
|
|
['Istanbul','Berlin','Bensheim']
|
|
-- 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
|
|
)
|
|
-- explain
|
|
Expression ((Project names + (Projection + (Change column names to column identifiers + (Project names + Projection)))))
|
|
Aggregating
|
|
Expression ((Before GROUP BY + (Change column names to column identifiers + (Project names + (Projection + DROP unused columns after JOIN)))))
|
|
Join (JOIN FillRightFirst)
|
|
Expression (Change column names to column identifiers)
|
|
ReadFromStorage (SystemNumbers)
|
|
Expression (Change column names to column identifiers)
|
|
ReadFromStorage (SystemNumbers)
|
|
-- execute
|
|
0
|
|
2
|
|
1
|
|
-- 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
|
|
)
|
|
-- explain
|
|
Expression (Project names)
|
|
Distinct (DISTINCT)
|
|
Distinct (Preliminary DISTINCT)
|
|
Expression ((Projection + (Change column names to column identifiers + (Project names + Projection))))
|
|
Aggregating
|
|
Expression ((Before GROUP BY + (Change column names to column identifiers + (Project names + (Projection + DROP unused columns after JOIN)))))
|
|
Join (JOIN FillRightFirst)
|
|
Expression (Change column names to column identifiers)
|
|
ReadFromStorage (SystemNumbers)
|
|
Expression (Change column names to column identifiers)
|
|
ReadFromStorage (SystemNumbers)
|
|
-- execute
|
|
12
|
|
-- 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
|
|
)
|
|
-- explain
|
|
Expression (Project names)
|
|
Distinct (DISTINCT)
|
|
Distinct (Preliminary DISTINCT)
|
|
Expression ((Projection + (Change column names to column identifiers + (Project names + Projection))))
|
|
Rollup
|
|
Aggregating
|
|
Expression ((Before GROUP BY + (Change column names to column identifiers + (Project names + (Projection + DROP unused columns after JOIN)))))
|
|
Join (JOIN FillRightFirst)
|
|
Expression (Change column names to column identifiers)
|
|
ReadFromStorage (SystemNumbers)
|
|
Expression (Change column names to column identifiers)
|
|
ReadFromStorage (SystemNumbers)
|
|
-- 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
|
|
)
|
|
-- explain
|
|
Expression ((Project names + (Projection + (Change column names to column identifiers + (Project names + Projection)))))
|
|
Rollup
|
|
Aggregating
|
|
Expression ((Before GROUP BY + (Change column names to column identifiers + (Project names + (Projection + DROP unused columns after JOIN)))))
|
|
Join (JOIN FillRightFirst)
|
|
Expression (Change column names to column identifiers)
|
|
ReadFromStorage (SystemNumbers)
|
|
Expression (Change column names to column identifiers)
|
|
ReadFromStorage (SystemNumbers)
|
|
-- execute
|
|
0
|
|
2
|
|
1
|
|
0
|
|
-- 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
|
|
)
|
|
-- explain
|
|
Expression (Project names)
|
|
Distinct (DISTINCT)
|
|
Distinct (Preliminary DISTINCT)
|
|
Expression ((Projection + (Change column names to column identifiers + (Project names + Projection))))
|
|
Cube
|
|
Aggregating
|
|
Expression ((Before GROUP BY + (Change column names to column identifiers + (Project names + (Projection + DROP unused columns after JOIN)))))
|
|
Join (JOIN FillRightFirst)
|
|
Expression (Change column names to column identifiers)
|
|
ReadFromStorage (SystemNumbers)
|
|
Expression (Change column names to column identifiers)
|
|
ReadFromStorage (SystemNumbers)
|
|
-- 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
|
|
)
|
|
-- explain
|
|
Expression ((Project names + (Projection + (Change column names to column identifiers + (Project names + Projection)))))
|
|
Cube
|
|
Aggregating
|
|
Expression ((Before GROUP BY + (Change column names to column identifiers + (Project names + (Projection + DROP unused columns after JOIN)))))
|
|
Join (JOIN FillRightFirst)
|
|
Expression (Change column names to column identifiers)
|
|
ReadFromStorage (SystemNumbers)
|
|
Expression (Change column names to column identifiers)
|
|
ReadFromStorage (SystemNumbers)
|
|
-- execute
|
|
0
|
|
2
|
|
1
|
|
0
|
|
-- 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
|
|
)
|
|
-- explain
|
|
Expression (Project names)
|
|
Distinct (DISTINCT)
|
|
Distinct (Preliminary DISTINCT)
|
|
Expression ((Projection + (Change column names to column identifiers + (Project names + Projection))))
|
|
TotalsHaving
|
|
Aggregating
|
|
Expression ((Before GROUP BY + (Change column names to column identifiers + (Project names + (Projection + DROP unused columns after JOIN)))))
|
|
Join (JOIN FillRightFirst)
|
|
Expression (Change column names to column identifiers)
|
|
ReadFromStorage (SystemNumbers)
|
|
Expression (Change column names to column identifiers)
|
|
ReadFromStorage (SystemNumbers)
|
|
-- 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
|
|
)
|
|
-- explain
|
|
Expression ((Project names + (Projection + (Change column names to column identifiers + (Project names + Projection)))))
|
|
TotalsHaving
|
|
Aggregating
|
|
Expression ((Before GROUP BY + (Change column names to column identifiers + (Project names + (Projection + DROP unused columns after JOIN)))))
|
|
Join (JOIN FillRightFirst)
|
|
Expression (Change column names to column identifiers)
|
|
ReadFromStorage (SystemNumbers)
|
|
Expression (Change column names to column identifiers)
|
|
ReadFromStorage (SystemNumbers)
|
|
-- execute
|
|
0
|
|
2
|
|
1
|
|
|
|
0
|
|
-- DISTINCT COUNT() with GROUP BY => do _not_ remove DISTINCT
|
|
-- query
|
|
select distinct count() from numbers(10) group by number
|
|
-- explain
|
|
Expression (Project names)
|
|
Distinct (DISTINCT)
|
|
Distinct (Preliminary DISTINCT)
|
|
Expression (Projection)
|
|
Aggregating
|
|
Expression ((Before GROUP BY + Change column names to column identifiers))
|
|
ReadFromStorage (SystemNumbers)
|
|
-- execute
|
|
1
|