Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions benchmarks/sql_benchmarks/grouped_count_distinct/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,18 @@ distributed rewrite, which remains selected with either flag value. The same
environment variable works with `./bench.sh run grouped_count_distinct`.

Q01-Q09 vary argument and grouping-key types, group count, distinct cardinality,
and skew. Q10 covers the unfavorable native shape: at the default four million
rows it has one million groups, each with four copies of the same value. Each
native input row probes both the group table and the per-group distinct set;
the rewrite's outer aggregate only sees the deduplicated pairs.
and skew. Q10 has one million groups, each with four copies of the same value,
at the default four million rows. It exercises the native accumulator's inline
first value, which lets repeated singleton values skip the distinct hash set.
The rewrite's outer aggregate only sees the deduplicated pairs.

When the average number of additional distinct values per group exceeds eight,
the native accumulator moves its inline values into the hash set and releases
the inline buffer. Later batches use the hash-only loop.

Q11 uses the same group count with at most two distinct values per group. Q12
has 95% of groups containing only NULL arguments, exposing the memory cost of
allocating inline value slots for groups without a non-NULL value.

Every query checks its result against an explicit distinct-pairs-then-count
query before timing. Keep the memory pool and limit the same on both sides.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ expect_plan AggregateExec

run
-- Int64, 1M groups with four identical values per group at the default 4M rows.
-- Native DISTINCT probes both the group table and its per-group set on each row.
-- Repeated singleton values exercise the native accumulator's inline first value.
SELECT many_g, count(DISTINCT dup_x) FROM grouped_distinct GROUP BY many_g;

cleanup sql_benchmarks/grouped_count_distinct/init/cleanup.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name Q11
group grouped_count_distinct

load sql_benchmarks/grouped_count_distinct/init/load.sql

assert I
WITH actual AS (
SELECT many_g AS g, count(DISTINCT x % 2) AS n
FROM grouped_distinct GROUP BY many_g
), expected AS (
SELECT g, count(x) AS n
FROM (SELECT DISTINCT many_g AS g, x % 2 AS x FROM grouped_distinct)
GROUP BY g
)
SELECT NOT EXISTS (SELECT * FROM actual EXCEPT SELECT * FROM expected)
AND NOT EXISTS (SELECT * FROM expected EXCEPT SELECT * FROM actual);
----
true

expect_plan AggregateExec

run
-- Int64, 1M groups, at most two distinct values per group at 4M rows.
SELECT many_g, count(DISTINCT x % 2)
FROM grouped_distinct GROUP BY many_g;

cleanup sql_benchmarks/grouped_count_distinct/init/cleanup.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name Q12
group grouped_count_distinct

load sql_benchmarks/grouped_count_distinct/init/load.sql

assert I
WITH actual AS (
SELECT many_g AS g, count(DISTINCT CASE WHEN many_g % 20 < 19 THEN NULL ELSE dup_x END) AS n
FROM grouped_distinct GROUP BY many_g
), expected AS (
SELECT g, count(x) AS n
FROM (SELECT DISTINCT many_g AS g, CASE WHEN many_g % 20 < 19 THEN NULL ELSE dup_x END AS x FROM grouped_distinct)
GROUP BY g
)
SELECT NOT EXISTS (SELECT * FROM actual EXCEPT SELECT * FROM expected)
AND NOT EXISTS (SELECT * FROM expected EXCEPT SELECT * FROM actual);
----
true

expect_plan AggregateExec

run
-- Int64, 1M groups; 95% of groups contain only NULL arguments at 4M rows.
SELECT many_g, count(DISTINCT CASE WHEN many_g % 20 < 19 THEN NULL ELSE dup_x END)
FROM grouped_distinct GROUP BY many_g;

cleanup sql_benchmarks/grouped_count_distinct/init/cleanup.sql
Loading