Commit Graph

3233 Commits

Author SHA1 Message Date
Jussi Saurio
b015fabb26 vdbe: fix panic when first value added to min()/max() accumulator is null 2025-07-10 21:02:57 +03:00
Jussi Saurio
63c5698050 vdbe: remove error prints from min()/max() and simplify 2025-07-10 21:02:57 +03:00
Pekka Enberg
9ddc77d54d Merge 'core/translate: Fix "misuse of aggregate function" error message' from Pekka Enberg
```
sqlite> CREATE TABLE test1(f1, f2);
sqlite> SELECT SUM(min(f1)) FROM test1;
Parse error: misuse of aggregate function min()
  SELECT SUM(min(f1)) FROM test1;
             ^--- error here
```
Spotted by SQLite TCL tests.

Closes #2032
2025-07-10 16:35:30 +03:00
Jussi Saurio
925a252815 Merge 'btree: Improve balance non root docs' from Jussi Saurio
Reviewed-by: Pere Diaz Bou <pere-altea@homail.com>

Closes #2031
2025-07-10 15:07:18 +03:00
Jussi Saurio
0b8c5f7c91 btree/balance: extra doc context for CellArray::cell_payloads 2025-07-10 15:06:27 +03:00
Jussi Saurio
475bced4f7 btree/balance: remove obsolete todo 2025-07-10 14:58:00 +03:00
Jussi Saurio
0316b5a517 btree/balance: rename CellArray::cell_data to cell_payloads 2025-07-10 14:57:45 +03:00
Jussi Saurio
0d973d78a9 btree/balance: add a diagram about divider cell assignment and some comments 2025-07-10 14:56:59 +03:00
Pekka Enberg
f24e254ec6 core/translate: Fix "misuse of aggregate function" error message
```
sqlite> CREATE TABLE test1(f1, f2);
sqlite> SELECT SUM(min(f1)) FROM test1;
Parse error: misuse of aggregate function min()
  SELECT SUM(min(f1)) FROM test1;
             ^--- error here
```

Spotted by SQLite TCL tests.
2025-07-10 14:29:59 +03:00
Pekka Enberg
6749af7037 Merge 'core/translate: Return error if SELECT needs tables and there are none' from Mikaël Francoeur
Fixes https://github.com/tursodatabase/turso/issues/1972

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

Closes #2023
2025-07-10 14:02:57 +03:00
Pekka Enberg
7a259957ac Merge 'properly set last_checksum after recovering wal' from Pere Diaz Bou
We store `last_checksum` to do cumulative checksumming. After reading
wal for recovery, we didn't set last checksum properly in case there
were no frames so this cause us to not initialize last_checksum
properly.

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

Closes #2030
2025-07-10 13:54:15 +03:00
Jussi Saurio
610b743f0d btree/balance: rename CellArray::cell_count to CellArray::cell_count_up_to_page 2025-07-10 13:51:56 +03:00
Jussi Saurio
924482981c btree/balance: rename CellArray::cell_size to CellArray::cell_size_bytes 2025-07-10 13:50:14 +03:00
Jussi Saurio
68cd948056 btree/balance: add extra documentation for page update dual pass 2025-07-10 13:47:08 +03:00
Jussi Saurio
3fc51ed4d9 btree/balance: rename leaf to is_leaf 2025-07-10 13:16:14 +03:00
Jussi Saurio
d88bbd488f btree/balance: rename leaf_data to is_table_leaf 2025-07-10 13:15:29 +03:00
Pere Diaz Bou
9258d33d8b properly set last_checksum after recovering wal
We store `last_checksum` to do cumulative checksumming. After reading
wal for recovery, we didn't set last checksum properly in case there
were no frames so this cause us to not initialize last_checksum
properly.
2025-07-10 12:15:00 +02:00
Jussi Saurio
b306550a69 format 2025-07-10 13:14:57 +03:00
Jussi Saurio
5ef0127409 btree/balance: rename count_cells_in_old_pages to old_cell_count_per_page_cumulative 2025-07-10 13:14:18 +03:00
Jussi Saurio
c31ee0e628 btree/balance: rename number_of_cells_per_page to cell_count_per_page_cumulative 2025-07-10 13:12:17 +03:00
Jussi Saurio
824065a91d btree/balance: rename cells to cell_data 2025-07-10 13:10:31 +03:00
Jussi Saurio
37f2317e49 btree/balance: add comment about divider cell 2025-07-10 13:09:29 +03:00
Jussi Saurio
4d691af3ee btree/balance: clearer variable name 2025-07-10 13:08:58 +03:00
Jussi Saurio
e51f0f5466 btree/balance: improve comment 2025-07-10 13:08:35 +03:00
Jussi Saurio
201edf3668 btree/balance: add comment 2025-07-10 13:05:54 +03:00
Jussi Saurio
fd0a47dc6b btree: simplify pattern match 2025-07-10 13:05:15 +03:00
Jussi Saurio
4dc3e2100f btree: rename balance_non_root related enum variants and add docs 2025-07-10 13:02:50 +03:00
Jussi Saurio
0eeabbb748 Merge 'btree/chore: remove unnecessary parameters to .cell_get()' from Jussi Saurio
we were providing the same damn arguments to `.cell_get()` and
`.cell_get_raw_region()` over and OVER and **OVER** and `O V E R`

Reviewed-by: Preston Thorpe (@PThorpe92)

Closes #2021
2025-07-10 12:22:37 +03:00
Jussi Saurio
c2b699c356 btree: make cell field names consistent 2025-07-09 23:43:03 +03:00
Mikaël Francoeur
89b0574fac return error if no tables 2025-07-09 14:58:24 -04:00
Jussi Saurio
641df7d7e9 improve my mental health by finally refactoring .cell_get() 2025-07-09 19:15:05 +03:00
Jussi Saurio
24219d2eb2 Merge 'Minor refactoring of btree' from meteorgan
Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #1917
2025-07-09 19:13:39 +03:00
meteorgan
0001348158 Minor refactoring of btree 2025-07-09 22:01:54 +08:00
Pekka Enberg
3f10427f52 core: Fix resolve_function() error messages
We need to return the original function name, not normalized one to be
compatible with SQLite.

Spotted by SQLite TCL tests.
2025-07-09 15:30:57 +03:00
Jussi Saurio
c9a6c289e0 clippy 2025-07-09 14:26:43 +03:00
Jussi Saurio
38650eee0e VDBE: fix op_insert re-entrancy
when updating last_insert_rowid we call return_if_io!(cursor.rowid())
which yields IO on large records. this causes op_insert to insert and
overwrite the same row many times. we need a state machine to ensure
that the insertion only happens once and the reading of rowid can
independently yield IO without causing a re-insert.
2025-07-09 14:26:40 +03:00
Jussi Saurio
11d4489740 Merge 'sqlite3_ondisk: generalize left-child-pointer reading function to both index/table btrees' from Jussi Saurio
Reviewed-by: Pere Diaz Bou <pere-altea@homail.com>

Closes #2015
2025-07-09 14:24:08 +03:00
Jussi Saurio
c752058a97 VDBE: introduce state machine for op_idx_insert for more granular IO control
Separates cursor.key_exists_in_index() into a state machine. The problem with
the main branch implementation is this:

`return_if_io!(seek)`
`return_if_io!(cursor.record())`

The latter may yield on IO and cause the seek to start over, causing an infinite
loop. With an explicit state machine we can control and prevent this.
2025-07-09 11:43:18 +03:00
Jussi Saurio
c13b2d5d90 sqlite3_ondisk: generalize left-child-pointer reading function to both index/table btrees 2025-07-09 11:07:42 +03:00
Pere Diaz Bou
f7465f665d add checkpoint lock to wal 2025-07-08 17:53:04 +02:00
meteorgan
99e0cf0603 add a constant MINIMUM_CELL_SIZE 2025-07-08 22:57:20 +08:00
meteorgan
04575456a9 fix Minimum cell size must not be less than 4 2025-07-08 22:57:20 +08:00
meteorgan
3065416bb2 cargo fmt 2025-07-08 22:57:20 +08:00
meteorgan
08be906bb1 return early if index is not found in op_idx_delete 2025-07-08 22:57:20 +08:00
meteorgan
f44d818400 cargo fmt 2025-07-08 22:57:20 +08:00
meteorgan
c6ef4898b0 fix: IdxDelete shouldn't raise error if P5 == 0 2025-07-08 22:57:20 +08:00
meteorgan
4a516ab414 Support except operator for compound select 2025-07-08 22:57:20 +08:00
Pere Diaz Bou
511b80a062 do not assert connection is closed and return error on api 2025-07-08 16:47:03 +02:00
Pere Diaz Bou
232beddf62 vdbe: fix compilation 2025-07-08 16:15:29 +02:00
Pere Diaz Bou
ef41c19542 assert is not closed already 2025-07-08 15:58:11 +02:00