PThorpe92
67eda10453
Allow reading altered tables by defaulting to null in Column insn
2025-04-05 16:19:56 -04:00
PThorpe92
83af71f140
Return accidentally deleted comment on SeekGE insn from merge conflict
2025-04-05 11:30:57 -04:00
PThorpe92
bd04b10f17
Fix btree tests to adapt to new type for BTreeKey
2025-04-05 11:19:10 -04:00
PThorpe92
abc97c8774
Add doc comments to new btree key enum and remove unused lifetimes
2025-04-05 11:19:10 -04:00
PThorpe92
6b42808f1a
Dont re-seek if we are inserting a new unique index
2025-04-05 11:19:10 -04:00
PThorpe92
a2b9d8d371
Use Correct flag on idx insert to prevent seeking
2025-04-05 11:19:09 -04:00
PThorpe92
068ab4ab27
Refactor btree to reuse existing insert and seek with idx keys
2025-04-05 11:19:09 -04:00
PThorpe92
007fbe8cc7
Fix unique index issue and prealloc in sql string for schema
2025-04-05 11:19:09 -04:00
PThorpe92
2c3fd509fe
Remove unused imports and consolidate ordering comparison
2025-04-05 11:19:09 -04:00
PThorpe92
e020ba3dfe
Add enum for interpreting a value as a register or literal for insns
2025-04-05 11:19:07 -04:00
PThorpe92
b0016a0ee2
Support create index with SeekEnd and IdxCreate opcode functionality
2025-04-05 11:15:36 -04:00
PThorpe92
45a8e5e226
Add close_cursors helper method to program builder
2025-04-05 11:06:18 -04:00
PThorpe92
20adedff4c
Remove Order enum in place of ast::SortOrder
2025-04-05 11:06:18 -04:00
PThorpe92
4741544dfd
Add query translation for create index
2025-04-05 11:06:18 -04:00
Ihor Andrianov
0c9464e3fc
reduce vec allocations, add comments for magic ifs
2025-04-05 15:15:10 +03:00
pedrocarlo
41f1f97138
cargo toml add extension static
...
adding doc
2025-04-04 18:29:13 -03:00
PThorpe92
e3985b6994
Remove unused mut ref from emit_update_instructions for tx context
2025-04-04 12:51:37 -04:00
PThorpe92
13e084351d
Change parse_limit function to accept reference value to ast::Limit
2025-04-04 12:38:18 -04:00
PThorpe92
f6a64a7b15
Support OFFSET clause for LIMIT in UPDATE queries
2025-04-04 12:35:30 -04:00
Pekka Enberg
c3eaf47180
Merge 'Add support for default values in INSERT statements' from Diego Reis
...
While working on #494 I noticed that default values defined in schemas
weren't being applied.
Before:

Now:

Closes #1249
2025-04-04 08:59:44 +03:00
Diego Reis
43daba9942
core/translate: Add support for default values in INSERT statements
2025-04-04 01:32:13 -03:00
Diego Reis
38d842d675
docs/insn: Standardizes comments for insn to doc comments
2025-04-04 00:56:54 -03:00
PThorpe92
ae2be30204
Move init label to proper place in create vtab translation
2025-04-03 20:22:14 -04:00
Ihor Andrianov
d4b8fa17f8
fix tests
2025-04-03 22:28:14 +03:00
Ihor Andrianov
34a132fcd3
fix output when group by is not part of resulting set
2025-04-03 22:28:13 +03:00
Ihor Andrianov
91ceab1626
improve naming and add comments for context
2025-04-03 22:28:13 +03:00
Ihor Andrianov
816cbacc9c
some smartie optimizations
2025-04-03 22:28:12 +03:00
Ihor Andrianov
2bcdd4e404
non group by cols are displayed in group by agg statements
2025-04-03 22:28:12 +03:00
Ihor Andrianov
4fd1dcdc73
small refine
2025-04-03 22:28:11 +03:00
Ihor Andrianov
36fe859d7d
create if only if non aggregate columns present
2025-04-03 22:28:11 +03:00
Ihor Andrianov
352fa6fd34
cargo fmt
2025-04-03 22:28:11 +03:00
Ihor Andrianov
b47c214a5e
fix aggregation functions without group by
2025-04-03 22:28:10 +03:00
TcMits
56fa9049c3
fix: overflow pos in write_page
2025-04-03 15:02:53 +07:00
Pekka Enberg
24063bd9c0
core/vdbe: Add newline between op functions
2025-04-02 18:57:07 +03:00
Pekka Enberg
c592e27dca
core/vdbe: Move explain() to last method in Program
...
...it's the least interesting one and we should have `step()` at the top.
2025-04-02 18:55:35 +03:00
Pekka Enberg
ed1854c8de
Merge 'Request load page on insert_into_page' from Pere Diaz Bou
...
We assumed page was loaded because before inserting we would move there.
`NewRowId` unfortunately moves cursor to the rightmost page causing
eviction of root page -- this arose the issue with `insert_into_page`
not loading the page we were supposed to have loaded so I added
`return_if_locked_maybe_load` which is a utility macro to check if the
page is locked and if not, load it if needed.
Closes #1138
2025-04-02 18:52:25 +03:00
Pere Diaz Bou
65c4cb1e0e
Merge 'core/vdbe: Rename execute_insn_* to op_*' from Pekka Enberg
...
The "execute::execute_insn" prefix is noisy, let's rename the
instruction operation functions to something shorter and sweeter.
Reviewed-by: Pere Diaz Bou <pere-altea@homail.com >
Closes #1235
2025-04-02 17:25:12 +02:00
Pekka Enberg
265457f175
Merge 'Don't emit Transaction for simple SELECT statements' from Diego Reis
...
First step to close #1226 .
Before:

After:

Reusing the same register is a bit trickier, I'm understanding how
SQLite does this optimization to apply here as well.
EDIT: Now we reuse the register and have the same number of bytecodes as
SQLite.

Reviewed-by: Pere Diaz Bou <pere-altea@homail.com >
Closes #1227
2025-04-02 18:12:20 +03:00
Pekka Enberg
3420955db7
core/vdbe: Rename execute_insn_* to op_*
...
The "execute::execute_insn" prefix is noisy, let's rename the
instruction operation functions to something shorter and sweeter.
2025-04-02 18:02:02 +03:00
Pere Diaz Bou
5dedc68fda
remove arc import
2025-04-02 16:56:34 +02:00
Pere Diaz Bou
e85fb86ff4
Request load page on insert_into_page
...
We assumed page was loaded because before inserting we would move there. `NewRowId` unfortunately moves cursor to the rightmost page causing eviction of root page -- this arose the issue with `insert_into_page` not loading the page we were supposed to have loaded so I added `return_if_locked_maybe_load` which is a utility macro to check if the page is locked and if not, load it if needed.
2025-04-02 16:24:53 +02:00
Pere Diaz Bou
46814d2bd7
ignore warning mut_from_ref
2025-04-02 16:18:36 +02:00
Pere Diaz Bou
e2d00a9f96
inline start transactions from pager and wal
...
Execute `SELECT 1`/limbo_execute_select_1
time: [30.543 ns 30.585 ns 30.632 ns]
2025-04-02 16:18:36 +02:00
Pere Diaz Bou
2a49fe9bd2
Remove RWLock from Shared wal state
...
WalShared state can be shared without having to wrap everything with a
lock, and instead use atomics on some places and rwlock on others -- for
now.
## Results:
From:
----
Execute `SELECT 1`/limbo_execute_select_1
time: [34.125 ns 34.218 ns 34.324 ns]
Execute `SELECT 1`/sqlite_execute_select_1
time: [28.124 ns 28.254 ns 28.385 ns]
To:
----
Gnuplot not found, using plotters backend
Execute `SELECT 1`/limbo_execute_select_1
time: [31.919 ns 32.113 ns 32.327 ns]
Execute `SELECT 1`/sqlite_execute_select_1
time: [29.662 ns 29.900 ns 30.139 ns]
2025-04-02 16:18:36 +02:00
Pekka Enberg
cd5ef7c7db
Merge 'Reuse register in binary expressions if they're equal ' from Diego Reis
...
Alongside with #1227 , this PR closes #1226
Before:

After:

Closes #1234
2025-04-02 17:02:35 +03:00
Pere Diaz Bou
66f70d571d
fmt
2025-04-02 13:14:26 +00:00
Pere Diaz Bou
f5221589f0
remove wrong usage of feature = json
2025-04-02 15:00:51 +02:00
Pere Diaz Bou
7e4b57f2e2
VDBE with direct function dispatch
...
This PR is unapologetically stolen from @vmg's implementation in Vitess
implemented here https://github.com/vitessio/vitess/pull/12369 . If you
want a more in depth explanation of how this works you can read the
[blog post he carefully
wrote](https://planetscale.com/blog/faster-interpreters-in-go-catching-up-with-cpp ).
In limbo we have a huge problem with [register
spilling](https://en.wikipedia.org/wiki/Register_allocation ), this can
be easily observed with the prolog of `Program::step` before:
```llvm
start:
%e.i.i304.i = alloca [0 x i8], align 8
%formatter.i305.i = alloca [64 x i8], align 8
%buf.i306.i = alloca [24 x i8], align 8
%formatter.i259.i = alloca [64 x i8], align 8
..................... these are repeated for hundreds of lines
.....................
%formatter.i52.i = alloca [64 x i8], align 8
%buf.i53.i = alloca [24 x i8], align 8
%formatter.i.i = alloca [64 x i8], align 8
%buf.i.i = alloca [24 x i8], align 8
%_87.i = alloca [48 x i8], align 8
%_82.i = alloca [24 x i8], align 8
%_73.i = alloca [24 x i8], align 8
%_66.i8446 = alloca [24 x i8], align 8
%_57.i = alloca [24 x i8], align 8
%_48.i = alloca [24 x i8], align 8
```
After these changes we completely remove the need of register spilling
(yes that is the complete prolog):
```llvm
start:
%self1 = alloca [80 x i8], align 8
%pager = alloca [8 x i8], align 8
%mv_store = alloca [8 x i8], align 8
store ptr %0, ptr %mv_store, align 8
store ptr %1, ptr %pager, align 8
%2 = getelementptr inbounds i8, ptr %state, i64 580
%3 = getelementptr inbounds i8, ptr %state, i64 576
%4 = getelementptr inbounds i8, ptr %self, i64 16
%5 = getelementptr inbounds i8, ptr %self, i64 8
%6 = getelementptr inbounds i8, ptr %self1, i64 8
br label %bb1, !dbg !286780
```
When it comes to branch prediction, we don't really fix a lot because
thankfully rust already compiles `match` expressions
to a jump table:
```llvm
%insn = getelementptr inbounds [0 x %"vdbe::insn::Insn"], ptr %self657,
i64 0, i64 %index, !dbg !249527
%332 = load i8, ptr %insn, align 8, !dbg !249528 , !range !38291 ,
!noundef !14
switch i8 %332, label %default.unreachable26674 [
i8 0, label %bb111
i8 1, label %bb101
i8 2, label %bb100
i8 3, label %bb110
...
i8 104, label %bb5
i8 105, label %bb16
i8 106, label %bb14
], !dbg !249530
```
Some results
----
```
function dispatch:
Execute `SELECT 1`/limbo_execute_select_1
time: [29.498 ns 29.548 ns 29.601 ns]
change: [-3.6125% -3.3592% -3.0804%] (p = 0.00 <
0.05)
main:
Execute `SELECT 1`/limbo_execute_select_1
time: [33.789 ns 33.832 ns 33.878 ns]
```
2025-04-02 14:55:37 +02:00
Diego Reis
3c531ac5ec
core/expr: Reuse register in binary expressions if they're equal
2025-04-02 09:15:41 -03:00
Diego Reis
86f8719b69
core/expr: Extract binary insn emission in a separate function
2025-04-02 09:14:01 -03:00