Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ad3ae64

Browse files
committed
Fill in extraUpdatedCols in logical replication
The extraUpdatedCols field of the target RTE records which generated columns are affected by an update. This is used in a variety of places, including per-column triggers and foreign data wrappers. When an update was initiated by a logical replication subscription, this field was not filled in, so such an update would not affect generated columns in a way that is consistent with normal updates. To fix, factor out some code from analyze.c to fill in extraUpdatedCols in the logical replication worker as well. Reviewed-by: Pavel Stehule <pavel.stehule@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/b05e781a-fa16-6b52-6738-761181204567@2ndquadrant.com
1 parent f4ae722 commit ad3ae64

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

src/backend/parser/analyze.c

+12-6
Original file line numberDiff line numberDiff line change
@@ -2346,10 +2346,18 @@ transformUpdateTargetList(ParseState *pstate, List *origTlist)
23462346
if (orig_tl != NULL)
23472347
elog(ERROR, "UPDATE target count mismatch --- internal error");
23482348

2349-
/*
2350-
* Record in extraUpdatedCols generated columns referencing updated base
2351-
* columns.
2352-
*/
2349+
fill_extraUpdatedCols(target_rte, tupdesc);
2350+
2351+
return tlist;
2352+
}
2353+
2354+
/*
2355+
* Record in extraUpdatedCols generated columns referencing updated base
2356+
* columns.
2357+
*/
2358+
void
2359+
fill_extraUpdatedCols(RangeTblEntry *target_rte, TupleDesc tupdesc)
2360+
{
23532361
if (tupdesc->constr &&
23542362
tupdesc->constr->has_generated_stored)
23552363
{
@@ -2371,8 +2379,6 @@ transformUpdateTargetList(ParseState *pstate, List *origTlist)
23712379
defval.adnum - FirstLowInvalidHeapAttributeNumber);
23722380
}
23732381
}
2374-
2375-
return tlist;
23762382
}
23772383

23782384
/*

src/backend/replication/logical/worker.c

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "miscadmin.h"
4343
#include "nodes/makefuncs.h"
4444
#include "optimizer/optimizer.h"
45+
#include "parser/analyze.h"
4546
#include "parser/parse_relation.h"
4647
#include "pgstat.h"
4748
#include "postmaster/bgworker.h"
@@ -737,6 +738,8 @@ apply_handle_update(StringInfo s)
737738
i + 1 - FirstLowInvalidHeapAttributeNumber);
738739
}
739740

741+
fill_extraUpdatedCols(target_rte, RelationGetDescr(rel->localrel));
742+
740743
PushActiveSnapshot(GetTransactionSnapshot());
741744
ExecOpenIndices(estate->es_result_relation_info, false);
742745

src/include/parser/analyze.h

+2
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,6 @@ extern void applyLockingClause(Query *qry, Index rtindex,
4646
extern List *BuildOnConflictExcludedTargetlist(Relation targetrel,
4747
Index exclRelIndex);
4848

49+
extern void fill_extraUpdatedCols(RangeTblEntry *target_rte, TupleDesc tupdesc);
50+
4951
#endif /* ANALYZE_H */

0 commit comments

Comments
 (0)