Commit graph

86 commits

Author SHA1 Message Date
Preston Thorpe
71944c9d49
Merge 'Revert "Merge 'fix stack overflow in long unary expressions' from "' from Jussi Saurio
This reverts commit b40cdb1bfd, reversing
changes made to cd22c4dc48.
Closes #4306
Closes #4302
Reopens #4197

Closes #4307
2025-12-20 13:43:40 -05:00
Preston Thorpe
a10051dde4
Merge 'Fix RTRIM ignoring trailing tabs' from Krishna Vishal
`str::trim_end()` removes trailing tabs too. Replaced it with
`trim_end_matches(' ')`. Rust `str::trim` functions seem problematic
because they remove non-ascii whitespace and others.
Behavior now:
```
turso> select 'x' || char(9) = 'x' collate rtrim;
┌─────────────────────────────────────┐
│ 'x' || char (9) = 'x' COLLATE rtrim │
├─────────────────────────────────────┤
│                                   0 │
└─────────────────────────────────────┘
```
Closes: #3480

Reviewed-by: Mikaël Francoeur (@LeMikaelF)

Closes #3891
2025-12-20 10:33:59 -05:00
Jussi Saurio
3428359a73 Revert "Merge 'fix stack overflow in long unary expressions' from "
This reverts commit b40cdb1bfd, reversing
changes made to cd22c4dc48.
2025-12-20 10:09:34 +02:00
ziord
b6d7144087 add tests 2025-12-17 19:51:57 -05:00
pedrocarlo
d4919abd77 add some tests 2025-12-05 19:44:28 -03:00
Jussi Saurio
e0791406b5 Fix two bugs with compound selects
1. Previously compound select would not start a transaction if
   the rightmost subselect had no table references, e.g.
   SELECT * FROM t UNION VALUES(1)

2. Previously the column names for the query were taken from the
   rightmost subselect - instead, they should be taken from the
   leftmost subselect.
2025-12-05 17:14:58 +02:00
Krishna Vishal
8bf87c86d6 Add test 2025-12-03 12:49:23 +05:30
Mikaël Francoeur
751853aff1
fix large number comparison across types 2025-12-01 17:37:48 -05:00
Mikaël Francoeur
d93d466c6d
compare as i64 if possible 2025-12-01 17:37:48 -05:00
Pavan-Nambi
bad9dce789
add alias to colnames explicitly as column-N 2025-11-25 07:55:50 +05:30
Mikaël Francoeur
e65fbfe6f6
use i64 for register values p1,p2,p3,p5 2025-11-16 09:58:05 -05:00
pedrocarlo
176fa283bf add some ai generated queries to test for affinity related queries 2025-11-10 11:15:54 +02:00
pedrocarlo
0eb0fc5c22 add tests 2025-11-02 11:27:05 -03:00
RS2007
bdf720d205 adding regression test for duplicate cte 2025-10-31 23:15:11 +05:30
Jussi Saurio
3294b78051 Initialize LIMIT after after ORDER BY / GROUP BY initialization
Currently LIMIT 0 jumps to "after the main loop", and it is done
before ORDER BY and GROUP BY cursor have had a chance to be initialized,
which causes a panic.

Simplest fix for now is to delay the LIMIT initialization.
2025-10-28 13:08:05 +02:00
bit-aloo
b2769afffd
add test 2025-10-24 16:08:15 +05:30
PThorpe92
79c5234122
Add TCL test for self ambiguous join 2025-10-16 16:43:08 -04:00
PThorpe92
959df4c4bc
Add TCL test for rowid from clause subquery panic 2025-10-16 13:40:10 -04:00
Jussi Saurio
4e6f373e3d
Merge 'Fix: Evaluating expression in LIMIT and OFFSET clauses.' from
Some checks are pending
Build & publish @tursodatabase/database / db-bindings-x86_64-pc-windows-msvc - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / db-bindings-x86_64-unknown-linux-gnu - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / sync-bindings-aarch64-apple-darwin - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / sync-bindings-aarch64-unknown-linux-gnu - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / sync-bindings-wasm32-wasip1-threads - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / Test DB bindings on browser@20 (push) Blocked by required conditions
Python / test (push) Blocked by required conditions
Python / lint (push) Waiting to run
Python / linux (x86_64) (push) Waiting to run
Python / macos-arm64 (aarch64) (push) Waiting to run
Python / sdist (push) Waiting to run
Python / Release (push) Blocked by required conditions
Rust / cargo-fmt-check (push) Waiting to run
Rust / build-native (blacksmith-4vcpu-ubuntu-2404) (push) Waiting to run
Rust / build-native (macos-latest) (push) Waiting to run
Rust Benchmarks+Nyrkiö / clickbench (push) Waiting to run
Rust Benchmarks+Nyrkiö / tpc-h-criterion (push) Waiting to run
Rust Benchmarks+Nyrkiö / tpc-h (push) Waiting to run
Rust Benchmarks+Nyrkiö / vfs-bench-compile (push) Waiting to run
Build & publish @tursodatabase/database / sync-bindings-x86_64-pc-windows-msvc - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / sync-bindings-x86_64-unknown-linux-gnu - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / Test DB bindings on Linux-x64-gnu - node@20 (push) Blocked by required conditions
Build & publish @tursodatabase/database / Publish (push) Blocked by required conditions
Python / configure-strategy (push) Waiting to run
Rust / build-native (windows-latest) (push) Waiting to run
Rust / clippy (push) Waiting to run
Rust / simulator (push) Waiting to run
Rust / test-limbo (push) Waiting to run
Rust / test-sqlite (push) Waiting to run
Rust Benchmarks+Nyrkiö / bench (push) Waiting to run
Closes #3687 .
Previously, the `try_fold_expr_to_i64` function casted `NULL` as `0`
when evaluating expressions in `LIMIT` or `OFFSET` clauses. I removed
this function since evaluating the expression directly and relying on
the MustBeInt operation for casting seems to handle everything.

Closes #3695
2025-10-15 10:36:36 +03:00
Jussi Saurio
25cf56b8e8 Fix expected error message 2025-10-15 09:41:44 +03:00
rajajisai
9bbf3bb780 Add tests 2025-10-12 22:46:53 -04:00
Pavan-Nambi
7e8dabaee5
make comparison case sensitive 2025-10-12 18:02:03 +05:30
Diego Reis
da323fa0c4
Some clean ups and correctly working on WHERE clauses 2025-10-09 11:57:15 -03:00
Jussi Saurio
7948259d37
Merge 'optimizer: optimize range scans to use upper and lower bounds more efficiently' from Jussi Saurio
Some checks are pending
Build & publish @tursodatabase/database / db-bindings-x86_64-pc-windows-msvc - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / db-bindings-x86_64-unknown-linux-gnu - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / sync-bindings-aarch64-apple-darwin - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / sync-bindings-aarch64-unknown-linux-gnu - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / sync-bindings-wasm32-wasip1-threads - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / sync-bindings-x86_64-pc-windows-msvc - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / sync-bindings-x86_64-unknown-linux-gnu - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / Test DB bindings on Linux-x64-gnu - node@20 (push) Blocked by required conditions
Build & publish @tursodatabase/database / Test DB bindings on browser@20 (push) Blocked by required conditions
Build & publish @tursodatabase/database / Publish (push) Blocked by required conditions
Python / configure-strategy (push) Waiting to run
Python / test (push) Blocked by required conditions
Python / lint (push) Waiting to run
Python / linux (x86_64) (push) Waiting to run
Python / macos-arm64 (aarch64) (push) Waiting to run
Python / sdist (push) Waiting to run
Python / Release (push) Blocked by required conditions
Rust / clippy (push) Waiting to run
Rust / cargo-fmt-check (push) Waiting to run
Rust / build-native (blacksmith-4vcpu-ubuntu-2404) (push) Waiting to run
Rust / build-native (macos-latest) (push) Waiting to run
Rust / build-native (windows-latest) (push) Waiting to run
Rust Benchmarks+Nyrkiö / tpc-h-criterion (push) Waiting to run
Rust Benchmarks+Nyrkiö / tpc-h (push) Waiting to run
Rust Benchmarks+Nyrkiö / vfs-bench-compile (push) Waiting to run
Rust / simulator (push) Waiting to run
Rust / test-limbo (push) Waiting to run
Rust / test-sqlite (push) Waiting to run
Rust Benchmarks+Nyrkiö / bench (push) Waiting to run
Rust Benchmarks+Nyrkiö / clickbench (push) Waiting to run
Made a new PR based on @sivukhin 's PR #2869 that had a lot of
conflicts. You can check out the PR description from there.
## The main idea is:
Before, if we had an index on `x` and had a query like `WHERE x > 100
and x < 200`, the plan would be something like:
```
- Seek to first row where x > 100
- Then, for every row, discard the row if x >= 200
```
This is highly wasteful in cases where there are a lot of rows where `x
>= 200`. Since our index is sorted on `x`, we know that once we hit the
_first_ row where `x >= 200`, we can stop iterating entirely.
So, the new plan is:
```
- Seek to first row where x > 100
- Then, iterate rows until x >= 200, and then stop
```
This also improves the situation for multi-column indexes. Imagine index
on `(x,y)` and a condition like `WHERE x = 100 and y > 100 and y < 200`.
Before, the plan was:
```
- Seek to first row where x=100 and y > 100
- Then, iterate rows while x = 100 and discard the row if y >= 200
- Stop when x > 100
```
This also suffers from a problem where if there are a lot of rows where
`x=100` and `y >= 200`, we go through those rows unnecessarily. The new
plan is:
```
- Seek to first row where x=100 and y > 100
- Then, iterate rows while x = 100 and y < 200
- Stop when either x > 100 or y >= 200
```
Which prevents us from iterating rows like `x=100, y = 666`
unnecessarily because we know the index is sorted on `(x,y)` - once we
hit any row where `x>100` OR `x=100, y >= 200`, we can stop.

Closes #3644
2025-10-09 14:47:15 +03:00
Nikita Sivukhin
4313f57ecb Optimize range scans 2025-10-09 11:47:41 +03:00
Jussi Saurio
a343dacaaf translate: make bind_and_rewrite_expr() reject identifiers if no referenced tables exist 2025-10-07 23:34:26 +03:00
Nikita Sivukhin
e5aa836ad5 add simple test 2025-09-30 17:57:25 +04:00
Diego Reis
90f4d69774 fix(3301): Remove identifier assert assumption
Not every identifier should be double-quoted
2025-09-29 22:33:21 -03:00
Jussi Saurio
726bc24e78 Support referring to rowid as _rowid_ or oid 2025-09-24 09:17:28 +03:00
bit-aloo
881b986302
improve the limi exprs test with foreach block 2025-08-26 19:56:25 +05:30
bit-aloo
05267454dc
remove redundant step during limit/offset evaluation and add test coverage most of the datatypes and some expression 2025-08-26 19:56:25 +05:30
bit-aloo
26d71603ac
add a test to test limit expressiveness 2025-08-26 19:56:12 +05:30
Jussi Saurio
86b1232268 chore: enable indexes by default 2025-08-01 15:44:56 +03:00
Jussi Saurio
7259751eba
Merge 'Support the OFFSET clause for Compound select' from meteorgan
Closes #2376
2025-08-01 10:18:13 +03:00
meteorgan
6262ff4267 support offset for values 2025-08-01 00:46:46 +08:00
Glauber Costa
9d41fa4489 implement IN patterns for non-conditional SELECT queries
Extracts the core logic of IN from the conditional version, and uses the
conditional metadata to determine the jump. Then Uses the AddImm
operator we just added to force the integer conversion at the end (like
SQLite does).
2025-07-31 08:11:41 -05:00
meteorgan
a0f5554b08 support the OFFSET clause for Compound select 2025-07-31 17:43:54 +08:00
meteorgan
aa69b279c3 support limit 2025-07-28 00:58:20 +08:00
meteorgan
ea660b947d support VALUES clauses for compound select 2025-07-27 19:13:23 +08:00
Glauber Costa
b5927dcfd5 support doubly qualified identifiers 2025-07-25 14:52:45 -05:00
Jussi Saurio
022f679fab chore: make every CREATE TABLE stmt in entire repo have 1 space after tbl name
`BTreeTable::to_sql` makes us incompatible with SQLite by losing e.g. the original whitespace provided during the CREATE TABLE command.

For now let's fix our tests by regex-replacing every CREATE TABLE in
the entire repo to have exactly 1 space after the table name in the
CREATE TABLE statement.
2025-07-22 11:35:21 +03:00
Glauber Costa
cbdd5c5fc7 improve handling of double quotes
I ended up hitting #1974 today and wanted to fix it. I worked with
Claude to generate a more comprehensive set of queries that could fail
aside from just the insert query described in the issue. He got most of
them right - lots of cases were indeed failing. The ones that were
gibberish, he told me I was absolutely right for pointing out they were
bad.

But alas. With the test cases generated, we can work on fixing it. The
place where the assertion was hit, all we need to do there is return
true (but we assert that this is indeed a string literal, it shouldn't
be anything else at this point).

There are then just a couple of places where we need to make sure we
handle double quotes correctly. We already tested for single quotes in a
couple of places, but never for double quotes.

There is one funny corner case where you can just select "col" from tbl,
and if there is no column "col" on the table, that is treated as a
string literal. We handle that too.

Fixes #1974
2025-07-18 10:39:02 -05:00
Nikita Sivukhin
9a347d8852 add simple tcl test 2025-07-14 13:01:15 +04:00
Mikaël Francoeur
89b0574fac return error if no tables 2025-07-09 14:58:24 -04:00
meteorgan
829e44c539 fix test data 2025-07-08 22:57:20 +08:00
meteorgan
6768f073c8 add tests for except operator 2025-07-08 22:57:20 +08:00
Pekka Enberg
9c1b7897ac Fix URLs to point to github.com/tursodatabase/turso 2025-06-30 11:23:53 +03:00
meteorgan
2c4847210f ajust code to accommodate index_experimental feature 2025-06-27 11:50:19 +08:00
meteorgan
41def8895f make intersect in compound work with insert 2025-06-27 11:50:19 +08:00
meteorgan
1fcc2ddd90 support limit 2025-06-27 11:50:19 +08:00