Commit Graph

3024 Commits

Author SHA1 Message Date
pedrocarlo
521d4d85ca adding seed to output of failed tests 2025-02-19 14:23:09 -03: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
Pekka Enberg
28a85edbc8 Merge 'Fix incorrect CAST text->numeric if valid prefix is 1 char long' from Jussi Saurio
Closes #1031
2025-02-18 17:44:01 +02:00
Pekka Enberg
48e705fb53 Merge 'Fix invalid text columns generated by dump' from Kingsley Yung
Fix #1012
In the INSERT statement generated by dump function, if the type affinity
of the value is TEXT, replace each single quotation mark with two single
quotation marks, and wrap it with single quotation marks.
Example:
```plaintext
limbo> CREATE TABLE users (id INT PRIMARY KEY, name VARCHAR(100));
INSERT INTO users (id, name) VALUES
(1, 'Alice'),
(2, 'Bob'),
(3, 'Char''lie');
SELECT * FROM users;

1|Alice
2|Bob
3|Char'lie
limbo> .dump
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE users (id INT PRIMARY KEY, name VARCHAR (100));
INSERT INTO users VALUES(1,'Alice');
INSERT INTO users VALUES(2,'Bob');
INSERT INTO users VALUES(3,'Char''lie');
COMMIT;
```

Closes #1034
2025-02-18 17:43:25 +02:00
Kingsley Yung
67ff5c4ae1 Fix invalid text columns generated by dump
In the INSERT statement generated by dump function, if the type affinity
of the value is TEXT, replace each single quotation mark with two single
quotation marks, and wrap it with single quotation marks.
2025-02-18 23:26:56 +08: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
Pekka Enberg
76ca4c7b01 Merge 'Fix not evaling constant conditions when no tables in query' from Jussi Saurio
This PR is extracted from the sqlite fuzzing exploration effort in
https://github.com/tursodatabase/limbo/pull/1021
---
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.

Closes #1023
2025-02-18 10:07:04 +02:00
Pekka Enberg
b25429d5a5 Merge 'Fix cli test for new output name' from Preston Thorpe
fixes CI failing for CLI tests after `raw` was renamed to output

Closes #1028
2025-02-18 08:56:01 +02:00
Pekka Enberg
e82aea6b8f Merge 'removing dangling limbo_output.txt file and setting rule in gitignore' from Pedro Muniz
When testing with `test-shell` the test may error and the error file
will be tracked in git. Added gitignore rule to always not track
`limbo_output.txt`

Closes #1027
2025-02-18 08:55:55 +02:00
PThorpe92
6a1f9ed773 Fix cli test for new output name 2025-02-17 22:33:55 -05:00
pedrocarlo
95246dec80 removing dangling limbo_output.txt file and setting rule in gitignore to prevent this issue in the future 2025-02-18 00:30:16 -03:00
Pekka Enberg
caa83b347e cli: Rename "raw" output mode to "list"
Change the name of the output mode to match SQLite.
2025-02-17 21:26:15 +02:00
Pekka Enberg
97601658a9 scripts: Add "publish-crates.sh" helper 2025-02-17 21:19:08 +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
9a2e8a6411 Merge 'Add some missing supported features in WHERE clause' from Jussi Saurio
This PR is sourced from the fuzzing exploration PR in
https://github.com/tursodatabase/limbo/pull/1021
**Adds missing support:**
Support all the same literals in WHERE clause position as in SELECT
position
Support CAST in WHERE clause position
Support FunctionCall in WHERE clause position
Support Column in WHERE clause position
Support Rowid in WHERE clause position
Support CASE in WHERE clause position
Support LIKE in SELECT position
Support Unary expressions in WHERE clause position
Support rest of the Binary expressions in WHERE clause position
Support TEXT in remainder operations
**Fix:**
Remove incorrect constant folding optimization for NULL
**Testing utils:**
Enhance sqlite fuzzer to mostly be able to work with the same set of
possible expressions in both SELECT and WHERE clause position

Closes #1024
2025-02-17 13:07:09 +02:00
Jussi Saurio
55ff1d2061 remove comment 2025-02-17 10:59:04 +02:00
Jussi Saurio
7eaa3f4da0 Extract variable 2025-02-17 10:58:38 +02:00
Jussi Saurio
6940ca84bd Add more column <op> column binary op possibilities to fuzzer 2025-02-17 10:57:58 +02:00
Jussi Saurio
bece5b601a Add comment about translate_like_base 2025-02-17 10:55:26 +02:00
Jussi Saurio
12242ad359 Add more TCL tests for exprs in select/where positions 2025-02-17 07:43:09 +02:00
Jussi Saurio
e07007896f tests/fuzz: use mostly the same expression options in select and predicate position 2025-02-17 07:43:09 +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
Jussi Saurio
e3cfba8452 Merge 'fix 24/48 bit width serial types parsing' from Nikita Sivukhin
For serial types 3 and 5 SQLite uses twos-complement representation of
24bit and 48bit widths integers. Limbo need to follow same

Reviewed-by: Jussi Saurio (@jussisaurio)

Closes #1020
2025-02-16 15:49:32 +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
0679357fda insert numbers from different categories in order to cover cases of different serial type usage 2025-02-16 12:33:26 +04:00
Jussi Saurio
c300b4f8a6 Merge 'Fix and predicate' from Nikita Sivukhin
This PR adds simple fuzz test with `SELECT` over data in table and fixes
bug in codegen for `AND` binary operator.
The new fuzz test resembles `logical_expression_fuzz` - but right now
Limbo do not support a lot of conditions (for example, `SELECT * FROM
users WHERE NOT deleted` will fail with `not implemented` error) - so
fuzz test written from scratch and limits `WHERE` condition structure to
the features supported right now.

Closes #1017
2025-02-15 21:21:37 +02:00
Nikita Sivukhin
77d4bb6e0e fix after merge 2025-02-15 23:00:30 +04:00
Nikita Sivukhin
db7544fe7a Merge branch 'tursodatabase:main' into fix-and-predicate 2025-02-15 22:57:56 +04:00
Nikita Sivukhin
becc58565d run IO in fuzz tests 2025-02-15 22:48:01 +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
Pekka Enberg
d1282dc413 Merge 'Fix IdxGt, IdxGe, IdxLt, and IdxLe instructions' from Jussi Saurio
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 and then make the rest of the comparisons as normal loop
condition expressions.
Note that IdxLE and IdxLT are currently "dead" opcodes since they were
recently introduced in #1010 but not yet utilized, as we lack support
for descending indexes

Closes #1016
2025-02-15 17:07:06 +02:00
Nikita Sivukhin
3233d60bea trying to debug hungs in CI 2025-02-15 18:03:29 +04: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
Nikita Sivukhin
e7c501a3be add simple fuzz test with table data 2025-02-15 16:27:11 +04:00
Nikita Sivukhin
10d0dc218b add comment about config.toml env var 2025-02-15 15:05:36 +04:00