@@ -52,6 +52,7 @@ static void append_child_relation(PlannerInfo *root, RelOptInfo *rel, Index rti,
5252static Node * wrapper_make_expression (WrapperNode * wrap ,int index ,bool * alwaysTrue );
5353static void set_pathkeys (PlannerInfo * root ,RelOptInfo * childrel ,Path * path );
5454static void disable_inheritance (Query * parse );
55+ bool inheritance_disabled ;
5556
5657static WrapperNode * walk_expr_tree (Expr * expr ,const PartRelationInfo * prel );
5758static int make_hash (const PartRelationInfo * prel ,int value );
@@ -127,6 +128,7 @@ my_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
127128if (initialization_needed )
128129init ();
129130
131+ inheritance_disabled = false;
130132disable_inheritance (parse );
131133result = standard_planner (parse ,cursorOptions ,boundParams );
132134return result ;
@@ -157,7 +159,16 @@ disable_inheritance(Query *parse)
157159prel = (PartRelationInfo * )
158160hash_search (relations , (const void * )& rte -> relid ,HASH_FIND ,0 );
159161if (prel != NULL )
162+ {
160163rte -> inh = false;
164+ /*
165+ * Sometimes user uses the ONLY statement and in this case
166+ * rte->inh is also false. We should differ the case
167+ * when user uses ONLY statement from case when we
168+ * make rte->inh false intentionally.
169+ */
170+ inheritance_disabled = true;
171+ }
161172}
162173break ;
163174case RTE_SUBQUERY :
@@ -198,7 +209,7 @@ my_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
198209PartRelationInfo * prel = NULL ;
199210
200211/* This works on for SELECT queries */
201- if (root -> parse -> commandType != CMD_SELECT )
212+ if (root -> parse -> commandType != CMD_SELECT || ! inheritance_disabled )
202213return ;
203214
204215/* Lookup partitioning information for parent relation */