Skip to content

Commit f7d62b5

Browse files
committed
copy relkind in handle_modification_query()
1 parent caf6194 commit f7d62b5

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/planner_tree_modification.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
#include "partition_filter.h"
1717
#include "planner_tree_modification.h"
1818

19+
#include "access/htup_details.h"
1920
#include "miscadmin.h"
2021
#include "optimizer/clauses.h"
2122
#include "storage/lmgr.h"
23+
#include "utils/lsyscache.h"
2224
#include "utils/syscache.h"
2325

2426

@@ -302,9 +304,23 @@ handle_modification_query(Query *parse)
302304

303305
LOCKMODE lockmode = RowExclusiveLock; /* UPDATE | DELETE */
304306

305-
/* Make sure that 'child' exists */
307+
HeapTuple syscache_htup;
308+
char child_relkind;
309+
310+
/* Lock 'child' table */
306311
LockRelationOid(child, lockmode);
307-
if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(child)))
312+
313+
/* Make sure that 'child' exists */
314+
syscache_htup = SearchSysCache1(RELOID, ObjectIdGetDatum(child));
315+
if (HeapTupleIsValid(syscache_htup))
316+
{
317+
Form_pg_class reltup = (Form_pg_class) GETSTRUCT(syscache_htup);
318+
319+
/* Fetch child's relkind and free cache entry */
320+
child_relkind = reltup->relkind;
321+
ReleaseSysCache(syscache_htup);
322+
}
323+
else
308324
{
309325
UnlockRelationOid(child, lockmode);
310326
return; /* nothing to do here */
@@ -327,8 +343,9 @@ handle_modification_query(Query *parse)
327343
if (tuple_map) /* just checking the pointer! */
328344
return;
329345

330-
/* Update RTE's relid */
346+
/* Update RTE's relid and relkind (for FDW) */
331347
rte->relid = child;
348+
rte->relkind = child_relkind;
332349

333350
/* HACK: unset the 'inh' flag (no children) */
334351
rte->inh = false;

0 commit comments

Comments
 (0)