@@ -33,8 +33,6 @@ static void my_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry
3333static PlannedStmt * my_planner_hook (Query * parse ,int cursorOptions ,ParamListInfo boundParams );
3434
3535static void append_child_relation (PlannerInfo * root ,RelOptInfo * rel ,Index rti ,RangeTblEntry * rte ,int childOID );
36- static void set_pathkeys (PlannerInfo * root ,RelOptInfo * childrel ,Path * path );
37- static void disable_inheritance (Query * parse );
3836
3937static List * walk_expr_tree (Expr * expr ,const PartRelationInfo * prel );
4038static int make_hash (const PartRelationInfo * prel ,int value );
@@ -95,53 +93,35 @@ PlannedStmt *
9593my_planner_hook (Query * parse ,int cursorOptions ,ParamListInfo boundParams )
9694{
9795PlannedStmt * result ;
98-
99- if (initialization_needed )
100- init ();
101-
102- disable_inheritance (parse );
103- result = standard_planner (parse ,cursorOptions ,boundParams );
104- return result ;
105- }
106-
107- /*
108- *
109- */
110- static void
111- disable_inheritance (Query * parse )
112- {
11396RangeTblEntry * rte ;
11497ListCell * lc ;
11598PartRelationInfo * prel ;
11699
117- if (parse -> commandType != CMD_SELECT )
118- return ;
100+ if (initialization_needed )
101+ init () ;
119102
120- foreach (lc ,parse -> rtable )
103+ /* Disable inheritance for relations covered by pathman (only for SELECT for now) */
104+ if (parse -> commandType == CMD_SELECT )
121105{
122- rte = (RangeTblEntry * )lfirst (lc );
123- switch (rte -> rtekind )
106+ foreach (lc ,parse -> rtable )
124107{
125- case RTE_RELATION :
126- if (rte -> inh )
127- {
128- /* look up this relation in pathman relations */
129- prel = (PartRelationInfo * )
130- hash_search (relations , (const void * )& rte -> relid ,HASH_FIND ,0 );
131- if (prel != NULL )
132- rte -> inh = false;
133- }
134- break ;
135- case RTE_SUBQUERY :
136- /* recursively disable inheritance for subqueries */
137- disable_inheritance (rte -> subquery );
138- break ;
139- default :
140- break ;
108+ rte = (RangeTblEntry * )lfirst (lc );
109+ if (rte -> inh )
110+ {
111+ /* look up this relation in pathman relations */
112+ prel = (PartRelationInfo * )
113+ hash_search (relations , (const void * )& rte -> relid ,HASH_FIND ,0 );
114+ if (prel != NULL )
115+ rte -> inh = false;
116+ }
141117}
142118}
119+
120+ result = standard_planner (parse ,cursorOptions ,boundParams );
121+ return result ;
143122}
144123
124+
145125static void
146126my_shmem_startup (void )
147127{
@@ -183,6 +163,7 @@ my_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
183163children = lappend_int (children ,prel -> children [i ]);
184164
185165/* Run over restrictions and collect children partitions */
166+ ereport (LOG , (errmsg ("Checking restrictions" )));
186167foreach (lc ,rel -> baserestrictinfo )
187168{
188169RestrictInfo * rinfo = (RestrictInfo * )lfirst (lc );
@@ -195,7 +176,14 @@ my_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
195176}
196177}
197178
198- /* expand simple_rte_array and simple_rel_array */
179+ // if (children == NIL)
180+ // {
181+ // ereport(LOG, (errmsg("Restrictions empty. Copy children from partrel")));
182+ // // children = get_children_oids(partrel);
183+ // // children = list_copy(partrel->children);
184+
185+ // }
186+
199187if (list_length (children )> 0 )
200188{
201189RelOptInfo * * new_rel_array ;
@@ -224,16 +212,65 @@ my_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
224212root -> simple_rte_array = new_rte_array ;
225213/* TODO: free old arrays */
226214}
215+ else
216+ {
217+ ereport (LOG , (errmsg ("Children count is 0" )));
218+ }
219+
220+ ereport (LOG , (errmsg ("Appending children" )));
221+ // Добавляем самого себя
222+ // append_child_relation(root, rel, rti, rte, partrel->oid);
223+ // {
224+ // AppendRelInfo *appinfo;
225+ // appinfo = makeNode(AppendRelInfo);
226+ // appinfo->parent_relid = rti;
227+ // appinfo->child_relid = rti;
228+ // appinfo->parent_reloid = rte->relid;
229+ // root->append_rel_list = lappend(root->append_rel_list, appinfo);
230+ // }
231+ // root->hasInheritedTarget = true;
227232
228233foreach (lc ,children )
229234{
230235childOID = (Oid )lfirst_int (lc );
231236append_child_relation (root ,rel ,rti ,rte ,childOID );
237+ // root->simple_rel_array_size += 1;
232238}
233239
234240/* TODO: clear old path list */
235241rel -> pathlist = NIL ;
242+ // if (root->parse->commandType == CMD_SELECT)
236243set_append_rel_pathlist (root ,rel ,rti ,rte );
244+ // else
245+ // {
246+ // set_plain_rel_pathlist(root, rel, rte);
247+ // /* Set plin pathlist for each child relation */
248+ // intparentRTindex = rti;
249+ // ListCell *l;
250+ // foreach(l, root->append_rel_list)
251+ // {
252+ // AppendRelInfo *appinfo = (AppendRelInfo *) lfirst(l);
253+ // intchildRTindex;
254+ // RangeTblEntry *childRTE;
255+ // RelOptInfo *childrel;
256+
257+ // /* append_rel_list contains all append rels; ignore others */
258+ // if (appinfo->parent_relid != parentRTindex || appinfo->parent_relid == rti)
259+ // continue;
260+
261+ // /* Re-locate the child RTE and RelOptInfo */
262+ // childRTindex = appinfo->child_relid;
263+ // // childRTE = root->simple_rte_array[childRTindex];
264+ // // childrel = root->simple_rel_array[childRTindex];
265+ // root->simple_rel_array[childRTindex] = NULL;
266+
267+ // /*
268+ // * Compute the child's access paths.
269+ // */
270+ // // set_plain_rel_pathlist(root, childrel, childRTE);
271+ // // set_cheapest(childrel);
272+ // }
273+ // }
237274}
238275
239276/* Invoke original hook if needed */
@@ -317,11 +354,7 @@ change_varnos(Node *node, Oid old_varno, Oid new_varno)
317354change_varno_walker (node ,& context );
318355}
319356
320- <<<<<<< HEAD
321357static bool
322- == == == =
323- bool
324- >>>>>>> pathman :
325358change_varno_walker (Node * node ,change_varno_context * context )
326359{
327360if (node == NULL )
@@ -663,7 +696,6 @@ static void
663696set_plain_rel_pathlist (PlannerInfo * root ,RelOptInfo * rel ,RangeTblEntry * rte )
664697{
665698Relids required_outer ;
666- Path * path ;
667699
668700/*
669701 * We don't support pushing join clauses into the quals of a seqscan, but
@@ -673,9 +705,7 @@ set_plain_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
673705required_outer = rel -> lateral_relids ;
674706
675707/* Consider sequential scan */
676- path = create_seqscan_path (root ,rel ,required_outer ,0 );
677- add_path (rel ,path );
678- set_pathkeys (root ,rel ,path );
708+ add_path (rel ,create_seqscan_path (root ,rel ,required_outer ,0 ));
679709
680710/* Consider index scans */
681711create_index_paths (root ,rel );
@@ -760,19 +790,6 @@ set_append_rel_pathlist(PlannerInfo *root, RelOptInfo *rel,
760790
761791}
762792
763- void
764- set_pathkeys (PlannerInfo * root ,RelOptInfo * childrel ,Path * path )
765- {
766- ListCell * lc ;
767- PathKey * pathkey ;
768-
769- foreach (lc ,root -> sort_pathkeys )
770- {
771- pathkey = (PathKey * )lfirst (lc );
772- path -> pathkeys = lappend (path -> pathkeys ,pathkey );
773- }
774- }
775-
776793static List *
777794accumulate_append_subpath (List * subpaths ,Path * path )
778795{
@@ -827,9 +844,6 @@ on_partitions_removed(PG_FUNCTION_ARGS) {
827844prel = (PartRelationInfo * )
828845hash_search (relations , (const void * )& relid ,HASH_FIND ,0 );
829846
830- if (!prel )
831- PG_RETURN_NULL ();
832-
833847/* remove children relations */
834848switch (prel -> parttype )
835849{