Commit Graph

1655 Commits

Author SHA1 Message Date
Zaid Humayun
2ff27834ff fix: addresses comment https://github.com/tursodatabase/limbo/pull/897#discussion_r1948154297 by @pereman2
this commit adds the final touches to the state machine for btree_destroy and also introduces a state machine for clear_overflow_pages
this addresses the issue of IO interrupting an operation in progress and solves the following problems:
* performance issues with repeating an operation
* missing page issues with clear overflow pages
2025-02-19 21:46:26 +05:30
Zaid Humayun
8ce305ad44 fixed compiler errors after rebase 2025-02-19 21:46:26 +05:30
Zaid Humayun
f7dc0d42df btree_destroy: implemented functionality with state machine 2025-02-19 21:46:26 +05:30
Zaid Humayun
07efc9b902 DROP TABLE: index drop
added missing instructions to drop the indices for a table physically from btree pages in a loop
2025-02-19 21:46:26 +05:30
Zaid Humayun
34f390abc9 cleanup: removed commented code 2025-02-19 21:46:26 +05:30
Zaid Humayun
e0105398a6 btree: modified the btree_destroy subroutine
modified the btree_destroy subroutine to do an iterative DFS and use the stack cell counters to keep track of whether children have been removed. adds a unit test.
2025-02-19 21:46:26 +05:30
Zaid Humayun
dc2bb7cb9b DropTable: implementation complete
added helper methods to Schema to remove table and indices from in-memory structures
completed the implementation for DropTable using that
2025-02-19 21:46:26 +05:30
Zaid Humayun
40b08c559c vdbe: modified instruction DropTable
the instruction DropTable has been modified to correctly match SQLite semantics
2025-02-19 21:46:26 +05:30
Zaid Humayun
fbc8cd7e70 vdbe: modified the Null instruction
modified the Null instruction to more closely match SQLite semantics. Allows passing in a second register and all registers from r1..r2 area set to null
2025-02-19 21:46:26 +05:30
Zaid Humayun
97d87955cc DROP TABLE: renamed BTreeCusor::btree_drop to BTreeCursor::btree_destroy
this more closely matches semantics
2025-02-19 21:46:26 +05:30
Zaid Humayun
508dad77ab DROP TABLE: modified program instructions
correctly emitting constant instructions and also calling Destroy instead of DropTable instruction for removing btree pages
2025-02-19 21:46:25 +05:30
Zaid Humayun
713465c592 instruction: added destroy instruction
added required functionality for destroy. minor cleanup of print statements
2025-02-19 21:46:25 +05:30
Zaid Humayun
caab612901 resolved all conflicts after rebase from upstream/main 2025-02-19 21:46:25 +05:30
Zaid Humayun
b8bebf3fa3 translate: updated the command to more closely match SQLite semantics
the command for drop table translation has been updated so that it more closely matches the semantics of SQLite's drop table command.

there are a few more things missing like ephemeral tables, destroy etc.
2025-02-19 21:46:25 +05:30
Zaid Humayun
76e2d98381 drop table: addresses issue https://github.com/tursodatabase/limbo/issues/894 which requires DROP TABLE to be implemented
this is the initial commit is for the implementation of DROP TABLE. It adds support for the DROP TABLE instruction and adds a DropBTree instruction. It also implements the btree_drop method in btree.rs which makes use of free_page method which will be implemented via PR https://github.com/tursodatabase/limbo/pull/785
2025-02-19 21:46:25 +05:30
Pekka Enberg
9973c22137 core: Specify mimalloc version
The "*" version is not allowed on crates.io.
2025-02-18 19:40:00 +02:00
Pekka Enberg
98010517d5 Merge 'Add affinity() function to Column' from Jussi Saurio
This is a first step to supporting [sqlite column
affinity](https://www.sqlite.org/datatype3.html) properly in limbo --
just adds an `affinity()` function to `Column` that can then be used
elsewhere

Closes #1030
2025-02-18 17:44:38 +02:00
Jussi Saurio
baf2aec3e9 Fix incorrect CAST text->numeric if valid prefix is 1 char long 2025-02-18 15:07:36 +02:00
Jussi Saurio
89e48a16db Add affinity() function to Column 2025-02-18 10:56:30 +02:00
Pekka Enberg
899ba8367e Merge 'Fix remainder panic on zero right-hand-side' from Jussi Saurio
Closes #1025
2025-02-18 10:08:23 +02:00
Jussi Saurio
8e5499e5ed Fix not evaling constant conditions when no tables in query
We were not evaluating constant conditions (e.g '1 IS NULL')
when there were no tables referenced in the query, because
our WHERE term evaluation was based on "during which loop"
to evaluate them. However, when there are no tables, there are
no loops, so they were never evaluated.
2025-02-17 13:10:27 +02:00
Jussi Saurio
ec3ae2ace6 Fix remainder panic on zero right-hand-side 2025-02-17 13:09:33 +02:00
Jussi Saurio
bece5b601a Add comment about translate_like_base 2025-02-17 10:55:26 +02:00
Jussi Saurio
447f91e5ee optimizer.rs: remove constant folding optimization for NULL since it's incorrect 2025-02-17 07:43:09 +02:00
Jussi Saurio
9bf5b9609f expr.rs: Binary: use translate_expr()'s impl for currently unsupported ops in translate_condition_expr() 2025-02-17 07:43:09 +02:00
Jussi Saurio
28ad12699f expr.rs: Unary: use shared impl in translate_expr() and translate_condition_expr() 2025-02-17 07:43:09 +02:00
Jussi Saurio
dc852fee8c expr.rs: Like: use shared impl in translate_expr() and translate_condition_expr() 2025-02-17 07:43:09 +02:00
Jussi Saurio
c6b8100d64 expr.rs: Case: call translate_expr() from translate_condition_expr() 2025-02-17 07:43:09 +02:00
Jussi Saurio
4f384e3a02 expr.rs: Rowid: call translate_expr() from translate_condition_expr() 2025-02-17 07:43:09 +02:00
Jussi Saurio
d91ba9573b expr.rs: Column: call translate_expr() from translate_condition_expr() 2025-02-17 07:43:08 +02:00
Jussi Saurio
7023ffc215 expr.rs: FunctionCall: call translate_expr() from translate_condition_expr() 2025-02-17 07:43:08 +02:00
Jussi Saurio
b93e01d59f expr.rs: Cast: call translate_expr() from translate_condition_expr() 2025-02-17 07:43:05 +02:00
Nikita Sivukhin
37e27131e3 fix inequality 2025-02-16 12:49:55 +04:00
Nikita Sivukhin
d2a507e458 add unit tests for reading integer serial types 2025-02-16 12:46:45 +04:00
Nikita Sivukhin
279652b271 extend sign for 24/48 bit width serial types 2025-02-16 12:46:18 +04:00
Nikita Sivukhin
db7544fe7a Merge branch 'tursodatabase:main' into fix-and-predicate 2025-02-15 22:57:56 +04:00
Jussi Saurio
aea8b416bc Merge 'mvcc: comments and small cleanup' from Jussi Saurio
Closes #930
2025-02-15 18:18:01 +02:00
Jussi Saurio
01f51a4c20 Merge 'Fix math binary' from Nikita Sivukhin
Fix codegen for binary functions and add fuzz test for math functions
(we need to compile `rusqlite` with `-DSQLITE_ENABLE_MATH_FUNCTIONS` in
order to bundle sqlite with math functions compiled)

Reviewed-by: Jussi Saurio (@jussisaurio)

Closes #1015
2025-02-15 18:17:08 +02:00
Jussi Saurio
cbfd77849d Merge 'Fix substr' from Nikita Sivukhin
Align `substr` implementation with SQLite spec
(https://www.sqlite.org/lang_corefunc.html#substr):
> The substr(X,Y,Z) function returns a substring of input string X that
begins with the Y-th character and which is Z characters long. If Z is
omitted then substr(X,Y) returns all characters through the end of the
string X beginning with the Y-th. The left-most character of X is number
1. If Y is negative then the first character of the substring is found
by counting from the right rather than the left. If Z is negative then
the abs(Z) characters preceding the Y-th character are returned. If X is
a string then characters indices refer to actual UTF-8 characters. If X
is a BLOB then the indices refer to bytes.

Reviewed-by: Jussi Saurio (@jussisaurio)

Closes #1013
2025-02-15 18:16:57 +02:00
Nikita Sivukhin
ee8b03528d fix codegen for and predicate - as jump_if_condition_is_true can be overwritten higher in the stack 2025-02-15 16:27:27 +04:00
Jussi Saurio
e4541edb48 Fix IdxGt,IdxGe,IdxLt,IdxLe instructions
According to SQLite documentation, the way to use these instructions
is to compare the seek key to the index key as you would with the
Compare opcode. The compare opcode states:

"Compare two vectors of registers in reg(P1)..reg(P1+P3-1)
(call this vector "A") and in reg(P2)..reg(P2+P3-1) ("B")."

In other words, we should compare the same number of columns from each,
not compare the entire keys.

This fixes a few Clickbench queries returning incorrect results, and
so closes #1009

---

Future work: support index seek keys that use multiple columns. Our
index seek is many times slower than SQLite because we're not utilizing
all the possible columns -- instead we just use the first index column
to seek.
2025-02-15 12:44:56 +02:00
Nikita Sivukhin
e25660833b fix codegen for binary functions 2025-02-15 14:33:57 +04:00
Nikita Sivukhin
91d723016d fix test 2025-02-15 13:29:14 +04:00
Nikita Sivukhin
b35dab5b6d fix substr implementation 2025-02-15 13:21:43 +04:00
Pekka Enberg
30f700174c Merge 'Added IdxLE and IdxLT opcodes' from Omolola Olamide
I added the two opcodes as an initial step. They are pretty easy to
implement since we already have the counterparts i.e., IdxGE and IdxGT
Is there a design reason behind their omission @penberg @PThorpe92?
I noticed the same for SeekLE and SeekLT.

Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #1010
2025-02-15 11:10:17 +02:00
Pekka Enberg
20e37e485a Merge 'Implement the legacy_file_format pragma' from Glauber Costa
easy implementation, sqlite claims it is a noop now
"This pragma no longer functions. It has become a no-op. The
capabilities formerly provided by PRAGMA legacy_file_format are now
available using the SQLITE_DBCONFIG_LEGACY_FILE_FORMAT option to the
sqlite3_db_config() C-language interface."

Closes #1007
2025-02-15 11:03:05 +02:00
Pekka Enberg
c53897cb6c Merge 'Support numeric column references in GROUP BY' from Jussi Saurio
We already supported this for ORDER BY but not GROUP BY - again noticed
this when running against some clickbench queries

Closes #1008
2025-02-15 11:02:28 +02:00
[B
e52f218136 fix format 2025-02-14 21:10:51 +01:00
[B
5214cf9859 Added IdxLE and IdxLT opcodes 2025-02-14 20:22:30 +01:00
Jussi Saurio
eca196a54b Support numeric column references in GROUP BY 2025-02-14 16:57:45 +02:00