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

Remove unique filter of where clauses #518

Merged

Conversation

matthewmcgarvey
Copy link
Member

@matthewmcgarvey matthewmcgarvey commented Nov 10, 2020

Fixes #487

With the addition of OR to the query builder, where clauses can no longer be uniquely filtered because two clauses are not equal just because they have they same condition, they could be separated by an OR and affect the outcome if removed. For example, these two clauses are not the same but the current query builder would turn the first into the second because of the way it checks for uniqueness:

SELECT *
FROM users
WHERE name = 'Paul'
    AND age = 18
    OR name = 'Paul'
    AND age = 100;
SELECT *
FROM users
WHERE name = 'Paul'
    AND age = 18
    OR age = 100;

This will not affect any queries negatively as truly duplicate conditions are handled as expected by Postgres.

Copy link
Member

@jwoertink jwoertink left a comment

Choose a reason for hiding this comment

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

This looks good. I wonder if we can come up with some sort of query analyzer deal at some point to help sort of bring this back in. Since one of the main goals of Avram is to help catch bugs in development, and part of that being poorly written SQL (i.e. slow queries, duplicate where clauses, etc...), it would be nice to figure out a way to add something to help catch things like this.

For now, I don't think there's much we can do, so this is probably ok.

@matthewmcgarvey matthewmcgarvey merged commit 5e9f38f into luckyframework:master Nov 10, 2020
@matthewmcgarvey matthewmcgarvey deleted the unique-where-bad branch November 10, 2020 16:45
@matthewmcgarvey matthewmcgarvey restored the unique-where-bad branch January 25, 2021 22:17
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.

Ensuring uniqueness of SQL where conditions won't work when "or" conditions are added
2 participants