# name: test/optimizer/perfect_ht.test # description: Test aggregates that can trigger a perfect HT # group: [optimizer] statement ok CREATE TABLE timeseries(year INTEGER, val INTEGER); statement ok INSERT INTO timeseries VALUES (1996, 10), (1997, 12), (1996, 20), (2001, 30), (NULL, 1), (1996, NULL); # this query uses a perfect aggregate HT query II EXPLAIN SELECT year, SUM(val), COUNT(val), COUNT(*) FROM timeseries GROUP BY year ORDER BY year; ---- physical_plan :.*PERFECT_HASH_GROUP_BY.* statement ok PRAGMA perfect_ht_threshold=0; # if we set the threshold to 0, the perfect HT is not used anymore query II EXPLAIN SELECT year, SUM(val), COUNT(val), COUNT(*) FROM timeseries GROUP BY year ORDER BY year; ---- physical_plan :.*PERFECT_HASH_GROUP_BY.* statement ok PRAGMA perfect_ht_threshold=1; # if we set it too small, it is not used still query II EXPLAIN SELECT year, SUM(val), COUNT(val), COUNT(*) FROM timeseries GROUP BY year ORDER BY year; ---- physical_plan :.*PERFECT_HASH_GROUP_BY.* # we can also use it with many columns, as long as the threshold is high enough statement ok create table manycolumns as select i a, i b, i c, i d, i e, i f, i g, i h, i, i j from range(0,2) tbl(i); statement ok PRAGMA perfect_ht_threshold=30; query II explain select a, b, c, d, e, f, g, h, i, j FROM manycolumns GROUP BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ---- physical_plan :.*PERFECT_HASH_GROUP_BY.* # the threshold has to be in range statement error PRAGMA perfect_ht_threshold=-1; ---- :.*out of range.* statement error PRAGMA perfect_ht_threshold=100; ---- :.*out of range.*