Commit Graph

804 Commits

Author SHA1 Message Date
Kacper Madej
19ae42dfa3 Implement json_array 2024-12-20 11:15:48 +01:00
Raul Ferrando
d74012bb59 fix pragma parsing potential errors 2024-12-18 17:26:16 +01:00
Raul Ferrando
a6d1a7cb56 pragma: inital approach to handle pragma statements
This change refactors how PRAGMA statements are handled, introducing a
more organized and extensible structure to simplify adding new PRAGMA
properties in the future.

Previously, only the `cache_size` PRAGMA was supported. With this
update, support for the `journal_mode` PRAGMA has been added.
2024-12-18 17:26:16 +01:00
jussisaurio
783ec65c77 Merge 'Expression equality checking, some optimizations' from Preston Thorpe
This PR mainly adds custom logic to check equality in ast expressions.
Not sure if this belongs in the `vendored` parser or not, let me know
and I'll bring it out. Also replaces `Vec` arguments with slice refs
where possible, as well as some clippy warnings in the same `emitter`
file.
I'll write some more tests tomorrow to make sure this is as thorough as
possible.
EDIT: failed test same issue referenced in #484. Marking as draft until
more tests + cases added

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

Closes #488
2024-12-17 22:09:20 +02:00
PThorpe92
1833dcb618 Shrink shell help msg and replace hardcoded path for shell tests 2024-12-16 20:14:04 -05:00
PThorpe92
66c44a021f Move ast expr equality check out of vendored, remove allocs and add cases 2024-12-16 19:39:06 -05:00
PThorpe92
25772ee1f3 Implement custom expression equality checking 2024-12-16 19:39:05 -05:00
PThorpe92
8d18263fd6 Replace vec args with slices where possible, clippy warnings 2024-12-16 19:39:05 -05:00
Lauri Virtanen
fe42930239 Take log function argument count from function context 2024-12-17 00:14:26 +02:00
Lauri Virtanen
f5c82503f9 Be more explicit with pi() being the only nullary math function 2024-12-17 00:14:25 +02:00
Lauri Virtanen
e69ee80fac Support log(X) and log(B,X) math functions 2024-12-17 00:14:25 +02:00
Lauri Virtanen
89d0289444 Support pi() function 2024-12-17 00:14:25 +02:00
Lauri Virtanen
5e426a7624 Support binary math functions 2024-12-16 22:29:05 +02:00
Lauri Virtanen
f69fdc1645 Support unary math functions 2024-12-16 19:31:20 +02:00
Lauri Virtanen
9720f63a55 Add types for mathematical functions 2024-12-16 19:31:20 +02:00
Pekka Enberg
61269e9c03 Merge 'Fix primary key handling' from Jussi Saurio
Closes #438
**Fixes:**
- Return the actual primary key instead of the rowid when the primary
key is not a rowid alias
sqlite:
```
limbo> create table foo (pk TEXT PRIMARY KEY, value);
sqlite> insert into foo values ('one', 'payload');
sqlite> insert into foo values ('two', 'payload');
sqlite> select * from foo;
one|payload
two|payload
```
limbo now:
```
limbo> create table foo (pk TEXT PRIMARY KEY, value);
limbo> insert into foo values ('one', 'payload');
limbo> insert into foo values ('two', 'payload');
limbo> select * from foo;
one|payload
two|payload
```
limbo before:
```
limbo> select * from foo;
1|payload
2|payload
```
Then, discovered two issues when running the whole TCL test suite
against a copy of `testing.db` that does not have rowid aliases in the
tables:
- Fix trying to convert a Scan into an IndexSearch when the associated
Expr refers to a different instance of the same table in a self-join
- Fix `scan_loop_body_labels` being pushed to in different parts of the
codegen for Scan/Search nodes resulting in incorrect label resolutions
**Additions:**
- Add a new db `testing/testing_norowidalias.db` that is a carbon copy
of `testing/testing.db` except the `id` columns of `users` and
`products` are not rowid aliases (i.e. they are `INT PRIMARY KEY`
instead of `INTEGER PRIMARY KEY`
- Run all TCL tests against both test databases with `do_execsql_test`
```
(testing/testing.db)                        Running test: coalesce-from-table
(testing/testing_norowidalias.db)           Running test: coalesce-from-table
(testing/testing.db)                        Running test: coalesce-from-table-column
(testing/testing_norowidalias.db)           Running test: coalesce-from-table-column
(testing/testing.db)                        Running test: coalesce-from-table-multiple-columns
(testing/testing_norowidalias.db)           Running test: coalesce-from-table-multiple-columns
(testing/testing.db)                        Running test: glob-fn
(testing/testing_norowidalias.db)           Running test: glob-fn
(testing/testing.db)                        Running test: where-glob
(testing/testing_norowidalias.db)           Running test: where-glob
(testing/testing.db)                        Running test: where-glob-question-mark
(testing/testing_norowidalias.db)           Running test: where-glob-question-mark
```
- Allow running tests against specific db file with
`do_execsql_test_on_specific_db $path`
- Wondering if I should add a new table with e.g. text primary key and
add some db-specific tests on that table...?

Closes #449
2024-12-16 18:49:19 +02:00
Pere Diaz Bou
a03749be21 Merge 'Page cache by page_number and frame_number' from Pere Diaz Bou
Since page cache is now shared by default, we need to cache pages by
page number and something else. I chose to go with max_frame of
connection, because this connection will have a max_frame set until from
the start of a transaction until the end of it.
With key pairs of (pgno, max_frame) we make sure each connection is
caching based on the snapshot it is at as two different connections
might have the same pageno being using but a different frame. If both
have same max_frame then they will share same page.

Closes #468
2024-12-16 10:08:34 +01:00
jussisaurio
419ccc327e Dont assume GROUP BY has aggregates 2024-12-16 00:30:38 +02:00
Pere Diaz Bou
a4d7fee090 typos 2024-12-15 22:54:32 +01:00
Pere Diaz Bou
78d8bb1fa6 comments for everyone 2024-12-15 22:52:49 +01:00
Pere Diaz Bou
37005a23d2 fix checkpoint 2024-12-15 18:55:23 +00:00
Pere Diaz Bou
de3449be5a add todo for cache invalidation 2024-12-15 10:03:10 +01:00
Pere Diaz Bou
c6481c4250 add missing propagation error 2024-12-15 10:02:08 +01:00
Pere Diaz Bou
e75b90e35b add contents to checkpoint page 2024-12-15 10:01:22 +01:00
PThorpe92
7fc9835899 Optimize replace byte vec with boxed array in memory page 2024-12-14 23:39:51 -05:00
PThorpe92
ce2851ac8d Fix properly opening new connection in shell 2024-12-14 21:20:10 -05:00
PThorpe92
89819eebf6 Expose memoryIO from limbo_core 2024-12-14 20:52:45 -05:00
PThorpe92
a323db6f46 Add in-memory IO implementation 2024-12-14 20:52:44 -05:00
Ikko Eltociear Ashimine
043fba2632 core: update btree.rs
postion -> position
2024-12-15 03:31:46 +09:00
jussisaurio
351cb7b3f3 fix bug with incorrect ordering of scan loop body labels stack elements 2024-12-14 17:12:24 +02:00
jussisaurio
a04cf611e0 fix bug with making an index search node in a self join where expr refers to other instance of same table 2024-12-14 17:11:32 +02:00
jussisaurio
961e57df94 Fix returning rowid instead of PK when PK is not a rowid alias 2024-12-14 15:51:08 +02:00
Pekka Enberg
e3d8de8919 Merge 'Add two arguments version of unhex(x, y) function' from Kacper Kołodziej
Part of solution for #144

Closes #470
2024-12-14 09:02:30 +02:00
Kacper Kołodziej
c04839d9e0 functions: add unhex(x, y) version
For `unhex(x, y)` handle trimming `y` characters from the beginning and
end of `x` value before decoding.

Part of solutions of #144.
2024-12-14 00:55:44 +01:00
jussisaurio
5e9e2dffe9 support TRUE and FALSE in predicates 2024-12-13 22:58:29 +02:00
Pere Diaz Bou
39a75147d4 Page cache by page_number and frame_number
Since page cache is now shared by default, we need to cache pages by
page number and something else. I chose to go with max_frame of
connection, because this connection will have a max_frame set until from
the start of a transaction until the end of it.

With key pairs of (pgno, max_frame) we make sure each connection is
caching based on the snapshot it is at as two different connections
might have the same pageno being using but a different frame. If both
have same max_frame then they will share same page.
2024-12-13 21:57:27 +01:00
Pekka Enberg
138b3a00e8 Merge 'use correct min/max frames' from Pere Diaz Bou
Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #465
2024-12-13 18:48:26 +02:00
Pere Diaz Bou
1e5239a164 use correct min/max frames 2024-12-13 14:06:29 +01:00
Pere Diaz Bou
352b3540ee loop writing header while initializing
if somehow this doesn't finish in a single loop, do more just in case
2024-12-13 13:25:56 +01:00
Pere Diaz Bou
1a663a6ed7 cargo stuff rm 2024-12-13 13:09:13 +01:00
Pere Diaz Bou
b43e8e46f6 impl sync/send for cache 2024-12-13 13:09:13 +01:00
Pere Diaz Bou
97dd95abea core: change Rc<RefCell<Page>> to Arc<Page>
This includes an inner struct in Page wrapped with Unsafe cell to access
it. This is done intentionally because concurrency control of pages is
handled by pages and not by the page itself.
2024-12-13 13:09:13 +01:00
Pere Diaz Bou
c816186326 fmt 2024-12-13 13:09:13 +01:00
Pere Diaz Bou
3fda2d09b9 Extract multi threaded part from WalFile to WalFileShared
Since we expect to ensure thread safety between multiple threads in the
future, we extract what is important to be shared between multiple
connections with regards to WAL.

This is WIP so I just put whatever feels like important behind a RwLock
but expect this to change to Atomics in the future as needed. Maybe even
these locks might disappear because they will be better served with
transaction locks.
2024-12-13 13:09:13 +01:00
Pere Diaz Bou
a4297702bd extract page cache to be multi threaded 2024-12-13 13:09:13 +01:00
Pekka Enberg
2b85d2a600 Merge 'Add implementation and tests for replace scalar function' from Alperen Keleş
Adds `replace` scalar function.

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

Closes #446
2024-12-13 11:02:08 +02:00
JeanArhancet
8bf6572e9e feat: support unary positive 2024-12-13 02:07:34 +01:00
alpaylan
4f395623ab fix the comment on replace panic in case of text cast failure 2024-12-12 15:03:35 -05:00
alpaylan
5742c51c5c improve error messages on replace function call 2024-12-12 14:14:04 -05:00
Alperen Keleş
841a4fe2f8 Merge branch 'tursodatabase:main' into main 2024-12-12 13:13:41 -05:00