Commit graph

112 commits

Author SHA1 Message Date
Pekka Enberg
90c1e3fc06 Switch Connection to use Arc instead of Rc
Connection needs to be Arc so that bindings can wrap it with `Mutex` for
multi-threading.
2025-06-16 10:43:19 +03:00
Jussi Saurio
bdbd021bbb Fix large inserts to unique indexes hanging
We were incorrectly setting `moved_before` as `false` after checking
for unique constraint violation, but the reality is that after the
uniqueness check, we are already correctly positioned -- if no match
was found, the cursor is positioned at either:

a) no row, or
b) at the first entry that is greater than the key we are inserting.

This means we don't have to move anymore and can just insert.
2025-06-12 12:25:17 +03:00
Krishna Vishal
7db6e2dfea Decrease db rows and increase random values 2025-06-11 00:33:48 +05:30
krishvishal
5837f7329f clean up 2025-06-11 00:33:47 +05:30
krishvishal
e01f4d55f7 Reduce fuzz iters 2025-06-11 00:33:47 +05:30
krishvishal
9eb2235135 A simple fuzz test for fuzzing seeking ops 2025-06-11 00:33:05 +05:30
Pere Diaz Bou
0698249c5e test_delete_with_index 2025-06-10 14:16:26 +03:00
Pere Diaz Bou
da4190a23e Convert u64 rowid to i64
Rowids can be negative, therefore let's swap to i64
2025-05-30 13:07:31 +02:00
Pere Diaz Bou
28bd24b7d4 clear page cache on transaction failure
This is the first step towards rollback, since we still don't spill
pages with WAL, we can simply invalidate page cache in case of failure.
2025-05-28 15:54:28 +02:00
Jussi Saurio
b72b99c973 Merge 'feature: INSERT INTO <table> SELECT' from Pedro Muniz
Closes #1528 .
- Modified `translate_select` so that the caller can define if the
statement is top-level statement or a subquery.
- Refactored `translate_insert` to offload the translation of multi-row
VALUES and SELECT statements to `translate_select`
- I did not try to change much of `populate_column_registers` as I did
not want to break `translate_virtual_table_insert`. Ideally, I would
want to unite this remaining logic folding `populate_column_registers`
into `populate_columns_multiple_rows` and the
`translate_virtual_table_insert` into `translate_insert`. But, I think
this may be best suited for a separate PR.
## TODO
- ~Tests~ - *Done*
- ~Need to emit a temp table when we are selecting and inserting into
the Same Table -
https://github.com/sqlite/sqlite/blob/master/src/insert.c#L1369~ -
*Done*
- Optimization when table have the exact same schema - open an Issue
about it
- Virtual Tables do not benefit yet from this feature - open an Issue
about it

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

Closes #1566
2025-05-27 10:50:26 +03:00
Jussi Saurio
3ba9f2ab97 Small cleanups to pager/wal/vdbe - mostly naming
- Instead of using a confusing CheckpointStatus for many different things,
  introduce the following statuses:
    * PagerCacheflushStatus - cacheflush can result in either:
      - the WAL being written to disk and fsynced
      - but also a checkpoint to the main BD file, and fsyncing the main DB file

      Reflect this in the type.
    * WalFsyncStatus - previously CheckpointStatus was also used for this, even
      though fsyncing the WAL doesn't checkpoint.
    * CheckpointStatus/CheckpointResult is now used only for actual checkpointing.

- Rename HaltState to CommitState (program.halt_state -> program.commit_state)
- Make WAL a non-optional property in Pager
  * This gets rid of a lot of if let Some(...) boilerplate
  * For ephemeral indexes, provide a DummyWAL implementation that does nothing.
- Rename program.halt() to program.commit_txn()
- Add some documentation comments to structs and functions
2025-05-26 10:37:34 +03:00
pedrocarlo
ee93316c46 fix num_values detection + emitting correct column for temp_table + tests 2025-05-25 19:15:28 -03:00
Jussi Saurio
d5623e752b make compound_select_fuzz() test more likely to generate duplicate rows 2025-05-25 21:27:45 +03:00
Jussi Saurio
d893a55c55 UNION 2025-05-25 21:23:04 +03:00
Jussi Saurio
2df01f0b6f clippy stfu 2025-05-25 10:29:30 +03:00
Jussi Saurio
8ed5334ca7 tests/fuzz: add compound_select_fuzz() 2025-05-24 13:12:41 +03:00
Jussi Saurio
cbb3efab82 Fuzz: modify rowid_seek_fuzz so that it catches this regression in the future 2025-05-23 14:28:25 +03:00
pedrocarlo
f28ce2b757 add collations to btree cursor 2025-05-19 15:22:55 -03:00
Pekka Enberg
e3f71259d8 Rename OwnedValue -> Value
We have not had enough merge conflicts for a while so let's do a
tree-wide rename.
2025-05-15 09:59:46 +03:00
pedrocarlo
3526a206e4 support Unique properly by creating a vec of auto indices 2025-05-14 11:34:39 -03:00
PThorpe92
e91d17f06e
Add tests for parameter binding for update, select and delete queries 2025-05-13 12:50:10 -04:00
PThorpe92
4e3efe655d
Add integration test for binding parameters on insert of multiple rows 2025-05-10 07:46:30 -04:00
PThorpe92
50f2621c12
Add several more rust tests for parameter binding 2025-05-10 07:46:29 -04:00
PThorpe92
56f5f47e86
Remove try init from tracing subscriber in tests to prevent excessive output 2025-05-10 07:46:29 -04:00
PThorpe92
9b8227dbf8
Add extensive rust integration tests for bindings parameters 2025-05-10 07:46:29 -04:00
Jussi Saurio
c9eb56b54a Merge 'Read only mode' from Pedro Muniz
Closes #1413 . Basically, SQLite emits a check in a transaction to see
if it is attempting to write. If the db is in read only mode, it throws
an error, else the statement is executed. Mirroring how Rusqlite does
it, I modified the `OpenFlags` to use bitflags to better configure how
we open our VFS. This modification, will enable us to run tests against
the same database in parallel.

Closes #1433
2025-05-03 19:15:06 +03:00
pedrocarlo
2b3285d669 test opening in read only mode 2025-05-02 16:31:11 -03:00
Pere Diaz Bou
c808863256 test update with index 2025-05-01 11:44:23 +03:00
Pere Diaz Bou
e503bb4641 run_query helper for test_write_path 2025-05-01 11:36:29 +03:00
Pere Diaz Bou
63a94e7c62 Merge 'Emit IdxDelete instruction and some fixes on seek after deletion' from Pere Diaz Bou
Previously `DELETE FROM ...` only emitted deletes for main table, but
this is incorrect as we want to remove entries from index tables as
well.

Closes #1383
2025-04-28 09:13:54 +03:00
Pere Diaz Bou
b7970a286d implement IdxDelete
clippy

revert op_idx_ge changes

fmt

fmt again

rever op_idx_gt changes
2025-04-24 16:23:34 +02:00
Jussi Saurio
48071b7ad7 tests/fuzz/compound_index_seek: order select cols by definition order 2025-04-23 17:34:32 +03:00
Jussi Saurio
517390a4ea tests/fuzz/compound_index_seek: show which table had failed query 2025-04-23 16:57:43 +03:00
Timo Kösters
68d8b86bb7
fix: get name of rowid column 2025-04-22 08:46:37 +02:00
Jussi Saurio
8477ff0d3d tests/fuzz: amend compound index key fuzz to include nonindexed columns some of the time 2025-04-18 15:13:13 +03:00
Jussi Saurio
95bc644244 tests/fuzz: make compound key fuzz test a bit stricter with ordering 2025-04-16 14:10:25 +03:00
Jussi Saurio
8757510606 test/fuzz: revamp compound key seek fuzz test to include desc indexes and be more efficient 2025-04-16 13:58:12 +03:00
Jussi Saurio
1141cbaf3b logical_expr_fuzz: add primary keys to test table to detect issues w index usage 2025-04-12 11:12:48 +03:00
Jussi Saurio
3d1b4c5292 test/fuzz: modify compound index scan fuzz to utilize both pk columns in where clause 2025-04-10 15:06:18 +03:00
Jussi Saurio
d9bae633c0 Add rowid_seek_fuzz() test 2025-04-09 10:14:29 +03:00
Jussi Saurio
431ef2fa6a Add TCL/differential fuzz tests for verifying index scan behavior 2025-04-09 10:14:29 +03:00
Pere Diaz Bou
587cdac2c1 ignore sequential write beause it takes too long 2025-03-29 22:26:29 +01:00
Pere Diaz Bou
a13b33fec9 clippy again 2025-03-29 22:07:43 +01:00
Pere Diaz Bou
d9f5cd870d clippy 2025-03-29 22:04:08 +01:00
Pere Diaz Bou
ee55116ca6 return row as reference to registers 2025-03-29 22:04:08 +01:00
Pere Diaz Bou
bf37fd3314 wip 2025-03-29 22:02:49 +01:00
Pere Diaz Bou
01cdcf719c remove ignored from sequential tests 2025-03-28 11:30:19 +01:00
Pere Diaz Bou
dc8acf1a4a cell_get no allocations 2025-03-28 11:12:27 +01:00
Pere Diaz Bou
d01423df83 fix clippy 2025-03-27 17:54:32 +01:00
Pere Diaz Bou
be3badc1f3 modify a few btree log level and add end_write_txn after checkpoint 2025-03-12 15:48:22 +01:00