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

Appearance settings

Commit ad3ae64

Browse filesBrowse 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
Copy full SHA for ad3ae64

File tree

Expand file treeCollapse file tree

3 files changed

+17
-6
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+17
-6
lines changed

‎src/backend/parser/analyze.c

Copy file name to clipboardExpand all lines: src/backend/parser/analyze.c
+12-6Lines changed: 12 additions & 6 deletions
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

Copy file name to clipboardExpand all lines: src/backend/replication/logical/worker.c
+3Lines changed: 3 additions & 0 deletions
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

Copy file name to clipboardExpand all lines: src/include/parser/analyze.h
+2Lines changed: 2 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.