@@ -885,7 +885,8 @@ modifytable_contains_fdw(List *rtable, ModifyTable *node)
885885
886886/*
887887 * Find a single deepest subpartition using quals.
888- * Return InvalidOid if it's not possible.
888+ * It's always better to narrow down the set of tables to be scanned.
889+ * Return InvalidOid if it's not possible (e.g. table is not partitioned).
889890 */
890891static Oid
891892find_deepest_partition (Oid relid , Index rti , Expr * quals )
@@ -931,8 +932,13 @@ find_deepest_partition(Oid relid, Index rti, Expr *quals)
931932 Oid * children = PrelGetChildrenArray (prel ),
932933 child = children [irange_lower (irange )];
933934
935+ /* Scan this partition */
936+ result = child ;
937+
934938 /* Try to go deeper and see if there are subpartitions */
935- result = find_deepest_partition (child , rti , quals );
939+ child = find_deepest_partition (child , rti , quals );
940+ if (OidIsValid (child ))
941+ result = child ;
936942 }
937943 break ;
938944
@@ -943,8 +949,6 @@ find_deepest_partition(Oid relid, Index rti, Expr *quals)
943949 /* Don't forget to close 'prel'! */
944950 close_pathman_relation_info (prel );
945951 }
946- /* Otherwise, return this table */
947- else result = relid ;
948952
949953 return result ;
950954}
@@ -967,7 +971,10 @@ eval_extern_params_mutator(Node *node, ParamListInfo params)
967971 param -> paramid > 0 &&
968972 param -> paramid <= params -> numParams )
969973 {
970- ParamExternData * prm = CustomEvalParamExternCompat (param , params );
974+ ParamExternData prmdata ; /* storage for 'prm' (PG 11) */
975+ ParamExternData * prm = CustomEvalParamExternCompat (param ,
976+ params ,
977+ & prmdata );
971978
972979 if (OidIsValid (prm -> ptype ))
973980 {
0 commit comments