Commit Graph

125 Commits

Author SHA1 Message Date
Nils Koch
2827b86917 chore: fix clippy warnings 2025-06-23 19:52:13 +01:00
Pekka Enberg
882c5ca168 Merge 'Simple integrity check on btree' from Pere Diaz Bou
This PR adds support for the instruction `IntegrityCk` which performs an
integrity check on the contents of a single table. Next PR I will try to
implement the rest of the integrity check where we would check indexes
containt correct amount of data and some more.
<img width="1151" alt="image" src="https://github.com/user-
attachments/assets/29d54148-55ba-480f-b972-e38587f0a483" />

Closes #1719
2025-06-16 13:46:26 +03:00
Jussi Saurio
3f90fad131 Merge 'Simulator Ast Generation + Simulator Unary Operator + Refactor to use limbo_core::Value in Simulator for massive code reuse' from Pedro Muniz
This PR is a Drop-In replacement to the Predicate defined in the
Simulator. Predicate is basically the same as our ast::Expr, but it
supports a small number of the SQL expression syntax. By creating a
NewType that wraps ast::Expr we can tap into our already mostly
correctly defined parser structs. This change will enable us to easily
add generation for more types of sql queries.
I also added an ArbitraryFrom impl for ast::Expr that can be used in a
freestyle way (for now) for differential testing.
This PR also aims to implement Unary Operator logic similar to the
Binary Operator logic we have for predicate. After this change we may
need to adjust the Logic for how some assertions are triggered.
<s>Sometimes the `Select-Select-Optimizer` property thinks that these
two queries should return the same thing:
```sql
SELECT (twinkling_winstanley.sensible_federations > x'66616e7461737469625e0f37879823db' AND twinkling_winstanley.sincere_niemeyer < -7428368947470022783) FROM twinkling_winstanley WHERE 1;

SELECT * FROM twinkling_winstanley WHERE twinkling_winstanley.sensible_federations > x'66616e7461737469625e0f37879823db' AND twinkling_winstanley.sincere_niemeyer < -7428368947470022783;
```
However after running the shrunk plan manually, the simulator was
incorrect in asserting that. Maybe this a bug a in the generation of
such a query? Not sure yet. </s>
<b>EDIT: The simulator was correctly catching a bug and I thought I was
the problem. The bug was in `exec_if` and I fixed it in this PR.</b>
I still need to expand the Unary Operator generation to other types of
predicates. For now, I just implemented it for `SimplePredicate` as I'm
trying to avoid to bloat even more this PR.
<b>EDIT: I decided to just have one PR open for all the changes I'm
making to make my life a bit easier and to avoid merge conflicts with my
own branches that I keep spawning for new code.</b>
PS: This should only be considered for merging after
https://github.com/tursodatabase/limbo/pull/1619 is merged. Then, I will
remove the draft status from this PR.

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

Closes #1674
2025-06-13 11:23:10 +03:00
Levy A.
b88cb99ff0 fix warnings and some refactoring 2025-06-11 14:19:06 -03:00
Levy A.
49a6ddad97 wip 2025-06-11 14:19:04 -03:00
Levy A.
fa621115b5 fix: broken test 2025-06-11 14:17:36 -03:00
Levy A.
f92e000277 fix: remove unused variable 2025-06-11 14:17:36 -03:00
Levy A.
91f981a8b1 fix(compat): sqlite firt checks if old_table exists
something like `ALTER TABLE a RENAME TO a` should fail with
`no such table: a` if `a` doesn't exists.
2025-06-11 14:17:36 -03:00
Pere Diaz Bou
c2541c0e52 fix order pragma integrity check 2025-06-11 18:59:25 +02:00
pedrocarlo
470093ca03 fix generation for string literal 2025-06-11 11:32:17 -03:00
pedrocarlo
f535ff1398 add optional serde implementations for parser ast 2025-06-11 11:32:17 -03:00
pedrocarlo
acb8a47911 sanitize string for ast::Literal 2025-06-11 11:31:47 -03:00
Pere Diaz Bou
9383ba207d introduce integrity_check pragma 2025-06-11 11:14:29 +02:00
Krishna Vishal
0d5cbc4f1d Add affinity check as a function as ast::Operator impl 2025-06-11 00:33:48 +05:30
Jussi Saurio
85972fd744 Merge 'Fix rowid to_sql_string' from Pedro Muniz
Addresses the panic encountered here:
https://github.com/tursodatabase/limbo/pull/1690 . Sorry about that.

Closes #1693
2025-06-10 18:11:51 +03:00
pedrocarlo
36f60e4dd1 Fix rowid to_sql_string printing 2025-06-10 10:48:05 -03:00
pedrocarlo
0f2849f7e1 serde and serde_json as workspace dependencies 2025-06-09 11:38:15 -03:00
Pere Diaz Bou
8cd7c7e82e Merge 'fix: make keyword_token safe by validating UTF-8 input' from ankit
This PR fixes an unsound usage of unsafe {
str::from_utf8_unchecked(word) } in the public function keyword_token in
mod.rs.
The function now uses std::str::from_utf8(word).ok()? to safely handle
invalid UTF-8, eliminating the unsoundness.
No logic or API changes.
Code compiles and tests pass (where possible).
Closes: https://github.com/tursodatabase/libsql/issues/1859

Reviewed-by: Pere Diaz Bou <pere-altea@homail.com>

Closes #1677
2025-06-09 16:07:37 +02:00
Jussi Saurio
eec7c0529c Merge 'Beginnings of AUTOVACUUM' from Zaid Humayun
This PR adds the beginnings of
[AUTOVACUUM](https://www.sqlite.org/lang_vacuum.html) to Limbo. It adds
a feature flag called `omit_autovacuum` which is analogous to
`SQLITE_OMIT_AUTOVACUUM`. It is off by default, same as SQLite.
It introduces the concept of [pointer map pages](https://www.sqlite.org/
fileformat.html#pointer_map_or_ptrmap_pages) which are reverse index
pages used to map pages to their parents. This is used to swap pages
(when a table is deleted for instance) to keep root pages clustered at
the beginning of the file. It's also used while creating a table to
ensure that root pages are clustered at the beginning (although, this
isn't completely implemented yet)
Finally, it also adds a couple of missing instructions like `Int64` that
are required for `PRAGMA` commands related to `auto_vacuum` settings
<img width="1512" alt="Screenshot 2025-05-28 at 8 47 51 PM"
src="https://github.com/user-
attachments/assets/d52eb74f-5b79-4d52-9401-1bdc2dcc304d" />

Closes #1600
2025-06-09 08:20:24 +03:00
Zaid Humayun
5827a33517 Beginnings of AUTOVACUUM
This commit introduces AUTOVACUUM to Limbo. It introduces the concept of ptrmap pages and also adds some additional instructions that are required to make AUTOVACUUM PRAGMA work
2025-06-06 23:14:22 +05:30
ankit
4c3c72b666 fix: make keyword_token safe by validating UTF-8 input 2025-06-06 16:25:49 +05:30
pedrocarlo
22d1a1eaa8 fix blob printing 2025-06-04 12:06:43 -03:00
pedrocarlo
ebee9516ba clippy 2025-06-04 12:06:43 -03:00
pedrocarlo
5f379fe2d6 when no context is needed use Display Impl 2025-06-04 12:06:43 -03:00
pedrocarlo
f90bebbfbc small fix and remove dbg 2025-06-04 12:06:43 -03:00
pedrocarlo
6773dca595 impl ToSqlString for VACUUM stmt + tests 2025-06-04 12:06:43 -03:00
pedrocarlo
d86ff4dea3 impl ToSqlString for UPDATE stmt + tests 2025-06-04 12:06:42 -03:00
pedrocarlo
659ef8fcf7 impl ToSqlString for REINDEX, RELEASE, ROLLBACK, SAVEPOINT stmt + tests 2025-06-04 12:06:42 -03:00
pedrocarlo
e9cbd29dd1 impl ToSqlString for PRAGMA stmt + tests 2025-06-04 12:06:42 -03:00
pedrocarlo
260a26d612 impl ToSqlString for INSERT stmt + tests 2025-06-04 12:06:42 -03:00
pedrocarlo
5710976d95 impl ToSqlString for DROP INDEX, TABLE, TRIGGER, and VIEW stmt 2025-06-04 12:06:42 -03:00
pedrocarlo
8ff0a3c780 impl ToSqlString for DETACH stmt 2025-06-04 12:06:42 -03:00
pedrocarlo
0dc5ca668c test for DELETE + fixes 2025-06-04 12:06:42 -03:00
pedrocarlo
3b1da29b50 impl ToSqlString for DELETE stmt 2025-06-04 12:06:42 -03:00
pedrocarlo
6ba6fae2c6 CREATE VIRTUAL TABLE tests 2025-06-04 12:06:42 -03:00
pedrocarlo
c8f9e29262 impl ToSqlString for CREATE VIRTUAL TABLE stmt + fixes 2025-06-04 12:06:42 -03:00
pedrocarlo
563ab2fdf3 impl ToSqlString for CREATE VIEW stmt + tests 2025-06-04 12:06:42 -03:00
pedrocarlo
87b9540b4a test for create trigger + fixes 2025-06-04 12:06:42 -03:00
pedrocarlo
a22d06cd66 impl ToSqlString for CREATE TRIGGER stmt 2025-06-04 12:06:42 -03:00
pedrocarlo
ba215c8ba9 test for create table + fixes 2025-06-04 12:06:42 -03:00
pedrocarlo
8a7cc7669d impl ToSqlString for CREATE TABLE stmt 2025-06-04 12:06:42 -03:00
pedrocarlo
a8f5257240 impl ToSqlString for CREATE INDEX stmt 2025-06-04 12:06:42 -03:00
pedrocarlo
b47e3a990e impl ToSqlString for COMMIT stmt 2025-06-04 12:06:42 -03:00
pedrocarlo
4f736daa7c impl ToSqlString for BEGIN stmt 2025-06-04 12:06:42 -03:00
pedrocarlo
2a2132e479 impl ToSqlString for Attach stmt 2025-06-04 12:06:42 -03:00
pedrocarlo
355e9a2c96 impl ToSqlString for analyze stmt 2025-06-04 12:06:42 -03:00
pedrocarlo
43b1d4f5da alter table tests + fixes 2025-06-04 12:06:42 -03:00
pedrocarlo
7fb3d40ec2 implement ToSqlString for AlterTable 2025-06-04 12:06:42 -03:00
pedrocarlo
e0c2a09d71 more tests for select + fixes 2025-06-04 12:06:42 -03:00
pedrocarlo
5b6ed60133 simpler select tests + fixes to printing 2025-06-04 12:06:42 -03:00