Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge 'Fix null compare operations not giving null' from Vrishabh
In limbo when we do any compare operations like `Eq, gt, lt, gte, lte` with nulls , we were actually giving the result as true where as sqlite3 gives null. This is because if we had a null, we were incorrectly going to conditional branch and not increment program by 1. Also the sqlite generates `ZeroOrNull` op in these cases (https://github.com/sqlite/sqlite/blob/version-3.45.3/src/expr.c#L4644) but we were generating a Integer instruction. The below outputs can give a clearer picture. This PR aims to fix this. sqlite3 output ``` SQLite version 3.48.0 Enter ".help" for usage hints. Connected to a transient in-memory database. Use ".open FILENAME" to reopen on a persistent database. sqlite> select 8 = null; sqlite> select 8 > null; sqlite> explain select 8 > null; addr opcode p1 p2 p3 p4 p5 comment ---- ------------- ---- ---- ---- ------------- -- ------------- 0 Init 0 6 0 0 1 Integer 1 1 0 0 2 Gt 3 4 2 64 3 ZeroOrNull 2 1 3 0 4 ResultRow 1 1 0 0 5 Halt 0 0 0 0 6 Integer 8 2 0 0 7 Null 0 3 0 0 8 Goto 0 1 0 0 sqlite> explain select 8 = null; addr opcode p1 p2 p3 p4 p5 comment ---- ------------- ---- ---- ---- ------------- -- ------------- 0 Init 0 6 0 0 1 Integer 1 1 0 0 2 Eq 3 4 2 64 3 ZeroOrNull 2 1 3 0 4 ResultRow 1 1 0 0 5 Halt 0 0 0 0 6 Integer 8 2 0 0 7 Null 0 3 0 0 8 Goto 0 1 0 0 ``` Limbo Output ``` Limbo v0.0.12 Enter ".help" for usage hints. Connected to a transient in-memory database. Use ".open FILENAME" to reopen on a persistent database limbo> select 8 = null; 1 limbo> select 8 > null; 1 limbo> explain select 8 > null; addr opcode p1 p2 p3 p4 p5 comment ---- ----------------- ---- ---- ---- ------------- -- ------- 0 Init 0 8 0 0 Start at 8 1 Integer 8 2 0 0 r[2]=8 2 Null 0 3 0 0 r[3]=NULL 3 Integer 1 1 0 0 r[1]=1 4 Gt 2 3 6 0 if r[2]>r[3] goto 6 5 Integer 0 1 0 0 r[1]=0 6 ResultRow 1 1 0 0 output=r[1] 7 Halt 0 0 0 0 8 Transaction 0 0 0 0 9 Goto 0 1 0 0 limbo> explain select 8 = null; addr opcode p1 p2 p3 p4 p5 comment ---- ----------------- ---- ---- ---- ------------- -- ------- 0 Init 0 8 0 0 Start at 8 1 Integer 8 2 0 0 r[2]=8 2 Null 0 3 0 0 r[3]=NULL 3 Integer 1 1 0 0 r[1]=1 4 Eq 2 3 6 0 if r[2]==r[3] goto 6 5 Integer 0 1 0 0 r[1]=0 6 ResultRow 1 1 0 0 output=r[1] 7 Halt 0 0 0 0 8 Transaction 0 0 0 0 9 Goto 0 1 0 0 limbo> ``` Limbo Output with this PR ``` Limbo v0.0.12 Enter ".help" for usage hints. Connected to a transient in-memory database. Use ".open FILENAME" to reopen on a persistent database limbo> select 8 = null; limbo> select 8 > null; limbo> explain select 8 > null; addr opcode p1 p2 p3 p4 p5 comment ---- ----------------- ---- ---- ---- ------------- -- ------- 0 Init 0 8 0 0 Start at 8 1 Integer 8 2 0 0 r[2]=8 2 Null 0 3 0 0 r[3]=NULL 3 Integer 1 1 0 0 r[1]=1 4 Gt 2 3 6 0 if r[2]>r[3] goto 6 5 ZeroOrNull 2 1 3 0 ((r[2]=NULL)|(r[3]=NULL)) ? r[1]=NULL : r[1]=0 6 ResultRow 1 1 0 0 output=r[1] 7 Halt 0 0 0 0 8 Transaction 0 0 0 0 9 Goto 0 1 0 0 limbo> explain select 8 = null; addr opcode p1 p2 p3 p4 p5 comment ---- ----------------- ---- ---- ---- ------------- -- ------- 0 Init 0 8 0 0 Start at 8 1 Integer 8 2 0 0 r[2]=8 2 Null 0 3 0 0 r[3]=NULL 3 Integer 1 1 0 0 r[1]=1 4 Eq 2 3 6 0 if r[2]==r[3] goto 6 5 ZeroOrNull 2 1 3 0 ((r[2]=NULL)|(r[3]=NULL)) ? r[1]=NULL : r[1]=0 6 ResultRow 1 1 0 0 output=r[1] 7 Halt 0 0 0 0 8 Transaction 0 0 0 0 9 Goto 0 1 0 0 ``` Closes #733
- Loading branch information