-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
merge alts & perf improvements #2378
Conversation
…cting tree simplification and perf gain
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.
a_expr rewritten in "old style" to minimize ambiguities
Not sure it's a good change. Have you tested performance before and after only that change (ignoring merging of alternatives and applying kleene operators)? Not recursive rules create a lot of redundant nodes in the parse tree and they take up extra memory. Also, they uglify the grammar.
in short
regarding a_expr: |
There are a large number of transformations in this PR. Is it possible to break this PR into several? For example, one can focus on kleene-operator rewrites; a second can focus on alt merging; a third can focus on (non-controversial) reformating. As it is, this is a lot to go over. And, there are several transformations that are missing or incorrect. For example, there are three kleene rewrites possible before And, just reading some of the alt-merges, I can check these changes against what my tools in Trash that do, which includes these two transformations (and a ML reformatter), but many more. And, by the way, the changes here are excellent. Thanks for making this PR. --Ken |
hi @kaby76 , thanks for the comment yes, not all (but not so many) transformations are strict, eg createfunctionstamt . I suppose that grammar will be used to parse syntactically correct script - and will not be used to check the syntax of the script, so if grammar will be able to parse to "non-allowed" statement variations - it is ok. Why do I do it that way? I do it for my practical usage in some pet-project tool, so, obviously, I do changes, needed specifically to me - at the 1st place. About breaking PR into several smallest. btw, @kaby76 , what do you think about rewriting a_expr using old-style? |
@OleksiiKovalov Sorry, I haven't looked over the changes that much. I only noticed the change an hour or two ago. I'll start with the non-controversial (i.e., easy) kleene rewrites to verify they are good. |
Again, thank you @OleksiiKovalov for this PR. I am first looking over the BTW, the tool is important because I am using it to modify the C++14/17/20/23 grammars I am writing, derived from the ISO C++ Specs. So, I need it to work flawlessly.
|
hi @KvanTTT , I've applied all recommended transformations, including undoing "avoid leading options", formatting long rules, recommendations by kaby76, etc |
Looks good. Let's leave other fixes to further pull requests. |
@OleksiiKovalov @KvanTTT May I ask what is "a_expr" "b_expr" "c_expr" in PG grammar? |
I know that they come from PG's definitions now. |
| TABLE relation_expr | ||
| select_with_parens set_operator_with_all_or_distinct (simple_select | select_with_parens) | ||
) | ||
(set_operator_with_all_or_distinct (simple_select | select_with_parens))* | ||
; | ||
|
||
set_operator |
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.
It seems PG treats INTERSECT tighter than UNION and EXCEPT but in our grammar file it's the same?
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.
https://www.postgresql.org/docs/current/queries-union.html
As shown here, you can use parentheses to control the order of evaluation. Without parentheses, UNION and EXCEPT associate left-to-right, but INTERSECT binds more tightly than those two operators. Thus
What does this PR do?
Lots recursion->kleene operators conversion for lists
a_expr rewritten in "old style" to minimize ambiguities
merged alts for some rules
Why?
now grammar looks uniform with other grammars
How is it checked?
Tested using unit tests over the tests scripts from the original PostgreSQL repository
Pro
Contra