Commit ad3ae647 authored by Peter Eisentraut's avatar Peter Eisentraut

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: default avatarPavel Stehule <pavel.stehule@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/b05e781a-fa16-6b52-6738-761181204567@2ndquadrant.com
parent f4ae7221
...@@ -2346,10 +2346,18 @@ transformUpdateTargetList(ParseState *pstate, List *origTlist) ...@@ -2346,10 +2346,18 @@ transformUpdateTargetList(ParseState *pstate, List *origTlist)
if (orig_tl != NULL) if (orig_tl != NULL)
elog(ERROR, "UPDATE target count mismatch --- internal error"); elog(ERROR, "UPDATE target count mismatch --- internal error");
/* fill_extraUpdatedCols(target_rte, tupdesc);
* Record in extraUpdatedCols generated columns referencing updated base
* columns. return tlist;
*/ }
/*
* Record in extraUpdatedCols generated columns referencing updated base
* columns.
*/
void
fill_extraUpdatedCols(RangeTblEntry *target_rte, TupleDesc tupdesc)
{
if (tupdesc->constr && if (tupdesc->constr &&
tupdesc->constr->has_generated_stored) tupdesc->constr->has_generated_stored)
{ {
...@@ -2371,8 +2379,6 @@ transformUpdateTargetList(ParseState *pstate, List *origTlist) ...@@ -2371,8 +2379,6 @@ transformUpdateTargetList(ParseState *pstate, List *origTlist)
defval.adnum - FirstLowInvalidHeapAttributeNumber); defval.adnum - FirstLowInvalidHeapAttributeNumber);
} }
} }
return tlist;
} }
/* /*
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include "miscadmin.h" #include "miscadmin.h"
#include "nodes/makefuncs.h" #include "nodes/makefuncs.h"
#include "optimizer/optimizer.h" #include "optimizer/optimizer.h"
#include "parser/analyze.h"
#include "parser/parse_relation.h" #include "parser/parse_relation.h"
#include "pgstat.h" #include "pgstat.h"
#include "postmaster/bgworker.h" #include "postmaster/bgworker.h"
...@@ -737,6 +738,8 @@ apply_handle_update(StringInfo s) ...@@ -737,6 +738,8 @@ apply_handle_update(StringInfo s)
i + 1 - FirstLowInvalidHeapAttributeNumber); i + 1 - FirstLowInvalidHeapAttributeNumber);
} }
fill_extraUpdatedCols(target_rte, RelationGetDescr(rel->localrel));
PushActiveSnapshot(GetTransactionSnapshot()); PushActiveSnapshot(GetTransactionSnapshot());
ExecOpenIndices(estate->es_result_relation_info, false); ExecOpenIndices(estate->es_result_relation_info, false);
......
...@@ -46,4 +46,6 @@ extern void applyLockingClause(Query *qry, Index rtindex, ...@@ -46,4 +46,6 @@ extern void applyLockingClause(Query *qry, Index rtindex,
extern List *BuildOnConflictExcludedTargetlist(Relation targetrel, extern List *BuildOnConflictExcludedTargetlist(Relation targetrel,
Index exclRelIndex); Index exclRelIndex);
extern void fill_extraUpdatedCols(RangeTblEntry *target_rte, TupleDesc tupdesc);
#endif /* ANALYZE_H */ #endif /* ANALYZE_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment