ClickHouse/tests/queries/0_stateless/00597_push_down_predicate.reference
Azat Khuzhin 82e7e7d9cb Fix constant folding for expressions depends from subqueries result
Do not use subquery result, when value is unknown, for constant folding.

v2: fix simple subqueries, fixes 00597_push_down_predicate.
v3:
- use identity over introducing yet another cast analog (as suggested by @akuzm)
- simpler suitable_for_const_folding check
v4: use identity(cast()) since only cast() can provide corrent type (for
data types that does not have it's own type, i.e. DateTime)
v5: do not optimize consts if only_analyze isset, regardless the block
content
2021-01-21 21:26:50 +03:00

587 lines
7.3 KiB
Plaintext

-------No need for predicate optimization, but still works-------
1
1
1
2000-01-01 1 test string 1 1
-------Forbid push down-------
SELECT count()
FROM
(
SELECT
[number] AS a,
[number * 2] AS b
FROM system.numbers
LIMIT 1
) AS t
ARRAY JOIN
a,
b
WHERE NOT ignore(a + b)
1
SELECT
a,
b
FROM
(
SELECT 1 AS a
)
ANY LEFT JOIN
(
SELECT
1 AS a,
1 AS b
) USING (a)
WHERE b = 0
SELECT
a,
b
FROM
(
SELECT
1 AS a,
1 AS b
)
ANY RIGHT JOIN
(
SELECT 1 AS a
) USING (a)
WHERE b = 0
SELECT
a,
b
FROM
(
SELECT 1 AS a
)
ANY FULL OUTER JOIN
(
SELECT
1 AS a,
1 AS b
) USING (a)
WHERE b = 0
SELECT
a,
b
FROM
(
SELECT
1 AS a,
1 AS b
)
ANY FULL OUTER JOIN
(
SELECT 1 AS a
) USING (a)
WHERE b = 0
-------Need push down-------
SELECT toString(value) AS value
FROM
(
SELECT 1 AS value
)
1
SELECT id
FROM
(
SELECT 1 AS id
UNION ALL
SELECT 2 AS `--predicate_optimizer_0`
WHERE 0
)
WHERE id = 1
1
SELECT id
FROM
(
SELECT arrayJoin([1, 2, 3]) AS id
WHERE id = 1
)
WHERE id = 1
1
SELECT id
FROM
(
SELECT arrayJoin([1, 2, 3]) AS id
WHERE id = 1
)
WHERE id = 1
1
SELECT
id,
subquery
FROM
(
SELECT
1 AS id,
identity(cast(1, \'UInt8\')) AS subquery
)
WHERE subquery = 1
1 1
SELECT
a,
b
FROM
(
SELECT
toUInt64(sum(id) AS b) AS a,
b
FROM test_00597
HAVING a = 3
)
WHERE a = 3
3 3
SELECT
date,
id,
name,
value
FROM
(
SELECT
date,
name,
value,
min(id) AS id
FROM test_00597
GROUP BY
date,
name,
value
HAVING id = 1
)
WHERE id = 1
2000-01-01 1 test string 1 1
SELECT
a,
b
FROM
(
SELECT
toUInt64(sum(id) AS b) AS a,
b
FROM test_00597 AS table_alias
HAVING b = 3
) AS outer_table_alias
WHERE b = 3
3 3
SELECT
date,
id,
name,
value
FROM
(
SELECT
date,
id,
name,
value
FROM test_00597
WHERE id = 1
)
WHERE id = 1
2000-01-01 1 test string 1 1
SELECT
date,
id,
name,
value
FROM
(
SELECT
date,
id,
name,
value
FROM
(
SELECT
date,
id,
name,
value
FROM test_00597
WHERE id = 1
)
WHERE id = 1
)
WHERE id = 1
2000-01-01 1 test string 1 1
SELECT
date,
id,
name,
value
FROM
(
SELECT
date,
id,
name,
value
FROM
(
SELECT
date,
id,
name,
value
FROM test_00597
WHERE id = 1
) AS b
WHERE id = 1
)
WHERE id = 1
2000-01-01 1 test string 1 1
SELECT
date,
id,
name,
value
FROM
(
SELECT
date,
id,
name,
value
FROM test_00597
WHERE id = 1
)
WHERE id = 1
2000-01-01 1 test string 1 1
SELECT
date,
id,
name,
value
FROM
(
SELECT
date,
id,
name,
value
FROM
(
SELECT
date,
id,
name,
value
FROM test_00597
WHERE id = 1
)
WHERE id = 1
)
WHERE id = 1
2000-01-01 1 test string 1 1
SELECT
date,
id,
name,
value
FROM
(
SELECT
date,
id,
name,
value
FROM test_00597
WHERE id = 1
) AS b
WHERE id = 1
2000-01-01 1 test string 1 1
SELECT
date,
id,
name,
value
FROM
(
SELECT
date,
id,
name,
value
FROM
(
SELECT
date,
id,
name,
value
FROM test_00597
WHERE id = 1
) AS a
WHERE id = 1
) AS b
WHERE id = 1
2000-01-01 1 test string 1 1
SELECT
id,
date,
value
FROM
(
SELECT
id,
date,
min(value) AS value
FROM test_00597
WHERE id = 1
GROUP BY
id,
date
)
WHERE id = 1
1 2000-01-01 1
SELECT
date,
id,
name,
value
FROM
(
SELECT
date,
id,
name,
value
FROM test_00597
WHERE id = 1
UNION ALL
SELECT
date,
id,
name,
value
FROM test_00597
WHERE id = 1
)
WHERE id = 1
2000-01-01 1 test string 1 1
2000-01-01 1 test string 1 1
SELECT
date,
id,
name,
value,
date,
name,
value
FROM
(
SELECT
date,
id,
name,
value
FROM test_00597
WHERE id = 1
)
ANY LEFT JOIN
(
SELECT id
FROM test_00597
) USING (id)
WHERE id = 1
2000-01-01 1 test string 1 1 2000-01-01 test string 1 1
SELECT
id,
date,
name,
value
FROM
(
SELECT toInt8(1) AS id
)
ANY LEFT JOIN
(
SELECT
date,
id,
name,
value
FROM test_00597
) AS test_00597 USING (id)
WHERE value = 1
1 2000-01-01 test string 1 1
SELECT value
FROM
(
SELECT toInt8(1) AS id
)
ANY LEFT JOIN test_00597 AS b USING (id)
WHERE value = 1
1
SELECT
date,
id,
name,
value
FROM
(
SELECT
date,
id,
name,
value,
date,
name,
value
FROM
(
SELECT
date,
id,
name,
value
FROM test_00597
WHERE id = 1
)
ANY LEFT JOIN
(
SELECT id
FROM test_00597
) USING (id)
WHERE id = 1
)
WHERE id = 1
2000-01-01 1 test string 1 1
SELECT
date,
id,
name,
value,
b.date,
b.name,
b.value
FROM
(
SELECT
date,
id,
name,
value
FROM test_00597
)
ANY LEFT JOIN
(
SELECT
date,
id,
name,
value
FROM test_00597
) AS b USING (id)
WHERE b.id = 1
2000-01-01 1 test string 1 1 2000-01-01 test string 1 1
SELECT
id,
date,
name,
value
FROM
(
SELECT
toInt8(1) AS id,
toDate(\'2000-01-01\') AS date
FROM system.numbers
LIMIT 1
)
ANY LEFT JOIN
(
SELECT
date,
id,
name,
value
FROM test_00597
) AS b USING (date, id)
WHERE b.date = toDate(\'2000-01-01\')
1 2000-01-01 test string 1 1
SELECT
date,
id,
name,
value,
`b.date`,
`b.id`,
`b.name`,
`b.value`
FROM
(
SELECT
date,
id,
name,
value,
b.date,
b.id,
b.name,
b.value
FROM
(
SELECT
date,
id,
name,
value
FROM test_00597
WHERE id = 1
) AS a
ANY LEFT JOIN
(
SELECT
date,
id,
name,
value
FROM test_00597
) AS b ON id = b.id
WHERE id = 1
)
WHERE id = 1
2000-01-01 1 test string 1 1 2000-01-01 1 test string 1 1
SELECT
date,
id,
name,
value,
r.date,
r.name,
r.value
FROM
(
SELECT
date,
id,
name,
value
FROM test_00597
)
SEMI LEFT JOIN
(
SELECT
date,
id,
name,
value
FROM
(
SELECT
date,
id,
name,
value
FROM test_00597
WHERE id = 1
)
WHERE id = 1
) AS r USING (id)
WHERE r.id = 1
2000-01-01 1 test string 1 1 2000-01-01 test string 1 1