8000 Ignore dropped columns during apply of update/delete. · postgres/postgres@4cdaea7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4cdaea7

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

File tree

2 files changed

+64
-3
lines changed

2 files changed

+64
-3
lines changed

src/backend/executor/execReplication.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,14 @@ tuple_equals_slot(TupleDesc desc, HeapTuple tup, TupleTableSlot *slot)
236236
Form_pg_attribute att;
237237
TypeCacheEntry *typentry;
238238

239+
att = TupleDescAttr(desc, attrnum);
240+
241+
/*
242+
* Ignore dropped columns as the publisher doesn't send those
243+
*/
244+
if (att->attisdropped)
245+
continue;
246+
239247
/*
240248
* If one value is NULL and other is not, then they are certainly not
241249
* equal
@@ -249,8 +257,6 @@ tuple_equals_slot(TupleDesc desc, HeapTuple tup, TupleTableSlot *slot)
249257
if (isnull[attrnum])
250258
continue;
251259

252-
att = TupleDescAttr(desc, attrnum);
253-
254260
typentry = lookup_type_cache(att->atttypid, TYPECACHE_EQ_OPR_FINFO);
255261
if (!OidIsValid(typentry->eq_opr_finfo.fn_oid))
256262
ereport(ERROR,

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

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use warnings;
44
use PostgresNode;
55
use TestLib;
6-
use Test::More tests => 5;
6+
use Test::More tests => 6;
77

88
# Bug #15114
99

@@ -177,3 +177,58 @@
177177

178178
$node_publisher->stop('fast');
179179
$node_subscriber->stop('fast');
180+
181+
# The bug was that when the REPLICA IDENTITY FULL is used with dropped columns,
182+
# we fail to apply updates and deletes
183+
my $node_publisher_d_cols = get_new_node('node_publisher_d_cols');
184+
$node_publisher_d_cols->init(allows_streaming => 'logical');
185+
$node_publisher_d_cols->start;
186+
187+
my $node_subscriber_d_cols = get_new_node('node_subscriber_d_cols');
188+
$node_subscriber_d_cols->init(allows_streaming => 'logical');
189+
$node_subscriber_d_cols->start;
190+
191+
$node_publisher_d_cols->safe_psql(
192+
'postgres', qq(
193+
CREATE TABLE dropped_cols (a int, b_drop int, c int);
194+
ALTER TABLE dropped_cols REPLICA IDENTITY FULL;
195+
CREATE PUBLICATION pub_dropped_cols FOR TABLE dropped_cols;
196+
-- some initial data
197+
INSERT INTO dropped_cols VALUES (1, 1, 1);
198+
));
199+
200+
$node_subscriber_d_cols->safe_psql(
201+
'postgres', qq(
202+
CREATE TABLE dropped_cols (a int, b_drop int, c int);
203+
));
204+
205+
my $publisher_connstr_d_cols =
206+
$node_publisher_d_cols->connstr . ' dbname=postgres';
207+
$node_subscriber_d_cols->safe_psql('postgres',
208+
"CREATE SUBSCRIPTION sub_dropped_cols CONNECTION '$publisher_connstr_d_cols application_name=sub_dropped_cols' PUBLICATION pub_dropped_cols"
209+
);
210+
$node_subscriber_d_cols->wait_for_subscription_sync($node_publisher_d_cols,
211+
'sub_dropped_cols');
212+
213+
$node_publisher_d_cols->safe_psql(
214+
'postgres', qq(
215+
ALTER TABLE dropped_cols DROP COLUMN b_drop;
216+
));
217+
$node_subscriber_d_cols->safe_psql(
218+
'postgres', qq(
219+
ALTER TABLE dropped_cols DROP COLUMN b_drop;
220+
));
221+
222+
$node_publisher_d_cols->safe_psql(
223+
'postgres', qq(
224+
UPDATE dropped_cols SET a = 100;
225+
));
226+
$node_publisher_d_cols->wait_for_catchup('sub_dropped_cols');
227+
228+
is( $node_subscriber_d_cols->safe_psql(
229+
'postgres', "SELECT count(*) FROM dropped_cols WHERE a = 100"),
230+
qq(1),
231+
'replication with RI FULL and dropped columns');
232+
233+
$node_publisher_d_cols->stop('fast');
234+
$node_subscriber_d_cols->stop('fast');

0 commit comments

Comments
 (0)
0