-
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
[postgresql] a_expr_qual/a_expr_qual_op is ambiguous. #4306
Comments
AnalysisIn the input file colate.sql.
This seemingly simple expression involving
This is all fine, but the problem is the context target_el. grammars-v4/sql/postgresql/PostgreSQLParser.g4 Lines 4100 to 4103 in 199a512
We see here that
|
Changing Also, while this fixes the ambiguity for collate.sql, the parse time does not improve at all. This is because there is a huge max-k required. https://github.com/antlr/grammars-v4/blob/199a5121ece05d2f2e7eca330d0738220499e80c/sql/postgresql/examples/collate.sql#L87C9-L217C4. Rule target_list is the culprit. (There is a way to fix the grammar for fallbacks by duplication.) First things first, though. |
Cloning the rule |
I was in error. target_el is correct. The problem is expressions in the presence of the alias. |
The trick is to provide a semantic predicate before qual_op.
changed to
with
This disambiguates the use of the postfix operator, only allowing it for |
* Fix for #4306 * Workaround for the '!=-' operator.
Consider the test input file collate.sql. The parse is ambiguous for a_expr_qual_op. See the two parse trees in ambig.txt.
This ambiguity is a major contributor to the performance issues in the grammar. This file takes ~1.3s to parse cold start (~0.4s warm start), and it is only 276 lines long!
Note, I chose this file because it had the least number of non-zero ambiguities, which is 1. If you try to take a test input with a large number of ambiguities,
trparse --ambig
will take a long time. To find the file with the least non-zero number of ambiguities, I did$ dotnet trperf -c aF ../examples/*.sql | grep -v '^0' | awk '{sum[$2] += $1} END {for (key in sum) print sum[key], key}' | sort -k1 -n | head
.The text was updated successfully, but these errors were encountered: