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

Simple custom lexical precedence in PostgreSQL dialect #1379

Merged
merged 1 commit into from
Aug 14, 2024

Conversation

samuelcolvin
Copy link
Contributor

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 that Token::DuckIntDiv will now return MulDivModOp precedence, not UNKOWN.

Copy link
Contributor

@lovasoa lovasoa left a comment

Choose a reason for hiding this comment

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

🎉

@coveralls
Copy link

Pull Request Test Coverage Report for Build 10387878575

Details

  • 88 of 93 (94.62%) changed or added relevant lines in 4 files are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.07%) to 89.124%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/dialect/postgresql.rs 22 23 95.65%
src/dialect/mod.rs 50 54 92.59%
Files with Coverage Reduction New Missed Lines %
src/dialect/mod.rs 2 68.6%
Totals Coverage Status
Change from base Build 10370172981: 0.07%
Covered Lines: 27641
Relevant Lines: 31014

💛 - Coveralls

Copy link
Contributor

@alamb alamb 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 @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 {
Copy link
Contributor

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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

@alamb alamb merged commit f223530 into apache:main Aug 14, 2024
10 checks passed
@samuelcolvin samuelcolvin deleted the simplify-custom-precedence branch August 14, 2024 15:48
@samuelcolvin
Copy link
Contributor Author

thanks a lot.

@samuelcolvin
Copy link
Contributor Author

@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 const (or drop the Precedence enum and just have const values on the trait) and probably improve performance significantly in general.

That would of course be a big change to the public API, but worthwhile IMHO.

@alamb
Copy link
Contributor

alamb commented Aug 15, 2024

@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 const (or drop the Precedence enum and just have const values on the trait) and probably improve performance significantly in general.

That would of course be a big change to the public API, but worthwhile IMHO.

I agree with both points

@lovasoa
Copy link
Contributor

lovasoa commented Aug 15, 2024

In my use case (SQLPage), SQL parsing overhead is negligible. Have you ever been bottlenecked by sql parsing?

@alamb
Copy link
Contributor

alamb commented Aug 15, 2024

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)

ayman-sigma pushed a commit to sigmacomputing/sqlparser-rs that referenced this pull request Nov 19, 2024
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.

4 participants