Allow to use multiple statements extensively.
authorTatsuo Ishii <ishii@sraoss.co.jp>
Sun, 12 Feb 2023 10:59:00 +0000 (19:59 +0900)
committerTatsuo Ishii <ishii@sraoss.co.jp>
Wed, 15 Feb 2023 08:06:54 +0000 (17:06 +0900)
commitfd32f5ef996cad36d5b1554e92a33ea7a815419a
treeb6b492cbbb411dee5a889ce20bff30a52a287b94
parent14bbb5afa58b5d57cf6bb77ee31e06f804c6a0cb
Allow to use multiple statements extensively.

This commit tries to eliminate pgpool's long standing limitations
regarding multiple statements (multi-statements).

Previously

BEGIN;SELECT;
SAVEPOINT foo;

will fail in streaming replication mode because "BEGIN" was sent to
the primar node, but "SAVEPOINT" will be sent to both the primary and
standbys, and standbys will complain "SAVEPOINT can only be used in
transaction blocks".

Basic idea to solve the problem is, tracking explicit transactions
started by multi-statement queries so that all commands including
PREPARE, EXECUTE, DEALLOCATE, SAVEPOINT and COMMIT/ROLLBACK are sent
to the primary node in streaming replication mode or logical
replication mode.  In native replication or snapshot isolation mode,
those queries are sent to all of the backend nodes.

For this purpose new member: is_tx_started_by_multi_statement is added
to session context and also support functions are added.

extern bool is_tx_started_by_multi_statement_query(void);
extern void set_tx_started_by_multi_statement_query(void);
extern void unset_tx_started_by_multi_statement_query(void);

Discussion: https://www.pgpool.net/pipermail/pgpool-hackers/2023-February/004287.html
Back-patch-through: 4.2 as backport to 4.1 and before looks difficult
src/context/pool_query_context.c
src/context/pool_session_context.c
src/include/context/pool_session_context.h
src/protocol/CommandComplete.c
src/protocol/pool_process_query.c
src/protocol/pool_proto_modules.c