The full answer
DPP is on by default and needs no setting. The settings that matter are the one that switches it on, the broadcast thresholds that decide whether the filtering side can be broadcast and reused, adaptive query execution, and statistics that make those size estimates accurate. Most tuning is really about table layout and joins.
1. The switch
spark.conf.get("spark.sql.optimizer.dynamicPartitionPruning.enabled") # 'true' by default
Turn it off only to diagnose a problem.
2. Broadcast thresholds
spark.conf.set("spark.sql.autoBroadcastJoinThreshold", 50 * 1024 * 1024) # default 10 MB
spark.conf.set("spark.sql.adaptive.autoBroadcastJoinThreshold", 50 * 1024 * 1024) # runtime decision under AQE
DPP normally reuses the broadcast of the filtered dimension table. If that table is above the threshold, there is no broadcast to reuse and no pruning. Raising the threshold moderately can enable DPP, but each broadcast table must fit in driver and executor memory. A broadcast() hint on the dimension does the same for one query.
3. Adaptive query execution
spark.sql.adaptive.enabled is true by default. AQE can turn a sort-merge join into a broadcast join after the filtered dimension turns out small, and DPP then follows the final join strategy.
4. Internal settings (rarely changed)
spark.sql.optimizer.dynamicPartitionPruning.reuseBroadcastOnly(default true): only prune when a broadcast can be reused. Setting it to false lets Spark run the dimension side as a separate subquery when it estimates the saving is worth computing it twice.spark.sql.optimizer.dynamicPartitionPruning.useStatsandfallbackFilterRatio(0.5): how that estimate is made with and without statistics. These are internal and may change between versions, so test any change on your workload.
5. Statistics
ANALYZE TABLE dates COMPUTE STATISTICS;
ANALYZE TABLE sales COMPUTE STATISTICS FOR COLUMNS date_id;
Accurate sizes let the optimizer choose broadcasts and estimate filter selectivity correctly.
6. Table design (the biggest factor)
- Partition fact tables by the column they are commonly joined and filtered on, usually a date, with modest cardinality.
- Join on the partition column directly, with matching types, so no cast hides it.
Nuances
- More broadcasting increases driver and executor memory use; watch for out-of-memory errors and broadcast timeouts.
- DPP helps file-based tables and sources that support runtime filtering, not, for example, JDBC sources.
- On Databricks, Delta tables also get dynamic file pruning, which skips files using statistics even on non-partition columns, with its own settings.
- Check every change with
explain("formatted")(look fordynamicpruningexpression(... IN dynamicpruning#...)rather thandynamicpruningexpression(true)) and the partitions-read metric in the SQL tab.
Last updated 16 October 2026
Sources