1d540f44创建于 2021年9月23日历史提交
-- predictability
SET synchronous_commit = on;
SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding');
 ?column? 
----------
 init
(1 row)

CREATE TABLE spill_test(data text);
-- consume DDL
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1') limit 10;
 data 
------
(0 rows)

-- spilling main xact
BEGIN;
INSERT INTO spill_test SELECT 'serialize-topbig--1:'||g.i FROM generate_series(1, 5000) g(i);
COMMIT;
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1') limit 10;
                                data                                 
---------------------------------------------------------------------
 BEGIN
 table public.spill_test: INSERT: data[text]:'serialize-topbig--1:1'
 table public.spill_test: INSERT: data[text]:'serialize-topbig--1:2'
 table public.spill_test: INSERT: data[text]:'serialize-topbig--1:3'
 table public.spill_test: INSERT: data[text]:'serialize-topbig--1:4'
 table public.spill_test: INSERT: data[text]:'serialize-topbig--1:5'
 table public.spill_test: INSERT: data[text]:'serialize-topbig--1:6'
 table public.spill_test: INSERT: data[text]:'serialize-topbig--1:7'
 table public.spill_test: INSERT: data[text]:'serialize-topbig--1:8'
 table public.spill_test: INSERT: data[text]:'serialize-topbig--1:9'
(10 rows)

-- spilling subxact, nothing in main
BEGIN;
SAVEPOINT s;
INSERT INTO spill_test SELECT 'serialize-subbig--1:'||g.i FROM generate_series(1, 5000) g(i);
RELEASE SAVEPOINT s;
COMMIT;
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1') limit 10;
                                data                                 
---------------------------------------------------------------------
 BEGIN
 table public.spill_test: INSERT: data[text]:'serialize-subbig--1:1'
 table public.spill_test: INSERT: data[text]:'serialize-subbig--1:2'
 table public.spill_test: INSERT: data[text]:'serialize-subbig--1:3'
 table public.spill_test: INSERT: data[text]:'serialize-subbig--1:4'
 table public.spill_test: INSERT: data[text]:'serialize-subbig--1:5'
 table public.spill_test: INSERT: data[text]:'serialize-subbig--1:6'
 table public.spill_test: INSERT: data[text]:'serialize-subbig--1:7'
 table public.spill_test: INSERT: data[text]:'serialize-subbig--1:8'
 table public.spill_test: INSERT: data[text]:'serialize-subbig--1:9'
(10 rows)

-- spilling subxact, spilling main xact
BEGIN;
SAVEPOINT s;
INSERT INTO spill_test SELECT 'serialize-subbig-topbig--1:'||g.i FROM generate_series(1, 5000) g(i);
RELEASE SAVEPOINT s;
INSERT INTO spill_test SELECT 'serialize-subbig-topbig--2:'||g.i FROM generate_series(5001, 10000) g(i);
COMMIT;
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1') limit 10;
                                    data                                    
----------------------------------------------------------------------------
 BEGIN
 table public.spill_test: INSERT: data[text]:'serialize-subbig-topbig--1:1'
 table public.spill_test: INSERT: data[text]:'serialize-subbig-topbig--1:2'
 table public.spill_test: INSERT: data[text]:'serialize-subbig-topbig--1:3'
 table public.spill_test: INSERT: data[text]:'serialize-subbig-topbig--1:4'
 table public.spill_test: INSERT: data[text]:'serialize-subbig-topbig--1:5'
 table public.spill_test: INSERT: data[text]:'serialize-subbig-topbig--1:6'
 table public.spill_test: INSERT: data[text]:'serialize-subbig-topbig--1:7'
 table public.spill_test: INSERT: data[text]:'serialize-subbig-topbig--1:8'
 table public.spill_test: INSERT: data[text]:'serialize-subbig-topbig--1:9'
(10 rows)

-- spilling subxact, non-spilling main xact
BEGIN;
SAVEPOINT s;
INSERT INTO spill_test SELECT 'serialize-subbig-topsmall--1:'||g.i FROM generate_series(1, 5000) g(i);
RELEASE SAVEPOINT s;
INSERT INTO spill_test SELECT 'serialize-subbig-topsmall--2:'||g.i FROM generate_series(5001, 5001) g(i);
COMMIT;
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1') limit 10;
                                     data                                     
------------------------------------------------------------------------------
 BEGIN
 table public.spill_test: INSERT: data[text]:'serialize-subbig-topsmall--1:1'
 table public.spill_test: INSERT: data[text]:'serialize-subbig-topsmall--1:2'
 table public.spill_test: INSERT: data[text]:'serialize-subbig-topsmall--1:3'
 table public.spill_test: INSERT: data[text]:'serialize-subbig-topsmall--1:4'
 table public.spill_test: INSERT: data[text]:'serialize-subbig-topsmall--1:5'
 table public.spill_test: INSERT: data[text]:'serialize-subbig-topsmall--1:6'
 table public.spill_test: INSERT: data[text]:'serialize-subbig-topsmall--1:7'
 table public.spill_test: INSERT: data[text]:'serialize-subbig-topsmall--1:8'
 table public.spill_test: INSERT: data[text]:'serialize-subbig-topsmall--1:9'
(10 rows)

-- not-spilling subxact, spilling main xact
BEGIN;
SAVEPOINT s;
INSERT INTO spill_test SELECT 'serialize-subbig-topbig--1:'||g.i FROM generate_series(1, 5000) g(i);
RELEASE SAVEPOINT s;
INSERT INTO spill_test SELECT 'serialize-subbig-topbig--2:'||g.i FROM generate_series(5001, 10000) g(i);
COMMIT;
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1') limit 10;
                                    data                                    
----------------------------------------------------------------------------
 BEGIN
 table public.spill_test: INSERT: data[text]:'serialize-subbig-topbig--1:1'
 table public.spill_test: INSERT: data[text]:'serialize-subbig-topbig--1:2'
 table public.spill_test: INSERT: data[text]:'serialize-subbig-topbig--1:3'
 table public.spill_test: INSERT: data[text]:'serialize-subbig-topbig--1:4'
 table public.spill_test: INSERT: data[text]:'serialize-subbig-topbig--1:5'
 table public.spill_test: INSERT: data[text]:'serialize-subbig-topbig--1:6'
 table public.spill_test: INSERT: data[text]:'serialize-subbig-topbig--1:7'
 table public.spill_test: INSERT: data[text]:'serialize-subbig-topbig--1:8'
 table public.spill_test: INSERT: data[text]:'serialize-subbig-topbig--1:9'
(10 rows)

-- spilling main xact, spilling subxact
BEGIN;
INSERT INTO spill_test SELECT 'serialize-topbig-subbig--1:'||g.i FROM generate_series(1, 5000) g(i);
SAVEPOINT s;
INSERT INTO spill_test SELECT 'serialize-topbig-subbig--2:'||g.i FROM generate_series(5001, 10000) g(i);
RELEASE SAVEPOINT s;
COMMIT;
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1') limit 10;
                                    data                                    
----------------------------------------------------------------------------
 BEGIN
 table public.spill_test: INSERT: data[text]:'serialize-topbig-subbig--1:1'
 table public.spill_test: INSERT: data[text]:'serialize-topbig-subbig--1:2'
 table public.spill_test: INSERT: data[text]:'serialize-topbig-subbig--1:3'
 table public.spill_test: INSERT: data[text]:'serialize-topbig-subbig--1:4'
 table public.spill_test: INSERT: data[text]:'serialize-topbig-subbig--1:5'
 table public.spill_test: INSERT: data[text]:'serialize-topbig-subbig--1:6'
 table public.spill_test: INSERT: data[text]:'serialize-topbig-subbig--1:7'
 table public.spill_test: INSERT: data[text]:'serialize-topbig-subbig--1:8'
 table public.spill_test: INSERT: data[text]:'serialize-topbig-subbig--1:9'
(10 rows)

-- spilling main xact, not spilling subxact
BEGIN;
INSERT INTO spill_test SELECT 'serialize-topbig-subsmall--1:'||g.i FROM generate_series(1, 5000) g(i);
SAVEPOINT s;
INSERT INTO spill_test SELECT 'serialize-topbig-subsmall--2:'||g.i FROM generate_series(5001, 5001) g(i);
RELEASE SAVEPOINT s;
COMMIT;
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1') limit 10;
                                     data                                     
------------------------------------------------------------------------------
 BEGIN
 table public.spill_test: INSERT: data[text]:'serialize-topbig-subsmall--1:1'
 table public.spill_test: INSERT: data[text]:'serialize-topbig-subsmall--1:2'
 table public.spill_test: INSERT: data[text]:'serialize-topbig-subsmall--1:3'
 table public.spill_test: INSERT: data[text]:'serialize-topbig-subsmall--1:4'
 table public.spill_test: INSERT: data[text]:'serialize-topbig-subsmall--1:5'
 table public.spill_test: INSERT: data[text]:'serialize-topbig-subsmall--1:6'
 table public.spill_test: INSERT: data[text]:'serialize-topbig-subsmall--1:7'
 table public.spill_test: INSERT: data[text]:'serialize-topbig-subsmall--1:8'
 table public.spill_test: INSERT: data[text]:'serialize-topbig-subsmall--1:9'
(10 rows)

-- spilling subxact, followed by another spilling subxact
BEGIN;
SAVEPOINT s1;
INSERT INTO spill_test SELECT 'serialize-subbig-subbig--1:'||g.i FROM generate_series(1, 5000) g(i);
RELEASE SAVEPOINT s1;
SAVEPOINT s2;
INSERT INTO spill_test SELECT 'serialize-subbig-subbig--2:'||g.i FROM generate_series(5001, 10000) g(i);
RELEASE SAVEPOINT s2;
COMMIT;
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1') limit 10;
                                    data                                    
----------------------------------------------------------------------------
 BEGIN
 table public.spill_test: INSERT: data[text]:'serialize-subbig-subbig--1:1'
 table public.spill_test: INSERT: data[text]:'serialize-subbig-subbig--1:2'
 table public.spill_test: INSERT: data[text]:'serialize-subbig-subbig--1:3'
 table public.spill_test: INSERT: data[text]:'serialize-subbig-subbig--1:4'
 table public.spill_test: INSERT: data[text]:'serialize-subbig-subbig--1:5'
 table public.spill_test: INSERT: data[text]:'serialize-subbig-subbig--1:6'
 table public.spill_test: INSERT: data[text]:'serialize-subbig-subbig--1:7'
 table public.spill_test: INSERT: data[text]:'serialize-subbig-subbig--1:8'
 table public.spill_test: INSERT: data[text]:'serialize-subbig-subbig--1:9'
(10 rows)

-- spilling subxact, followed by not spilling subxact
BEGIN;
SAVEPOINT s1;
INSERT INTO spill_test SELECT 'serialize-subbig-subsmall--1:'||g.i FROM generate_series(1, 5000) g(i);
RELEASE SAVEPOINT s1;
SAVEPOINT s2;
INSERT INTO spill_test SELECT 'serialize-subbig-subsmall--2:'||g.i FROM generate_series(5001, 5001) g(i);
RELEASE SAVEPOINT s2;
COMMIT;
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1') limit 10;
                                     data                                     
------------------------------------------------------------------------------
 BEGIN
 table public.spill_test: INSERT: data[text]:'serialize-subbig-subsmall--1:1'
 table public.spill_test: INSERT: data[text]:'serialize-subbig-subsmall--1:2'
 table public.spill_test: INSERT: data[text]:'serialize-subbig-subsmall--1:3'
 table public.spill_test: INSERT: data[text]:'serialize-subbig-subsmall--1:4'
 table public.spill_test: INSERT: data[text]:'serialize-subbig-subsmall--1:5'
 table public.spill_test: INSERT: data[text]:'serialize-subbig-subsmall--1:6'
 table public.spill_test: INSERT: data[text]:'serialize-subbig-subsmall--1:7'
 table public.spill_test: INSERT: data[text]:'serialize-subbig-subsmall--1:8'
 table public.spill_test: INSERT: data[text]:'serialize-subbig-subsmall--1:9'
(10 rows)

-- not spilling subxact, followed by spilling subxact
BEGIN;
SAVEPOINT s1;
INSERT INTO spill_test SELECT 'serialize-subsmall-subbig--1:'||g.i FROM generate_series(1, 1) g(i);
RELEASE SAVEPOINT s1;
SAVEPOINT s2;
INSERT INTO spill_test SELECT 'serialize-subsmall-subbig--2:'||g.i FROM generate_series(2, 5001) g(i);
RELEASE SAVEPOINT s2;
COMMIT;
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1') limit 10;
                                     data                                     
------------------------------------------------------------------------------
 BEGIN
 table public.spill_test: INSERT: data[text]:'serialize-subsmall-subbig--1:1'
 table public.spill_test: INSERT: data[text]:'serialize-subsmall-subbig--2:2'
 table public.spill_test: INSERT: data[text]:'serialize-subsmall-subbig--2:3'
 table public.spill_test: INSERT: data[text]:'serialize-subsmall-subbig--2:4'
 table public.spill_test: INSERT: data[text]:'serialize-subsmall-subbig--2:5'
 table public.spill_test: INSERT: data[text]:'serialize-subsmall-subbig--2:6'
 table public.spill_test: INSERT: data[text]:'serialize-subsmall-subbig--2:7'
 table public.spill_test: INSERT: data[text]:'serialize-subsmall-subbig--2:8'
 table public.spill_test: INSERT: data[text]:'serialize-subsmall-subbig--2:9'
(10 rows)

-- spilling subxact, containing another spilling subxact
BEGIN;
SAVEPOINT s1;
INSERT INTO spill_test SELECT 'serialize-nested-subbig-subbig--1:'||g.i FROM generate_series(1, 5000) g(i);
SAVEPOINT s2;
INSERT INTO spill_test SELECT 'serialize-nested-subbig-subbig--2:'||g.i FROM generate_series(5001, 10000) g(i);
RELEASE SAVEPOINT s2;
RELEASE SAVEPOINT s1;
COMMIT;
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1') limit 10;
                                       data                                        
-----------------------------------------------------------------------------------
 BEGIN
 table public.spill_test: INSERT: data[text]:'serialize-nested-subbig-subbig--1:1'
 table public.spill_test: INSERT: data[text]:'serialize-nested-subbig-subbig--1:2'
 table public.spill_test: INSERT: data[text]:'serialize-nested-subbig-subbig--1:3'
 table public.spill_test: INSERT: data[text]:'serialize-nested-subbig-subbig--1:4'
 table public.spill_test: INSERT: data[text]:'serialize-nested-subbig-subbig--1:5'
 table public.spill_test: INSERT: data[text]:'serialize-nested-subbig-subbig--1:6'
 table public.spill_test: INSERT: data[text]:'serialize-nested-subbig-subbig--1:7'
 table public.spill_test: INSERT: data[text]:'serialize-nested-subbig-subbig--1:8'
 table public.spill_test: INSERT: data[text]:'serialize-nested-subbig-subbig--1:9'
(10 rows)

-- spilling subxact, containing a not spilling subxact
BEGIN;
SAVEPOINT s1;
INSERT INTO spill_test SELECT 'serialize-nested-subbig-subsmall--1:'||g.i FROM generate_series(1, 5000) g(i);
SAVEPOINT s2;
INSERT INTO spill_test SELECT 'serialize-nested-subbig-subsmall--2:'||g.i FROM generate_series(5001, 5001) g(i);
RELEASE SAVEPOINT s2;
RELEASE SAVEPOINT s1;
COMMIT;
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1') limit 10;
                                        data                                         
-------------------------------------------------------------------------------------
 BEGIN
 table public.spill_test: INSERT: data[text]:'serialize-nested-subbig-subsmall--1:1'
 table public.spill_test: INSERT: data[text]:'serialize-nested-subbig-subsmall--1:2'
 table public.spill_test: INSERT: data[text]:'serialize-nested-subbig-subsmall--1:3'
 table public.spill_test: INSERT: data[text]:'serialize-nested-subbig-subsmall--1:4'
 table public.spill_test: INSERT: data[text]:'serialize-nested-subbig-subsmall--1:5'
 table public.spill_test: INSERT: data[text]:'serialize-nested-subbig-subsmall--1:6'
 table public.spill_test: INSERT: data[text]:'serialize-nested-subbig-subsmall--1:7'
 table public.spill_test: INSERT: data[text]:'serialize-nested-subbig-subsmall--1:8'
 table public.spill_test: INSERT: data[text]:'serialize-nested-subbig-subsmall--1:9'
(10 rows)

-- not spilling subxact, containing a spilling subxact
BEGIN;
SAVEPOINT s1;
INSERT INTO spill_test SELECT 'serialize-nested-subsmall-subbig--1:'||g.i FROM generate_series(1, 1) g(i);
SAVEPOINT s2;
INSERT INTO spill_test SELECT 'serialize-nested-subsmall-subbig--2:'||g.i FROM generate_series(2, 5001) g(i);
RELEASE SAVEPOINT s2;
RELEASE SAVEPOINT s1;
COMMIT;
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1') limit 10;
                                        data                                         
-------------------------------------------------------------------------------------
 BEGIN
 table public.spill_test: INSERT: data[text]:'serialize-nested-subsmall-subbig--1:1'
 table public.spill_test: INSERT: data[text]:'serialize-nested-subsmall-subbig--2:2'
 table public.spill_test: INSERT: data[text]:'serialize-nested-subsmall-subbig--2:3'
 table public.spill_test: INSERT: data[text]:'serialize-nested-subsmall-subbig--2:4'
 table public.spill_test: INSERT: data[text]:'serialize-nested-subsmall-subbig--2:5'
 table public.spill_test: INSERT: data[text]:'serialize-nested-subsmall-subbig--2:6'
 table public.spill_test: INSERT: data[text]:'serialize-nested-subsmall-subbig--2:7'
 table public.spill_test: INSERT: data[text]:'serialize-nested-subsmall-subbig--2:8'
 table public.spill_test: INSERT: data[text]:'serialize-nested-subsmall-subbig--2:9'
(10 rows)

-- not spilling subxact, containing a spilling subxact that aborts and one that commits
BEGIN;
SAVEPOINT s1;
INSERT INTO spill_test SELECT 'serialize-nested-subbig-subbigabort--1:'||g.i FROM generate_series(1, 5000) g(i);
SAVEPOINT s2;
INSERT INTO spill_test SELECT 'serialize-nested-subbig-subbigabort--2:'||g.i FROM generate_series(5001, 10000) g(i);
ROLLBACK TO SAVEPOINT s2;
SAVEPOINT s3;
INSERT INTO spill_test SELECT 'serialize-nested-subbig-subbigabort-subbig-3:'||g.i FROM generate_series(5001, 10000) g(i);
RELEASE SAVEPOINT s1;
COMMIT;
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1') limit 10;
                                          data                                          
----------------------------------------------------------------------------------------
 BEGIN
 table public.spill_test: INSERT: data[text]:'serialize-nested-subbig-subbigabort--1:1'
 table public.spill_test: INSERT: data[text]:'serialize-nested-subbig-subbigabort--1:2'
 table public.spill_test: INSERT: data[text]:'serialize-nested-subbig-subbigabort--1:3'
 table public.spill_test: INSERT: data[text]:'serialize-nested-subbig-subbigabort--1:4'
 table public.spill_test: INSERT: data[text]:'serialize-nested-subbig-subbigabort--1:5'
 table public.spill_test: INSERT: data[text]:'serialize-nested-subbig-subbigabort--1:6'
 table public.spill_test: INSERT: data[text]:'serialize-nested-subbig-subbigabort--1:7'
 table public.spill_test: INSERT: data[text]:'serialize-nested-subbig-subbigabort--1:8'
 table public.spill_test: INSERT: data[text]:'serialize-nested-subbig-subbigabort--1:9'
(10 rows)

DROP TABLE spill_test;
SELECT pg_drop_replication_slot('regression_slot');
WARNING:  replicationSlotMinLSN is InvalidXLogRecPtr!!!
CONTEXT:  referenced column: pg_drop_replication_slot
WARNING:  replicationSlotMaxLSN is InvalidXLogRecPtr!!!
CONTEXT:  referenced column: pg_drop_replication_slot
 pg_drop_replication_slot 
--------------------------
 
(1 row)