forked from ClickHouse/ClickHouse
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an optimization that removes redundant equality
checks on boolean functions. This fixes a bug in which the primary index is not used for queries like SELECT * FROM <table> WHERE <pk> in (<n>) = 1
- Loading branch information
1 parent
f36ae13
commit 9d4f1d8
Showing
4 changed files
with
194 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
tests/queries/0_stateless/03032_redundant_equals.reference
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
100 | ||
100 | ||
100 | ||
100 | ||
100 | ||
100 | ||
0 | ||
0 | ||
0 | ||
1 | ||
100 | ||
101 | ||
100 | ||
101 | ||
100 | ||
101 | ||
100 | ||
1 | ||
1 | ||
1 | ||
1 | ||
1 | ||
1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
DROP TABLE IF EXISTS test_table; | ||
|
||
CREATE TABLE test_table | ||
( | ||
k UInt64, | ||
) | ||
ENGINE = MergeTree | ||
ORDER BY k; | ||
|
||
INSERT INTO test_table SELECT number FROM numbers(10000000); | ||
|
||
SELECT * FROM test_table WHERE k in (100) = 1; | ||
SELECT * FROM test_table WHERE k = (100) = 1; | ||
SELECT * FROM test_table WHERE k not in (100) = 0; | ||
SELECT * FROM test_table WHERE k != (100) = 0; | ||
SELECT * FROM test_table WHERE 1 = (k = 100); | ||
SELECT * FROM test_table WHERE 0 = (k not in (100)); | ||
SELECT * FROM test_table WHERE k < 1 = 1; | ||
SELECT * FROM test_table WHERE k >= 1 = 0; | ||
SELECT * FROM test_table WHERE k > 1 = 0; | ||
SELECT * FROM test_table WHERE ((k not in (101) = 0) OR (k in (100) = 1)) = 1; | ||
SELECT * FROM test_table WHERE (NOT ((k not in (100) = 0) OR (k in (100) = 1))) = 0; | ||
SELECT * FROM test_table WHERE (NOT ((k in (101) = 0) OR (k in (100) = 1))) = 1; | ||
SELECT * FROM test_table WHERE ((k not in (101) = 0) OR (k in (100) = 1)) = 1; | ||
SELECT * FROM test_table WHERE ((k not in (99) = 1) AND (k in (100) = 1)) = 1; | ||
|
||
SELECT count() | ||
FROM | ||
( | ||
EXPLAIN PLAN indexes=1 | ||
SELECT * FROM test_table WHERE k in (100) = 1 | ||
) | ||
WHERE | ||
explain LIKE '%Granules: 1/%'; | ||
|
||
SELECT count() | ||
FROM | ||
( | ||
EXPLAIN PLAN indexes=1 | ||
SELECT * FROM test_table WHERE k >= 1 = 0 | ||
) | ||
WHERE | ||
explain LIKE '%Granules: 1/%'; | ||
|
||
SELECT count() | ||
FROM | ||
( | ||
EXPLAIN PLAN indexes=1 | ||
SELECT * FROM test_table WHERE k not in (100) = 0 | ||
) | ||
WHERE | ||
explain LIKE '%Granules: 1/%'; | ||
|
||
SELECT count() | ||
FROM | ||
( | ||
EXPLAIN PLAN indexes=1 | ||
SELECT * FROM test_table WHERE k > 1 = 0 | ||
) | ||
WHERE | ||
explain LIKE '%Granules: 1/%'; | ||
|
||
SELECT count() | ||
FROM | ||
( | ||
EXPLAIN PLAN indexes=1 | ||
SELECT * FROM test_table WHERE (NOT ((k not in (100) = 0) OR (k in (100) = 1))) = 0 | ||
) | ||
WHERE | ||
explain LIKE '%Granules: 1/%'; | ||
|
||
|
||
SELECT count() | ||
FROM | ||
( | ||
EXPLAIN PLAN indexes=1 | ||
SELECT * FROM test_table WHERE (NOT ((k in (101) = 0) OR (k in (100) = 1))) = 1 | ||
) | ||
WHERE | ||
explain LIKE '%Granules: 1/%'; | ||
|
||
|
||
DROP TABLE test_table; |