Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OR behavior seems broken #850

Open
glommer opened this issue Feb 1, 2025 · 0 comments
Open

OR behavior seems broken #850

glommer opened this issue Feb 1, 2025 · 0 comments

Comments

@glommer
Copy link
Contributor

glommer commented Feb 1, 2025

This could be a bug in the new IS / ISNOT implementation, but very likely it is the logic for OR, since the bytecode we generate is different, and it seems just that we are being asked to do the wrong comparison.

Data:

sqlite> .dump
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE demo (id INTEGER, value TEXT);
INSERT INTO demo VALUES(1,'A');
INSERT INTO demo VALUES(2,NULL);
INSERT INTO demo VALUES(3,'B');
INSERT INTO demo VALUES(4,NULL);
INSERT INTO demo VALUES(5,'C');
COMMIT;

SQLite

sqlite> select * from demo where value is null or id == 2;
2|
4|
sqlite> explain select * from demo where value is null or id == 2;
addr  opcode         p1    p2    p3    p4             p5  comment
----  -------------  ----  ----  ----  -------------  --  -------------
0     Init           0     12    0                    0   Start at 12
1     OpenRead       0     2     0     2              0   root=2 iDb=0; demo
2     Rewind         0     11    0                    0
3       Column         0     1     1                    128 r[1]= cursor 0 column 1
4       IsNull         1     7     0                    0   if r[1]==NULL goto 7 <==== NOTICE IsNull is generated here
5       Column         0     0     1                    0   r[1]= cursor 0 column 0
6       Ne             2     10    1     BINARY-8       84  if r[1]!=r[2] goto 10
7       Column         0     0     3                    0   r[3]= cursor 0 column 0
8       Column         0     1     4                    0   r[4]= cursor 0 column 1
9       ResultRow      3     2     0                    0   output=r[3..4]
10    Next           0     3     0                    1
11    Halt           0     0     0                    0
12    Transaction    0     0     1     0              1   usesStmtJournal=0
13    Integer        2     2     0                    0   r[2]=2
14    Goto           0     1     0                    0

Limbo:

limbo> select * from demo where value is not null or id == 2;
2|
limbo> explain select * from demo where value is null or id == 2;
addr  opcode             p1    p2    p3    p4             p5  comment
----  -----------------  ----  ----  ----  -------------  --  -------
0     Init               0     15    0                    0   Start at 15
1     OpenReadAsync      0     2     0                    0   table=demo, root=2
2     OpenReadAwait      0     0     0                    0
3     RewindAsync        0     0     0                    0
4     RewindAwait        0     14    0                    0   Rewind table demo
5       Column           0     1     3                    0   r[3]=demo.value
6       NotNull          3     7     0                    0   r[3]!=NULL -> goto 7.  <=== NOTICE NotNull is generated here
7       Column           0     0     4                    0   r[4]=demo.id
8       Ne               4     5     12                   0   if r[4]!=r[5] goto 12
9       Column           0     0     1                    0   r[1]=demo.id
10      Column           0     1     2                    0   r[2]=demo.value
11      ResultRow        1     2     0                    0   output=r[1..2]
12    NextAsync          0     0     0                    0
13    NextAwait          0     5     0                    0
14    Halt               0     0     0                    0
15    Transaction        0     0     0                    0
16    Integer            2     5     0                    0   r[5]=2
17    Goto               0     1     0                    0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant