Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backport #61257 to 23.12: Fix possible incorrect result of aggregate …
…function `uniqExact`
- Loading branch information
1 parent
b28e249
commit 6d185f9
Showing
15 changed files
with
107 additions
and
4 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
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
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
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
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
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
16 changes: 16 additions & 0 deletions
16
tests/queries/0_stateless/03008_optimize_equal_ranges.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,16 @@ | ||
0 30000 | ||
1 30000 | ||
2 30000 | ||
0 30000 | ||
1 30000 | ||
2 30000 | ||
0 449985000 | ||
1 449985000 | ||
2 449985000 | ||
0 449985000 | ||
1 449985000 | ||
2 449985000 | ||
sum 1 1 | ||
sum 16 1 | ||
uniqExact 1 1 | ||
uniqExact 16 0 |
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,29 @@ | ||
DROP TABLE IF EXISTS t_optimize_equal_ranges; | ||
|
||
CREATE TABLE t_optimize_equal_ranges (a UInt64, b String, c UInt64) ENGINE = MergeTree ORDER BY a; | ||
|
||
SET max_block_size = 1024; | ||
SET max_bytes_before_external_group_by = 0; | ||
SET optimize_aggregation_in_order = 0; | ||
SET optimize_use_projections = 0; | ||
|
||
INSERT INTO t_optimize_equal_ranges SELECT 0, toString(number), number FROM numbers(30000); | ||
INSERT INTO t_optimize_equal_ranges SELECT 1, toString(number), number FROM numbers(30000); | ||
INSERT INTO t_optimize_equal_ranges SELECT 2, toString(number), number FROM numbers(30000); | ||
|
||
SELECT a, uniqExact(b) FROM t_optimize_equal_ranges GROUP BY a ORDER BY a SETTINGS max_threads = 16; | ||
SELECT a, uniqExact(b) FROM t_optimize_equal_ranges GROUP BY a ORDER BY a SETTINGS max_threads = 1; | ||
SELECT a, sum(c) FROM t_optimize_equal_ranges GROUP BY a ORDER BY a SETTINGS max_threads = 16; | ||
SELECT a, sum(c) FROM t_optimize_equal_ranges GROUP BY a ORDER BY a SETTINGS max_threads = 1; | ||
|
||
SYSTEM FLUSH LOGS; | ||
|
||
SELECT | ||
used_aggregate_functions[1] AS func, | ||
Settings['max_threads'] AS threads, | ||
ProfileEvents['AggregationOptimizedEqualRangesOfKeys'] > 0 | ||
FROM system.query_log | ||
WHERE type = 'QueryFinish' AND current_database = currentDatabase() AND query LIKE '%SELECT%FROM%t_optimize_equal_ranges%' | ||
ORDER BY func, threads; | ||
|
||
DROP TABLE t_optimize_equal_ranges; |
Empty file.
36 changes: 36 additions & 0 deletions
36
tests/queries/0_stateless/03008_uniq_exact_equal_ranges.sql
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,36 @@ | ||
DROP TABLE IF EXISTS t_uniq_exact; | ||
|
||
CREATE TABLE t_uniq_exact (a UInt64, b String, c UInt64) ENGINE = MergeTree ORDER BY a; | ||
|
||
SET group_by_two_level_threshold_bytes = 1; | ||
SET group_by_two_level_threshold = 1; | ||
SET max_threads = 4; | ||
SET max_bytes_before_external_group_by = 0; | ||
SET optimize_aggregation_in_order = 0; | ||
|
||
INSERT INTO t_uniq_exact SELECT 0, randomPrintableASCII(5), rand() FROM numbers(300000); | ||
INSERT INTO t_uniq_exact SELECT 1, randomPrintableASCII(5), rand() FROM numbers(300000); | ||
INSERT INTO t_uniq_exact SELECT 2, randomPrintableASCII(5), rand() FROM numbers(300000); | ||
INSERT INTO t_uniq_exact SELECT 3, randomPrintableASCII(5), rand() FROM numbers(300000); | ||
INSERT INTO t_uniq_exact SELECT 4, randomPrintableASCII(5), rand() FROM numbers(300000); | ||
INSERT INTO t_uniq_exact SELECT 5, randomPrintableASCII(5), rand() FROM numbers(300000); | ||
INSERT INTO t_uniq_exact SELECT 6, randomPrintableASCII(5), rand() FROM numbers(300000); | ||
INSERT INTO t_uniq_exact SELECT 7, randomPrintableASCII(5), rand() FROM numbers(300000); | ||
INSERT INTO t_uniq_exact SELECT 8, randomPrintableASCII(5), rand() FROM numbers(300000); | ||
INSERT INTO t_uniq_exact SELECT 9, randomPrintableASCII(5), rand() FROM numbers(300000); | ||
|
||
OPTIMIZE TABLE t_uniq_exact FINAL; | ||
|
||
SELECT a, uniqExact(b) FROM t_uniq_exact GROUP BY a ORDER BY a | ||
SETTINGS min_hit_rate_to_use_consecutive_keys_optimization = 1.0 | ||
EXCEPT | ||
SELECT a, uniqExact(b) FROM t_uniq_exact GROUP BY a ORDER BY a | ||
SETTINGS min_hit_rate_to_use_consecutive_keys_optimization = 0.5; | ||
|
||
SELECT a, sum(c) FROM t_uniq_exact GROUP BY a ORDER BY a | ||
SETTINGS min_hit_rate_to_use_consecutive_keys_optimization = 1.0 | ||
EXCEPT | ||
SELECT a, sum(c) FROM t_uniq_exact GROUP BY a ORDER BY a | ||
SETTINGS min_hit_rate_to_use_consecutive_keys_optimization = 0.5; | ||
|
||
DROP TABLE t_uniq_exact; |