Why do sqlite btree child keys have <= keys and not < keys

This commit is contained in:
jussisaurio
2024-10-06 23:48:59 +03:00
parent 15a66ea662
commit e5cf052f07
2 changed files with 37 additions and 14 deletions

View File

@@ -346,9 +346,9 @@ impl BTreeCursor {
};
mem_page.advance();
let comparison = match cmp {
SeekOp::GT => rowid_key <= *_rowid,
SeekOp::GE => rowid_key < *_rowid,
SeekOp::EQ => rowid_key < *_rowid,
SeekOp::GT => rowid_key < *_rowid,
SeekOp::GE => rowid_key <= *_rowid,
SeekOp::EQ => rowid_key <= *_rowid,
};
if comparison {
let mem_page =
@@ -378,9 +378,9 @@ impl BTreeCursor {
mem_page.advance();
let record = crate::storage::sqlite3_ondisk::read_record(payload)?;
let comparison = match cmp {
SeekOp::GT => index_key <= &record,
SeekOp::GE => index_key < &record,
SeekOp::EQ => index_key < &record,
SeekOp::GT => index_key < &record,
SeekOp::GE => index_key <= &record,
SeekOp::EQ => index_key <= &record,
};
if comparison {
let mem_page =

View File

@@ -270,7 +270,7 @@ do_execsql_test where-complex-parentheses {
5|sweatshirt}
# regression test for primary key index behavior
do_execsql_test where-id-index-seek-test {
do_execsql_test where-id-index-seek-regression-test {
select id from users where id > 9995;
} {9996
9997
@@ -278,11 +278,34 @@ do_execsql_test where-id-index-seek-test {
9999
10000}
do_execsql_test where-id-index-seek-regression-test-2 {
select count(1) from users where id > 0;
} {10000}
# regression test for secondary index (users.age) behavior
do_execsql_test where-id-index-seek-test-2 {
select id,age from users where age >= 100 limit 5;
} {186|100
198|100
301|100
364|100
460|100}
do_execsql_test where-age-index-seek-regression-test {
select age from users where age >= 100 limit 20;
} {100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100}
do_execsql_test where-age-index-seek-regression-test-2 {
select count(1) from users where age > 0;
} {10000}