postgresql/src/include/replication
Tom Lane d67354d870 Fix limitations on what SQL commands can be issued to a walsender.
In logical replication mode, a WalSender is supposed to be able
to execute any regular SQL command, as well as the special
replication commands.  Poor design of the replication-command
parser caused it to fail in various cases, notably:

* semicolons embedded in a command, or multiple SQL commands
sent in a single message;

* dollar-quoted literals containing odd numbers of single
or double quote marks;

* commands starting with a comment.

The basic problem here is that we're trying to run repl_scanner.l
across the entire input string even when it's not a replication
command.  Since repl_scanner.l does not understand all of the
token types known to the core lexer, this is doomed to have
failure modes.

We certainly don't want to make repl_scanner.l as big as scan.l,
so instead rejigger stuff so that we only lex the first token of
a non-replication command.  That will usually look like an IDENT
to repl_scanner.l, though a comment would end up getting reported
as a '-' or '/' single-character token.  If the token is a replication
command keyword, we push it back and proceed normally with repl_gram.y
parsing.  Otherwise, we can drop out of exec_replication_command()
without examining the rest of the string.

(It's still theoretically possible for repl_scanner.l to fail on
the first token; but that could only happen if it's an unterminated
single- or double-quoted string, in which case you'd have gotten
largely the same error from the core lexer too.)

In this way, repl_gram.y isn't involved at all in handling general
SQL commands, so we can get rid of the SQLCmd node type.  (In
the back branches, we can't remove it because renumbering enum
NodeTag would be an ABI break; so just leave it sit there unused.)

I failed to resist the temptation to clean up some other sloppy
coding in repl_scanner.l while at it.  The only externally-visible
behavior change from that is it now accepts \r and \f as whitespace,
same as the core lexer.

Per bug #17379 from Greg Rychlewski.  Back-patch to all supported
branches.

Discussion: https://postgr.es/m/17379-6a5c6cfb3f1f5e77@postgresql.org
2022-01-24 15:33:34 -05:00
..
backup_manifest.h Initial pgindent and pgperltidy run for v13. 2020-05-14 13:06:50 -04:00
basebackup.h Also rename 'struct manifest_info'. 2020-04-23 09:47:50 -04:00
decode.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
logical.h Rework XLogReader callback system 2020-05-08 15:40:11 -04:00
logicallauncher.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
logicalproto.h Prepare to support non-tables in publications 2020-03-19 08:25:07 +01:00
logicalrelation.h Don't try to print data type names in slot_store_error_callback(). 2021-07-02 16:04:54 -04:00
logicalworker.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
message.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
origin.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
output_plugin.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
pgoutput.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
reorderbuffer.h Fix ABI break introduced by commit 4daa140a2f. 2021-06-24 15:21:50 +05:30
slot.h Advance old-segment horizon properly after slot invalidation 2021-07-16 12:07:30 -04:00
snapbuild.h Reset properly snapshot export state during transaction abort 2021-10-18 11:56:52 +09:00
syncrep.h Fix race conditions in synchronous standby management. 2020-04-18 14:02:44 -04:00
walreceiver.h Initial pgindent and pgperltidy run for v13. 2020-05-14 13:06:50 -04:00
walsender.h Generate backup manifests for base backups, and validate them. 2020-04-03 15:05:59 -04:00
walsender_private.h Fix limitations on what SQL commands can be issued to a walsender. 2022-01-24 15:33:34 -05:00
worker_internal.h Rename the logical replication global "wrconn" 2021-05-12 19:13:54 -04:00