ClickHouse/tests/queries/0_stateless/02500_remove_redundant_distinct.reference
Igor Nikonov cc3c8a4e30 Add test
2023-03-15 12:44:22 +00:00

480 lines
12 KiB
Plaintext

-- Disabled query_plan_remove_redundant_distinct
Expression (Projection)
Distinct
Distinct (Preliminary DISTINCT)
Expression ((Before ORDER BY + Projection))
Distinct
Distinct (Preliminary DISTINCT)
Expression ((Before ORDER BY + Projection))
Distinct
Distinct (Preliminary DISTINCT)
Expression (Before ORDER BY)
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 ((Projection + (Before ORDER BY + (Projection + (Before ORDER BY + Projection)))))
Distinct
Distinct (Preliminary DISTINCT)
Expression (Before ORDER BY)
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 (Projection)
Distinct
Sorting (Sorting for ORDER BY)
Distinct (Preliminary DISTINCT)
Union
Expression ((Before ORDER BY + Projection))
Distinct
Distinct (Preliminary DISTINCT)
Expression (Before ORDER BY)
ReadFromStorage (SystemNumbers)
Expression (( + Projection))
Distinct
Distinct (Preliminary DISTINCT)
Expression (Before ORDER BY)
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 (Projection)
Distinct
Distinct (Preliminary DISTINCT)
Expression (Before ORDER BY)
Join (JOIN FillRightFirst)
Expression ((Before JOIN + Projection))
Distinct
Distinct (Preliminary DISTINCT)
Expression (Before ORDER BY)
ReadFromStorage (SystemNumbers)
Expression ((Joined actions + (Rename joined columns + Projection)))
Distinct
Distinct (Preliminary DISTINCT)
Expression (Before ORDER BY)
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 ((Projection + (Before ORDER BY + (Projection + (Before ORDER BY + Projection)))))
Distinct
Distinct (Preliminary DISTINCT)
Expression (Before ORDER BY)
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 ((Projection + (Before ORDER BY + (Projection + (Before ORDER BY + Projection)))))
Distinct
Distinct (Preliminary DISTINCT)
Expression (Before ORDER BY)
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 (Projection)
Distinct
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)
-- 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 (Projection)
Distinct
Distinct (Preliminary DISTINCT)
Expression ((Before ORDER BY + Projection))
Filling
Distinct
Sorting (Sorting for ORDER BY)
Distinct (Preliminary DISTINCT)
Expression (Before ORDER BY)
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 (( + Projection))
Distinct
Distinct (Preliminary DISTINCT)
Expression (Before ORDER BY)
Filter ((WHERE + Projection))
Distinct
Distinct (Preliminary DISTINCT)
Expression (Before ORDER BY)
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 ((Projection + (Before ORDER BY + (Projection + Before ORDER BY))))
Aggregating
Expression ((Before GROUP BY + (Projection + Before ORDER BY)))
Join (JOIN FillRightFirst)
Expression (Before JOIN)
ReadFromStorage (SystemNumbers)
Expression ((Joined actions + (Rename joined columns + (Projection + Before ORDER BY))))
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 (Projection)
Distinct
Distinct (Preliminary DISTINCT)
Expression ((Before ORDER BY + (Projection + Before ORDER BY)))
Aggregating
Expression ((Before GROUP BY + (Projection + Before ORDER BY)))
Join (JOIN FillRightFirst)
Expression (Before JOIN)
ReadFromStorage (SystemNumbers)
Expression ((Joined actions + (Rename joined columns + (Projection + Before ORDER BY))))
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 (Projection)
Distinct
Distinct (Preliminary DISTINCT)
Expression ((Before ORDER BY + (Projection + Before ORDER BY)))
Rollup
Aggregating
Expression ((Before GROUP BY + (Projection + Before ORDER BY)))
Join (JOIN FillRightFirst)
Expression (Before JOIN)
ReadFromStorage (SystemNumbers)
Expression ((Joined actions + (Rename joined columns + (Projection + Before ORDER BY))))
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 ((Projection + (Before ORDER BY + (Projection + Before ORDER BY))))
Rollup
Aggregating
Expression ((Before GROUP BY + (Projection + Before ORDER BY)))
Join (JOIN FillRightFirst)
Expression (Before JOIN)
ReadFromStorage (SystemNumbers)
Expression ((Joined actions + (Rename joined columns + (Projection + Before ORDER BY))))
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 (Projection)
Distinct
Distinct (Preliminary DISTINCT)
Expression ((Before ORDER BY + (Projection + Before ORDER BY)))
Cube
Aggregating
Expression ((Before GROUP BY + (Projection + Before ORDER BY)))
Join (JOIN FillRightFirst)
Expression (Before JOIN)
ReadFromStorage (SystemNumbers)
Expression ((Joined actions + (Rename joined columns + (Projection + Before ORDER BY))))
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 ((Projection + (Before ORDER BY + (Projection + Before ORDER BY))))
Cube
Aggregating
Expression ((Before GROUP BY + (Projection + Before ORDER BY)))
Join (JOIN FillRightFirst)
Expression (Before JOIN)
ReadFromStorage (SystemNumbers)
Expression ((Joined actions + (Rename joined columns + (Projection + Before ORDER BY))))
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 (Projection)
Distinct
Distinct (Preliminary DISTINCT)
Expression ((Before ORDER BY + (Projection + Before ORDER BY)))
TotalsHaving
Aggregating
Expression ((Before GROUP BY + (Projection + Before ORDER BY)))
Join (JOIN FillRightFirst)
Expression (Before JOIN)
ReadFromStorage (SystemNumbers)
Expression ((Joined actions + (Rename joined columns + (Projection + Before ORDER BY))))
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 ((Projection + (Before ORDER BY + (Projection + Before ORDER BY))))
TotalsHaving
Aggregating
Expression ((Before GROUP BY + (Projection + Before ORDER BY)))
Join (JOIN FillRightFirst)
Expression (Before JOIN)
ReadFromStorage (SystemNumbers)
Expression ((Joined actions + (Rename joined columns + (Projection + Before ORDER BY))))
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 (Projection)
Distinct
Distinct (Preliminary DISTINCT)
Expression (Before ORDER BY)
Aggregating
Expression (Before GROUP BY)
ReadFromStorage (SystemNumbers)
-- execute
1