Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: filter push down union in r cte #17031

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ impl Rule for RulePushDownFilterUnion {
let filter: Filter = s_expr.plan().clone().try_into()?;
let union_s_expr = s_expr.child(0)?;
let union: UnionAll = union_s_expr.plan().clone().try_into()?;
if !union.cte_scan_names.is_empty() {
// If the union has cte scan names, it's not allowed to push down filter.
state.add_result(s_expr.clone());
return Ok(());
}

// Create a filter which matches union's right child.
let index_pairs: HashMap<IndexType, IndexType> = union
Expand Down
40 changes: 40 additions & 0 deletions tests/sqllogictests/suites/query/cte/r_cte_union_all.test
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,43 @@ SELECT * FROM t;
7
8
9

# bug: https://github.com/databendlabs/databend/issues/17027
statement ok
CREATE or replace TABLE parent_child
(
parent VARCHAR(30),
child VARCHAR(30)
);

statement ok
INSERT INTO parent_child
VALUES ('Org','Org'),('Org','Global'),('Global','North'),
('Global','South'),('Global','East'),('Global','West'),
('Global','Org detail'),('North','North East'),('North','North West');

query I
WITH RECURSIVE tree_values
(parent, child)
AS (
SELECT parent, child
FROM parent_child
WHERE parent = child
UNION ALL
SELECT c.parent, c.child
FROM parent_child c
INNER JOIN tree_values p
ON p.child = c.parent
WHERE c.parent != c.child
)
select parent, child from tree_values
where parent = 'Global';
----
Global East
Global North
Global Org detail
Global South
Global West

statement ok
drop table parent_child;
Loading