Add case-heavy LEFT JOIN benchmark and debug timing/logging for PushDownFilter hot paths (#20664)
## Which issue does this PR close?
* Part of #20002.
## Rationale for this change
The `PushDownFilter` optimizer rule shows a severe planner-time
performance pathology in the `sql_planner_extended` benchmark, where
profiling indicates it dominates total planning CPU time and repeatedly
recomputes expression types.
This PR adds a deterministic, CASE-heavy LEFT JOIN benchmark to reliably
reproduce the worst-case behavior and introduces lightweight debug-only
timing + counters inside `push_down_filter` to make it easier to
pinpoint expensive sub-sections (e.g. predicate simplification and join
predicate inference) during profiling.
## What changes are included in this PR?
* **Benchmark: add a deterministic CASE-heavy LEFT JOIN workload**
* Adds `build_case_heavy_left_join_query` and helpers to construct a
CASE-nested predicate chain over a `LEFT JOIN`.
* Adds a new benchmark `logical_plan_optimize_case_heavy_left_join` to
stress planning/optimization time.
* Adds an A/B benchmark group `push_down_filter_case_heavy_left_join_ab`
that sweeps predicate counts and CASE depth, comparing:
* default optimizer with `push_down_filter` enabled
* optimizer with `push_down_filter` removed
* **Optimizer instrumentation (debug-only)**
* Adds a small `with_debug_timing` helper gated by `log_enabled!(Debug)`
to record microsecond timings for specific sections.
* Instruments and logs:
* time spent in `infer_join_predicates`
* time spent in `simplify_predicates`
* counts of parent predicates, `on_filters`, inferred join predicates
* before/after predicate counts for simplification
## Are these changes tested?
* No new unit/integration tests were added because this PR is focused on
**benchmarking and debug-only instrumentation** rather than changing
optimizer semantics.
* Coverage is provided by:
* compiling/running the `sql_planner_extended` benchmark
* validating both benchmark variants (with/without `push_down_filter`)
produce optimized plans without errors
* enabling `RUST_LOG=debug` to confirm timing sections and counters emit
as expected
## Are there any user-facing changes?
* No user-facing behavior changes.
* The optimizer logic is unchanged; only **debug logging** is added
(emits only when `RUST_LOG` enables Debug for the relevant modules).
* Benchmark suite additions only affect developers running benches.
## LLM-generated code disclosure
This PR includes LLM-generated code and comments. All LLM-generated
content has been manually reviewed and tested.DataFusion is an extensible query engine written in Rust that uses Apache Arrow as its in-memory format.
This crate provides libraries and binaries for developers building fast and feature-rich database and analytic systems, customized for particular workloads. See use cases for examples. The following related subprojects target end users:
“Out of the box,” DataFusion offers SQL and DataFrame APIs, excellent performance, built-in support for CSV, Parquet, JSON, and Avro, extensive customization, and a great community.
DataFusion features a full query planner, a columnar, streaming, multi-threaded, vectorized execution engine, and partitioned data sources. You can customize DataFusion at almost all points including additional data sources, query languages, functions, custom operators and more. See the Architecture section for more details.
Here are links to important resources:
DataFusion is great for building projects such as domain-specific query engines, new database platforms and data pipelines, query languages and more. It lets you start quickly from a fully working engine, and then customize those features specific to your needs. See the list of known users.
Please see the contributor guide and communication pages for more information.
This crate has several features which can be specified in your Cargo.toml.
Default features:
nested_expressions: functions for working with nested types such as array_to_stringcompression: reading files compressed with xz2, bzip2, flate2, and zstdcrypto_expressions: cryptographic functions such as md5 and sha256datetime_expressions: date and time functions such as to_timestampencoding_expressions: encode and decode functionsparquet: support for reading the Apache Parquet formatsql: support for SQL parsing and planningregex_expressions: regular expression functions, such as regexp_matchunicode_expressions: include Unicode-aware functions such as character_lengthunparser: enables support to reverse LogicalPlans back into SQLrecursive_protection: uses recursive for stack overflow protection.Optional features:
avro: support for reading the Apache Avro formatbacktrace: include backtrace information in error messagesparquet_encryption: support for using Parquet Modular Encryptionserde: enable arrow-schema's serde featurePublic methods in Apache DataFusion evolve over time: while we try to maintain a stable API, we also improve the API over time. As a result, we typically deprecate methods before removing them, according to the deprecation guidelines.
Cargo.lockFollowing the guidance on committing Cargo.lock files, this project commits its Cargo.lock file.
CI uses the committed Cargo.lock file, and dependencies are updated regularly using Dependabot PRs.