From e52f807c7df55d186657efc6fa58a8a75d8b48ed Mon Sep 17 00:00:00 2001 From: Jussi Saurio Date: Tue, 26 Aug 2025 09:08:48 +0300 Subject: [PATCH 1/2] Fix: return NULL for rowid() when cursor's null flag is on Fixes TPC-H query 13 from returning an incorrect result. In this specific case, we were returning non-null `IdxRowid` values for the right-hand side table even when there was no match with the left-hand side table, meaning the join produced matches even in cases where there shouldn't have been any. Closes #2794 --- core/storage/btree.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/storage/btree.rs b/core/storage/btree.rs index b2c36a560..58be7a5e4 100644 --- a/core/storage/btree.rs +++ b/core/storage/btree.rs @@ -4320,6 +4320,9 @@ impl BTreeCursor { return Ok(IOResult::Done(None)); } } + if self.get_null_flag() { + return Ok(IOResult::Done(None)); + } if self.has_record.get() { let page = self.stack.top(); let page = page.get(); From 3905f0af46a9a39a1caef9f7cd7c0439712a8b87 Mon Sep 17 00:00:00 2001 From: Jussi Saurio Date: Tue, 26 Aug 2025 09:21:58 +0300 Subject: [PATCH 2/2] Add regression test for issue 2794 --- testing/join.test | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/testing/join.test b/testing/join.test index db25128ec..853ccc875 100755 --- a/testing/join.test +++ b/testing/join.test @@ -302,3 +302,12 @@ do_execsql_test left-join-backwards-iteration { } {12|Alan| 11|Travis|accessories 10|Daniel|coat} + +# regression test for issue 2794: not nulling out rowid properly when left join does not match +do_execsql_test_on_specific_db {:memory:} min-null-regression-test { + create table t (x integer primary key, y); + create table u (x integer primary key, y); + insert into t values (1,1),(2,2); + insert into u values (1,1),(3,3); + select count(u.x) from t left join u using(y); +} {1} \ No newline at end of file