public inbox for [email protected]
help / color / mirror / Atom feedFrom: [email protected] <[email protected]>
To: Önder Kalacı <[email protected]>
Cc: Amit Kapila <[email protected]>
Cc: PostgreSQL Hackers <[email protected]>
Subject: RE: Dropped and generated columns might cause wrong data on subs when REPLICA IDENTITY FULL
Date: Mon, 20 Mar 2023 07:18:22 +0000
Message-ID: <OSZPR01MB6310B8C55B6184B07958B0A9FD809@OSZPR01MB6310.jpnprd01.prod.outlook.com> (raw)
In-Reply-To: <CACawEhUAW2Jiwo3xwYSoB0rfjuWMtYhS_X+ZVHWXZBysjKPXKg@mail.gmail.com>
References: <CACawEhVQC9WoofunvXg12aXtbqKnEgWxoRx3+v8q32AWYsdpGg@mail.gmail.com>
<OSZPR01MB6310CE109F65A9B62A25CE1EFDB99@OSZPR01MB6310.jpnprd01.prod.outlook.com>
<CACawEhUCg-tRGzRqRq+qHaR+kPdZ=N1fP=A4_cCYd0LuNLUgnA@mail.gmail.com>
<CAA4eK1+ZXLQLCKOwEzvpCJ2XXapANY66S773zMbqbUL_7LBUiQ@mail.gmail.com>
<OSZPR01MB6310A7627F4587CB5547086AFDBC9@OSZPR01MB6310.jpnprd01.prod.outlook.com>
<CACawEhVCoCj5n1LUWBd12gd1S9ONkB3jf7fw5kK5njA==1X3rg@mail.gmail.com>
<CAA4eK1LLsHLnq9F62brVV3EfA7oqStJoQ6ki89Jy1UHBMRrYVA@mail.gmail.com>
<CACawEhWkFwQ5Zuu9NOQiJtjnQY+At8JuhKQ6cJ7wEvWv+Vb=+g@mail.gmail.com>
<OSZPR01MB63107F0FFFF821A14747277DFDBD9@OSZPR01MB6310.jpnprd01.prod.outlook.com>
<CACawEhUAW2Jiwo3xwYSoB0rfjuWMtYhS_X+ZVHWXZBysjKPXKg@mail.gmail.com>
On Fri, Mar 17, 2023 11:29 PM Önder Kalacı <[email protected]> wrote:
>
> Thanks for sharing. Fixed
>
>
> This time I was able to run all the tests with all the patches applied.
>
> Again, the generated column fix also has some minor differences
> per version. So, overall we have 6 patches with very minor
> differences :)
Thanks for updating the patches. It seems you forgot to attach the patches of
dropped columns for HEAD and pg15, I think they are the same as v2.
On HEAD, we can re-use clusters in other test cases, which can save some time.
(see fccaf259f22f4a)
In the patches for pg12 and pg11, I am not sure why not add the test at end of
the file 100_bugs.pl. I think it would be better to be consistent with other
versions.
The attached patches modify these two points. Besides, I made some minor
changes, ran pgindent and pgperltidy. These are patches for dropped columns,
because I think this would be submitted first, and we can discuss the fix for
generated columns later.
Regards,
Shi Yu
Attachments:
[application/octet-stream] v4-pg12-0001-Ignore-dropped-columns-when-REPLICA-IDENTITY-FUL.patch (3.9K, ../OSZPR01MB6310B8C55B6184B07958B0A9FD809@OSZPR01MB6310.jpnprd01.prod.outlook.com/2-v4-pg12-0001-Ignore-dropped-columns-when-REPLICA-IDENTITY-FUL.patch)
download | inline diff:
From 2630e83ff8e93ee4dea259ebee187fcb4a2a01c3 Mon Sep 17 00:00:00 2001
From: Cloud User
<pguser@citustestclustervm0.qn5vgvlwtv0erjkuazj1o4q4gb.bx.internal.cloudapp.net>
Date: Fri, 17 Mar 2023 14:37:30 +0000
Subject: [PATCH v12] Ignore dropped columns when REPLICA IDENTITY FULL
Dropped columns are filled with NULL values on slot_store_data()
but not on table_scan_getnextslot(). With this commit, we skip
such columns while checking tuple equality.
---
src/backend/executor/execReplication.c | 10 ++++-
src/test/subscription/t/100_bugs.pl | 57 +++++++++++++++++++++++++-
2 files changed, 64 insertions(+), 3 deletions(-)
diff --git a/src/backend/executor/execReplication.c b/src/backend/executor/execReplication.c
index 6289322127..02b3300213 100644
--- a/src/backend/executor/execReplication.c
+++ b/src/backend/executor/execReplication.c
@@ -242,6 +242,14 @@ tuples_equal(TupleTableSlot *slot1, TupleTableSlot *slot2)
Form_pg_attribute att;
TypeCacheEntry *typentry;
+ att = TupleDescAttr(slot1->tts_tupleDescriptor, attrnum);
+
+ /*
+ * Ignore dropped columns as the publisher doesn't send those
+ */
+ if (att->attisdropped)
+ continue;
+
/*
* If one value is NULL and other is not, then they are certainly not
* equal
@@ -255,8 +263,6 @@ tuples_equal(TupleTableSlot *slot1, TupleTableSlot *slot2)
if (slot1->tts_isnull[attrnum] || slot2->tts_isnull[attrnum])
continue;
- att = TupleDescAttr(slot1->tts_tupleDescriptor, attrnum);
-
typentry = lookup_type_cache(att->atttypid, TYPECACHE_EQ_OPR_FINFO);
if (!OidIsValid(typentry->eq_opr_finfo.fn_oid))
ereport(ERROR,
diff --git a/src/test/subscription/t/100_bugs.pl b/src/test/subscription/t/100_bugs.pl
index cbf46a3d33..e1a04b1a93 100644
--- a/src/test/subscription/t/100_bugs.pl
+++ b/src/test/subscription/t/100_bugs.pl
@@ -3,7 +3,7 @@ use strict;
use warnings;
use PostgresNode;
use TestLib;
-use Test::More tests => 5;
+use Test::More tests => 6;
# Bug #15114
@@ -179,3 +179,58 @@ is( $node_subscriber->safe_psql(
$node_publisher->stop('fast');
$node_subscriber->stop('fast');
+
+# The bug was that when the REPLICA IDENTITY FULL is used with dropped columns,
+# we fail to apply updates and deletes
+my $node_publisher_d_cols = get_new_node('node_publisher_d_cols');
+$node_publisher_d_cols->init(allows_streaming => 'logical');
+$node_publisher_d_cols->start;
+
+my $node_subscriber_d_cols = get_new_node('node_subscriber_d_cols');
+$node_subscriber_d_cols->init(allows_streaming => 'logical');
+$node_subscriber_d_cols->start;
+
+$node_publisher_d_cols->safe_psql(
+ 'postgres', qq(
+ CREATE TABLE dropped_cols (a int, b_drop int, c int);
+ ALTER TABLE dropped_cols REPLICA IDENTITY FULL;
+ CREATE PUBLICATION pub_dropped_cols FOR TABLE dropped_cols;
+ -- some initial data
+ INSERT INTO dropped_cols VALUES (1, 1, 1);
+));
+
+$node_subscriber_d_cols->safe_psql(
+ 'postgres', qq(
+ CREATE TABLE dropped_cols (a int, b_drop int, c int);
+));
+
+my $publisher_connstr_d_cols =
+ $node_publisher_d_cols->connstr . ' dbname=postgres';
+$node_subscriber_d_cols->safe_psql('postgres',
+ "CREATE SUBSCRIPTION sub_dropped_cols CONNECTION '$publisher_connstr_d_cols application_name=sub_dropped_cols' PUBLICATION pub_dropped_cols"
+);
+$node_subscriber_d_cols->wait_for_subscription_sync($node_publisher_d_cols,
+ 'sub_dropped_cols');
+
+$node_publisher_d_cols->safe_psql(
+ 'postgres', qq(
+ ALTER TABLE dropped_cols DROP COLUMN b_drop;
+));
+$node_subscriber_d_cols->safe_psql(
+ 'postgres', qq(
+ ALTER TABLE dropped_cols DROP COLUMN b_drop;
+));
+
+$node_publisher_d_cols->safe_psql(
+ 'postgres', qq(
+ UPDATE dropped_cols SET a = 100;
+));
+$node_publisher_d_cols->wait_for_catchup('sub_dropped_cols');
+
+is( $node_subscriber_d_cols->safe_psql(
+ 'postgres', "SELECT count(*) FROM dropped_cols WHERE a = 100"),
+ qq(1),
+ 'replication with RI FULL and dropped columns');
+
+$node_publisher_d_cols->stop('fast');
+$node_subscriber_d_cols->stop('fast');
--
2.31.1
[application/octet-stream] v4-pg13-pg14-0001-Ignore-dropped-columns-when-REPLICA-IDENTITY-FUL.patch (3.7K, ../OSZPR01MB6310B8C55B6184B07958B0A9FD809@OSZPR01MB6310.jpnprd01.prod.outlook.com/3-v4-pg13-pg14-0001-Ignore-dropped-columns-when-REPLICA-IDENTITY-FUL.patch)
download | inline diff:
From 5a64f6a0129350551e44f8f1fdab9fa65faf0af7 Mon Sep 17 00:00:00 2001
From: Cloud User
<pguser@citustestclustervm0.qn5vgvlwtv0erjkuazj1o4q4gb.bx.internal.cloudapp.net>
Date: Fri, 17 Mar 2023 14:54:52 +0000
Subject: [PATCH v14] Ignore dropped columns when REPLICA IDENTITY FULL
Dropped columns are filled with NULL values on slot_store_data()
but not on table_scan_getnextslot(). With this commit, we skip
such columns while checking tuple equality.
---
src/backend/executor/execReplication.c | 10 ++++-
src/test/subscription/t/100_bugs.pl | 56 +++++++++++++++++++++++++-
2 files changed, 63 insertions(+), 3 deletions(-)
diff --git a/src/backend/executor/execReplication.c b/src/backend/executor/execReplication.c
index 8f116b78cc..db7414eaf7 100644
--- a/src/backend/executor/execReplication.c
+++ b/src/backend/executor/execReplication.c
@@ -243,6 +243,14 @@ tuples_equal(TupleTableSlot *slot1, TupleTableSlot *slot2,
Form_pg_attribute att;
TypeCacheEntry *typentry;
+ att = TupleDescAttr(slot1->tts_tupleDescriptor, attrnum);
+
+ /*
+ * Ignore dropped columns as the publisher doesn't send those
+ */
+ if (att->attisdropped)
+ continue;
+
/*
* If one value is NULL and other is not, then they are certainly not
* equal
@@ -256,8 +264,6 @@ tuples_equal(TupleTableSlot *slot1, TupleTableSlot *slot2,
if (slot1->tts_isnull[attrnum] || slot2->tts_isnull[attrnum])
continue;
- att = TupleDescAttr(slot1->tts_tupleDescriptor, attrnum);
-
typentry = eq[attrnum];
if (typentry == NULL)
{
diff --git a/src/test/subscription/t/100_bugs.pl b/src/test/subscription/t/100_bugs.pl
index 91602c4339..b9da72eaf2 100644
--- a/src/test/subscription/t/100_bugs.pl
+++ b/src/test/subscription/t/100_bugs.pl
@@ -6,7 +6,7 @@ use strict;
use warnings;
use PostgresNode;
use TestLib;
-use Test::More tests => 7;
+use Test::More tests => 8;
# Bug #15114
@@ -298,3 +298,57 @@ is( $node_subscriber->safe_psql(
$node_publisher->stop('fast');
$node_subscriber->stop('fast');
+
+# The bug was that when the REPLICA IDENTITY FULL is used with dropped columns,
+# we fail to apply updates and deletes
+my $node_publisher_d_cols = get_new_node('node_publisher_d_cols');
+$node_publisher_d_cols->init(allows_streaming => 'logical');
+$node_publisher_d_cols->start;
+
+my $node_subscriber_d_cols = get_new_node('node_subscriber_d_cols');
+$node_subscriber_d_cols->init(allows_streaming => 'logical');
+$node_subscriber_d_cols->start;
+
+$node_publisher_d_cols->safe_psql(
+ 'postgres', qq(
+ CREATE TABLE dropped_cols (a int, b_drop int, c int);
+ ALTER TABLE dropped_cols REPLICA IDENTITY FULL;
+ CREATE PUBLICATION pub_dropped_cols FOR TABLE dropped_cols;
+ -- some initial data
+ INSERT INTO dropped_cols VALUES (1, 1, 1);
+));
+
+$node_subscriber_d_cols->safe_psql(
+ 'postgres', qq(
+ CREATE TABLE dropped_cols (a int, b_drop int, c int);
+));
+
+my $publisher_connstr_d_cols =
+ $node_publisher_d_cols->connstr . ' dbname=postgres';
+$node_subscriber_d_cols->safe_psql('postgres',
+ "CREATE SUBSCRIPTION sub_dropped_cols CONNECTION '$publisher_connstr_d_cols' PUBLICATION pub_dropped_cols"
+);
+$node_subscriber_d_cols->wait_for_subscription_sync;
+
+$node_publisher_d_cols->safe_psql(
+ 'postgres', qq(
+ ALTER TABLE dropped_cols DROP COLUMN b_drop;
+));
+$node_subscriber_d_cols->safe_psql(
+ 'postgres', qq(
+ ALTER TABLE dropped_cols DROP COLUMN b_drop;
+));
+
+$node_publisher_d_cols->safe_psql(
+ 'postgres', qq(
+ UPDATE dropped_cols SET a = 100;
+));
+$node_publisher_d_cols->wait_for_catchup('sub_dropped_cols');
+
+is( $node_subscriber_d_cols->safe_psql(
+ 'postgres', "SELECT count(*) FROM dropped_cols WHERE a = 100"),
+ qq(1),
+ 'replication with RI FULL and dropped columns');
+
+$node_publisher_d_cols->stop('fast');
+$node_subscriber_d_cols->stop('fast');
--
2.31.1
[application/octet-stream] v4-pg15-0001-Ignore-dropped-columns-when-REPLICA-IDENTITY-FUL.patch (3.6K, ../OSZPR01MB6310B8C55B6184B07958B0A9FD809@OSZPR01MB6310.jpnprd01.prod.outlook.com/4-v4-pg15-0001-Ignore-dropped-columns-when-REPLICA-IDENTITY-FUL.patch)
download | inline diff:
From 7136dc5b58ecf27866a9d4900ad362a53421d8ea Mon Sep 17 00:00:00 2001
From: Onder Kalaci <[email protected]>
Date: Thu, 16 Mar 2023 18:06:54 +0300
Subject: [PATCH v15] Ignore dropped columns when REPLICA IDENTITY FULL
Dropped columns are filled with NULL values on slot_store_data()
but not on table_scan_getnextslot(). With this commit, we skip
such columns while checking tuple equality.
---
src/backend/executor/execReplication.c | 10 ++++-
src/test/subscription/t/100_bugs.pl | 56 ++++++++++++++++++++++++++
2 files changed, 64 insertions(+), 2 deletions(-)
diff --git a/src/backend/executor/execReplication.c b/src/backend/executor/execReplication.c
index 6014f2e248..f37119670e 100644
--- a/src/backend/executor/execReplication.c
+++ b/src/backend/executor/execReplication.c
@@ -243,6 +243,14 @@ tuples_equal(TupleTableSlot *slot1, TupleTableSlot *slot2,
Form_pg_attribute att;
TypeCacheEntry *typentry;
+ att = TupleDescAttr(slot1->tts_tupleDescriptor, attrnum);
+
+ /*
+ * Ignore dropped columns as the publisher doesn't send those
+ */
+ if (att->attisdropped)
+ continue;
+
/*
* If one value is NULL and other is not, then they are certainly not
* equal
@@ -256,8 +264,6 @@ tuples_equal(TupleTableSlot *slot1, TupleTableSlot *slot2,
if (slot1->tts_isnull[attrnum] || slot2->tts_isnull[attrnum])
continue;
- att = TupleDescAttr(slot1->tts_tupleDescriptor, attrnum);
-
typentry = eq[attrnum];
if (typentry == NULL)
{
diff --git a/src/test/subscription/t/100_bugs.pl b/src/test/subscription/t/100_bugs.pl
index 6247aa7730..e8ad45f426 100644
--- a/src/test/subscription/t/100_bugs.pl
+++ b/src/test/subscription/t/100_bugs.pl
@@ -299,4 +299,60 @@ is( $node_subscriber->safe_psql(
$node_publisher->stop('fast');
$node_subscriber->stop('fast');
+# The bug was that when the REPLICA IDENTITY FULL is used with dropped columns,
+# we fail to apply updates and deletes
+my $node_publisher_d_cols =
+ PostgreSQL::Test::Cluster->new('node_publisher_d_cols');
+$node_publisher_d_cols->init(allows_streaming => 'logical');
+$node_publisher_d_cols->start;
+
+my $node_subscriber_d_cols =
+ PostgreSQL::Test::Cluster->new('node_subscriber_d_cols');
+$node_subscriber_d_cols->init(allows_streaming => 'logical');
+$node_subscriber_d_cols->start;
+
+$node_publisher_d_cols->safe_psql(
+ 'postgres', qq(
+ CREATE TABLE dropped_cols (a int, b_drop int, c int);
+ ALTER TABLE dropped_cols REPLICA IDENTITY FULL;
+ CREATE PUBLICATION pub_dropped_cols FOR TABLE dropped_cols;
+ -- some initial data
+ INSERT INTO dropped_cols VALUES (1, 1, 1);
+));
+
+$node_subscriber_d_cols->safe_psql(
+ 'postgres', qq(
+ CREATE TABLE dropped_cols (a int, b_drop int, c int);
+));
+
+my $publisher_connstr_d_cols =
+ $node_publisher_d_cols->connstr . ' dbname=postgres';
+$node_subscriber_d_cols->safe_psql('postgres',
+ "CREATE SUBSCRIPTION sub_dropped_cols CONNECTION '$publisher_connstr_d_cols' PUBLICATION pub_dropped_cols"
+);
+$node_subscriber_d_cols->wait_for_subscription_sync;
+
+$node_publisher_d_cols->safe_psql(
+ 'postgres', qq(
+ ALTER TABLE dropped_cols DROP COLUMN b_drop;
+));
+$node_subscriber_d_cols->safe_psql(
+ 'postgres', qq(
+ ALTER TABLE dropped_cols DROP COLUMN b_drop;
+));
+
+$node_publisher_d_cols->safe_psql(
+ 'postgres', qq(
+ UPDATE dropped_cols SET a = 100;
+));
+$node_publisher_d_cols->wait_for_catchup('sub_dropped_cols');
+
+is( $node_subscriber_d_cols->safe_psql(
+ 'postgres', "SELECT count(*) FROM dropped_cols WHERE a = 100"),
+ qq(1),
+ 'replication with RI FULL and dropped columns');
+
+$node_publisher_d_cols->stop('fast');
+$node_subscriber_d_cols->stop('fast');
+
done_testing();
--
2.31.1
[application/octet-stream] v4-HEAD-0001-Ignore-dropped-columns-when-REPLICA-IDENTITY-FULL.patch (3.6K, ../OSZPR01MB6310B8C55B6184B07958B0A9FD809@OSZPR01MB6310.jpnprd01.prod.outlook.com/5-v4-HEAD-0001-Ignore-dropped-columns-when-REPLICA-IDENTITY-FULL.patch)
download | inline diff:
From 4d8d7ef3a565c53b7b463b609995276fc16f1f82 Mon Sep 17 00:00:00 2001
From: Onder Kalaci <[email protected]>
Date: Thu, 16 Mar 2023 18:06:54 +0300
Subject: [PATCH v4] Ignore dropped columns when REPLICA IDENTITY FULL
Dropped columns are filled with NULL values on slot_store_data()
but not on table_scan_getnextslot(). With this commit, we skip
such columns while checking tuple equality.
---
src/backend/executor/execReplication.c | 10 ++++-
src/test/subscription/t/100_bugs.pl | 55 ++++++++++++++++++++++++++
2 files changed, 63 insertions(+), 2 deletions(-)
diff --git a/src/backend/executor/execReplication.c b/src/backend/executor/execReplication.c
index fa8628e3e1..652732c6ed 100644
--- a/src/backend/executor/execReplication.c
+++ b/src/backend/executor/execReplication.c
@@ -289,6 +289,14 @@ tuples_equal(TupleTableSlot *slot1, TupleTableSlot *slot2,
Form_pg_attribute att;
TypeCacheEntry *typentry;
+ att = TupleDescAttr(slot1->tts_tupleDescriptor, attrnum);
+
+ /*
+ * Ignore dropped columns as the publisher doesn't send those
+ */
+ if (att->attisdropped)
+ continue;
+
/*
* If one value is NULL and other is not, then they are certainly not
* equal
@@ -302,8 +310,6 @@ tuples_equal(TupleTableSlot *slot1, TupleTableSlot *slot2,
if (slot1->tts_isnull[attrnum] || slot2->tts_isnull[attrnum])
continue;
- att = TupleDescAttr(slot1->tts_tupleDescriptor, attrnum);
-
typentry = eq[attrnum];
if (typentry == NULL)
{
diff --git a/src/test/subscription/t/100_bugs.pl b/src/test/subscription/t/100_bugs.pl
index 036576acab..549a1b5fe3 100644
--- a/src/test/subscription/t/100_bugs.pl
+++ b/src/test/subscription/t/100_bugs.pl
@@ -370,6 +370,61 @@ $result = $node_subscriber->safe_psql('postgres', "SELECT * FROM sch2.t1");
is( $result, qq(1
3), 'check data in subscriber sch2.t1 after schema rename');
+# Again, drop replication state but not tables.
+$node_subscriber->safe_psql('postgres', "DROP SUBSCRIPTION tap_sub_sch");
+$node_publisher->safe_psql('postgres', "DROP PUBLICATION tap_pub_sch");
+
+$node_publisher->stop('fast');
+$node_subscriber->stop('fast');
+
+# The bug was that when the REPLICA IDENTITY FULL is used with dropped columns,
+# we fail to apply updates and deletes
+$node_publisher->rotate_logfile();
+$node_publisher->start();
+
+$node_subscriber->rotate_logfile();
+$node_subscriber->start();
+
+$node_publisher->safe_psql(
+ 'postgres', qq(
+ CREATE TABLE dropped_cols (a int, b_drop int, c int);
+ ALTER TABLE dropped_cols REPLICA IDENTITY FULL;
+ CREATE PUBLICATION pub_dropped_cols FOR TABLE dropped_cols;
+ -- some initial data
+ INSERT INTO dropped_cols VALUES (1, 1, 1);
+));
+
+$node_subscriber->safe_psql(
+ 'postgres', qq(
+ CREATE TABLE dropped_cols (a int, b_drop int, c int);
+));
+
+$publisher_connstr = $node_publisher->connstr . ' dbname=postgres';
+$node_subscriber->safe_psql('postgres',
+ "CREATE SUBSCRIPTION sub_dropped_cols CONNECTION '$publisher_connstr' PUBLICATION pub_dropped_cols"
+);
+$node_subscriber->wait_for_subscription_sync;
+
+$node_publisher->safe_psql(
+ 'postgres', qq(
+ ALTER TABLE dropped_cols DROP COLUMN b_drop;
+));
+$node_subscriber->safe_psql(
+ 'postgres', qq(
+ ALTER TABLE dropped_cols DROP COLUMN b_drop;
+));
+
+$node_publisher->safe_psql(
+ 'postgres', qq(
+ UPDATE dropped_cols SET a = 100;
+));
+$node_publisher->wait_for_catchup('sub_dropped_cols');
+
+is( $node_subscriber->safe_psql(
+ 'postgres', "SELECT count(*) FROM dropped_cols WHERE a = 100"),
+ qq(1),
+ 'replication with RI FULL and dropped columns');
+
$node_publisher->stop('fast');
$node_subscriber->stop('fast');
--
2.31.1
[application/octet-stream] v4-pg11-0001-Ignore-dropped-columns-when-REPLICA-IDENTITY-FUL.patch (3.9K, ../OSZPR01MB6310B8C55B6184B07958B0A9FD809@OSZPR01MB6310.jpnprd01.prod.outlook.com/6-v4-pg11-0001-Ignore-dropped-columns-when-REPLICA-IDENTITY-FUL.patch)
download | inline diff:
From 5798dbd131485355ffd674dbd6aa86dedfffb032 Mon Sep 17 00:00:00 2001
From: Cloud User
<pguser@citustestclustervm0.qn5vgvlwtv0erjkuazj1o4q4gb.bx.internal.cloudapp.net>
Date: Fri, 17 Mar 2023 14:20:10 +0000
Subject: [PATCH v11] Ignore dropped columns when REPLICA IDENTITY FULL
Dropped columns are filled with NULL values on slot_store_data()
but not on table_scan_getnextslot(). With this commit, we skip
such columns while checking tuple equality.
---
src/backend/executor/execReplication.c | 10 ++++-
src/test/subscription/t/100_bugs.pl | 57 +++++++++++++++++++++++++-
2 files changed, 64 insertions(+), 3 deletions(-)
diff --git a/src/backend/executor/execReplication.c b/src/backend/executor/execReplication.c
index 108162bb35..f54759425b 100644
--- a/src/backend/executor/execReplication.c
+++ b/src/backend/executor/execReplication.c
@@ -236,6 +236,14 @@ tuple_equals_slot(TupleDesc desc, HeapTuple tup, TupleTableSlot *slot)
Form_pg_attribute att;
TypeCacheEntry *typentry;
+ att = TupleDescAttr(desc, attrnum);
+
+ /*
+ * Ignore dropped columns as the publisher doesn't send those
+ */
+ if (att->attisdropped)
+ continue;
+
/*
* If one value is NULL and other is not, then they are certainly not
* equal
@@ -249,8 +257,6 @@ tuple_equals_slot(TupleDesc desc, HeapTuple tup, TupleTableSlot *slot)
if (isnull[attrnum])
continue;
- att = TupleDescAttr(desc, attrnum);
-
typentry = lookup_type_cache(att->atttypid, TYPECACHE_EQ_OPR_FINFO);
if (!OidIsValid(typentry->eq_opr_finfo.fn_oid))
ereport(ERROR,
diff --git a/src/test/subscription/t/100_bugs.pl b/src/test/subscription/t/100_bugs.pl
index 08e5f0bcb0..564e099e40 100644
--- a/src/test/subscription/t/100_bugs.pl
+++ b/src/test/subscription/t/100_bugs.pl
@@ -3,7 +3,7 @@ use strict;
use warnings;
use PostgresNode;
use TestLib;
-use Test::More tests => 5;
+use Test::More tests => 6;
# Bug #15114
@@ -177,3 +177,58 @@ is( $node_subscriber->safe_psql(
$node_publisher->stop('fast');
$node_subscriber->stop('fast');
+
+# The bug was that when the REPLICA IDENTITY FULL is used with dropped columns,
+# we fail to apply updates and deletes
+my $node_publisher_d_cols = get_new_node('node_publisher_d_cols');
+$node_publisher_d_cols->init(allows_streaming => 'logical');
+$node_publisher_d_cols->start;
+
+my $node_subscriber_d_cols = get_new_node('node_subscriber_d_cols');
+$node_subscriber_d_cols->init(allows_streaming => 'logical');
+$node_subscriber_d_cols->start;
+
+$node_publisher_d_cols->safe_psql(
+ 'postgres', qq(
+ CREATE TABLE dropped_cols (a int, b_drop int, c int);
+ ALTER TABLE dropped_cols REPLICA IDENTITY FULL;
+ CREATE PUBLICATION pub_dropped_cols FOR TABLE dropped_cols;
+ -- some initial data
+ INSERT INTO dropped_cols VALUES (1, 1, 1);
+));
+
+$node_subscriber_d_cols->safe_psql(
+ 'postgres', qq(
+ CREATE TABLE dropped_cols (a int, b_drop int, c int);
+));
+
+my $publisher_connstr_d_cols =
+ $node_publisher_d_cols->connstr . ' dbname=postgres';
+$node_subscriber_d_cols->safe_psql('postgres',
+ "CREATE SUBSCRIPTION sub_dropped_cols CONNECTION '$publisher_connstr_d_cols application_name=sub_dropped_cols' PUBLICATION pub_dropped_cols"
+);
+$node_subscriber_d_cols->wait_for_subscription_sync($node_publisher_d_cols,
+ 'sub_dropped_cols');
+
+$node_publisher_d_cols->safe_psql(
+ 'postgres', qq(
+ ALTER TABLE dropped_cols DROP COLUMN b_drop;
+));
+$node_subscriber_d_cols->safe_psql(
+ 'postgres', qq(
+ ALTER TABLE dropped_cols DROP COLUMN b_drop;
+));
+
+$node_publisher_d_cols->safe_psql(
+ 'postgres', qq(
+ UPDATE dropped_cols SET a = 100;
+));
+$node_publisher_d_cols->wait_for_catchup('sub_dropped_cols');
+
+is( $node_subscriber_d_cols->safe_psql(
+ 'postgres', "SELECT count(*) FROM dropped_cols WHERE a = 100"),
+ qq(1),
+ 'replication with RI FULL and dropped columns');
+
+$node_publisher_d_cols->stop('fast');
+$node_subscriber_d_cols->stop('fast');
--
2.30.0.windows.2
view thread (5+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected]
Subject: RE: Dropped and generated columns might cause wrong data on subs when REPLICA IDENTITY FULL
In-Reply-To: <OSZPR01MB6310B8C55B6184B07958B0A9FD809@OSZPR01MB6310.jpnprd01.prod.outlook.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox