Skip to content

Commit b1b42bb

Browse files
committed
Merge wip/sql-size-metric-2: generated SQL size and speed against ratcheted baselines
2 parents 0915c74 + be4c1c3 commit b1b42bb

34 files changed

Lines changed: 10146 additions & 4 deletions

‎.github/workflows/ci.yml‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,13 @@ jobs:
5454
- name: Replay recorded cases on DuckDB
5555
run: >-
5656
cargo run --locked -p sqlquack -- verify --require-verified --python .venv/bin/python
57-
--translation-statements target/translation-statements.json
57+
--translation-statements target/translation-statements.json --sql-sizes target/sql-sizes.json
5858
- name: Check the result-matching measure against its baselines
5959
run: >-
6060
make translation-results RESULTS_BASE="$EVIDENCE_BASE"
61+
- name: Check the generated SQL's size against its baselines
62+
run: >-
63+
make sql-sizes RESULTS_BASE="$EVIDENCE_BASE"
6164
6265
polyglot-check:
6366
name: Exact parser check on DuckShop

‎Makefile‎

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ PYTHON_TYPED := scripts tests/unit/scripts python/src $(PYTHON_API_TESTS)
3030
PYTHON_TESTS := tests/unit/scripts $(PYTHON_API_TESTS)
3131
endif
3232

33-
.PHONY: distribution-notices format rust-lint python-check fensu syntax-coverage depth-probe depth-probe-debug gate-build evidence-guard polyglot-guard engine-free generate-cases generated-cases generate-syntax-cases syntax-cases corpus-rerecord generate-referee-cases referee-cases referee-pending translation-results check-ci check-merge test test-rust test-python python-module python-api python-wheel verify-recorded polyglot-duckshop census-duckshop fuzz-smoke gate gate-parallel census duckshop-compiled duckshop-measure
33+
.PHONY: distribution-notices format rust-lint python-check fensu syntax-coverage depth-probe depth-probe-debug gate-build evidence-guard polyglot-guard engine-free generate-cases generated-cases generate-syntax-cases syntax-cases corpus-rerecord generate-referee-cases referee-cases referee-pending translation-results sql-sizes sql-size-baseline sql-benchmark check-ci check-merge test test-rust test-python python-module python-api python-wheel verify-recorded polyglot-duckshop census-duckshop fuzz-smoke gate gate-parallel census duckshop-compiled duckshop-measure
3434

3535
format:
3636
cargo fmt --all
@@ -203,11 +203,44 @@ TRANSLATION_REPORT ?= target/translation-results.json
203203
RESULTS_BASE ?= $(EVIDENCE_BASE)
204204
RESULTS_BASE_FILE := target/translation-results-base.json
205205

206+
# Verify also writes the bytes of DuckDB SQL each converted case emits to SQL_SIZES, which must equal
207+
# coverage/sql-size/baseline.json and must not grow against the baseline at RESULTS_BASE beyond what
208+
# coverage/sql-size/allowances.toml rules.
209+
SQL_SIZES ?= target/sql-sizes.json
210+
SQL_SIZE_BASELINE := coverage/sql-size/baseline.json
211+
SQL_SIZE_BASE_FILE := target/sql-size-base.json
212+
SQL_SIZE_ALLOWANCES := coverage/sql-size/allowances.toml
213+
206214
verify-recorded:
207215
mkdir -p $(dir $(COVERAGE_REPORT))
208216
cargo run --release --locked -p sqlquack -- verify $(VERIFY_FLAGS) $(COVERAGE_FLAGS) --python $(VERIFY_PYTHON) \
209-
--translation-statements $(TRANSLATION_STATEMENTS)
217+
--translation-statements $(TRANSLATION_STATEMENTS) --sql-sizes $(SQL_SIZES)
210218
$(MAKE) translation-results
219+
$(MAKE) sql-sizes
220+
221+
# The generated-SQL size ratchet over the sizes verify wrote; see verify-recorded.
222+
sql-sizes:
223+
@if git show $(RESULTS_BASE):$(SQL_SIZE_BASELINE) > $(SQL_SIZE_BASE_FILE) 2>/dev/null; \
224+
then against="--against $(SQL_SIZE_BASE_FILE)"; \
225+
else echo "sql-sizes: $(RESULTS_BASE) has no baseline; checking the committed one only"; against=; fi; \
226+
uv run python -m scripts.check_sql_sizes $(SQL_SIZES) --baseline $(SQL_SIZE_BASELINE) \
227+
--allowances $(SQL_SIZE_ALLOWANCES) $$against
228+
229+
# Rewrites coverage/sql-size/baseline.json from the sizes the last verify-recorded wrote.
230+
sql-size-baseline:
231+
uv run python -m scripts.check_sql_sizes $(SQL_SIZES) --baseline $(SQL_SIZE_BASELINE) --update
232+
233+
# Times the converted VARIANT and decimal division examples over a million rows against hand-written
234+
# DuckDB SQL, and fails when one's time over its reference exceeds twice the ratio
235+
# coverage/sql-size/benchmarks.json records. SQL_BENCHMARK_ARGS=--update records the ratios.
236+
SQL_BENCHMARK_ARGS ?=
237+
sql-benchmark:
238+
cargo build --locked --release -p sqlquack
239+
target="$${CARGO_TARGET_DIR:-target}"; \
240+
library="$$(ls "$$target"/duckdb-download/*/*/libduckdb.so 2>/dev/null | head -1)"; \
241+
test -n "$$library" || { echo "sql-benchmark: no libduckdb.so under $$target/duckdb-download" >&2; exit 1; }; \
242+
LD_LIBRARY_PATH="$$(dirname "$$library")" uv run python -m scripts.benchmark_sql --sqlquack "$$target/release/sqlquack" \
243+
--budget coverage/sql-size/benchmarks.json $(SQL_BENCHMARK_ARGS)
211244

212245
# The result-matching measure over the statements verify wrote; see verify-recorded.
213246
translation-results:
@@ -296,10 +329,11 @@ fuzz-smoke:
296329
# timed conversion on DuckShop, and the fuzz smoke. The pre-push verify hook runs this.
297330
# After the static gate, the independent targets run in parallel, each target's output kept
298331
# together; any failure fails the gate. The verify hook builds what they need beforehand. The fuzz
299-
# smoke runs alone afterwards, so its time-boxed run gets the machine to itself.
332+
# smoke and then the SQL timing benchmark run alone afterwards, so each gets the machine to itself.
300333
gate: check-ci $(if $(filter command line,$(origin DUCKSHOP_COMPILED)),,duckshop-compiled)
301334
$(MAKE) -j --output-sync=target gate-parallel
302335
$(MAKE) fuzz-smoke
336+
$(MAKE) sql-benchmark
303337

304338
gate-parallel: test-rust test-python verify-recorded polyglot-duckshop census-duckshop
305339

‎coverage/sql-size/allowances.toml‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Ruled growth of generated SQL, which `make sql-sizes` honours against the base branch's baseline.
2+
#
3+
# [[case]] lets one case grow from exactly `from` bytes, its size in the base baseline, to at most
4+
# `to` bytes. [[total]] lets the cases both baselines hold grow by at most `bytes` beyond the growth
5+
# the [[case]] entries allow, when the base baseline's total is exactly `from`. Each needs the
6+
# `reason` for the longer SQL and the `ruling` that accepted it. Once the change lands, `from` no
7+
# longer matches the base, so the entry applies to nothing; remove it in the next change.
8+
#
9+
# [[case]]
10+
# case = "conversion/example.toml#some_case"
11+
# from = 1200
12+
# to = 1480
13+
# reason = "the fix guards a NULL operand the old SQL ignored"
14+
# ruling = "D000"
15+
#
16+
# [[total]]
17+
# from = 46486521
18+
# bytes = 3000
19+
# reason = "..."
20+
# ruling = "D000"

0 commit comments

Comments
 (0)