use crate::idents::unwrap_expr;
use sqlparser::ast::{BinaryOperator, Expr, Value};
pub(super) fn rejects_all(selection: Option<&Expr>) -> bool {
selection.is_some_and(always_false)
}
fn always_false(expr: &Expr) -> bool {
match unwrap_expr(expr) {
Expr::Value(value) => matches!(value.value, Value::Boolean(false)),
Expr::BinaryOp {
left,
op: BinaryOperator::And,
right,
} => always_false(left) || always_false(right),
_ => false,
}
}
pub(super) fn rejects_groups(having: Option<&Expr>) -> bool {
having.is_some_and(group_rejected)
}
fn group_rejected(expr: &Expr) -> bool {
match unwrap_expr(expr) {
Expr::Value(value) => matches!(value.value, Value::Boolean(false) | Value::Null),
Expr::BinaryOp {
left,
op: BinaryOperator::And,
right,
} => group_rejected(left) || group_rejected(right),
_ => false,
}
}