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

Commitb7ae039

Browse files
author
Amit Kapila
committed
Ignore dropped and generated columns from the column list.
We don't allow different column lists for the same table in the differentpublications of the single subscription. A publication with a column listexcept for dropped and generated columns should be considered the same asa publication with no column list (which implicitly includes all columnsas part of the columns list). However, as we were not excluding thedropped and generated columns from the column list combining suchpublications leads to an error "cannot use different column lists fortable ...".We decided not to backpatch this fix as there is a risk of users seeingthis as a behavior change and also we didn't see any field report of thiscase.Author: Shi yuReviewed-by: Amit KapilaDiscussion:https://postgr.es/m/OSZPR01MB631091CCBC56F195B1B9ACB0FDFE9@OSZPR01MB6310.jpnprd01.prod.outlook.com
1 parentdca8b01 commitb7ae039

File tree

6 files changed

+97
-6
lines changed

6 files changed

+97
-6
lines changed

‎src/backend/catalog/pg_publication.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,36 @@ pg_get_publication_tables(PG_FUNCTION_ARGS)
11531153
nulls[2]= true;
11541154
}
11551155

1156+
/* Show all columns when the column list is not specified. */
1157+
if (nulls[1]== true)
1158+
{
1159+
Relationrel=table_open(relid,AccessShareLock);
1160+
intnattnums=0;
1161+
int16*attnums;
1162+
TupleDescdesc=RelationGetDescr(rel);
1163+
inti;
1164+
1165+
attnums= (int16*)palloc(desc->natts*sizeof(int16));
1166+
1167+
for (i=0;i<desc->natts;i++)
1168+
{
1169+
Form_pg_attributeatt=TupleDescAttr(desc,i);
1170+
1171+
if (att->attisdropped||att->attgenerated)
1172+
continue;
1173+
1174+
attnums[nattnums++]=att->attnum;
1175+
}
1176+
1177+
if (nattnums>0)
1178+
{
1179+
values[1]=PointerGetDatum(buildint2vector(attnums,nattnums));
1180+
nulls[1]= false;
1181+
}
1182+
1183+
table_close(rel,AccessShareLock);
1184+
}
1185+
11561186
rettuple=heap_form_tuple(funcctx->tuple_desc,values,nulls);
11571187

11581188
SRF_RETURN_NEXT(funcctx,HeapTupleGetDatum(rettuple));

‎src/backend/catalog/system_views.sql

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,8 @@ CREATE VIEW pg_publication_tables AS
371371
C.relnameAS tablename,
372372
(SELECT array_agg(a.attnameORDER BYa.attnum)
373373
FROM pg_attribute a
374-
WHEREa.attrelid=GPT.relidANDa.attnum>0AND
375-
NOTa.attisdroppedAND
376-
(a.attnum= ANY(GPT.attrs)ORGPT.attrs ISNULL)
374+
WHEREa.attrelid=GPT.relidAND
375+
a.attnum= ANY(GPT.attrs)
377376
)AS attnames,
378377
pg_get_expr(GPT.qual,GPT.relid)AS rowfilter
379378
FROM pg_publication P,

‎src/backend/replication/pgoutput/pgoutput.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,16 +1058,31 @@ pgoutput_column_list_init(PGOutputData *data, List *publications,
10581058
/* Build the column list bitmap in the per-entry context. */
10591059
if (!pub_no_list)/* when not null */
10601060
{
1061+
inti;
1062+
intnliveatts=0;
1063+
TupleDescdesc=RelationGetDescr(relation);
1064+
10611065
pgoutput_ensure_entry_cxt(data,entry);
10621066

10631067
cols=pub_collist_to_bitmapset(cols,cfdatum,
10641068
entry->entry_cxt);
10651069

1070+
/* Get the number of live attributes. */
1071+
for (i=0;i<desc->natts;i++)
1072+
{
1073+
Form_pg_attributeatt=TupleDescAttr(desc,i);
1074+
1075+
if (att->attisdropped||att->attgenerated)
1076+
continue;
1077+
1078+
nliveatts++;
1079+
}
1080+
10661081
/*
10671082
* If column list includes all the columns of the table,
10681083
* set it to NULL.
10691084
*/
1070-
if (bms_num_members(cols)==RelationGetNumberOfAttributes(relation))
1085+
if (bms_num_members(cols)==nliveatts)
10711086
{
10721087
bms_free(cols);
10731088
cols=NULL;

‎src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@
5757
*/
5858

5959
/*yyyymmddN */
60-
#defineCATALOG_VERSION_NO202301092
60+
#defineCATALOG_VERSION_NO202301131
6161

6262
#endif

‎src/test/regress/expected/rules.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1446,7 +1446,7 @@ pg_publication_tables| SELECT p.pubname,
14461446
c.relname AS tablename,
14471447
( SELECT array_agg(a.attname ORDER BY a.attnum) AS array_agg
14481448
FROM pg_attribute a
1449-
WHERE ((a.attrelid = gpt.relid) AND (a.attnum> 0) AND (NOT a.attisdropped) AND ((a.attnum= ANY ((gpt.attrs)::smallint[])) OR (gpt.attrs IS NULL)))) AS attnames,
1449+
WHERE ((a.attrelid = gpt.relid) AND (a.attnum = ANY ((gpt.attrs)::smallint[])))) AS attnames,
14501450
pg_get_expr(gpt.qual, gpt.relid) AS rowfilter
14511451
FROM pg_publication p,
14521452
LATERAL pg_get_publication_tables((p.pubname)::text) gpt(relid, attrs, qual),

‎src/test/subscription/t/031_column_list.pl

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,53 @@
11841184
is($result,qq(t
11851185
t),'check the number of columns in the old tuple');
11861186

1187+
# TEST: Generated and dropped columns are not considered for the column list.
1188+
# So, the publication having a column list except for those columns and a
1189+
# publication without any column (aka all columns as part of the columns
1190+
# list) are considered to have the same column list.
1191+
$node_publisher->safe_psql(
1192+
'postgres',qq(
1193+
CREATE TABLE test_mix_4 (a int PRIMARY KEY, b int, c int, d int GENERATED ALWAYS AS (a + 1) STORED);
1194+
ALTER TABLE test_mix_4 DROP COLUMN c;
1195+
1196+
CREATE PUBLICATION pub_mix_7 FOR TABLE test_mix_4 (a, b);
1197+
CREATE PUBLICATION pub_mix_8 FOR TABLE test_mix_4;
1198+
1199+
-- initial data
1200+
INSERT INTO test_mix_4 VALUES (1, 2);
1201+
));
1202+
1203+
$node_subscriber->safe_psql(
1204+
'postgres',qq(
1205+
DROP SUBSCRIPTION sub1;
1206+
CREATE TABLE test_mix_4 (a int PRIMARY KEY, b int, c int, d int);
1207+
));
1208+
1209+
$node_subscriber->safe_psql(
1210+
'postgres',qq(
1211+
CREATE SUBSCRIPTION sub1 CONNECTION '$publisher_connstr' PUBLICATION pub_mix_7, pub_mix_8;
1212+
));
1213+
1214+
$node_subscriber->wait_for_subscription_sync;
1215+
1216+
is($node_subscriber->safe_psql(
1217+
'postgres',"SELECT * FROM test_mix_4 ORDER BY a"),
1218+
qq(1|2||),
1219+
'initial synchronization with multiple publications with the same column list'
1220+
);
1221+
1222+
$node_publisher->safe_psql(
1223+
'postgres',qq(
1224+
INSERT INTO test_mix_4 VALUES (3, 4);
1225+
));
1226+
1227+
$node_publisher->wait_for_catchup('sub1');
1228+
1229+
is($node_subscriber->safe_psql(
1230+
'postgres',"SELECT * FROM test_mix_4 ORDER BY a"),
1231+
qq(1|2||
1232+
3|4||),
1233+
'replication with multiple publications with the same column list');
11871234

11881235
# TEST: With a table included in multiple publications with different column
11891236
# lists, we should catch the error when creating the subscription.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp