Skip to content

Commit ed9f75e

Browse files
authored
refactor: parameterize apply subqueries with runtime index probes (#317)
* refactor: split apply into scalar and mark variants * refactor(execution): revert mutable plan dispatch and remove Option<LogicalPlan> * perf(execution): avoid materializing join tuples for filter evaluation * refactor: localize appended mark-apply right outputs precisely * refactor: remove semi/anti join support in favor of apply-based subqueries * feat: parameterize EXISTS/IN subqueries with runtime index probes * refactor: simplify parameterized index scan runtime probe flow * test: update SLT explain output for runtime probes * refactor: remove unused index range reset helper * chore: codefmt
1 parent 585ae80 commit ed9f75e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+3770
-1822
lines changed

src/binder/expr.rs

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -244,18 +244,24 @@ impl<'a, T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'a, '_, T
244244
})
245245
}
246246
Expr::Exists { subquery, negated } => {
247-
let (sub_query, column, correlated) = self.bind_subquery(None, subquery)?;
248-
let (_, sub_query) = if !self.context.is_step(&QueryBindStep::Where) {
249-
self.bind_temp_table(column, sub_query)?
250-
} else {
251-
(column, sub_query)
252-
};
247+
let (sub_query, _column, correlated) = self.bind_subquery(None, subquery)?;
248+
let (_, marker_ref) = self
249+
.bind_temp_table_alias(ScalarExpression::Constant(DataValue::Boolean(true)), 0);
253250
self.context.sub_query(SubQueryType::ExistsSubQuery {
254-
negated: *negated,
255251
plan: sub_query,
256252
correlated,
253+
output_column: marker_ref.output_column(),
257254
});
258-
Ok(ScalarExpression::Constant(DataValue::Boolean(true)))
255+
if *negated {
256+
Ok(ScalarExpression::Unary {
257+
op: expression::UnaryOperator::Not,
258+
expr: Box::new(marker_ref),
259+
evaluator: None,
260+
ty: LogicalType::Boolean,
261+
})
262+
} else {
263+
Ok(marker_ref)
264+
}
259265
}
260266
Expr::Subquery(subquery) => {
261267
let (sub_query, column, correlated) = self.bind_subquery(None, subquery)?;
@@ -276,7 +282,7 @@ impl<'a, T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'a, '_, T
276282
subquery,
277283
negated,
278284
} => {
279-
let left_expr = Box::new(self.bind_expr(expr)?);
285+
let left_expr = self.bind_expr(expr)?;
280286
let (sub_query, column, correlated) =
281287
self.bind_subquery(Some(left_expr.return_type()), subquery)?;
282288

@@ -287,19 +293,33 @@ impl<'a, T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'a, '_, T
287293
}
288294

289295
let (alias_expr, sub_query) = self.bind_temp_table(column, sub_query)?;
296+
let predicate = ScalarExpression::Binary {
297+
op: expression::BinaryOperator::Eq,
298+
left_expr: Box::new(left_expr),
299+
right_expr: Box::new(alias_expr),
300+
evaluator: None,
301+
ty: LogicalType::Boolean,
302+
};
303+
let (_, marker_ref) = self
304+
.bind_temp_table_alias(ScalarExpression::Constant(DataValue::Boolean(true)), 0);
290305
self.context.sub_query(SubQueryType::InSubQuery {
291306
negated: *negated,
292307
plan: sub_query,
293308
correlated,
309+
output_column: marker_ref.output_column(),
310+
predicate,
294311
});
295312

296-
Ok(ScalarExpression::Binary {
297-
op: expression::BinaryOperator::Eq,
298-
left_expr,
299-
right_expr: Box::new(alias_expr),
300-
evaluator: None,
301-
ty: LogicalType::Boolean,
302-
})
313+
if *negated {
314+
Ok(ScalarExpression::Unary {
315+
op: expression::UnaryOperator::Not,
316+
expr: Box::new(marker_ref),
317+
evaluator: None,
318+
ty: LogicalType::Boolean,
319+
})
320+
} else {
321+
Ok(marker_ref)
322+
}
303323
}
304324
Expr::Tuple(exprs) => {
305325
let mut bond_exprs = Vec::with_capacity(exprs.len());

src/binder/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,16 @@ pub enum SubQueryType {
152152
correlated: bool,
153153
},
154154
ExistsSubQuery {
155-
negated: bool,
156155
plan: LogicalPlan,
157156
correlated: bool,
157+
output_column: ColumnRef,
158158
},
159159
InSubQuery {
160160
negated: bool,
161161
plan: LogicalPlan,
162162
correlated: bool,
163+
output_column: ColumnRef,
164+
predicate: ScalarExpression,
163165
},
164166
}
165167

0 commit comments

Comments
 (0)