From c14ed1bc3ea23d4dcca2b99dde9eb536aeb59968 Mon Sep 17 00:00:00 2001 From: "Andrey V. Lepikhov" Date: Wed, 18 Aug 2021 13:12:09 +0300 Subject: [PATCH] Bugfix. Multimaster mustn't send the T_CallStmt utility statement to all multimaster nodes. Also, replay the problem of sequence generation in a stored procedure in multimaster.sql. --- expected/multimaster.out | 42 ++++++++++++++++++++++++++++++++++++++++ sql/multimaster.sql | 29 +++++++++++++++++++++++++++ src/ddl.c | 1 + 3 files changed, 72 insertions(+) diff --git a/expected/multimaster.out b/expected/multimaster.out index 8508626372..269756626e 100644 --- a/expected/multimaster.out +++ b/expected/multimaster.out @@ -488,3 +488,45 @@ table seq_test; 105 (8 rows) +-- +-- Check a sequence generation by function, procedure, direct insertion. +-- +CREATE SEQUENCE seq1; +CREATE TABLE t1 (id int); +CREATE OR REPLACE PROCEDURE p1 () LANGUAGE 'plpgsql' AS $$ +BEGIN + INSERT INTO t1 (id) VALUES (nextval('seq1'::regclass)); +END; $$; +CREATE OR REPLACE FUNCTION p2 () RETURNS VOID LANGUAGE 'plpgsql' AS $$ +BEGIN + INSERT INTO t1 (id) VALUES (nextval('seq1'::regclass)); +END; $$; +-- Generate value by different ways. +CALL p1(); +SELECT p2(); + p2 +---- + +(1 row) + +INSERT INTO t1 (id) VALUES (nextval('seq1'::regclass)); +-- Fix generated values of a sequence +SELECT * FROM t1 ORDER BY id; + id +---- + 1 + 4 + 7 +(3 rows) + +-- Try to UPDATE. In the case of data divergence we will get an error. +UPDATE t1 SET id = id + 1; +-- Check for new values, just to be sure. +SELECT * FROM t1 ORDER BY id; + id +---- + 2 + 5 + 8 +(3 rows) + diff --git a/sql/multimaster.sql b/sql/multimaster.sql index b030b44687..52ec1f717c 100644 --- a/sql/multimaster.sql +++ b/sql/multimaster.sql @@ -327,3 +327,32 @@ insert into seq_test values (default); insert into seq_test values (default); \c :node1 table seq_test; + +-- +-- Check a sequence generation by function, procedure, direct insertion. +-- +CREATE SEQUENCE seq1; +CREATE TABLE t1 (id int); +CREATE OR REPLACE PROCEDURE p1 () LANGUAGE 'plpgsql' AS $$ +BEGIN + INSERT INTO t1 (id) VALUES (nextval('seq1'::regclass)); +END; $$; + +CREATE OR REPLACE FUNCTION p2 () RETURNS VOID LANGUAGE 'plpgsql' AS $$ +BEGIN + INSERT INTO t1 (id) VALUES (nextval('seq1'::regclass)); +END; $$; + +-- Generate value by different ways. +CALL p1(); +SELECT p2(); +INSERT INTO t1 (id) VALUES (nextval('seq1'::regclass)); + +-- Fix generated values of a sequence +SELECT * FROM t1 ORDER BY id; + +-- Try to UPDATE. In the case of data divergence we will get an error. +UPDATE t1 SET id = id + 1; + +-- Check for new values, just to be sure. +SELECT * FROM t1 ORDER BY id; diff --git a/src/ddl.c b/src/ddl.c index 0bd82284c0..f15f01f57a 100644 --- a/src/ddl.c +++ b/src/ddl.c @@ -947,6 +947,7 @@ MtmProcessUtilitySender(PlannedStmt *pstmt, const char *queryString, case T_PlannedStmt: case T_FetchStmt: case T_DoStmt: + case T_CallStmt: case T_CommentStmt: case T_PrepareStmt: case T_ExecuteStmt: