Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita50f50a

Browse files
committed
logical decoding: old/newtuple in spooled UPDATE changes was switched around.
Somehow I managed to flip the order of restoring old & new tuples whende-spooling a change in a large transaction from disk. This happens toonly take effect when a change is spooled to disk which has old/newversions of the tuple. That only is the case for UPDATEs where heprimary key changed or where replica identity is changed to FULL.The tests didn't catch this because either spooled updates, or updatesthat changed primary keys, were tested; not both at the same time.Found while adding tests for the following commit.Backpatch: 9.4, where logical decoding was added
1 parent465dd92 commita50f50a

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

‎contrib/test_decoding/expected/ddl.out

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,21 @@ ORDER BY 1,2;
196196
20467 | table public.tr_etoomuch: DELETE: id[integer]:1 | table public.tr_etoomuch: UPDATE: id[integer]:9999 data[integer]:-9999
197197
(3 rows)
198198

199+
-- check updates of primary keys work correctly
200+
BEGIN;
201+
CREATE TABLE spoolme AS SELECT g.i FROM generate_series(1, 5000) g(i);
202+
UPDATE tr_etoomuch SET id = -id WHERE id = 5000;
203+
DELETE FROM spoolme;
204+
DROP TABLE spoolme;
205+
COMMIT;
206+
SELECT data
207+
FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1')
208+
WHERE data ~ 'UPDATE';
209+
data
210+
-------------------------------------------------------------------------------------------------------------
211+
table public.tr_etoomuch: UPDATE: old-key: id[integer]:5000 new-tuple: id[integer]:-5000 data[integer]:5000
212+
(1 row)
213+
199214
/*
200215
* check whether we decode subtransactions correctly in relation with each
201216
* other

‎contrib/test_decoding/sql/ddl.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,18 @@ FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids',
114114
GROUP BYsubstring(data,1,24)
115115
ORDER BY1,2;
116116

117+
-- check updates of primary keys work correctly
118+
BEGIN;
119+
CREATETABLEspoolmeASSELECTg.iFROM generate_series(1,5000) g(i);
120+
UPDATE tr_etoomuchSET id=-idWHERE id=5000;
121+
DELETEFROM spoolme;
122+
DROPTABLE spoolme;
123+
COMMIT;
124+
125+
SELECT data
126+
FROM pg_logical_slot_get_changes('regression_slot',NULL,NULL,'include-xids','0','skip-empty-xacts','1')
127+
WHERE data ~'UPDATE';
128+
117129
/*
118130
* check whether we decode subtransactions correctly in relation with each
119131
* other

‎src/backend/replication/logical/reorderbuffer.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2266,29 +2266,29 @@ ReorderBufferRestoreChange(ReorderBuffer *rb, ReorderBufferTXN *txn,
22662266
caseREORDER_BUFFER_CHANGE_UPDATE:
22672267
/* fall through */
22682268
caseREORDER_BUFFER_CHANGE_DELETE:
2269-
if (change->data.tp.newtuple)
2269+
if (change->data.tp.oldtuple)
22702270
{
22712271
Sizelen= offsetof(ReorderBufferTupleBuf,data)
22722272
+((ReorderBufferTupleBuf*)data)->tuple.t_len
22732273
- offsetof(HeapTupleHeaderData,t_bits);
22742274

2275-
change->data.tp.newtuple=ReorderBufferGetTupleBuf(rb);
2276-
memcpy(change->data.tp.newtuple,data,len);
2277-
change->data.tp.newtuple->tuple.t_data=
2278-
&change->data.tp.newtuple->header;
2275+
change->data.tp.oldtuple=ReorderBufferGetTupleBuf(rb);
2276+
memcpy(change->data.tp.oldtuple,data,len);
2277+
change->data.tp.oldtuple->tuple.t_data=
2278+
&change->data.tp.oldtuple->header;
22792279
data+=len;
22802280
}
22812281

2282-
if (change->data.tp.oldtuple)
2282+
if (change->data.tp.newtuple)
22832283
{
22842284
Sizelen= offsetof(ReorderBufferTupleBuf,data)
22852285
+((ReorderBufferTupleBuf*)data)->tuple.t_len
22862286
- offsetof(HeapTupleHeaderData,t_bits);
22872287

2288-
change->data.tp.oldtuple=ReorderBufferGetTupleBuf(rb);
2289-
memcpy(change->data.tp.oldtuple,data,len);
2290-
change->data.tp.oldtuple->tuple.t_data=
2291-
&change->data.tp.oldtuple->header;
2288+
change->data.tp.newtuple=ReorderBufferGetTupleBuf(rb);
2289+
memcpy(change->data.tp.newtuple,data,len);
2290+
change->data.tp.newtuple->tuple.t_data=
2291+
&change->data.tp.newtuple->header;
22922292
data+=len;
22932293
}
22942294
break;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp