Krishna Vishal
515712b7f2
Fix sorter
2025-07-14 03:28:54 +05:30
Pekka Enberg
725c3e4ddc
Rename limbo_sqlite3_parser crate to turso_sqlite3_parser
2025-06-29 12:34:46 +03:00
pedrocarlo
4a3119786e
refactor BtreeCursor and Sorter to accept Vec of collations
2025-05-19 15:22:55 -03:00
pedrocarlo
bf1fe9e0b3
Actually fixed group by and order by collation
2025-05-19 15:22:15 -03:00
Jussi Saurio
3798b4aa8b
use SortOrder in sorters always
2025-04-24 10:34:06 +03:00
Jussi Saurio
f53448ae75
Fix bug: we cant remove order by terms from the head of the list
2025-04-24 10:34:06 +03:00
Pere Diaz Bou
d9f5cd870d
clippy
2025-03-29 22:04:08 +01:00
Pere Diaz Bou
bf37fd3314
wip
2025-03-29 22:02:49 +01:00
Tiago Ribeiro
295691d81b
Update core/vdbe to use the new retrieval methods to access Record values.
2025-02-10 00:27:51 -07:00
Pekka Enberg
f3902ef9b6
core: Rename OwnedRecord to Record
...
We only have one record type so let's call it `Record`.
2025-02-06 13:40:34 +02:00
Jussi Saurio
9e32ce6c77
Add Cursor enum and store a single BTreeMap of cursors in ProgramState
2025-01-26 12:57:15 +02:00
Jussi Saurio
bf48c0ae72
Remove trait Cursor
2025-01-11 17:19:25 +02:00
김선우
9a8b94ef93
First successful implementation of delete planning
2024-12-22 13:16:16 +09:00
krishvishal
7e2928a5f1
Feature: last_insert_rowid()
...
- Changed `Cursor` trait to be able to get access to `root_page`
- SQLite only updates last_insert_rowid for non-schema inserts. So we check if the `InsertAwait` is not for `root_page` before
updating rowid
2024-12-09 22:48:42 +05:30
limeng.1
8cca659052
impl order by desc
2024-11-19 11:39:07 +08:00
Pere Diaz Bou
9f72655e30
tree_create -> btree_create
2024-11-18 10:31:47 +01:00
Pere Diaz Bou
090615b289
create btree table + parse schema
2024-11-16 16:24:28 +01:00
Pekka Enberg
fdf3b0d16b
Merge '(core): Primary key index scans and single-column secondary index scans' from Jussi Saurio
...
This PR adds an index on `users.age` to `testing.db`, and support for
indexed lookups. Only single-column ascending indexes are currently
supported.
This PR also gets rid of `Operator::Seekrowid` in favor of
`Operator::Search` which handles all non-full-table-scan searches: 1.
integer primary key (rowid) point queries 2. integer primary key index
scans, and 3. secondary index scans.
examples:
```
limbo> select first_name, age from users where age > 90 limit 10;
Miranda|90
Sarah|90
Justin|90
Justin|90
John|90
Jeremy|90
Stephanie|90
Joshua|90
Jenny|90
Jennifer|90
limbo> explain query plan select first_name, age from users where age > 90 limit 10;
QUERY PLAN
`--TAKE 10
`--PROJECT first_name, age
| `--SEARCH users USING INDEX age_idx
limbo> explain select first_name, age from users where age > 90 limit 10;
addr opcode p1 p2 p3 p4 p5 comment
---- ----------------- ---- ---- ---- ------------- -- -------
0 Init 0 15 0 0 Start at 15
1 OpenReadAsync 0 2 0 0 table=users, root=2
2 OpenReadAwait 0 0 0 0
3 OpenReadAsync 1 274 0 0 table=age_idx, root=274
4 OpenReadAwait 0 0 0 0
5 Integer 90 1 0 0 r[1]=90
6 SeekGT 1 14 1 0
7 DeferredSeek 1 0 0 0
8 Column 0 1 2 0 r[2]=users.first_name
9 Column 0 9 3 0 r[3]=users.age
10 ResultRow 2 2 0 0 output=r[2..3]
11 DecrJumpZero 4 14 0 0 if (--r[4]==0) goto 14
12 NextAsync 1 0 0 0
13 NextAwait 1 7 0 0
14 Halt 0 0 0 0
15 Transaction 0 0 0 0
16 Integer 10 4 0 0 r[4]=10
17 Goto 0 1 0 0
```
Sqlite version:
```
sqlite> explain select first_name, age from users where age > 90 limit 10;
addr opcode p1 p2 p3 p4 p5 comment
---- ------------- ---- ---- ---- ------------- -- -------------
0 Init 0 13 0 0 Start at 13
1 Integer 10 1 0 0 r[1]=10; LIMIT counter
2 OpenRead 0 2 0 10 0 root=2 iDb=0; users
3 OpenRead 1 274 0 k(2,,) 0 root=274 iDb=0; age_idx
4 Integer 90 2 0 0 r[2]=90
5 SeekGT 1 12 2 1 0 key=r[2]
6 DeferredSeek 1 0 0 0 Move 0 to 1.rowid if needed
7 Column 0 1 3 0 r[3]= cursor 0 column 1
8 Column 1 0 4 0 r[4]= cursor 1 column 0
9 ResultRow 3 2 0 0 output=r[3..4]
10 DecrJumpZero 1 12 0 0 if (--r[1])==0 goto 12
11 Next 1 6 0 0
12 Halt 0 0 0 0
13 Transaction 0 0 3 0 1 usesStmtJournal=0
14 Goto 0 1 0 0
```
---
´Seek` instructions are also now supported for primary key rowid
searches:
```
limbo> select id, first_name from users where id > 9995;
9996|Donald
9997|Ruth
9998|Dorothy
9999|Gina
10000|Nicole
limbo> explain query plan select id, first_name from users where id > 9995;
QUERY PLAN
`--PROJECT id, first_name
`--SEARCH users USING INTEGER PRIMARY KEY (rowid=?)
limbo> explain select id, first_name from users where id > 9995;
addr opcode p1 p2 p3 p4 p5 comment
---- ----------------- ---- ---- ---- ------------- -- -------
0 Init 0 11 0 0 Start at 11
1 OpenReadAsync 0 2 0 0 table=users, root=2
2 OpenReadAwait 0 0 0 0
3 Integer 9995 1 0 0 r[1]=9995
4 SeekGT 0 10 1 0
5 RowId 0 2 0 0 r[2]=users.rowid
6 Column 0 1 3 0 r[3]=users.first_name
7 ResultRow 2 2 0 0 output=r[2..3]
8 NextAsync 0 0 0 0
9 NextAwait 0 5 0 0
10 Halt 0 0 0 0
11 Transaction 0 0 0 0
12 Goto 0 1 0 0
```
sqlite:
```
sqlite> explain select id, first_name from users where id > 9995;
addr opcode p1 p2 p3 p4 p5 comment
---- ------------- ---- ---- ---- ------------- -- -------------
0 Init 0 8 0 0 Start at 8
1 OpenRead 0 2 0 2 0 root=2 iDb=0; users
2 SeekGT 0 7 1 0 key=r[1]; pk
3 Rowid 0 2 0 0 r[2]=users.rowid
4 Column 0 1 3 0 r[3]= cursor 0 column 1
5 ResultRow 2 2 0 0 output=r[2..3]
6 Next 0 3 0 0
7 Halt 0 0 0 0
8 Transaction 0 0 3 0 1 usesStmtJournal=0
9 Integer 9995 1 0 0 r[1]=9995
10 Goto 0 1 0 0
```
---
More complex example with a join that uses both a rowid lookup and a
secondary index scan:
```
limbo> explain query plan select u.first_name, p.name from users u join products p on u.id = p.id and u.age > 70;
QUERY PLAN
`--PROJECT u.first_name, p.name
`--JOIN
| |--SEARCH u USING INDEX age_idx
| `--SEARCH p USING INTEGER PRIMARY KEY (rowid=?)
limbo> explain select u.first_name, p.name from users u join products p on u.id = p.id and u.age > 70;
addr opcode p1 p2 p3 p4 p5 comment
---- ----------------- ---- ---- ---- ------------- -- -------
0 Init 0 18 0 0 Start at 18
1 OpenReadAsync 0 2 0 0 table=u, root=2
2 OpenReadAwait 0 0 0 0
3 OpenReadAsync 1 274 0 0 table=age_idx, root=274
4 OpenReadAwait 0 0 0 0
5 OpenReadAsync 2 3 0 0 table=p, root=3
6 OpenReadAwait 0 0 0 0
7 Integer 70 1 0 0 r[1]=70
8 SeekGT 1 17 1 0
9 DeferredSeek 1 0 0 0
10 RowId 0 2 0 0 r[2]=u.rowid
11 SeekRowid 2 2 15 0 if (r[2]!=p.rowid) goto 15
12 Column 0 1 3 0 r[3]=u.first_name
13 Column 2 1 4 0 r[4]=p.name
14 ResultRow 3 2 0 0 output=r[3..4]
15 NextAsync 1 0 0 0
16 NextAwait 1 9 0 0
17 Halt 0 0 0 0
18 Transaction 0 0 0 0
19 Goto 0 1 0 0
```
sqlite:
```
sqlite> explain select u.first_name, p.name from users u join products p on u.id = p.id and u.age > 70;
addr opcode p1 p2 p3 p4 p5 comment
---- ------------- ---- ---- ---- ------------- -- -------------
0 Init 0 14 0 0 Start at 14
1 OpenRead 0 2 0 10 0 root=2 iDb=0; users
2 OpenRead 2 274 0 k(2,,) 0 root=274 iDb=0; age_idx
3 OpenRead 1 3 0 2 0 root=3 iDb=0; products
4 Integer 70 1 0 0 r[1]=70
5 SeekGT 2 13 1 1 0 key=r[1]
6 DeferredSeek 2 0 0 0 Move 0 to 2.rowid if needed
7 IdxRowid 2 2 0 0 r[2]=rowid; users.rowid
8 SeekRowid 1 12 2 0 intkey=r[2]
9 Column 0 1 3 0 r[3]= cursor 0 column 1
10 Column 1 1 4 0 r[4]= cursor 1 column 1
11 ResultRow 3 2 0 0 output=r[3..4]
12 Next 2 6 0 0
13 Halt 0 0 0 0
14 Transaction 0 0 3 0 1 usesStmtJournal=0
15 Goto 0 1 0 0
```
Closes #350
2024-10-13 10:11:23 +03:00
Arpit Saxena
28a603f56a
[sorter] Hold records in Vec instead of a BTreeMap
...
We now just insert them one after the other in the vector. When rewind
is called, the vector is sorted. Iterating is just taking elements from
the vector
2024-10-09 17:58:28 +05:30
jussisaurio
15a66ea662
single seek function in cursor trait
2024-10-06 09:21:15 +03:00
jussisaurio
3d56fbd91c
stuff
2024-10-05 18:25:04 +03:00
jussisaurio
f02da18acd
index scan wip foo doesnt work yet
2024-10-05 18:25:04 +03:00
jussisaurio
a108dea825
GROUP BY
2024-09-14 16:14:45 +03:00
jussisaurio
e8c894e532
More flexible Emitter via stateful operators
2024-08-17 12:55:16 +03:00
gandeevanr
a9cb8157b5
initial pass at implementing NewRowId
2024-08-07 09:04:09 -07:00
jussisaurio
d965998cdf
btree_seek_rowid() implementation
2024-08-01 17:23:59 +03:00
Pere Diaz Bou
20dc068a9d
core: don't traverse twice
2024-07-31 17:27:02 +02:00
Pere Diaz Bou
3b9f5aa511
core: implement exists
2024-07-31 17:27:02 +02:00
Pere Diaz Bou
84bf0ea96a
core: remove a bunch of warnings
...
Signed-off-by: Pere Diaz Bou <pere-altea@hotmail.com >
2024-07-31 17:27:02 +02:00
Pere Diaz Bou
e6f8b34f2b
core: insert_to_page almost complete
2024-07-31 17:27:02 +02:00
Pere Diaz Bou
6357e88b46
core: implement vdbe opcodes minus newrowid
2024-07-31 17:25:01 +02:00
Pekka Enberg
351242561d
Kill anyhow usage
...
Switch anyhow to explicit `LimboError` type using thiserror crate, which
lets us make error handling more structured.
2024-07-25 17:15:08 +03:00
Pekka Enberg
966ee39589
core: Move sorter.rs to vdbe/
2024-07-23 14:54:41 +03:00