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(sql): breaking change💥 - fix expression parser operator precedence #4443

Merged

Conversation

sivukhin
Copy link
Contributor

@sivukhin sivukhin commented Apr 25, 2024

Context

This is second part of the PR #4386

This PR fixes expression parser operator precedence rules. Now, QuestDB will use precedence order which is close to the PostgreSQL (https://www.postgresql.org/docs/7.2/sql-precedence.html; the precedence rules validated extensively with ExpressionParserFuzzTest.java):

{"."},
{"::"},
{"-'1", "~'1"},
{"*", "/", "%"},
{"+", "-'2"},
{"<<", ">>", "<<=", ">>="},
{"||"},
{"&"},
{"^"},
{"|"},
{"in", "not in", "within", "not within", "between", "not between"},
{"<", "<=", ">", ">="},
{"=", "~'2", "!=", "<>", "!~", "like", "ilike", "is null", "is not null"},
{"not"},
{"and"},
{"or"}

In order to provide migration path for users QuestDB introduces temporary boolean flag in the config: cairo.sql.legacy.operator.precedence or QDB_CAIRO_SQL_LEGACY_OPERATOR_PRECEDENCE env var which enables legacy operator precedence in a switched-on (true) state + with cairo.sql.legacy.operator.precedence = true QuestDB will log mismatch in parsing behaviour between old & new precedence table:

2024-04-25T21:23:19.408159Z A i.q.g.ExpressionParser operator precedence compat mode: detected expression parsing behaviour change for query=[true or true and false] at position=13

@nwoolmer nwoolmer self-assigned this Apr 26, 2024
@nwoolmer nwoolmer added SQL Issues or changes relating to SQL execution Compatibility Compatibility with third-party tools and services labels Apr 26, 2024
@nwoolmer nwoolmer self-requested a review April 26, 2024 10:10
Copy link
Contributor

@nwoolmer nwoolmer left a comment

Choose a reason for hiding this comment

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

Putting the hold on it before I make some changes.

@nwoolmer nwoolmer requested a review from puzpuzpuz April 30, 2024 10:51
@nwoolmer nwoolmer added DO NOT MERGE These changes should not be merged to main branch ready for review labels May 8, 2024
@nwoolmer
Copy link
Contributor

nwoolmer commented May 8, 2024

To be merged after #4441

@sivukhin sivukhin force-pushed the sql-parser/operator-precedence-fix-only branch from ecdd683 to 449c1e7 Compare May 12, 2024 09:33
@puzpuzpuz
Copy link
Contributor

In order to provide migration path for users QuestDB introduces temporary flag in the config

This part of the PR description seems no longer relevant and should be updated.

puzpuzpuz
puzpuzpuz previously approved these changes May 21, 2024
Copy link
Contributor

@puzpuzpuz puzpuzpuz 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 another solid contribution!

There is a conflict due to a recent test change.

@nwoolmer
Copy link
Contributor

Looking to resolve conflicts now, bear with.

nwoolmer
nwoolmer previously approved these changes May 21, 2024
Copy link
Contributor

@nwoolmer nwoolmer left a comment

Choose a reason for hiding this comment

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

Thank you for all your effort sorting out this and its tandem PR, we really appreciate the help and attention to detail!

puzpuzpuz
puzpuzpuz previously approved these changes May 21, 2024
@puzpuzpuz
Copy link
Contributor

@sivukhin our build doesn't like your javadocs. :)

Is it ok if I send a PR to fix that against your fork?

@sivukhin
Copy link
Contributor Author

@puzpuzpuz, yes, sure. You can also push directly to my fork (sent you an invite; but feel free to decline and create PR into the fork)

@puzpuzpuz puzpuzpuz dismissed stale reviews from nwoolmer and themself via cfd7918 May 21, 2024 17:17
@nwoolmer nwoolmer removed DO NOT MERGE These changes should not be merged to main branch ready for review labels May 21, 2024
@bluestreak01 bluestreak01 merged commit 8261ae1 into questdb:master May 23, 2024
17 checks passed
@nwoolmer
Copy link
Contributor

Corresponding docs PR: https://github.com/questdb/questdb.io/pull/2286

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Compatibility Compatibility with third-party tools and services SQL Issues or changes relating to SQL execution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants