-
Notifications
You must be signed in to change notification settings - Fork 574
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
Simple custom lexical precedence in PostgreSQL dialect #1379
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
Pull Request Test Coverage Report for Build 10387878575Details
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @samuelcolvin -- this looks like an improvement to me. Thank you for the follow up
Since we haven't released the changes in #1360 to crates.io yet, this isn't an API change
I'll wait a day before merging this in case @lovasoa would like to review or comment on this PR as well
Update: I see @lovasoa has already approved it. So let's do this 🚀
fn prec_unary_not(&self) -> u8 { | ||
UNARY_NOT_PREC | ||
/// Uses (APPROXIMATELY) <https://www.postgresql.org/docs/7.0/operators.htm#AEN2026> as a reference | ||
fn prec_value(&self, prec: Precedence) -> u8 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a good idea.
My only potential concern with this approach is that it could be potentially slower, as it now has many more function calls, however I don't actually think we have a sqlparser benchmark so at this point so trying to make such a change would likely be a pre-mature optimization.
If anyone needs additional performance, we can do that as follow on PRs
|
||
fn prec_unary_not(&self) -> u8 { | ||
NOT_PREC | ||
fn prec_value(&self, prec: Precedence) -> u8 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
thanks a lot. |
@alamb if we care about performance, we should stop using dynamic dispatch and make the parser generic around the dialect, with that we could make lots of these methods That would of course be a big change to the public API, but worthwhile IMHO. |
I agree with both points |
In my use case (SQLPage), SQL parsing overhead is negligible. Have you ever been bottlenecked by sql parsing? |
No. There is more discussion here as well: #1381 (comment) |
As suggest mentioned by @lovasoa in #1360 (comment) the previous approach had unnecessary duplication, this should reduce the duplication of logic while still allowing complete freedom for how dialects decide precedence.
This doesn't change the logic for
PostgreSqlDialect
except thatToken::DuckIntDiv
will now returnMulDivModOp
precedence, notUNKOWN
.