Skip to content

Commit 2caffbb

Browse files
newlines
1 parent e98ff14 commit 2caffbb

1 file changed

Lines changed: 37 additions & 25 deletions

File tree

rfcs/1-distributed-dynamic-filtering.md

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,21 @@
33
## Contents
44

55
1. Background - Dynamic Filtering in Vanilla DataFusion
6-
2. Background - Dynamic Filtering in Trino and Spark
7-
2. Dynamic Filtering in Distributed DataFusion - Proposed Highlevel Design
8-
3. Gaps to Address in Vanilla DataFusion - What's blocking us?
6+
- "Global" Dynamic Filters
7+
- "Partition-Aware" Dynamic Filters
8+
2. Background - Dynamic Filtering in Trino and Spark
9+
- Trino
10+
- Spark
11+
3. Distributed Dynamic Filters
12+
- Local Case
13+
- Remote Case
14+
4. Implementation Details
15+
- Extracting Dynamic Filters
16+
- Routing Dynamic Filters
17+
- Displaying Dynamic Filters
18+
5. Gaps in Vanilla DataFusion
19+
- Getting `&DynamicFilterPhysicalExpr` from `ExecutionPlan`
20+
- Merging Dynamic Filters
921

1022
## 1. Background - Dynamic Filtering in Vanilla DataFusion
1123

@@ -30,7 +42,7 @@ CASE hash(expr) % N
3042
Ultimately, they are just an optimization over "global" dynamic filters because they make the filters
3143
more granular, letting us prune more efficiently.
3244

33-
### "Global" dynamic filter
45+
### "Global" Dynamic Filters
3446
```
3547
DynamicFilterPhysicalExpr:
3648
┌────────────────────────┐
@@ -53,7 +65,7 @@ more granular, letting us prune more efficiently.
5365
└──────────────────────────┘
5466
```
5567

56-
### "Partition-Aware Dynamic Filter"
68+
### "Partition-Aware" Dynamic Filter
5769
```
5870
DynamicFilterPhysicalExpr:
5971
┌────────────────────────┐
@@ -266,18 +278,18 @@ consumers may prune rows incorrectly.
266278

267279
Consider if these "global" dynamic filters generated in stage 2
268280

269-
Task 1: `DynamicFilterPhysicalExpr: a@0 >= v0 AND a@0 <= v1`
270-
Task 2: `DynamicFilterPhysicalExpr: a@0 >= v2`
271-
Task 3: `DynamicFilterPhysicalExpr: a@0 IN LIST [v3, v4 ...]`
281+
Task 1: `DynamicFilterPhysicalExpr: a@0 >= v0 AND a@0 <= v1`
282+
Task 2: `DynamicFilterPhysicalExpr: a@0 >= v2`
283+
Task 3: `DynamicFilterPhysicalExpr: a@0 IN LIST [v3, v4 ...]`
272284

273285
What is the correct filter to push to Stage 1 Task 1 and Stage 1 Task 2?
274286

275287
##### Option 1: OR the Filters Together
276288

277289
`DynamicFilterPhysicalExpr: a@0 >= v0 AND a@0 <= v1 OR a@0 >= v2 OR a@0 IN LIST [v3, v4 ...]`
278290

279-
Pros:
280-
It's simple.
291+
Pros:
292+
- It's simple.
281293

282294
Cons:
283295
- Loss of selectivity (not worse than single node execution which would have had one filter anyways). We may allow a row to pass a filter due to
@@ -290,17 +302,17 @@ Cons:
290302

291303
Similar to the above except you try to avoid ORing.
292304

293-
We could try converting these filters from this
294-
`DynamicFilterPhysicalExpr: a@0 >= 0 AND a@0 <= 5 OR IN LIST [10, 11]`
295-
`DynamicFilterPhysicalExpr: a@0 >= 1 AND a@0 <= 10 OR IN LIST [12, 13]`
305+
We could try converting these filters from this
306+
`DynamicFilterPhysicalExpr: a@0 >= 0 AND a@0 <= 5 OR IN LIST [10, 11]`
307+
`DynamicFilterPhysicalExpr: a@0 >= 1 AND a@0 <= 10 OR IN LIST [12, 13]`
296308

297-
To this
309+
To this
298310
`DynamicFilterPhysicalExpr: a@0 >= 0 AND a@0 <= 10 OR IN LIST [10, 11, 12, 13]`
299311

300-
Pros:
312+
Pros:
301313
- Less overhead than ORing
302314

303-
Cons:
315+
Cons:
304316
- Is brittle. What if we have to support non-range and non-IN-LIST expressions? It would be nice if dynamic filters in vanilla datafusion natively implemented a `merge` or `union` operation
305317
so we didn't have to worry about it.
306318

@@ -381,10 +393,10 @@ CASE Range(a@0)
381393
WHEN 0: v1 <= a@0 < v2 // distinct range
382394
```
383395

384-
Pros:
396+
Pros:
385397
- Simple.
386398

387-
Cons:
399+
Cons:
388400
- It relies on some subtle properties. When will this stop working?
389401
- If the hash repartitions below `NetworkShuffleExec`s produce a partition count that is not a multiple of `target_partitions`.
390402
[Here](https://github.com/datafusion-contrib/datafusion-distributed/blob/a6c326807fa3a5ff05b4b7e08a1bd1e3cd7bfe53/src/execution_plans/network_shuffle.rs?plain=1#L160) is where we scale up the `RepartitionExec` today
@@ -401,16 +413,16 @@ WHEN 0: a@0 >= v0 AND a@0 <= v1 OR a@0 IN LIST [v2, v3, v4 ...] OR a@0 >= v6
401413
WHEN 1: ... OR ... OR ...
402414
```
403415

404-
Pros
416+
Pros:
405417
- Filter evaluation may be cheaper
406418

407-
Cons
419+
Cons:
408420
- It's a bit brittle. We would need to manually modify `PhysicalExpr`s.
409421

410422
##### Proposal
411423

412424
This RFC proposes that we `OR` the cases together. If loss of selectivity is a conern, this can be addressed in a future implementation of distributed dynamic filtering. In the future,
413-
supporting an official `union()` or `merge()` operation for dynamic filters in vanilla datafusion would be a nice addition so we don't have to perform "expression surgery" in datafusion-distributed.
425+
supporting an official `union()` or `merge()` operation for dynamic filters which does a case-wise merge in vanilla datafusion would be a nice addition so we don't have to perform "expression surgery" in datafusion-distributed.
414426
This is discussed in the `Merging Dynamic Filters` section below.
415427

416428
```
@@ -473,7 +485,7 @@ This is discussed in the `Merging Dynamic Filters` section below.
473485
```
474486

475487

476-
## Implementation Details
488+
## 4. Implementation Details
477489

478490
### Extracting Dynamic Filters
479491

@@ -506,7 +518,7 @@ dynamic filter pruning work during execution, after execution we must propagate
506518
filters from data sources to the coordinator so they can be displayed.
507519

508520

509-
## Gaps in Vanilla DataFusion
521+
## 5. Gaps in Vanilla DataFusion
510522

511523
There are 2 main gaps in vanilla datafusion that we need to address:
512524
1. How do you get `&DynamicFilterPhysicalExpr` from `ExecutionPlan` nodes?
@@ -564,10 +576,10 @@ fn try_collect(
564576
}
565577
```
566578

567-
Pros:
579+
Pros:
568580
- Requires no changes to vanilla datafusion. We can ship this faster.
569581

570-
Cons:
582+
Cons:
571583
- Dynamic filtering will not work for users with custom plan nodes unless users register them
572584
- Distributed datafusion has to maintain a registry of all `ExecutionPlan` implementations in vanilla datafusion. This will need to be updated
573585
during upgrades.

0 commit comments

Comments
 (0)