only emit affinity check on index seek + check if affinity is necessary at all

This commit is contained in:
pedrocarlo
2025-11-06 17:30:15 -03:00
committed by Jussi Saurio
parent 27e234f949
commit 32535ef4ed
2 changed files with 23 additions and 6 deletions

View File

@@ -27,6 +27,7 @@ use crate::{
},
types::SeekOp,
vdbe::{
affinity,
builder::{CursorKey, CursorType, ProgramBuilder},
insn::{CmpInsFlags, IdxInsertFlags, Insn},
BranchOffset, CursorID,
@@ -1376,14 +1377,23 @@ fn emit_seek(
}
let num_regs = seek_def.size(&seek_def.start);
program.emit_insn(Insn::Affinity {
start_reg,
count: std::num::NonZeroUsize::new(num_regs).unwrap(),
affinities: seek_def
if is_index {
let affinities: String = seek_def
.iter_affinity(&seek_def.start)
.map(|affinity| affinity.aff_mask())
.collect(),
});
.collect();
if affinities.chars().any(|c| c != affinity::SQLITE_AFF_NONE) {
program.emit_insn(Insn::Affinity {
start_reg,
count: std::num::NonZeroUsize::new(num_regs).unwrap(),
affinities: seek_def
.iter_affinity(&seek_def.start)
.map(|affinity| affinity.aff_mask())
.collect(),
});
}
}
match seek_def.start.op {
SeekOp::GE { eq_only } => program.emit_insn(Insn::SeekGE {
is_index,

View File

@@ -83,9 +83,16 @@ impl Constraint {
if op.is_comparison() {
affinity = comparison_affinity(lhs, rhs, referenced_tables);
}
if side == BinaryExprSide::Lhs {
if affinity.expr_needs_no_affinity_change(lhs) {
affinity = Affinity::Blob;
}
(self.operator, lhs.clone(), affinity)
} else {
if affinity.expr_needs_no_affinity_change(rhs) {
affinity = Affinity::Blob;
}
(self.operator, rhs.clone(), affinity)
}
}