mirror of
https://github.com/tursodatabase/limbo.git
synced 2025-08-04 18:18:03 +00:00
Add can_pushdown_predicate fn to evaluate ast expressions for constness
This commit is contained in:
parent
853af16946
commit
0f34a813ff
1 changed files with 36 additions and 0 deletions
36
core/util.rs
36
core/util.rs
|
@ -2,6 +2,7 @@ use limbo_sqlite3_parser::ast::{self, CreateTableBody, Expr, FunctionTail, Liter
|
|||
use std::{rc::Rc, sync::Arc};
|
||||
|
||||
use crate::{
|
||||
function::Func,
|
||||
schema::{self, Column, Schema, Type},
|
||||
types::{OwnedValue, OwnedValueType},
|
||||
LimboError, OpenFlags, Result, Statement, StepResult, SymbolTable, IO,
|
||||
|
@ -565,6 +566,41 @@ pub fn columns_from_create_table_body(body: &ast::CreateTableBody) -> crate::Res
|
|||
.collect::<Vec<_>>())
|
||||
}
|
||||
|
||||
pub fn can_pushdown_predicate(expr: &Expr) -> bool {
|
||||
match expr {
|
||||
Expr::Literal(_) => true,
|
||||
Expr::Column { .. } => true,
|
||||
Expr::Binary(lhs, _, rhs) => can_pushdown_predicate(lhs) && can_pushdown_predicate(rhs),
|
||||
Expr::Parenthesized(exprs) => can_pushdown_predicate(exprs.first().unwrap()),
|
||||
Expr::Unary(_, expr) => can_pushdown_predicate(expr),
|
||||
Expr::FunctionCall { args, name, .. } => {
|
||||
let function = crate::function::Func::resolve_function(
|
||||
&name.0,
|
||||
args.as_ref().map_or(0, |a| a.len()),
|
||||
);
|
||||
matches!(function, Ok(Func::Scalar(_)))
|
||||
}
|
||||
Expr::Like { lhs, rhs, .. } => can_pushdown_predicate(lhs) && can_pushdown_predicate(rhs),
|
||||
Expr::Between {
|
||||
lhs, start, end, ..
|
||||
} => {
|
||||
can_pushdown_predicate(lhs)
|
||||
&& can_pushdown_predicate(start)
|
||||
&& can_pushdown_predicate(end)
|
||||
}
|
||||
Expr::Id(_) => true,
|
||||
Expr::Name(_) => true,
|
||||
Expr::Qualified(_, _) => true,
|
||||
Expr::DoublyQualified(_, _, _) => true,
|
||||
Expr::InTable { lhs, .. } => can_pushdown_predicate(lhs),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn is_deterministic(func: &Func) -> bool {
|
||||
matches!(func, Func::Scalar(_))
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, PartialEq)]
|
||||
pub struct OpenOptions<'a> {
|
||||
/// The authority component of the URI. may be 'localhost' or empty
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue