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

DELETE FROM WHERE plan differs from SQLite and gives incorrect result. #1019

Open
krishvishal opened this issue Feb 15, 2025 · 0 comments
Open

Comments

@krishvishal
Copy link
Contributor

limbo> CREATE TABLE t1(x INTEGER PRIMARY KEY);
    INSERT INTO t1 VALUES (1);
    INSERT INTO t1 VALUES (2);
    INSERT INTO t1 VALUES (3);
    INSERT INTO t1 VALUES (4);
limbo> DELETE FROM t1 WHERE x <3;
limbo> SELECT * from t1;
    2
    3
    4

limbo> EXPLAIN DELETE FROM t1 WHERE x <3;
addr  opcode             p1    p2    p3    p4             p5  comment
----  -----------------  ----  ----  ----  -------------  --  -------
0     Init               0     14    0                    0   Start at 14
1     OpenWriteAsync     0     2     0                    0   
2     OpenWriteAwait     0     0     0                    0   
3     Null               0     1     0                    0   r[1]=NULL
4     SeekGT             0     13    1                    0   
5       Integer          3     1     0                    0   r[1]=3
6       RowId            0     2     0                    0   r[2]=t1.rowid
7       Ge               2     1     13                   0   if r[2]>=r[1] goto 13
8       RowId            0     3     0                    0   r[3]=t1.rowid
9       DeleteAsync      0     0     0                    0   
10      DeleteAwait      0     0     0                    0   
11    NextAsync          0     0     0                    0   
12    NextAwait          0     6     0                    0   
13    Halt               0     0     0                    0   
14    Transaction        0     0     0                    0   
15    Goto               0     1     0                    0   

SQLite

sqlite> CREATE TABLE t1(x INTEGER PRIMARY KEY);
INSERT INTO t1 VALUES (1);
INSERT INTO t1 VALUES (2);
INSERT INTO t1 VALUES (3);
INSERT INTO t1 VALUES (4);
DELETE FROM t1 WHERE x <3;
SELECT * FROM t1;
3
4
sqlite> EXPLAIN DELETE FROM t1 where x < 3;
addr  opcode         p1    p2    p3    p4             p5  comment      
----  -------------  ----  ----  ----  -------------  --  -------------
0     Init           0     11    0                    0   
1     Null           0     1     0                    0   
2     OpenWrite      0     2     0     1              0   
3     Rewind         0     10    0                    0   
4     Integer        3     2     0                    0   
5       Rowid          0     3     0                    0   
6       Ge             2     10    3                    83  
7       Rowid          0     4     0                    0   
8       Delete         0     1     0     t1             2   
9     Next           0     5     0                    0   
10    Halt           0     0     0                    0   
11    Transaction    0     1     1     0              1   
12    Goto           0     1     0                    0   

Working on a fix for this.

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