penberg / limbo

Limbo is a work-in-progress, in-process OLTP database management system, compatible with SQLite.
MIT License
896 stars 49 forks source link

core: apply Real affinity on columns stored as int #115

Closed pereman2 closed 1 month ago

pereman2 commented 1 month ago

Values in sqlite3, as expected, can be stored in different formats to optimize disk usage. In this case, a 79.0 float will be transformed to a u8.

sqlite3 deals with this by adding a RealAffinity op after each column that might need it. Therefore, in this pr we do exactly that :).

sqlite3 explain

sqlite> explain select price from products limit 1;
addr  opcode         p1    p2    p3    p4             p5  comment
----  -------------  ----  ----  ----  -------------  --  -------------
0     Init           0     10    0                    0   Start at 10
1     Integer        1     1     0                    0   r[1]=1; LIMIT counter
2     OpenRead       0     3     0     3              0   root=3 iDb=0; products
3     Rewind         0     9     0                    0
4       Column         0     2     2                    0   r[2]= cursor 0 column 2
5       RealAffinity   2     0     0                    0
6       ResultRow      2     1     0                    0   output=r[2]
7       DecrJumpZero   1     9     0                    0   if (--r[1])==0 goto 9
8     Next           0     4     0                    1
9     Halt           0     0     0                    0
10    Transaction    0     0     2     0              1   usesStmtJournal=0
11    Goto           0     1     0                    0

limbo explain

> explain select price from products limit 1;
addr  opcode         p1    p2    p3    p4             p5  comment
----  -------------  ----  ----  ----  -------------  --  -------
0    Init           0     13    0       0   Start at 13
1    Integer        0     1     0       0
2    OpenReadAsync  0     3     0       0   root=3
3    OpenReadAwait  0     0     0       0
4    RewindAsync    0     0     0       0
5    RewindAwait    0     12    0       0
6      Column         0     2     1       0   r[1]= cursor 0 column 2
7      RealAffinity   1     0     0       0
8      ResultRow      1     1     0       0   output=r[1..2]
9      DecrJumpZero   0     12    0       0
10   NextAsync      0     0     0       0
11   NextAwait      0     5     0       0
12   Halt           0     0     0       0
13   Transaction    0     0     0       0
14   Goto           0     1     0       0

Fixes #114

pereman2 commented 1 month ago

hmmm why is test failing?

> select * from users, products limit 1;
1|Jamie|Foster|dylan00@example.com|496-522-9493|62375 Johnson Rest Suite 322|West Lauriestad|IL|35865|94|1|hat|79.0

test:

SQLITE_EXEC=./target/debug/limbo ./testing/all.test
Running test: select-const-1
Running test: select-const-2
Running test: select-avg
Running test: select-sum
Running test: select-limit
Running test: select-count
Running test: select-max
Running test: select-min
Running test: select-limit-0
Running test: pragma-cache-size
Running test: cross-join
Test FAILED: 'select * from users, products limit 1;'
returned '1|Jamie|Foster|dylan00@example.com|496-522-9493|62375 Johnson Rest Suite [322](https://github.com/penberg/limbo/actions/runs/9880223932/job/27288743610?pr=115#step:3:323)|West Lauriestad|IL|35865|94|1|hat|79'
expected '1|Jamie|Foster|dylan00@example.com|496-522-9493|62375 Johnson Rest Suite 322|West Lauriestad|IL|35865|94|1|hat|79.0'
make: *** [Makefile:42: test] Error 1

local:

fedora :: ~/fun/limbo » SQLITE_EXEC=./target/debug/limbo ./testing/all.test
Running test: select-const-1
Running test: select-const-2
Running test: select-avg
Running test: select-sum
Running test: select-limit
Running test: select-count
Running test: select-max
Running test: select-min
Running test: select-limit-0
Running test: pragma-cache-size
Running test: cross-join
Running test: cross-join-specific-columns
Running test: realify
pereman2 commented 1 month ago

nevermind, it was missing a commit from cli/main.rs