mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-08 10:44:20 +01:00
## Beef Followup to #1357 which did the same treatment for table btrees only. After this PR, all of our seeks use binary search for both interior and leaf pages. ## Perf comparison using TPC-H 1GB db for this query: ```sql limbo> explain select count(1) from lineitem join partsupp on l_partkey = ps_partkey and l_suppkey = ps_suppkey; addr opcode p1 p2 p3 p4 p5 comment ---- ----------------- ---- ---- ---- ------------- -- ------- 0 Init 0 18 0 0 Start at 18 1 OpenRead 0 10 0 0 table=lineitem, root=10 2 OpenRead 1 7 0 0 table=sqlite_autoindex_partsupp_1, root=7 3 Rewind 0 14 0 0 Rewind lineitem 4 Column 0 1 2 0 r[2]=lineitem.l_partkey 5 IsNull 2 13 0 0 if (r[2]==NULL) goto 13 6 Column 0 2 3 0 r[3]=lineitem.l_suppkey 7 IsNull 3 13 0 0 if (r[3]==NULL) goto 13 8 SeekGE 1 13 2 0 key=[2..3] <-- index seek here, for every row in lineitem 9 IdxGT 1 13 2 0 key=[2..3] 10 Integer 1 5 0 0 r[5]=1 11 AggStep 0 5 4 count 0 accum=r[4] step(r[5]) 12 Next 1 9 0 0 13 Next 0 4 0 0 14 AggFinal 0 4 0 count 0 accum=r[4] 15 Copy 4 1 0 0 r[1]=r[4] 16 ResultRow 1 1 0 0 output=r[1] 17 Halt 0 0 0 0 18 Transaction 0 0 0 0 write=false 19 Goto 0 1 0 0 ``` main: ```sql limbo> select count(1) from lineitem join partsupp on l_partkey = ps_partkey and l_suppkey = ps_suppkey; ┌───────────┐ │ count (1) │ ├───────────┤ │ 6001215 │ └───────────┘ Command stats: ---------------------------- total: 40.292102375 s (this includes parsing/coloring of cli app) ``` PR: ```sql limbo> select count(1) from lineitem join partsupp on l_partkey = ps_partkey and l_suppkey = ps_suppkey; ┌───────────┐ │ count (1) │ ├───────────┤ │ 6001215 │ └───────────┘ Command stats: ---------------------------- total: 14.021689916 s (this includes parsing/coloring of cli app) ``` almost 3x faster. buzzkill: still 3x slower than sqlite :) Closes #1387