mirror of
https://github.com/postgres/postgres.git
synced 2025-11-21 00:42:43 +03:00
Replicate generated columns when specified in the column list.
This commit allows logical replication to publish and replicate generated columns when explicitly listed in the column list. We also ensured that the generated columns were copied during the initial tablesync when they were published. We will allow to replicate generated columns even when they are not specified in the column list (via a new publication option) in a separate commit. The motivation of this work is to allow replication for cases where the client doesn't have generated columns. For example, the case where one is trying to replicate data from Postgres to the non-Postgres database. Author: Shubham Khanna, Vignesh C, Hou Zhijie Reviewed-by: Peter Smith, Hayato Kuroda, Shlok Kyal, Amit Kapila Discussion: https://postgr.es/m/B80D17B2-2C8E-4C7D-87F2-E5B4BE3C069E@gmail.com
This commit is contained in:
@@ -766,16 +766,12 @@ send_relation_and_attrs(Relation relation, TransactionId xid,
|
||||
{
|
||||
Form_pg_attribute att = TupleDescAttr(desc, i);
|
||||
|
||||
if (att->attisdropped || att->attgenerated)
|
||||
if (!logicalrep_should_publish_column(att, columns))
|
||||
continue;
|
||||
|
||||
if (att->atttypid < FirstGenbkiObjectId)
|
||||
continue;
|
||||
|
||||
/* Skip this attribute if it's not present in the column list */
|
||||
if (columns != NULL && !bms_is_member(att->attnum, columns))
|
||||
continue;
|
||||
|
||||
OutputPluginPrepareWrite(ctx, false);
|
||||
logicalrep_write_typ(ctx->out, xid, att->atttypid);
|
||||
OutputPluginWrite(ctx, false);
|
||||
@@ -1074,6 +1070,7 @@ pgoutput_column_list_init(PGOutputData *data, List *publications,
|
||||
int i;
|
||||
int nliveatts = 0;
|
||||
TupleDesc desc = RelationGetDescr(relation);
|
||||
bool att_gen_present = false;
|
||||
|
||||
pgoutput_ensure_entry_cxt(data, entry);
|
||||
|
||||
@@ -1085,17 +1082,30 @@ pgoutput_column_list_init(PGOutputData *data, List *publications,
|
||||
{
|
||||
Form_pg_attribute att = TupleDescAttr(desc, i);
|
||||
|
||||
if (att->attisdropped || att->attgenerated)
|
||||
if (att->attisdropped)
|
||||
continue;
|
||||
|
||||
if (att->attgenerated)
|
||||
{
|
||||
/*
|
||||
* Generated cols are skipped unless they are
|
||||
* present in a column list.
|
||||
*/
|
||||
if (!bms_is_member(att->attnum, cols))
|
||||
continue;
|
||||
|
||||
att_gen_present = true;
|
||||
}
|
||||
|
||||
nliveatts++;
|
||||
}
|
||||
|
||||
/*
|
||||
* If column list includes all the columns of the table,
|
||||
* set it to NULL.
|
||||
* Generated attributes are published only when they are
|
||||
* present in the column list. Otherwise, a NULL column
|
||||
* list means publish all columns.
|
||||
*/
|
||||
if (bms_num_members(cols) == nliveatts)
|
||||
if (!att_gen_present && bms_num_members(cols) == nliveatts)
|
||||
{
|
||||
bms_free(cols);
|
||||
cols = NULL;
|
||||
|
||||
Reference in New Issue
Block a user