Skip to content

Commit b584f7e

Browse files
add more tests for ProjectSet (#10868)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent f519b72 commit b584f7e

File tree

2 files changed

+44
-9
lines changed

2 files changed

+44
-9
lines changed

src/query/sql/src/planner/optimizer/heuristic/prune_unused_columns.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -208,16 +208,10 @@ impl UnusedColumnPruner {
208208
}
209209

210210
RelOperator::ProjectSet(op) => {
211-
let mut used = vec![];
212-
// Only keep columns needed by parent plan.
211+
// We can't prune SRFs because they may change the cardinality of result set,
212+
// even if the result column of an SRF is not used by any following expression.
213213
for s in op.srfs.iter() {
214-
if !required.contains(&s.index) {
215-
continue;
216-
}
217-
used.push(s.clone());
218-
s.scalar.used_columns().iter().for_each(|c| {
219-
required.insert(*c);
220-
})
214+
required.extend(s.scalar.used_columns().iter().copied());
221215
}
222216

223217
Ok(SExpr::create_unary(
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
statement ok
2+
drop database if exists project_set
3+
4+
statement ok
5+
create database project_set
6+
7+
statement ok
8+
use project_set
9+
10+
query T
11+
explain select number from (select unnest([1,2,3]), number from numbers(10)) t
12+
----
13+
ProjectSet
14+
├── estimated rows: 10.00
15+
├── set returning functions: unnest([1, 2, 3])
16+
└── TableScan
17+
├── table: default.system.numbers
18+
├── read rows: 10
19+
├── read bytes: 80
20+
├── partitions total: 1
21+
├── partitions scanned: 1
22+
├── push downs: [filters: [], limit: NONE]
23+
└── estimated rows: 10.00
24+
25+
query T
26+
explain select number from (select unnest([1,2,3,number]), number from numbers(10)) t
27+
----
28+
ProjectSet
29+
├── estimated rows: 10.00
30+
├── set returning functions: unnest(CAST(array(1, 2, 3, numbers.number (#0)) AS Array(UInt64 NULL)))
31+
└── TableScan
32+
├── table: default.system.numbers
33+
├── read rows: 10
34+
├── read bytes: 80
35+
├── partitions total: 1
36+
├── partitions scanned: 1
37+
├── push downs: [filters: [], limit: NONE]
38+
└── estimated rows: 10.00
39+
40+
statement ok
41+
drop database project_set

0 commit comments

Comments
 (0)