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

Fix SELECT -9223372036854775808 result differs from SQLite #814

Merged
merged 2 commits into from
Jan 30, 2025

Conversation

krishvishal
Copy link
Contributor

@krishvishal krishvishal commented Jan 29, 2025

Closes #812

-9223372036854775808 is MIN_INT64. So when we extract out the minus and try to parse the remainder it becomes greater than MAX_INT64 (9223372036854775807) and will trigger overflow, which converts the literal into Real. So we have to handle it as a special case.

@penberg penberg requested a review from jussisaurio January 29, 2025 10:02
@krishvishal
Copy link
Contributor Author

Before this fix:

SQLite query plan:

addr  opcode         p1    p2    p3    p4             p5  comment             
----  -------------  ----  ----  ----  -------------  --  -------------       
0     Init           0     1     0                    0                       
1     Int64          0     1     0     -9223372036854775808  0
2     ResultRow      1     1     0                    0                       
3     Halt           0     0     0                    0                       

Limbo query plan:

limbo> EXPLAIN SELECT -9223372036854775808;
addr  opcode             p1    p2    p3    p4             p5  comment
----  -----------------  ----  ----  ----  -------------  --  -------
0     Init               0     4     0                    0   Start at 4
1     Real               0     1     0     -9.223372036854776e18  0   r[1]=-9223372036854776000
2     ResultRow          1     1     0                    0   output=r[1]
3     Halt               0     0     0                    0
4     Transaction        0     0     0                    0
5     Goto               0     1     0                    0

After this fix:

Limbo query plan:

limbo> EXPLAIN SELECT -9223372036854775808;
addr  opcode             p1    p2    p3    p4             p5  comment
----  -----------------  ----  ----  ----  -------------  --  -------
0     Init               0     4     0                    0   Start at 4
1     Integer            0     1     0                    0   r[1]=-9223372036854775808
2     ResultRow          1     1     0                    0   output=r[1]
3     Halt               0     0     0                    0   
4     Transaction        0     0     0                    0   
5     Goto               0     1     0                    0   

Copy link
Contributor

@seonWKim seonWKim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 Thanks for the quick fix

@penberg penberg merged commit 4673ac9 into tursodatabase:main Jan 30, 2025
37 checks passed
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

Successfully merging this pull request may close these issues.

SELECT -9223372036854775808 result differs from SQLite
3 participants