Replace ConstraintInfo::plan_info with ConstraintInfo::index

The side of the binary expression no longer needs to be stored in
`ConstraintInfo`, since the optimizer now guarantees that it is always
on the right. As a result, only the index of the corresponding constraint
needs to be preserved.
This commit is contained in:
Piotr Rzysko
2025-08-03 16:06:02 +02:00
parent 8fb4fbf8af
commit 59ec2d3949
6 changed files with 15 additions and 23 deletions

View File

@@ -444,7 +444,7 @@ mod tests {
column_index: 6,
op: ConstraintOp::Eq,
usable: false,
plan_info: 0,
index: 0,
}];
let result = pragma_vtab.best_index(&constraints);
@@ -457,7 +457,7 @@ mod tests {
column_index,
op: ConstraintOp::Eq,
usable: true,
plan_info: 0,
index: 0,
}
}
}

View File

@@ -765,7 +765,7 @@ mod tests {
column_index: 1,
op: ConstraintOp::Eq,
usable: false,
plan_info: 0,
index: 0,
}];
let result = GenerateSeriesTable::best_index(&constraints, &[]);
@@ -778,7 +778,7 @@ mod tests {
column_index,
op: ConstraintOp::Eq,
usable: true,
plan_info: 0,
index: 0,
}
}
}

View File

@@ -427,7 +427,7 @@ pub fn convert_to_vtab_constraint(
column_index: constraint.table_col_pos as u32,
op,
usable: all_required_tables_are_on_left_side,
plan_info: ConstraintInfo::pack_plan_info(i as u32, true),
index: i,
})
})
.collect()

View File

@@ -423,8 +423,7 @@ fn build_vtab_scan_op(
)));
}
let (pred_idx, _) = vtab_constraint.unpack_plan_info();
let constraint = &table_constraints.constraints[pred_idx];
let constraint = &table_constraints.constraints[vtab_constraint.index];
if usage.omit {
where_clause[constraint.where_clause_pos.0].consumed = true;
}

View File

@@ -341,7 +341,7 @@ mod tests {
column_index: 1,
op: ConstraintOp::Eq,
usable: false,
plan_info: 0,
index: 0,
}];
let index_info = CompletionTable::best_index(&constraints, &[]).unwrap();
@@ -356,7 +356,7 @@ mod tests {
column_index,
op: ConstraintOp::Eq,
usable: true,
plan_info: 0,
index: 0,
}
}
}

View File

@@ -385,20 +385,13 @@ pub struct ConstraintInfo {
pub op: ConstraintOp,
/// Whether or not constraint is garaunteed to be enforced.
pub usable: bool,
/// packed integer with the index of the constraint in the planner,
/// and the side of the binary expr that the relevant column is on.
pub plan_info: u32,
}
impl ConstraintInfo {
#[inline(always)]
pub fn pack_plan_info(pred_idx: u32, is_right_side: bool) -> u32 {
((pred_idx) << 1) | (is_right_side as u32)
}
#[inline(always)]
pub fn unpack_plan_info(&self) -> (usize, bool) {
((self.plan_info >> 1) as usize, (self.plan_info & 1) != 0)
}
/// Index of the `Constraint` in the array precomputed by the optimizer
/// from the WHERE clause. Used internally to match this constraint with
/// the corresponding entry in `TableConstraints`.
///
/// This field is for optimizer use only and should not be accessed
/// by extensions.
pub index: usize,
}
pub type PrepareStmtFn = unsafe extern "C" fn(api: *mut Conn, sql: *const c_char) -> *mut Stmt;