Skip to content

Commit 5328b37

Browse files
author
Ubuntu
committed
fix(query): add recursive annotations to prevent stack overflow in CTE processing
Adds #[recursive::recursive] annotations to key CTE binding functions to prevent stack overflow when processing complex queries with many UNION operations. This follows the pattern established in PR #18268 and addresses the segmentation fault issue introduced in PR #18577. Fixes: - bind_query() - Main query binding entry point - m_cte_to_temp_table() - CTE temporary table creation - compute_cte_ref_count() - CTE reference counting - bind_cte_definition() - CTE definition binding - TableNameReplacer visitor methods - AST traversal for name replacement The recursive library automatically grows stack size when needed, preventing stack overflow on deeply nested or complex query structures.
1 parent 97ecd7f commit 5328b37

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

โ€Žsrc/query/sql/src/planner/binder/bind_query/bind.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ impl CTERefCounter {
6767
}
6868

6969
impl Binder {
70+
#[recursive::recursive]
7071
pub(crate) fn bind_query(
7172
&mut self,
7273
bind_context: &mut BindContext,
@@ -119,6 +120,7 @@ impl Binder {
119120
Ok(())
120121
}
121122

123+
#[recursive::recursive]
122124
pub fn compute_cte_ref_count(
123125
&self,
124126
with: &With,
@@ -209,6 +211,7 @@ impl Binder {
209211
))
210212
}
211213

214+
#[recursive::recursive]
212215
pub fn m_cte_to_temp_table(
213216
&mut self,
214217
cte: &CTE,
@@ -345,6 +348,7 @@ impl TableNameReplacer {
345348
}
346349
}
347350

351+
#[recursive::recursive]
348352
fn enter_table_reference(&mut self, table_reference: &mut TableReference) {
349353
if let TableReference::Table {
350354
database, table, ..
@@ -356,6 +360,7 @@ impl TableNameReplacer {
356360
}
357361
}
358362

363+
#[recursive::recursive]
359364
fn enter_expr(&mut self, expr: &mut Expr) {
360365
if let Expr::ColumnRef { column, .. } = expr {
361366
if column.database.is_none() || column.database.as_ref().unwrap().name == self.database

โ€Žsrc/query/sql/src/planner/binder/bind_table_reference/bind_cte.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ impl Binder {
165165
Ok((s_expr, new_bind_context))
166166
}
167167

168+
#[recursive::recursive]
168169
pub fn bind_cte_definition(
169170
&mut self,
170171
cte_name: &str,

0 commit comments

Comments
ย (0)