Skip to the page
Tecyfy

PySpark interview question · hard

What are the limitations of Dynamic Partition Pruning (DPP) in Spark, and how can they be addressed?

The short answerDPP only prunes partition columns, generally needs the filtering side to be broadcast, works only for certain join shapes, and only helps when the filter is selective and the data source supports it.

The full answer

DPP only prunes partition columns, generally needs the filtering side to be broadcast, works only for certain join shapes, and only helps when the filter is selective and the data source supports it. Each limitation has a workaround, but often the real answer is a better table layout or a different skipping technique.

LimitationWhy it happensHow to address it
Only partition columnsDPP skips partition directories, not rows or filesPartition large fact tables by the commonly joined key (often a date); for other columns use runtime Bloom filters, Delta data skipping with Z-ordering or liquid clustering, or Iceberg's file statistics
Small side must be broadcast (by default)Spark reuses the broadcast to avoid computing the dimension twiceFilter the dimension further, raise spark.sql.autoBroadcastJoinThreshold within memory limits, or add a broadcast() hint
Equi-joins on the bare column onlyA function or cast around the key hides the partition columnJoin on the column itself with matching types; store keys in the same type in both tables
Join type restrictionsPruning one side of an outer join would drop rows that must be keptRewrite as an inner join where the logic allows it, or filter the fact table explicitly
Low selectivityIf most partitions match, pruning saves littleAccept it, or change partition granularity
Source supportNeeds a file index or runtime filtering supportUse Parquet, ORC, Delta or Iceberg tables; for JDBC sources push filters into the query instead
Over-partitioningPartitioning by a high-cardinality key to make DPP work creates many small files and slow listingKeep partitions coarse (day or month); combine with file-level skipping
Planning overheadExtra subqueries and listing in very complex queriesUsually negligible; measure if planning time is high
Wrong estimatesMissing statistics stop broadcastsANALYZE TABLE ... COMPUTE STATISTICS, and keep adaptive query execution on

Explicit alternative when DPP doesn't apply Compute the keys yourself and filter the fact table on the partition column; static partition pruning then applies:

from pyspark.sql import functions as F

q1_dates = [r.date_id for r in dates.filter("quarter = 'Q1'").select("date_id").collect()]
sales_q1 = sales.filter(F.col("date_id").isin(q1_dates))

Only do this when the key list is small.

Checking it worked explain("formatted") shows dynamicpruningexpression(... IN dynamicpruning#...) when DPP applies, and dynamicpruningexpression(true) when Spark decided not to prune. Compare partitions read with the total in the Spark UI's SQL tab.

The overall lesson: DPP is a free bonus when tables are partitioned well and joins follow a star schema; it isn't a substitute for a good layout.

Last updated 16 October 2026

Sources

Where each fact comes from

  1. 1Performance tuning
  2. 2Spark configuration