mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-28 02:21:59 +00:00
Do not move to prewhere in select with joins
This commit is contained in:
parent
35431e91e3
commit
b76779797a
@ -560,7 +560,10 @@ InterpreterSelectQuery::InterpreterSelectQuery(
|
|||||||
view = nullptr;
|
view = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (try_move_to_prewhere && storage && storage->canMoveConditionsToPrewhere() && query.where() && !query.prewhere())
|
if (try_move_to_prewhere
|
||||||
|
&& storage && storage->canMoveConditionsToPrewhere()
|
||||||
|
&& query.where() && !query.prewhere()
|
||||||
|
&& !query.hasJoin()) /// Join may produce rows with nulls or default values, it's difficult to analyze if they affected or not.
|
||||||
{
|
{
|
||||||
/// PREWHERE optimization: transfer some condition from WHERE to PREWHERE if enabled and viable
|
/// PREWHERE optimization: transfer some condition from WHERE to PREWHERE if enabled and viable
|
||||||
if (const auto & column_sizes = storage->getColumnSizes(); !column_sizes.empty())
|
if (const auto & column_sizes = storage->getColumnSizes(); !column_sizes.empty())
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
-- { echoOn }
|
||||||
|
|
||||||
|
SELECT * FROM test1 LEFT JOIN test2 ON test1.col1 = test2.col1
|
||||||
|
WHERE test2.col1 IS NULL
|
||||||
|
ORDER BY test2.col1
|
||||||
|
;
|
||||||
|
12321 -30 \N \N
|
||||||
|
SELECT * FROM test2 RIGHT JOIN test1 ON test2.col1 = test1.col1
|
||||||
|
WHERE test2.col1 IS NULL
|
||||||
|
ORDER BY test2.col1
|
||||||
|
;
|
||||||
|
\N \N 12321 -30
|
||||||
|
SELECT * FROM test1 LEFT JOIN test2 ON test1.col1 = test2.col1
|
||||||
|
WHERE test2.col1 IS NOT NULL
|
||||||
|
ORDER BY test2.col1
|
||||||
|
;
|
||||||
|
123 123 123 5600
|
||||||
|
321 -32 321 5601
|
||||||
|
SELECT * FROM test2 RIGHT JOIN test1 ON test2.col1 = test1.col1
|
||||||
|
WHERE test2.col1 IS NOT NULL
|
||||||
|
ORDER BY test2.col1
|
||||||
|
;
|
||||||
|
123 5600 123 123
|
||||||
|
321 5601 321 -32
|
||||||
|
SELECT test2.col1, test1.* FROM test2 RIGHT JOIN test1 ON test2.col1 = test1.col1
|
||||||
|
WHERE test2.col1 IS NOT NULL
|
||||||
|
ORDER BY test2.col1
|
||||||
|
;
|
||||||
|
123 123 123
|
||||||
|
321 321 -32
|
||||||
|
SELECT test2.col3, test1.* FROM test2 RIGHT JOIN test1 ON test2.col1 = test1.col1
|
||||||
|
WHERE test2.col1 IS NOT NULL
|
||||||
|
ORDER BY test2.col1
|
||||||
|
;
|
||||||
|
5600 123 123
|
||||||
|
5601 321 -32
|
||||||
|
DROP TABLE IF EXISTS test1;
|
||||||
|
DROP TABLE IF EXISTS test2;
|
43
tests/queries/0_stateless/02534_join_prewhere_bug_44062.sql
Normal file
43
tests/queries/0_stateless/02534_join_prewhere_bug_44062.sql
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
|
||||||
|
CREATE OR REPLACE TABLE test1 ( `col1` UInt64, `col2` Int8 ) ENGINE = MergeTree ORDER BY col1;
|
||||||
|
CREATE OR REPLACE TABLE test2 ( `col1` UInt64, `col3` Int16 ) ENGINE = MergeTree ORDER BY col1;
|
||||||
|
|
||||||
|
INSERT INTO test1 VALUES (123, 123), (12321, -30), (321, -32);
|
||||||
|
INSERT INTO test2 VALUES (123, 5600), (321, 5601);
|
||||||
|
|
||||||
|
SET join_use_nulls = 1;
|
||||||
|
|
||||||
|
-- { echoOn }
|
||||||
|
|
||||||
|
SELECT * FROM test1 LEFT JOIN test2 ON test1.col1 = test2.col1
|
||||||
|
WHERE test2.col1 IS NULL
|
||||||
|
ORDER BY test2.col1
|
||||||
|
;
|
||||||
|
|
||||||
|
SELECT * FROM test2 RIGHT JOIN test1 ON test2.col1 = test1.col1
|
||||||
|
WHERE test2.col1 IS NULL
|
||||||
|
ORDER BY test2.col1
|
||||||
|
;
|
||||||
|
|
||||||
|
SELECT * FROM test1 LEFT JOIN test2 ON test1.col1 = test2.col1
|
||||||
|
WHERE test2.col1 IS NOT NULL
|
||||||
|
ORDER BY test2.col1
|
||||||
|
;
|
||||||
|
|
||||||
|
SELECT * FROM test2 RIGHT JOIN test1 ON test2.col1 = test1.col1
|
||||||
|
WHERE test2.col1 IS NOT NULL
|
||||||
|
ORDER BY test2.col1
|
||||||
|
;
|
||||||
|
|
||||||
|
SELECT test2.col1, test1.* FROM test2 RIGHT JOIN test1 ON test2.col1 = test1.col1
|
||||||
|
WHERE test2.col1 IS NOT NULL
|
||||||
|
ORDER BY test2.col1
|
||||||
|
;
|
||||||
|
|
||||||
|
SELECT test2.col3, test1.* FROM test2 RIGHT JOIN test1 ON test2.col1 = test1.col1
|
||||||
|
WHERE test2.col1 IS NOT NULL
|
||||||
|
ORDER BY test2.col1
|
||||||
|
;
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS test1;
|
||||||
|
DROP TABLE IF EXISTS test2;
|
Loading…
Reference in New Issue
Block a user