Runtime filter
| Also known as | Bloom filter join, dynamic filtering (Trino), runtime filtering (Impala), semi-join reduction |
|---|---|
| Field | Query optimization |
| Key parts | Creation side (small, filtered join input), application side (large join input), filter structure (bloom filter, value set or min/max range) |
| Open source implementations | Apache Spark (since 3.3.0), Trino, Apache Flink, Apache Impala |
| Related | Dynamic partition pruning, Bloom filter (data files), Shuffle, Sort-merge join, Predicate pushdown |
A runtime filter is a filter that a query engine builds while a join is running from the join keys of the smaller, filtered input and applies to the larger input before the join, so that rows which cannot find a match are dropped early.[1] In Apache Spark, a runtime filter is a bloom filter built from one side of a shuffle join and applied to the other side to reduce the data that goes into the shuffle; Spark added it in 3.3.0 and has enabled it by default since 3.4.0. Other engines have the same idea under other names, such as dynamic filtering in Trino.[2]
How does a runtime filter work?
A runtime filter has two sides. The creation side is the join input with a selective predicate, for example a dimension table filtered to a few rows; the engine reads its join keys and builds a compact filter from them. The application side is the large input; the engine applies the filter to it, ideally at the scan, so that rows whose keys are not in the filter never reach the join.
The filter structure varies. A bloom filter answers "might this key be present?" in a fixed amount of memory; it can return false positives but never false negatives, so it never drops a row that would match.[3] Other engines also use exact value sets or minimum and maximum ranges.
How does the runtime filter work in Apache Spark?
Spark's optimizer rule InjectRuntimeFilter inserts a runtime filter on one side of a join if it can build one from the other side. The source describes the filter as logically an IN subquery on the join keys, currently always implemented as a bloom filter.[1] The feature came from SPARK-32268, "Bloom Filter Join", fixed in 3.3.0, and SPARK-38841 enabled it by default in 3.4.0.[4][5]
At Spark 4.3.0, the rule adds a bloom filter on a join key only when:[1][6]
- the join is a shuffle join, or a broadcast join with a shuffle below the side to be filtered;
- the join keys are simple, cheap expressions;
- there is no dynamic partition pruning filter on the same key already;
- the creation side has a selective predicate, or is a fully materialized, repeatable cached input with evidence that pruning helps;
- the creation side is small enough: its estimated size must be under
spark.sql.optimizer.runtime.bloomFilter.creationSideThreshold(default 10MB), or, for a fully materialized, repeatable input with accurate statistics, underspark.sql.optimizer.runtime.bloomFilter.materializedCreationSideThreshold(default 100MB, since 4.3.0), which replaces the general threshold for such inputs; - the application side's scan size is over
spark.sql.optimizer.runtime.bloomFilter.applicationSideScanSizeThreshold(default 10GB); - the query has fewer than
spark.sql.optimizer.runtimeFilter.number.threshold(default 10) runtime filters already, a limit that protects the driver from running out of memory.
| Setting | Default | Since |
|---|---|---|
spark.sql.optimizer.runtime.bloomFilter.enabled |
true | 3.3.0 |
spark.sql.optimizer.runtime.bloomFilter.creationSideThreshold |
10MB | 3.3.0 |
spark.sql.optimizer.runtime.bloomFilter.materializedCreationSideThreshold |
100MB | 4.3.0 |
spark.sql.optimizer.runtime.bloomFilter.applicationSideScanSizeThreshold |
10GB | 3.3.0 |
spark.sql.optimizer.runtime.bloomFilter.expectedNumItems |
1000000 | 3.3.0 |
spark.sql.optimizer.runtime.bloomFilter.numBits |
8388608 | 3.3.0 |
spark.sql.optimizer.runtimeFilter.number.threshold |
10 | 3.3.0 |
All values are from SQLConf.scala at Spark 4.3.0.[6]
In a Spark plan, an injected runtime filter appears as a might_contain(...) predicate in a Filter on the application side, which refers to a scalar subquery that builds the bloom filter.[1][7] Spark does not push the bloom filter into file scans as a data filter; it is evaluated on the rows after the scan.[8]
Runtime filters in other engines
| Apache Spark | Trino | Apache Flink | Apache Impala | |
|---|---|---|---|---|
| Name | Runtime filter (bloom filter join)[1] | Dynamic filtering[2] | Runtime filter[9] | Runtime filtering[10] |
| On by default? | Yes, since 3.4.0[6] | Yes[2] | No (table.optimizer.runtime-filter.enabled is false)[9]
|
Yes; RUNTIME_FILTER_MODE defaults to GLOBAL in Impala 2.6 and higher[10]
|
| Filter structure | Bloom filter | Distinct value sets; falls back to per-column minimum and maximum when the build side exceeds size thresholds[2] | Not described on the configuration page | Bloom filter for HDFS-based tables; minimum and maximum filter for Kudu tables[10] |
| Applies to | Shuffle joins (and broadcast joins with a shuffle below them)[1] | Inner and right joins with =, <, <=, >, >= or IS NOT DISTINCT FROM, and semi-joins with IN[2]
|
Batch jobs only[9] | Joins; available since Impala 2.5[10] |
| Size limits | Creation side under 10MB (100MB for fully materialized inputs with accurate statistics), application side over 10GB by default[6] | Build-side thresholds before falling back to min and max[2] | Build side under 150 mb, probe side over 10 gb, filter ratio over 0.5 by default[9] | Controlled by query options[10] |
Runtime filter vs dynamic partition pruning
Both techniques move information across a join at run time. Dynamic partition pruning needs a partition column as the join key, and it skips whole partitions before they are read. A runtime filter works on any equi-join key, and it removes rows after the scan and before the shuffle. Spark checks for an existing DPP filter on a key before it injects a bloom filter on the same key.[1]
Runtime filters vs bloom filters in data files
A runtime filter is built for one query and thrown away. A bloom filter in a data file, such as an Apache Parquet column bloom filter, is written once with the file and lets readers skip row groups for equality filters with a literal value.[3]
See also
References
- ↑ 1.0 1.1 1.2 1.3 1.4 1.5 1.6 InjectRuntimeFilter.scala (v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ 2.0 2.1 2.2 2.3 2.4 2.5 Dynamic filtering (Trino 484). Trino Software Foundation.Retrieved 2026-11-23.
- ↑ 3.0 3.1 Bloom Filter. Apache Parquet.Retrieved 2026-11-23.
- ↑ SPARK-32268: Bloom Filter Join. Apache Software Foundation.Retrieved 2026-11-23.
- ↑ SPARK-38841: Enable Bloom filter join by default. Apache Software Foundation.Retrieved 2026-11-23.
- ↑ 6.0 6.1 6.2 6.3 SQLConf.scala (v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ BloomFilterMightContain.scala (v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ FileSourceStrategy.scala (v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ 9.0 9.1 9.2 9.3 Configuration (Apache Flink 2.3). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ 10.0 10.1 10.2 10.3 10.4 Runtime Filtering for Impala Queries. Apache Software Foundation.Retrieved 2026-11-23.