Commit Graph

585 Commits

Author SHA1 Message Date
Jussi Saurio
2495d15b96 Index insert fuzz 2025-04-22 11:52:20 +02:00
Pere Diaz Bou
fc4deb2b7b Merge 'btree: avoid reading entire cell when only rowid needed' from Jussi Saurio
This PR is based on #1357 and further improves performance:
```sql
limbo> select l_orderkey, 3 as revenue, o_orderdate, o_shippriority from lineitem, orders, customer where c_mktsegment = 'FURNITURE' and c_custkey = o_custkey and l_orderkey = o_orderkey and o_orderdate < cast('1995-03-29' as datetime) and l_shipdate > cast('1995-03-29' as datetime);
┌────────────┬─────────┬─────────────┬────────────────┐
│ l_orderkey │ revenue │ o_orderdate │ o_shippriority │
├────────────┼─────────┼─────────────┼────────────────┤
└────────────┴─────────┴─────────────┴────────────────┘
Command stats:
----------------------------
total: 3.728050958 s (this includes parsing/coloring of cli app)
```

Reviewed-by: Preston Thorpe (@PThorpe92)
Reviewed-by: Pere Diaz Bou <pere-altea@homail.com>

Closes #1358
2025-04-21 12:14:21 +02:00
Jussi Saurio
83c509a613 Fix bug: left join null flag not being cleared
In left joins, even if the join condition is not matched, the system
must emit a row for every row of the outer table:

-- this must return t1.count() rows, with NULLs for all columns of t2
SELECT * FROM t1 LEFT JOIN t2 ON FALSE;

Our logic for clearing the null flag was to do it in Next/Prev. However,
this is problematic for a few reasons:

- If the inner table of the left join is using SeekRowid, then Next/Prev
  is never called on its cursor, so the null flag doesn't get cleared.
- If the inner table of the left join is using a non-covering index seek,
  i.e. it iterates its rows using an index, but seeks to the main table
  to fetch data, then Next/Prev is never called on the main table, and the
  main table's null flag doesn't get cleared.

What this results in is NULL values incorrectly being emitted for the
inner table after the first correct NULL row, since the null flag is
correctly set to true, but never cleared.

This PR fixes the issue by clearing the null flag whenever seek() is
invoked on the cursor. Hence, the null flag is now cleared on:

- next()
- prev()
- seek()
2025-04-19 13:56:52 +03:00
Jussi Saurio
017cdb9568 btree: avoid reading entire cell when only rowid needed 2025-04-18 16:52:05 +03:00
Jussi Saurio
3dab59201d Separate both table&index move_to impls into different funcs 2025-04-18 16:27:50 +03:00
Jussi Saurio
0974ba6e71 default to using tablebtree_move_to in all calls to move_to with rowids 2025-04-18 16:11:36 +03:00
Jussi Saurio
12e689b9fc btree: use binary search on table leaf pages too 2025-04-18 16:11:36 +03:00
Jussi Saurio
3f9bdbdf14 btree: use binary search in move_to() for table btrees 2025-04-18 16:11:36 +03:00
Jussi Saurio
9d553c50cc Merge 'allow index entry delete' from Pere Diaz Bou
Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #1341
2025-04-18 15:26:05 +03:00
Pere Diaz Bou
262c630c16 fix validation with overflow cells 2025-04-17 18:28:42 +02:00
TcMits
a73f4db38b missing done var 2025-04-17 15:02:59 +07:00
TcMits
30f2a97782 shorter syntax 2025-04-16 19:55:52 +07:00
Jussi Saurio
b1073da4a5 btree: add support fo descending indexes 2025-04-16 13:58:12 +03:00
TcMits
30f5904f21 merge conflict 2025-04-16 15:29:11 +07:00
Jussi Saurio
1d9c6d6981 Merge 'btree: move some blocks of code to more reasonable places' from Jussi Saurio
Reviewed-by: Preston Thorpe (@PThorpe92)

Closes #1343
2025-04-16 11:13:15 +03:00
TcMits
8f5a39cc2b replace vec with array in btree balancing 2025-04-16 14:27:24 +07:00
Pere Diaz Bou
0518107443 Merge 'Feat balance shallower' from Lâm Hoàng Phúc
Fixed is_empty assertion in #1203 , but simulator still has error.
```sh
[ERROR] error Internal error: select '(engrossing_berger < X'6566651A3C70278D4E200657551D8071A1' AND competitive_petit > 1236742147.9451914)' should return no values for table 'super_becky'
```

Reviewed-by: Pere Diaz Bou <pere-altea@homail.com>
Reviewed-by: Pere Diaz Bou <pere-altea@homail.com>

Closes #1308
2025-04-15 11:02:31 +02:00
Pere Diaz Bou
aece4e5442 use seek instead of move_to in post balance delete 2025-04-15 10:59:49 +02:00
Jussi Saurio
5628cc27a6 btree: move allocate_overflow_page to Pager impl 2025-04-14 15:25:15 +03:00
Jussi Saurio
bf26e62465 btree: add doc comment about CellArray struct 2025-04-14 15:21:07 +03:00
Jussi Saurio
930f1d79b4 btree: move CellArray struct declaration next to impl 2025-04-14 15:19:56 +03:00
Jussi Saurio
d961baf5ac btree: move PageStack struct declaration next to impl 2025-04-14 15:18:21 +03:00
TcMits
96112f8e54 missing check for balance-shallower 2025-04-14 18:30:32 +07:00
TcMits
18d779924b post validation should be after balance-shallower 2025-04-14 18:13:47 +07:00
Pere Diaz Bou
651c00b4a8 allow index entry delete 2025-04-14 11:02:17 +02:00
TcMits
ee660187dc fix negative free space after balance-shallower 2025-04-14 14:25:18 +07:00
Jussi Saurio
d286a56e15 refactor: fold Async/Await insns into a single instruction 2025-04-14 09:40:20 +03:00
TcMits
b3c2593980 btree balance-shallower 2025-04-14 12:49:30 +07:00
Diego Reis
65d4c68cf2 core/pager: Wrap wal with Option 2025-04-13 11:10:05 -03:00
Diego Reis
da484b33aa core/storage: Add asserts to check invariants for current_page
While developing, I had an underflow issue during the casting: `current as usize`. Which could be found way faster with proper asserts.
2025-04-12 22:29:29 -03:00
Jussi Saurio
029a0c86b2 btree: remove IterationState
iteration direction must be known when seeking, and transitively
when using move_to() since seek() uses it, but otherwise IterationState
just brings way too much noise to the code -- it was meant to encode
invariants about how a cursor can be iterated, but it's not worth it.

iteration direction for seek()/move_to() can be inferred from the
SeekOp:

GE/GT/EQ: forward
LT/LE: backward

and get_next_record()/get_prev_record() already have different
logic for their respective iteration directions.
2025-04-11 13:40:51 +03:00
TcMits
a4a4879f3b fix cargo fmt check 2025-04-11 14:53:10 +07:00
TcMits
9d7a779757 Fix drop empty page in balancing 2025-04-11 14:41:56 +07:00
Pere Diaz Bou
745c2b92d0 unnecessary dirty set on overwrite 2025-04-10 22:24:15 +02:00
Pere Diaz Bou
038d78f096 overwrite when payload is equal size as current cell only
Prevoiusly we would overwrite even though size less than cell size. This
was wrong because it didn't update any fragment size or free blocks it
could. To be safe let's just overwrite only if local size is the same
amount.
2025-04-10 22:24:15 +02:00
Pere Diaz Bou
506c1a236c find_free_cell fix use of no_offset writes 2025-04-10 22:24:15 +02:00
Pekka Enberg
ef893da6c7 Merge 'core/btree: Add PageContent::new() helper' from Pekka Enberg
Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #1294
2025-04-10 20:53:41 +03:00
Pekka Enberg
a27126cd05 Merge 'B-Tree code cleanups' from Pekka Enberg
Reviewed-by: Pere Diaz Bou <pere-altea@homail.com>

Closes #1290
2025-04-10 20:53:33 +03:00
Pere Diaz Bou
62d0febdb6 panic on corruption 2025-04-10 16:01:24 +02:00
Pere Diaz Bou
8e93471d00 fix cell index selection while balancing
Cell index doesn't move in `move_to` unless we don't need to check next
cell. On the other hand, with rightmost pointer, we advance cell index
by 1 even though where we are moving to was to that page
2025-04-10 16:01:24 +02:00
Pekka Enberg
53633e8b6f core/btree: Add PageContent::new() helper 2025-04-10 13:14:38 +03:00
Pekka Enberg
a7fa7f7c62 core/btree: Unify debug() tracing 2025-04-10 08:39:07 +03:00
Pekka Enberg
761c03f7c5 core/btree: Clean up B-Tree offset comments 2025-04-10 08:27:55 +03:00
Pekka Enberg
86a4d3e33b core/btree: Move B-Tree header offsets in a module
The grouping (with a fancy comment) makes the code a bit more readable.
2025-04-10 08:19:08 +03:00
Pekka Enberg
11782cbff8 core/btree: Clean up imports 2025-04-10 07:52:10 +03:00
Pere Diaz Bou
6a02730c1a rebase fixes 2025-04-09 15:56:04 +02:00
Pere Diaz Bou
7b384f8e5c set iteration_state for insert 2025-04-09 15:29:06 +02:00
Pere Diaz Bou
6b7575bf3f fix tree traversal assumptions on traversal 2025-04-09 15:04:45 +02:00
Pere Diaz Bou
f2d9e1e8f5 fix divider cell in index 2025-04-09 15:04:45 +02:00
Pere Diaz Bou
12899034c9 make insert idx re-entrant 2025-04-09 15:04:45 +02:00