Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion core/vdbe/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4320,10 +4320,25 @@ pub fn op_seek(
),
_ => unreachable!("unexpected Insn {:?}", insn),
};
assert!(
assert!(
target_pc.is_offset(),
"op_seek: target_pc should be an offset, is: {target_pc:?}"
);

if let RecordSource::Unpacked { start_reg, num_regs } = record_source {
for i in 0..num_regs {
if state.registers[(start_reg + i) as usize].is_null() {
// To jump, we update the program counter directly and tell the engine to Step
let offset = match target_pc {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use target_pc.as_offset_int() here which has equivalent behavior

crate::vdbe::BranchOffset::Offset(o) => *o,
_ => unreachable!("Seek target must be an offset"),
};
state.pc = offset;
return Ok(InsnFunctionStepResult::Step);
}
}
}

let op = match insn {
Insn::SeekGE { eq_only, .. } => SeekOp::GE { eq_only: *eq_only },
Insn::SeekGT { .. } => SeekOp::GT,
Expand Down
23 changes: 23 additions & 0 deletions testing/sqltests/tests/joins/left_join_null_index_bug.sqltest
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@database :memory:

test left-join-null-index-bug {
CREATE TABLE a(id INTEGER PRIMARY KEY);
CREATE TABLE b(id INTEGER PRIMARY KEY, a_id INTEGER);
CREATE TABLE c(id INTEGER PRIMARY KEY, b_id INTEGER);

INSERT INTO a VALUES (1),(2);
INSERT INTO b VALUES (1,1);
INSERT INTO c VALUES (1,NULL);

CREATE INDEX idx_c_bid ON c(b_id);

SELECT a.id, b.id AS bid, c.id AS cid
FROM a
LEFT JOIN b ON a.id = b.a_id
LEFT JOIN c ON b.id = c.b_id
ORDER BY a.id;
}
expect {
1|1|
2||
}
Loading