Skip to content

Commit 2e8c43e

Browse files
zhuqi-lucasclaude
andcommitted
Fix FilterExec tree render missing fetch display
When `FilterExec` has a `fetch` (limit pushed down), the `TreeRender` display format does not show it, while `Default`/`Verbose` formats do. This makes `EXPLAIN FORMAT TREE` output incomplete for queries with LIMIT pushed into FilterExec. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1a0af76 commit 2e8c43e

3 files changed

Lines changed: 54 additions & 29 deletions

File tree

datafusion/physical-plan/src/filter.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,11 @@ impl DisplayAs for FilterExec {
505505
)
506506
}
507507
DisplayFormatType::TreeRender => {
508-
write!(f, "predicate={}", fmt_sql(self.predicate.as_ref()))
508+
write!(f, "predicate={}", fmt_sql(self.predicate.as_ref()))?;
509+
if let Some(fetch) = self.fetch {
510+
write!(f, ", fetch={fetch}")?;
511+
}
512+
Ok(())
509513
}
510514
}
511515
}

datafusion/sqllogictest/test_files/explain_tree.slt

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,7 +1552,7 @@ physical_plan
15521552
10)│ FilterExec │
15531553
11)│ -------------------- │
15541554
12)│ predicate: │
1555-
13)│ date = 2006-01-02
1555+
13)│ date = 2006-01-02, fetch=5
15561556
14)└─────────────┬─────────────┘
15571557
15)┌─────────────┴─────────────┐
15581558
16)│ RepartitionExec │
@@ -1775,15 +1775,16 @@ physical_plan
17751775
40)┌─────────────┴─────────────┐
17761776
41)│ FilterExec │
17771777
42)│ -------------------- │
1778-
43)│ predicate: a > 3 │
1779-
44)└─────────────┬─────────────┘
1780-
45)┌─────────────┴─────────────┐
1781-
46)│ DataSourceExec │
1782-
47)│ -------------------- │
1783-
48)│ bytes: 160 │
1784-
49)│ format: memory │
1785-
50)│ rows: 1 │
1786-
51)└───────────────────────────┘
1778+
43)│ predicate: │
1779+
44)│ a > 3, fetch=9 │
1780+
45)└─────────────┬─────────────┘
1781+
46)┌─────────────┴─────────────┐
1782+
47)│ DataSourceExec │
1783+
48)│ -------------------- │
1784+
49)│ bytes: 160 │
1785+
50)│ format: memory │
1786+
51)│ rows: 1 │
1787+
52)└───────────────────────────┘
17871788

17881789
# clean up
17891790
statement ok
@@ -1815,23 +1816,24 @@ physical_plan
18151816
06)┌─────────────┴─────────────┐
18161817
07)│ FilterExec │
18171818
08)│ -------------------- │
1818-
09)│ predicate: c3 > 0 │
1819-
10)└─────────────┬─────────────┘
1820-
11)┌─────────────┴─────────────┐
1821-
12)│ RepartitionExec │
1822-
13)│ -------------------- │
1823-
14)│ partition_count(in->out): │
1824-
15)│ 1 -> 4 │
1825-
16)│ │
1826-
17)│ partitioning_scheme: │
1827-
18)│ RoundRobinBatch(4) │
1828-
19)└─────────────┬─────────────┘
1829-
20)┌─────────────┴─────────────┐
1830-
21)│ StreamingTableExec │
1831-
22)│ -------------------- │
1832-
23)│ infinite: true │
1833-
24)│ limit: None │
1834-
25)└───────────────────────────┘
1819+
09)│ predicate: │
1820+
10)│ c3 > 0, fetch=5 │
1821+
11)└─────────────┬─────────────┘
1822+
12)┌─────────────┴─────────────┐
1823+
13)│ RepartitionExec │
1824+
14)│ -------------------- │
1825+
15)│ partition_count(in->out): │
1826+
16)│ 1 -> 4 │
1827+
17)│ │
1828+
18)│ partitioning_scheme: │
1829+
19)│ RoundRobinBatch(4) │
1830+
20)└─────────────┬─────────────┘
1831+
21)┌─────────────┴─────────────┐
1832+
22)│ StreamingTableExec │
1833+
23)│ -------------------- │
1834+
24)│ infinite: true │
1835+
25)│ limit: None │
1836+
26)└───────────────────────────┘
18351837

18361838
# Test explain tree for PlaceholderRowExec
18371839
query TT

datafusion/sqllogictest/test_files/limit.slt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,25 @@ SELECT COUNT(*) FROM (SELECT a FROM t1 WHERE a > 3 LIMIT 3 OFFSET 6);
385385
----
386386
1
387387

388+
# Verify that EXPLAIN FORMAT TREE shows fetch on FilterExec
389+
query TT
390+
EXPLAIN FORMAT TREE SELECT a FROM t1 WHERE a > 3 LIMIT 5;
391+
----
392+
physical_plan
393+
01)┌───────────────────────────┐
394+
02)│ FilterExec │
395+
03)│ -------------------- │
396+
04)│ predicate: │
397+
05)│ a > 3, fetch=5 │
398+
06)└─────────────┬─────────────┘
399+
07)┌─────────────┴─────────────┐
400+
08)│ DataSourceExec │
401+
09)│ -------------------- │
402+
10)│ bytes: 160 │
403+
11)│ format: memory │
404+
12)│ rows: 1 │
405+
13)└───────────────────────────┘
406+
388407
# generate BIGINT data from 1 to 1000 in multiple partitions
389408
statement ok
390409
CREATE TABLE t1000 (i BIGINT) AS
@@ -867,7 +886,7 @@ limit 1000;
867886

868887
# Config reset
869888

870-
# The SLT runner sets `target_partitions` to 4 instead of using the default, so
889+
# The SLT runner sets `target_partitions` to 4 instead of using the default, so
871890
# reset it explicitly.
872891
statement ok
873892
set datafusion.execution.target_partitions = 4;

0 commit comments

Comments
 (0)