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

implement is and is not where constraints #847

Merged
merged 5 commits into from
Feb 1, 2025

Conversation

glommer
Copy link
Contributor

@glommer glommer commented Feb 1, 2025

The main difference between = and != is how null values are handled.
SQLite passes a flag "NULLEQ" to Eq and Ne to disambiguate that.
In the presence of that flag, NULL = NULL.

Some prep work is done to make sure we can pass a flag instead of a
boolean to Eq and Ne. I looked into the bitflags crate but got a bit
scared with the list of dependencies.

Warning:

The following query produces a different result for Limbo:

select * from demo where value is null or id == 2;

I strongly suspect the issue is with the OR implementation, though. The bytecode generated is quite different.

Those two expr seem to be supported
Now it has the same name as NotNull, so it is easier to write macros
The main difference between = and != is how null values are handled.
SQLite passes a flag "NULLEQ" to Eq and Ne to disambiguate that.
In the presence of that flag, NULL = NULL.

Some prep work is done to make sure we can pass a flag instead of a
boolean to Eq and Ne. I looked into the bitflags crate but got a bit
scared with the list of dependencies.
@penberg penberg requested a review from jussisaurio February 1, 2025 07:24
@@ -6,6 +6,36 @@ use crate::storage::wal::CheckpointMode;
use crate::types::{OwnedRecord, OwnedValue};
use limbo_macros::Description;

#[derive(Clone, Copy, Debug, Default)]
pub struct Flags(usize);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we call this e.g. CmpInsnFlags and add a documentation comment:

/// Flags provided to comparison instructions (e.g. Eq, Ne) which determine behavior related to NULL values.

Copy link
Collaborator

@jussisaurio jussisaurio left a comment

Choose a reason for hiding this comment

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

Looks good, I'd rather rename the Flags struct.

Could you also create an issue about the OR behavior so we can track it

Those Flags in SQLite are global, but it doesn't mean it has to be
the case for us as well.
@glommer
Copy link
Contributor Author

glommer commented Feb 1, 2025

#850

This seems to really be just an alias for IS:

"The IS NOT DISTINCT FROM operator is an alternative spelling for the IS
operator. Likewise, the IS DISTINCT FROM operator means the same thing
as IS NOT. Standard SQL does not support the compact IS and IS NOT
notation. Those compact forms are an SQLite extension. You have to use
the prolix and much less readable IS NOT DISTINCT FROM and IS DISTINCT
FROM operators on other SQL database engines."
@penberg penberg merged commit 20d3399 into tursodatabase:main Feb 1, 2025
27 of 28 checks passed
This was referenced Feb 1, 2025
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.

3 participants