diff --git a/src/frontend/src/binder/bind_context.rs b/src/frontend/src/binder/bind_context.rs index 6a08e9393206..02dbc6a28bc1 100644 --- a/src/frontend/src/binder/bind_context.rs +++ b/src/frontend/src/binder/bind_context.rs @@ -81,12 +81,12 @@ pub struct LateralBindContext { /// WITH RECURSIVE t(n) AS ( /// # -------------^ => Init /// VALUES (1) -/// # ----------^ => BaseResolved (after binding the base term) /// UNION ALL -/// SELECT n+1 FROM t WHERE n < 100 -/// # ------------------^ => Bound (we know exactly what the entire cte looks like) +/// SELECT n + 1 FROM t WHERE n < 100 +/// # --------------------^ => BaseResolved (after binding the base term, this relation will be bound to `Relation::BackCteRef`) /// ) /// SELECT sum(n) FROM t; +/// # -----------------^ => Bound (we know exactly what the entire `RecursiveUnion` looks like, and this relation will be bound to `Relation::Share`) /// ``` #[derive(Default, Debug, Clone)] pub enum BindingCteState { diff --git a/src/frontend/src/binder/query.rs b/src/frontend/src/binder/query.rs index 9ab1918776fb..dd6ff9f36b81 100644 --- a/src/frontend/src/binder/query.rs +++ b/src/frontend/src/binder/query.rs @@ -284,6 +284,7 @@ impl Binder { fn bind_with(&mut self, with: With) -> Result<()> { for cte_table in with.cte_tables { + // note that the new share id is generated here let share_id = self.next_share_id(); let Cte { alias, query, .. } = cte_table; let table_name = alias.name.real_value(); diff --git a/src/frontend/src/optimizer/plan_node/logical_recursive_union.rs b/src/frontend/src/optimizer/plan_node/logical_recursive_union.rs index 0467113b515e..376e30ca3a19 100644 --- a/src/frontend/src/optimizer/plan_node/logical_recursive_union.rs +++ b/src/frontend/src/optimizer/plan_node/logical_recursive_union.rs @@ -22,9 +22,7 @@ use super::expr_visitable::ExprVisitable; use super::generic::GenericPlanRef; use super::utils::{childless_record, Distill}; use super::{ - generic, ColPrunable, ColumnPruningContext, ExprRewritable, Logical, PlanBase, PlanTreeNode, - PredicatePushdown, PredicatePushdownContext, RewriteStreamContext, ToBatch, ToStream, - ToStreamContext, + gen_filter_and_pushdown, generic, ColPrunable, ColumnPruningContext, ExprRewritable, Logical, PlanBase, PlanTreeNode, PredicatePushdown, PredicatePushdownContext, RewriteStreamContext, ToBatch, ToStream, ToStreamContext }; use crate::binder::ShareId; use crate::error::Result; @@ -97,10 +95,10 @@ impl ExprVisitable for LogicalRecursiveUnion {} impl PredicatePushdown for LogicalRecursiveUnion { fn predicate_pushdown( &self, - _predicate: Condition, - _ctx: &mut PredicatePushdownContext, + predicate: Condition, + ctx: &mut PredicatePushdownContext, ) -> PlanRef { - unimplemented!("recursive CTE not supported for predicate_pushdown of LogicalRecursiveUnion") + gen_filter_and_pushdown(node, filter_predicate, pushed_predicate, ctx) } }