Re: BUG #17379: Cannot issue multi-command statements using a replication connection
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: greg.rychlewski@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Date: 2022-01-24T19:00:11Z
Lists: pgsql-bugs
Attachments
- avoid-lexing-SQL-commands-in-repl_scanner.patch (text/x-diff) patch
I wrote: > [ assorted whining about replication-command lexing ] The business with unstable results turned out to be due to failure to reset the lexer's start state, so that's a one-line fix that I already pushed. Attached is the patch I propose to fix the rest of it. The core of this is deciding that we cannot try to run repl_scanner.l over the whole input string when it is not a replication command. That's just going to leave us chasing a moving target of what it has to know to lex successfully. If it were designed to never have any lexer failure conditions, maybe this could be made to work, but that ship already sailed. Hence, what this does is to lex just the first token, see if that's one of the replication-command keywords, and if so push it back so that repl_gram.y will succeed. If not, we just punt immediately without examining any more of the string. This gets rid of all of the other failure conditions discussed, and allows deletion of nearly as much code as it adds. Notably, we don't need the SQLCmd node type anymore, since repl_gram.y will never be asked to look at a general SQL command. Note: I put the switch() recognizing command-starting keywords into repl_scanner.l. I'd tried to put it in walsender.c, which seemed like a more natural place, but the keyword token names aren't currently exported outside repl_gram.y + repl_scanner.l. Moving them to a header file seems like way more work than is justified. You'd have to touch repl_scanner.l anyway while adding a new command keyword, so this arrangement isn't terribly awful. I also failed to resist the temptation to clean up some poor style in repl_scanner.l, as well as bad decisions like not having the same idea of what's whitespace as the core lexer does. The part about removing the SQLCmd node type can't be back-patched (since we can't renumber enum NodeTag in stable branches), but I don't see any reason the rest of this can't be. regards, tom lane
Commits
-
Fix limitations on what SQL commands can be issued to a walsender.
- 6aa5186146f1 15.0 landed
- d67354d870bb 13.6 landed
- 9af6d4b5a588 10.20 landed
- 689f75d6eb9a 12.10 landed
- 4ec54498c5ea 11.15 landed
- 1efcc5946d59 14.2 landed
-
Remember to reset yy_start state when firing up repl_scanner.l.
- ef9706bbc8ce 14.2 landed
- daf658982889 10.20 landed
- c94c6612da57 13.6 landed
- a8ce5c8d7888 12.10 landed
- 449a696236ff 11.15 landed
- 3c06ec6d1412 15.0 landed