You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by gi...@apache.org on 2026/06/22 11:19:45 UTC
(datafusion) 01/01: bench: add correlated-proxy case to the predicate_eval suite (#22919)
This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/main/pr-22919-f7598e3bceb7754ff0b4a1f9d34363498b4da907
in repository https://gitbox.apache.org/repos/asf/datafusion.git
commit 073e9edcad7907f3094243a935378c928eeaab2b
Author: Adrian Garcia Badaracco <17...@users.noreply.github.com>
AuthorDate: Mon Jun 22 13:19:23 2026 +0200
bench: add correlated-proxy case to the predicate_eval suite (#22919)
## Which issue does this PR close?
- Related to #11262 (predicate evaluation ordering). Extends the
`predicate_eval`
suite added in #22704. No single issue closed.
## Rationale for this change
The `correlation` subgroup's existing cases (q70–q72) use two predicates
of equal
cost and equal selectivity. For two conjuncts the evaluation cost of an
order is
`cost(first) + selectivity(first) × cost(second)`, which is symmetric
here — so
the two orders cost the same and correlation only affects the result
cardinality.
These cases measure the *overhead* of an ordering system, but give it no
opportunity: nothing in the suite rewards (or even detects)
correlation-aware
ordering.
This adds a case with real, measurable headroom that **only** joint
statistics can
find. A cheap integer predicate (`c0 = 1`, ~30%) is a perfect proxy for
three
string regexes (on `s1`/`s2`/`s3`); a fourth regex (on `s4`) has the
same ~30%
selectivity and the same cost but is independent. The four string
columns are
deliberately **identical in shape** — equal width, one marker at the
same offset,
an equally cheap regex each — so marginally the four regexes are
indistinguishable
in *any* position: neither a per-predicate cost/selectivity estimate nor
runtime
timing can prefer one over another. Conditionally — behind the proxy —
the three
correlated regexes keep every survivor while the `s4` regex still
discards ~70%.
The query is written in the natural-but-pessimal order (the redundant
regexes
grouped with their proxy, the informative one last). On an M-series
laptop the
written order runs ~1.7x slower than the hand-optimal order `[c0, s4,
s1/s2/s3]`
(16.5 ms vs 9.7 ms median per iteration), so:
- an ordering system using *marginal* per-predicate statistics (or an
independence assumption) is blind to the difference — every ranking of
the four
regexes looks equivalent;
- a system measuring the predicates' *joint* behaviour can reliably
collect ~1.7x.
## What changes are included in this PR?
- `load/corrproxy.sql` — the correlated-proxy dataset (deterministic,
generated
from `generate_series` like the existing datasets;
`PRED_ROWS`/`PRED_FILL`
knobs as elsewhere). The proxy and independent conditions are factored
into a
`WITH base` CTE as named booleans so each invariant has a single
definition.
- `queries/correlation/q73.sql`, `benchmarks/correlation/q73.benchmark`
— the new
case, following the suite's existing conventions.
Run with: `BENCH_NAME=predicate_eval BENCH_SUBGROUP=correlation cargo
bench --bench sql`
## Are these changes tested?
The suite's shared template asserts the query returns rows; the case
runs green
locally alongside q70–q72. The dataset invariants were verified on 1M
rows: equal
column widths (63), marginal selectivities all ~0.30, and
conditional-on-`c0`
selectivity 1.0 for `s1`/`s2`/`s3` vs ~0.30 for `s4`.
## Are there any user-facing changes?
No — benchmark-only.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Fable 5 <no...@anthropic.com>
---
.../benchmarks/correlation/q73.benchmark | 7 ++++
.../predicate_eval/load/corrproxy.sql | 44 ++++++++++++++++++++++
.../predicate_eval/queries/correlation/q73.sql | 14 +++++++
3 files changed, 65 insertions(+)
diff --git a/benchmarks/sql_benchmarks/predicate_eval/benchmarks/correlation/q73.benchmark b/benchmarks/sql_benchmarks/predicate_eval/benchmarks/correlation/q73.benchmark
new file mode 100644
index 0000000000..cc3f7bcf54
--- /dev/null
+++ b/benchmarks/sql_benchmarks/predicate_eval/benchmarks/correlation/q73.benchmark
@@ -0,0 +1,7 @@
+subgroup correlation
+
+template sql_benchmarks/predicate_eval/predicate_eval.benchmark.template
+SUBGROUP=correlation
+QPAD=73
+DATASET=corrproxy
+NAME=correlation_q73_redundant_proxy
diff --git a/benchmarks/sql_benchmarks/predicate_eval/load/corrproxy.sql b/benchmarks/sql_benchmarks/predicate_eval/load/corrproxy.sql
new file mode 100644
index 0000000000..f06e68d38c
--- /dev/null
+++ b/benchmarks/sql_benchmarks/predicate_eval/load/corrproxy.sql
@@ -0,0 +1,44 @@
+-- Correlated-proxy dataset: a cheap integer predicate that is a perfect proxy
+-- for three string predicates, plus one independent string predicate.
+--
+-- c0 = 1 for ~30% of rows (cheap proxy)
+-- s1, s2, s3 each contain a marker exactly where c0 = 1 (correlated)
+-- s4 contains a marker for an independent ~30% (independent)
+--
+-- The four string columns are deliberately *identical in shape*: same width,
+-- the same single marker at the same offset, each matched by an equally cheap
+-- regex with the same ~30% marginal selectivity. Marginally the four regex
+-- predicates are therefore indistinguishable -- same cost, same selectivity, in
+-- every position -- so neither a marginal cost/selectivity estimator nor
+-- runtime timing can prefer one over another. Only their *conditional*
+-- behaviour behind the proxy differs: after `c0 = 1`, the s1/s2/s3 regexes keep
+-- every survivor (each re-tests the proxy's condition) while the s4 regex still
+-- discards ~70%. Only joint statistics can see that; an independence assumption
+-- prices all four regexes identically in every position.
+--
+-- PRED_FILL sets the filler width on each side of the marker (a non-matching
+-- `regexp_like` must scan the whole value), and PRED_ROWS sizes the table.
+CREATE TABLE t AS
+WITH base AS (
+ SELECT
+ -- The cheap proxy and the independent control share one definition each, so
+ -- the perfect-proxy / independence invariants can't drift apart silently.
+ (value * 7) % 100 < 30 AS proxy, -- ~30%, drives c0 and s1/s2/s3
+ (value * 13) % 100 < 30 AS indep -- ~30%, independent of proxy, drives s4
+ FROM generate_series(1, ${PRED_ROWS:-1000000})
+)
+SELECT
+ CASE WHEN proxy THEN 1 ELSE 0 END AS c0,
+ repeat('q', ${PRED_FILL:-30})
+ || CASE WHEN proxy THEN 'aaa' ELSE 'zzz' END
+ || repeat('q', ${PRED_FILL:-30}) AS s1,
+ repeat('q', ${PRED_FILL:-30})
+ || CASE WHEN proxy THEN 'ccc' ELSE 'zzz' END
+ || repeat('q', ${PRED_FILL:-30}) AS s2,
+ repeat('q', ${PRED_FILL:-30})
+ || CASE WHEN proxy THEN 'ddd' ELSE 'zzz' END
+ || repeat('q', ${PRED_FILL:-30}) AS s3,
+ repeat('q', ${PRED_FILL:-30})
+ || CASE WHEN indep THEN 'bbb' ELSE 'zzz' END
+ || repeat('q', ${PRED_FILL:-30}) AS s4
+FROM base;
diff --git a/benchmarks/sql_benchmarks/predicate_eval/queries/correlation/q73.sql b/benchmarks/sql_benchmarks/predicate_eval/queries/correlation/q73.sql
new file mode 100644
index 0000000000..5e1e822e92
--- /dev/null
+++ b/benchmarks/sql_benchmarks/predicate_eval/queries/correlation/q73.sql
@@ -0,0 +1,14 @@
+-- Hidden: `c0 = 1` is a perfect proxy for the s1/s2/s3 regexes -- after the
+-- cheap proxy, each of those keeps every survivor while the equally selective
+-- (~30%) s4 regex still discards ~70%. The optimal order is [c0, s4, s1/s2/s3]
+-- (one informative regex on 30% of rows, the three redundant ones on 9%), but
+-- the four regexes are marginally identical -- same width, same marker offset,
+-- same cost, same selectivity -- so ranking them takes their *joint*
+-- distribution with the proxy. Written with the redundant regexes first,
+-- grouped with their proxy, as an author naturally would.
+SELECT count(*) FROM t
+WHERE c0 = 1
+ AND regexp_like(s1, 'a.a')
+ AND regexp_like(s2, 'c.c')
+ AND regexp_like(s3, 'd.d')
+ AND regexp_like(s4, 'b.b');
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org