mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-17 08:34:19 +01:00
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:
@@ -444,7 +444,7 @@ mod tests {
|
|||||||
column_index: 6,
|
column_index: 6,
|
||||||
op: ConstraintOp::Eq,
|
op: ConstraintOp::Eq,
|
||||||
usable: false,
|
usable: false,
|
||||||
plan_info: 0,
|
index: 0,
|
||||||
}];
|
}];
|
||||||
|
|
||||||
let result = pragma_vtab.best_index(&constraints);
|
let result = pragma_vtab.best_index(&constraints);
|
||||||
@@ -457,7 +457,7 @@ mod tests {
|
|||||||
column_index,
|
column_index,
|
||||||
op: ConstraintOp::Eq,
|
op: ConstraintOp::Eq,
|
||||||
usable: true,
|
usable: true,
|
||||||
plan_info: 0,
|
index: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -765,7 +765,7 @@ mod tests {
|
|||||||
column_index: 1,
|
column_index: 1,
|
||||||
op: ConstraintOp::Eq,
|
op: ConstraintOp::Eq,
|
||||||
usable: false,
|
usable: false,
|
||||||
plan_info: 0,
|
index: 0,
|
||||||
}];
|
}];
|
||||||
|
|
||||||
let result = GenerateSeriesTable::best_index(&constraints, &[]);
|
let result = GenerateSeriesTable::best_index(&constraints, &[]);
|
||||||
@@ -778,7 +778,7 @@ mod tests {
|
|||||||
column_index,
|
column_index,
|
||||||
op: ConstraintOp::Eq,
|
op: ConstraintOp::Eq,
|
||||||
usable: true,
|
usable: true,
|
||||||
plan_info: 0,
|
index: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -427,7 +427,7 @@ pub fn convert_to_vtab_constraint(
|
|||||||
column_index: constraint.table_col_pos as u32,
|
column_index: constraint.table_col_pos as u32,
|
||||||
op,
|
op,
|
||||||
usable: all_required_tables_are_on_left_side,
|
usable: all_required_tables_are_on_left_side,
|
||||||
plan_info: ConstraintInfo::pack_plan_info(i as u32, true),
|
index: i,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
|
|||||||
@@ -423,8 +423,7 @@ fn build_vtab_scan_op(
|
|||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
let (pred_idx, _) = vtab_constraint.unpack_plan_info();
|
let constraint = &table_constraints.constraints[vtab_constraint.index];
|
||||||
let constraint = &table_constraints.constraints[pred_idx];
|
|
||||||
if usage.omit {
|
if usage.omit {
|
||||||
where_clause[constraint.where_clause_pos.0].consumed = true;
|
where_clause[constraint.where_clause_pos.0].consumed = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -341,7 +341,7 @@ mod tests {
|
|||||||
column_index: 1,
|
column_index: 1,
|
||||||
op: ConstraintOp::Eq,
|
op: ConstraintOp::Eq,
|
||||||
usable: false,
|
usable: false,
|
||||||
plan_info: 0,
|
index: 0,
|
||||||
}];
|
}];
|
||||||
|
|
||||||
let index_info = CompletionTable::best_index(&constraints, &[]).unwrap();
|
let index_info = CompletionTable::best_index(&constraints, &[]).unwrap();
|
||||||
@@ -356,7 +356,7 @@ mod tests {
|
|||||||
column_index,
|
column_index,
|
||||||
op: ConstraintOp::Eq,
|
op: ConstraintOp::Eq,
|
||||||
usable: true,
|
usable: true,
|
||||||
plan_info: 0,
|
index: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -385,20 +385,13 @@ pub struct ConstraintInfo {
|
|||||||
pub op: ConstraintOp,
|
pub op: ConstraintOp,
|
||||||
/// Whether or not constraint is garaunteed to be enforced.
|
/// Whether or not constraint is garaunteed to be enforced.
|
||||||
pub usable: bool,
|
pub usable: bool,
|
||||||
/// packed integer with the index of the constraint in the planner,
|
/// Index of the `Constraint` in the array precomputed by the optimizer
|
||||||
/// and the side of the binary expr that the relevant column is on.
|
/// from the WHERE clause. Used internally to match this constraint with
|
||||||
pub plan_info: u32,
|
/// the corresponding entry in `TableConstraints`.
|
||||||
}
|
///
|
||||||
|
/// This field is for optimizer use only and should not be accessed
|
||||||
impl ConstraintInfo {
|
/// by extensions.
|
||||||
#[inline(always)]
|
pub index: usize,
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type PrepareStmtFn = unsafe extern "C" fn(api: *mut Conn, sql: *const c_char) -> *mut Stmt;
|
pub type PrepareStmtFn = unsafe extern "C" fn(api: *mut Conn, sql: *const c_char) -> *mut Stmt;
|
||||||
|
|||||||
Reference in New Issue
Block a user