Skip to content

Commit 9dac02c

Browse files
author
Amit Kapila
committed
Ignore generated columns during apply of update/delete.
We fail to apply updates and deletes when the REPLICA IDENTITY FULL is used for the table having generated columns. We didn't use to ignore generated columns while doing tuple comparison among the tuples from the publisher and subscriber during apply of updates and deletes. Author: Onder Kalaci Reviewed-by: Shi yu, Amit Kapila Backpatch-through: 12 Discussion: https://postgr.es/m/CACawEhVQC9WoofunvXg12aXtbqKnEgWxoRx3+v8q32AWYsdpGg@mail.gmail.com
1 parent 3ba8bce commit 9dac02c

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/backend/executor/execReplication.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,10 @@ tuples_equal(TupleTableSlot *slot1, TupleTableSlot *slot2,
246246
att = TupleDescAttr(slot1->tts_tupleDescriptor, attrnum);
247247

248248
/*
249-
* Ignore dropped columns as the publisher doesn't send those
249+
* Ignore dropped and generated columns as the publisher doesn't send
250+
* those
250251
*/
251-
if (att->attisdropped)
252+
if (att->attisdropped || att->attgenerated)
252253
continue;
253254

254255
/*

src/test/subscription/t/100_bugs.pl

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use warnings;
77
use PostgresNode;
88
use TestLib;
9-
use Test::More tests => 8;
9+
use Test::More tests => 9;
1010

1111
# Bug #15114
1212

@@ -299,8 +299,8 @@
299299
$node_publisher->stop('fast');
300300
$node_subscriber->stop('fast');
301301

302-
# The bug was that when the REPLICA IDENTITY FULL is used with dropped columns,
303-
# we fail to apply updates and deletes
302+
# The bug was that when the REPLICA IDENTITY FULL is used with dropped or
303+
# generated columns, we fail to apply updates and deletes
304304
my $node_publisher_d_cols = get_new_node('node_publisher_d_cols');
305305
$node_publisher_d_cols->init(allows_streaming => 'logical');
306306
$node_publisher_d_cols->start;
@@ -313,14 +313,18 @@
313313
'postgres', qq(
314314
CREATE TABLE dropped_cols (a int, b_drop int, c int);
315315
ALTER TABLE dropped_cols REPLICA IDENTITY FULL;
316-
CREATE PUBLICATION pub_dropped_cols FOR TABLE dropped_cols;
316+
CREATE TABLE generated_cols (a int, b_gen int GENERATED ALWAYS AS (5 * a) STORED, c int);
317+
ALTER TABLE generated_cols REPLICA IDENTITY FULL;
318+
CREATE PUBLICATION pub_dropped_cols FOR TABLE dropped_cols, generated_cols;
317319
-- some initial data
318320
INSERT INTO dropped_cols VALUES (1, 1, 1);
321+
INSERT INTO generated_cols (a, c) VALUES (1, 1);
319322
));
320323

321324
$node_subscriber_d_cols->safe_psql(
322325
'postgres', qq(
323326
CREATE TABLE dropped_cols (a int, b_drop int, c int);
327+
CREATE TABLE generated_cols (a int, b_gen int GENERATED ALWAYS AS (5 * a) STORED, c int);
324328
));
325329

326330
my $publisher_connstr_d_cols =
@@ -342,6 +346,7 @@
342346
$node_publisher_d_cols->safe_psql(
343347
'postgres', qq(
344348
UPDATE dropped_cols SET a = 100;
349+
UPDATE generated_cols SET a = 100;
345350
));
346351
$node_publisher_d_cols->wait_for_catchup('sub_dropped_cols');
347352

@@ -350,5 +355,10 @@
350355
qq(1),
351356
'replication with RI FULL and dropped columns');
352357

358+
is( $node_subscriber_d_cols->safe_psql(
359+
'postgres', "SELECT count(*) FROM generated_cols WHERE a = 100"),
360+
qq(1),
361+
'replication with RI FULL and generated columns');
362+
353363
$node_publisher_d_cols->stop('fast');
354364
$node_subscriber_d_cols->stop('fast');

0 commit comments

Comments
 (0)