[postgresql] Fix for #4302 -- ambiguity in stmtmulti #4303
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a fix for #4302.
Consider the input
VACUUM ANALYZE brin_test;
. This can be parsed with the current grammar in two ways:stmtmulti
=>stmt SEMI
==>VACUUM ANALYZE brin_test
;
.stmtmulti
=>stmt stmt SEMI
==>VACUUM
ANALYZE brin_test
;
. It is very likely this is meant to be one statement.The problem is how stmt are separated. In the official gram.y grammar, semicolon has to separate the two. Otherwise it should be considered as one stmt.
This change modifies the rules for meta-commands, which are not part of SQL, and the rules in the parser associated with SQL command separation. The changes in #2365 modified these rules in an incorrect way, introducing ambiguity in the grammar.
\'
is special. it must return a SEMI because that is how it is defined in the documentation at https://www.postgresql.org/docs/current/app-psql.html#APP-PSQL-META-COMMAND-SEMICOLON. They don't tell you there that meta-commands work this way also, but they do. As before, there is no attempt to "parse" the meta-commands themselves.The ambiguity for
opt_analyze
is eliminated.dotnet trperf -i 'VACUUM ANALYZE brin_test;' -c ard | grep -v '^0'
yields no output (astrperf
outputs in column 1 the number of ambiguity detected, andgrep
removes all lines that begin with '0').I should note that the parse time for
examples/*.sql
is not faster (37s after vs 44s before).Also, I really do not understand why there are error listeners defined for this grammar. These have nothing to do with the grammar and must be removed.