Test for proper filtering after intermediate PREWHERE steps

This commit is contained in:
Alexander Gololobov 2022-11-17 19:08:23 +01:00
parent 59a9fe0d92
commit 3d6aa4738f
2 changed files with 106 additions and 0 deletions

View File

@ -0,0 +1,78 @@
-- { echoOn }
CREATE TABLE test_filter(a Int32, b Int32, c Int32) ENGINE = MergeTree() ORDER BY a SETTINGS index_granularity = 3;
INSERT INTO test_filter SELECT number, number+1, (number/2 + 1) % 2 FROM numbers(15);
SELECT _part_offset, intDiv(_part_offset, 3) as granule, * FROM test_filter ORDER BY _part_offset;
0 0 0 1 1
1 0 1 2 1
2 0 2 3 0
3 1 3 4 0
4 1 4 5 1
5 1 5 6 1
6 2 6 7 0
7 2 7 8 0
8 2 8 9 1
9 3 9 10 1
10 3 10 11 0
11 3 11 12 0
12 4 12 13 1
13 4 13 14 1
14 4 14 15 0
-- Check that division by zero occurs on some rows
SELECT intDiv(b, c) FROM test_filter; -- { serverError ILLEGAL_DIVISION }
-- Filter out those rows using WHERE or PREWHERE
SELECT intDiv(b, c) FROM test_filter WHERE c != 0;
1
2
5
6
9
10
13
14
SELECT intDiv(b, c) FROM test_filter PREWHERE c != 0;
1
2
5
6
9
10
13
14
SELECT intDiv(b, c) FROM test_filter PREWHERE c != 0 WHERE b%2 != 0;
1
5
9
13
SET mutations_sync = 2, allow_experimental_lightweight_delete = 1;
-- Delete all rows where division by zero could occur
DELETE FROM test_filter WHERE c = 0;
-- Test that now division by zero doesn't occur without explicit condition
SELECT intDiv(b, c) FROM test_filter;
1
2
5
6
9
10
13
14
SELECT * FROM test_filter PREWHERE intDiv(b, c) > 0;
0 1 1
1 2 1
4 5 1
5 6 1
8 9 1
9 10 1
12 13 1
13 14 1
SELECT * FROM test_filter PREWHERE b != 0 WHERE intDiv(b, c) > 0;
0 1 1
1 2 1
4 5 1
5 6 1
8 9 1
9 10 1
12 13 1
13 14 1
-- { ehcoOff }
DROP TABLE test_filter;

View File

@ -0,0 +1,28 @@
DROP TABLE IF EXISTS test_filter;
-- { echoOn }
CREATE TABLE test_filter(a Int32, b Int32, c Int32) ENGINE = MergeTree() ORDER BY a SETTINGS index_granularity = 3;
INSERT INTO test_filter SELECT number, number+1, (number/2 + 1) % 2 FROM numbers(15);
SELECT _part_offset, intDiv(_part_offset, 3) as granule, * FROM test_filter ORDER BY _part_offset;
-- Check that division by zero occurs on some rows
SELECT intDiv(b, c) FROM test_filter; -- { serverError ILLEGAL_DIVISION }
-- Filter out those rows using WHERE or PREWHERE
SELECT intDiv(b, c) FROM test_filter WHERE c != 0;
SELECT intDiv(b, c) FROM test_filter PREWHERE c != 0;
SELECT intDiv(b, c) FROM test_filter PREWHERE c != 0 WHERE b%2 != 0;
SET mutations_sync = 2, allow_experimental_lightweight_delete = 1;
-- Delete all rows where division by zero could occur
DELETE FROM test_filter WHERE c = 0;
-- Test that now division by zero doesn't occur without explicit condition
SELECT intDiv(b, c) FROM test_filter;
SELECT * FROM test_filter PREWHERE intDiv(b, c) > 0;
SELECT * FROM test_filter PREWHERE b != 0 WHERE intDiv(b, c) > 0;
-- { ehcoOff }
DROP TABLE test_filter;