diff --git a/core/storage/btree.rs b/core/storage/btree.rs index ed9070514..481866ee7 100644 --- a/core/storage/btree.rs +++ b/core/storage/btree.rs @@ -417,6 +417,7 @@ impl BTreeCursor { /// Move the cursor to the record that matches the seek key and seek operation. /// This may be used to seek to a specific record in a point query (e.g. SELECT * FROM table WHERE col = 10) /// or e.g. find the first record greater than the seek key in a range query (e.g. SELECT * FROM table WHERE col > 10). + /// We don't include the rowid in the comparison and that's why the last value from the record is not included. fn seek( &mut self, key: SeekKey<'_>, @@ -464,9 +465,15 @@ impl BTreeCursor { }; let record = crate::storage::sqlite3_ondisk::read_record(payload)?; let found = match op { - SeekOp::GT => record > *index_key, - SeekOp::GE => record >= *index_key, - SeekOp::EQ => record == *index_key, + SeekOp::GT => { + &record.values[..record.values.len() - 1] > &index_key.values + } + SeekOp::GE => { + &record.values[..record.values.len() - 1] >= &index_key.values + } + SeekOp::EQ => { + &record.values[..record.values.len() - 1] == &index_key.values + } }; self.stack.advance(); if found { diff --git a/testing/where.test b/testing/where.test index 264bdfdd8..8a568d0fc 100755 --- a/testing/where.test +++ b/testing/where.test @@ -318,6 +318,10 @@ do_execsql_test where-age-index-seek-regression-test-2 { select count(1) from users where age > 0; } {10000} +do_execsql_test where-age-index-seek-regression-test-3 { + select age from users where age > 90 limit 1; +} {91} + do_execsql_test where-simple-between { SELECT * FROM products WHERE price BETWEEN 70 AND 100; } {1|hat|79.0