File: perfect_ht.test

package info (click to toggle)
duckdb 1.5.1-3
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 299,196 kB
  • sloc: cpp: 865,414; ansic: 57,292; python: 18,871; sql: 12,663; lisp: 11,751; yacc: 7,412; lex: 1,682; sh: 747; makefile: 564
file content (56 lines) | stat: -rw-r--r-- 1,634 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# 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	<REGEX>:.*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	<!REGEX>:.*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	<!REGEX>:.*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	<REGEX>:.*PERFECT_HASH_GROUP_BY.*

# the threshold has to be in range
statement error
PRAGMA perfect_ht_threshold=-1;
----
<REGEX>:.*out of range.*

statement error
PRAGMA perfect_ht_threshold=100;
----
<REGEX>:.*out of range.*