16
16
#include "partition_filter.h"
17
17
#include "planner_tree_modification.h"
18
18
19
+ #include "access/htup_details.h"
19
20
#include "miscadmin.h"
20
21
#include "optimizer/clauses.h"
21
22
#include "storage/lmgr.h"
23
+ #include "utils/lsyscache.h"
22
24
#include "utils/syscache.h"
23
25
24
26
@@ -302,9 +304,23 @@ handle_modification_query(Query *parse)
302
304
303
305
LOCKMODE lockmode = RowExclusiveLock ; /* UPDATE | DELETE */
304
306
305
- /* Make sure that 'child' exists */
307
+ HeapTuple syscache_htup ;
308
+ char child_relkind ;
309
+
310
+ /* Lock 'child' table */
306
311
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
308
324
{
309
325
UnlockRelationOid (child , lockmode );
310
326
return ; /* nothing to do here */
@@ -327,8 +343,9 @@ handle_modification_query(Query *parse)
327
343
if (tuple_map ) /* just checking the pointer! */
328
344
return ;
329
345
330
- /* Update RTE's relid */
346
+ /* Update RTE's relid and relkind (for FDW) */
331
347
rte -> relid = child ;
348
+ rte -> relkind = child_relkind ;
332
349
333
350
/* HACK: unset the 'inh' flag (no children) */
334
351
rte -> inh = false;
0 commit comments