Merge pull request #68843 from ClickHouse/fix-float

Fix flaky `02932_analyzer_rewrite_sum_column_and_constant `
This commit is contained in:
Nikita Mikhaylov 2024-08-24 13:40:53 +00:00 committed by GitHub
commit e7054029c4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 18 deletions

View File

@ -1635,21 +1635,21 @@ QUERY id: 0
JOIN TREE JOIN TREE
TABLE id: 10, alias: __table1, table_name: default.test_table TABLE id: 10, alias: __table1, table_name: default.test_table
SELECT sum(float64 + 2) From test_table; SELECT sum(float64 + 2) From test_table;
26.5 26.875
SELECT sum(2 + float64) From test_table; SELECT sum(2 + float64) From test_table;
26.5 26.875
SELECT sum(float64 - 2) From test_table; SELECT sum(float64 - 2) From test_table;
6.5 6.875
SELECT sum(2 - float64) From test_table; SELECT sum(2 - float64) From test_table;
-6.5 -6.875
SELECT sum(float64) + 2 * count(float64) From test_table; SELECT sum(float64) + 2 * count(float64) From test_table;
26.5 26.875
SELECT 2 * count(float64) + sum(float64) From test_table; SELECT 2 * count(float64) + sum(float64) From test_table;
26.5 26.875
SELECT sum(float64) - 2 * count(float64) From test_table; SELECT sum(float64) - 2 * count(float64) From test_table;
6.5 6.875
SELECT 2 * count(float64) - sum(float64) From test_table; SELECT 2 * count(float64) - sum(float64) From test_table;
-6.5 -6.875
EXPLAIN QUERY TREE (SELECT sum(float64 + 2) From test_table); EXPLAIN QUERY TREE (SELECT sum(float64 + 2) From test_table);
QUERY id: 0 QUERY id: 0
PROJECTION COLUMNS PROJECTION COLUMNS
@ -2463,25 +2463,25 @@ QUERY id: 0
JOIN TREE JOIN TREE
TABLE id: 12, alias: __table1, table_name: default.test_table TABLE id: 12, alias: __table1, table_name: default.test_table
SELECT sum(float64 + 2) + sum(float64 + 3) From test_table; SELECT sum(float64 + 2) + sum(float64 + 3) From test_table;
58 58.75
SELECT sum(float64 + 2) - sum(float64 + 3) From test_table; SELECT sum(float64 + 2) - sum(float64 + 3) From test_table;
-5 -5
SELECT sum(float64 - 2) + sum(float64 - 3) From test_table; SELECT sum(float64 - 2) + sum(float64 - 3) From test_table;
8 8.75
SELECT sum(float64 - 2) - sum(float64 - 3) From test_table; SELECT sum(float64 - 2) - sum(float64 - 3) From test_table;
5 5
SELECT sum(2 - float64) - sum(3 - float64) From test_table; SELECT sum(2 - float64) - sum(3 - float64) From test_table;
-5 -5
SELECT (sum(float64) + 2 * count(float64)) + (sum(float64) + 3 * count(float64)) From test_table; SELECT (sum(float64) + 2 * count(float64)) + (sum(float64) + 3 * count(float64)) From test_table;
58 58.75
SELECT (sum(float64) + 2 * count(float64)) - (sum(float64) + 3 * count(float64)) From test_table; SELECT (sum(float64) + 2 * count(float64)) - (sum(float64) + 3 * count(float64)) From test_table;
-5 -5
SELECT (sum(float64) - 2 * count(float64)) + (sum(float64) - 3 * count(float64)) From test_table; SELECT (sum(float64) - 2 * count(float64)) + (sum(float64) - 3 * count(float64)) From test_table;
8 8.75
SELECT (sum(float64) - 2 * count(float64)) - (sum(float64) - 3 * count(float64)) From test_table; SELECT (sum(float64) - 2 * count(float64)) - (sum(float64) - 3 * count(float64)) From test_table;
5 5
SELECT (2 * count(float64) - sum(float64)) + (3 * count(float64) - sum(float64)) From test_table; SELECT (2 * count(float64) - sum(float64)) + (3 * count(float64) - sum(float64)) From test_table;
-8 -8.75
EXPLAIN QUERY TREE (SELECT sum(float64 + 2) + sum(float64 + 3) From test_table); EXPLAIN QUERY TREE (SELECT sum(float64 + 2) + sum(float64 + 3) From test_table);
QUERY id: 0 QUERY id: 0
PROJECTION COLUMNS PROJECTION COLUMNS

View File

@ -25,11 +25,12 @@ CREATE TABLE test_table
decimal32 Decimal32(5), decimal32 Decimal32(5),
) ENGINE=MergeTree ORDER BY uint64; ) ENGINE=MergeTree ORDER BY uint64;
INSERT INTO test_table VALUES (1, 1.1, 1.11); -- Use Float64 numbers divisible by 1/16 (or some other small power of two), so that their sum doesn't depend on summation order.
INSERT INTO test_table VALUES (2, 2.2, 2.22); INSERT INTO test_table VALUES (1, 1.125, 1.11);
INSERT INTO test_table VALUES (3, 3.3, 3.33); INSERT INTO test_table VALUES (2, 2.250, 2.22);
INSERT INTO test_table VALUES (4, 4.4, 4.44); INSERT INTO test_table VALUES (3, 3.375, 3.33);
INSERT INTO test_table VALUES (5, 5.5, 5.55); INSERT INTO test_table VALUES (4, 4.500, 4.44);
INSERT INTO test_table VALUES (5, 5.625, 5.55);
-- { echoOn } -- { echoOn }
SELECT sum(uint64 + 1 AS i) from test_table where i > 0; SELECT sum(uint64 + 1 AS i) from test_table where i > 0;