Skip to content

Commit 8c18eef

Browse files
authored
fix: bind correlated subqueries (#191)
1 parent 173c395 commit 8c18eef

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/binder/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ impl<'a, T: Transaction> Binder<'a, T> {
299299
try_default!(&table_name, column_name);
300300
}
301301
if let Some(table) = table_name.or(bind_table_name) {
302-
let table_catalog = self.context.bind_table(&table)?;
302+
let table_catalog = self.context.bind_table(&table, self.parent)?;
303303

304304
let column_catalog = table_catalog
305305
.get_column_by_name(&column_name)

src/binder/mod.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,20 @@ impl<'a, T: Transaction> BinderContext<'a, T> {
178178
}
179179

180180
/// get table from bindings
181-
pub fn bind_table(&self, table_name: &str) -> Result<&TableCatalog, DatabaseError> {
181+
pub fn bind_table(
182+
&self,
183+
table_name: &str,
184+
parent: Option<&'a Binder<'a, T>>,
185+
) -> Result<&TableCatalog, DatabaseError> {
182186
let default_name = Arc::new(table_name.to_owned());
183187
let real_name = self.table_aliases.get(table_name).unwrap_or(&default_name);
184-
self.bind_table
185-
.iter()
186-
.find(|((t, _), _)| t == real_name)
187-
.ok_or(DatabaseError::InvalidTable(table_name.into()))
188-
.map(|v| *v.1)
188+
if let Some(table_catalog) = self.bind_table.iter().find(|((t, _), _)| t == real_name) {
189+
Ok(table_catalog.1)
190+
} else if let Some(binder) = parent {
191+
binder.context.bind_table(table_name, binder.parent)
192+
} else {
193+
Err(DatabaseError::InvalidTable(table_name.into()))
194+
}
189195
}
190196

191197
// Tips: The order of this index is based on Aggregate being bound first.

0 commit comments

Comments
 (0)