force predicate in SelectSelectOptimizer to evaluate to a boolean value

This commit is contained in:
pedrocarlo
2025-06-08 01:56:54 -03:00
parent b2fd5b9cd1
commit edc1c6fbc6
5 changed files with 14 additions and 7 deletions

View File

@@ -7,7 +7,7 @@ use crate::{
backtrack, one_of, pick,
predicate::{CompoundPredicate, SimplePredicate},
table::{GTValue, LTValue, LikeValue},
ArbitraryFrom as _, ArbitraryFromMaybe as _,
ArbitraryFrom, ArbitraryFromMaybe as _,
},
model::{
query::predicate::Predicate,
@@ -335,7 +335,6 @@ impl CompoundPredicate {
(0..rng.gen_range(0..=3))
.map(|_| SimplePredicate::arbitrary_from(rng, (table, row, true)).0)
.reduce(|accum, curr| {
// dbg!(&accum, &curr);
Predicate(Expr::Binary(
Box::new(accum.0),
ast::Operator::And,

View File

@@ -17,11 +17,13 @@ struct CompoundPredicate(Predicate);
#[derive(Debug)]
struct SimplePredicate(Predicate);
impl ArbitraryFrom<(&Table, &[SimValue], bool)> for SimplePredicate {
impl<A: AsRef<[SimValue]>> ArbitraryFrom<(&Table, A, bool)> for SimplePredicate {
fn arbitrary_from<R: Rng>(
rng: &mut R,
(table, row, predicate_value): (&Table, &[SimValue], bool),
(table, row, predicate_value): (&Table, A, bool),
) -> Self {
let row = row.as_ref();
// Pick an operator
let choice = rng.gen_range(0..2);
// Pick an operator
match predicate_value {

View File

@@ -1,4 +1,5 @@
use limbo_core::LimboError;
use limbo_sqlite3_parser::ast;
use serde::{Deserialize, Serialize};
use crate::{
@@ -692,10 +693,16 @@ fn property_select_select_optimizer<R: rand::Rng>(rng: &mut R, env: &SimulatorEn
let table = pick(&env.tables, rng);
// Generate a random predicate
let predicate = Predicate::arbitrary_from(rng, table);
// Transform into a Binary predicate to force values to be casted to a bool
let expr = ast::Expr::Binary(
Box::new(predicate.0),
ast::Operator::And,
Box::new(Predicate::true_().0),
);
Property::SelectSelectOptimizer {
table: table.name.clone(),
predicate,
predicate: Predicate(expr),
}
}

View File

@@ -48,7 +48,6 @@ pub fn expr_to_value(expr: &ast::Expr, row: &[SimValue], table: &Table) -> Optio
ast::Expr::Binary(lhs, op, rhs) => {
let lhs = expr_to_value(lhs, row, table)?;
let rhs = expr_to_value(rhs, row, table)?;
// dbg!(&lhs, &rhs);
Some(lhs.binary_compare(&rhs, *op))
}
ast::Expr::Like {

View File

@@ -61,7 +61,7 @@ pub struct SimulatorCLI {
#[clap(
long,
help = "disable Select-Select-Optimizer Property",
default_value_t = true // TODO: set this option to false after we have correctly asserted how this property should work
default_value_t = false
)]
pub disable_select_optimizer: bool,
}