AggJoin Shape-Comparison Studies

April 11, 2026 ยท View on GitHub

These files are historical shape-comparison studies, not same-query extension-enabled vs disabled benchmarks.

They compare:

  • a probe-side aggregate shape that is favorable to AGGJOIN
  • a build-side comparison shape that intentionally bails to native DuckDB

Those queries are algebraically related and were useful for stress-testing the executor and understanding direct/segmented-direct/hash regime changes, but they often differ in GROUP BY key choice and output cardinality. They should not be presented as plain "same query with aggjoin on/off" benchmark numbers.

The optimizer can do a limited planner-side probe/build swap for matched AGGJOIN shapes when all GROUP BY columns are on one side. That does not make these historical probe-side/build-side study files interchangeable with a true same-query on/off methodology.

For true same-query benchmark results, see benchmarks/README.md.

Setup

cd duckdb_aggjoin
git clone --depth 1 --branch v1.5.1 https://github.com/duckdb/duckdb.git duckdb
make

All commands below assume build/Release/duckdb was built by this repo's make target. That binary has aggjoin statically linked in, so these SQL files do not need LOAD aggjoin.

Running shape-comparison studies

build/Release/duckdb < shape_comparisons/core.sql
build/Release/duckdb < shape_comparisons/scaling.sql
build/Release/duckdb < shape_comparisons/asymmetric.sql

build/Release/duckdb < shape_comparisons/core_direct_100k.sql
build/Release/duckdb < shape_comparisons/core_direct_100k_probe_side.sql
build/Release/duckdb < shape_comparisons/core_direct_100k_build_side.sql

build/Release/duckdb < shape_comparisons/scaling_1k.sql
build/Release/duckdb < shape_comparisons/scaling_1k_probe_side.sql
build/Release/duckdb < shape_comparisons/scaling_1k_build_side.sql

On constrained hosts, use the timeout runner for slow build-side comparison cases:

benchmarks/run_with_timeout.sh shape_comparisons/scaling_1k_build_side.sql 120
benchmarks/run_with_timeout.sh shape_comparisons/core_high_blowup_build_side.sql 300

Methodology

  • core.sql, scaling.sql, and asymmetric.sql benchmark the aggregate query directly via COPY (...) TO ...; they no longer wrap the query in COUNT(*) FROM (...).
  • core_*.sql and scaling_*.sql are exact per-case splits of the monolithic suites.
  • *_probe_side.sql runs the AGGJOIN-friendly probe-side shape.
  • *_build_side.sql runs the build-side comparison shape that intentionally stays native.
  • These are stress tests for favorable vs unfavorable plan shapes. They are not same-query native baselines.

Core snapshot

10M probe rows, single-key SUM unless noted otherwise.

These numbers are the latest local split-run snapshot on this host.

#ScenarioProbe-side shapeBuild-side comparison shapeProbe-side / build-side ratio
1Direct mode, 100K keys0.246s13.750s55.9x
2Direct mode, 1M keys0.334s1.948s5.8x
3Hash mode, 3M keys0.412s1.076s2.6x
4Zipf-skewed, 100K keys0.170s>60s timed out>=352x
5Sparse, 100K rows over 10M range0.025s0.025sparity
6High blowup, 10K keys (1000x)0.085s253.094s2977x
7Multi-agg SUM+MIN+MAX+AVG, 1M keys0.566s3.877s6.9x

Scaling snapshot

10M probe rows, probe-side GROUP BY.

These numbers use the same shape-comparison methodology as the core suite.

KeysModeProbe-side shapeBuild-side comparison shapeProbe-side / build-side ratio
1KDirect0.079s>45s timed out>=569x
10KDirect0.081s>45s timed out>=556x
100KDirect0.241s13.852s57.5x
500KDirect0.264s3.148s11.9x
1MDirect0.332s1.963s5.9x
2MDirect boundary0.354s1.178s3.3x
3MSegmented direct0.416s1.061s2.5x
5MSegmented direct0.576s0.919s1.6x

These suites are still useful for:

  • direct vs segmented-direct vs hash regime studies
  • skew and blowup sensitivity
  • understanding why probe-side aggregate ownership matters

They are not the right numbers to use for "same query, extension on vs off" claims.