@@ -33,8 +33,6 @@ static void my_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry
33
33
static PlannedStmt * my_planner_hook (Query * parse ,int cursorOptions ,ParamListInfo boundParams );
34
34
35
35
static 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 );
38
36
39
37
static List * walk_expr_tree (Expr * expr ,const PartRelationInfo * prel );
40
38
static int make_hash (const PartRelationInfo * prel ,int value );
@@ -95,53 +93,35 @@ PlannedStmt *
95
93
my_planner_hook (Query * parse ,int cursorOptions ,ParamListInfo boundParams )
96
94
{
97
95
PlannedStmt * 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
- {
113
96
RangeTblEntry * rte ;
114
97
ListCell * lc ;
115
98
PartRelationInfo * prel ;
116
99
117
- if (parse -> commandType != CMD_SELECT )
118
- return ;
100
+ if (initialization_needed )
101
+ init () ;
119
102
120
- foreach (lc ,parse -> rtable )
103
+ /* Disable inheritance for relations covered by pathman (only for SELECT for now) */
104
+ if (parse -> commandType == CMD_SELECT )
121
105
{
122
- rte = (RangeTblEntry * )lfirst (lc );
123
- switch (rte -> rtekind )
106
+ foreach (lc ,parse -> rtable )
124
107
{
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
+ }
141
117
}
142
118
}
119
+
120
+ result = standard_planner (parse ,cursorOptions ,boundParams );
121
+ return result ;
143
122
}
144
123
124
+
145
125
static void
146
126
my_shmem_startup (void )
147
127
{
@@ -183,6 +163,7 @@ my_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
183
163
children = lappend_int (children ,prel -> children [i ]);
184
164
185
165
/* Run over restrictions and collect children partitions */
166
+ ereport (LOG , (errmsg ("Checking restrictions" )));
186
167
foreach (lc ,rel -> baserestrictinfo )
187
168
{
188
169
RestrictInfo * rinfo = (RestrictInfo * )lfirst (lc );
@@ -195,7 +176,14 @@ my_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
195
176
}
196
177
}
197
178
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
+
199
187
if (list_length (children )> 0 )
200
188
{
201
189
RelOptInfo * * new_rel_array ;
@@ -224,16 +212,65 @@ my_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
224
212
root -> simple_rte_array = new_rte_array ;
225
213
/* TODO: free old arrays */
226
214
}
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;
227
232
228
233
foreach (lc ,children )
229
234
{
230
235
childOID = (Oid )lfirst_int (lc );
231
236
append_child_relation (root ,rel ,rti ,rte ,childOID );
237
+ // root->simple_rel_array_size += 1;
232
238
}
233
239
234
240
/* TODO: clear old path list */
235
241
rel -> pathlist = NIL ;
242
+ // if (root->parse->commandType == CMD_SELECT)
236
243
set_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
+ // }
237
274
}
238
275
239
276
/* Invoke original hook if needed */
@@ -317,11 +354,7 @@ change_varnos(Node *node, Oid old_varno, Oid new_varno)
317
354
change_varno_walker (node ,& context );
318
355
}
319
356
320
- <<<<<<< HEAD
321
357
static bool
322
- == == == =
323
- bool
324
- >>>>>>> pathman :
325
358
change_varno_walker (Node * node ,change_varno_context * context )
326
359
{
327
360
if (node == NULL )
@@ -663,7 +696,6 @@ static void
663
696
set_plain_rel_pathlist (PlannerInfo * root ,RelOptInfo * rel ,RangeTblEntry * rte )
664
697
{
665
698
Relids required_outer ;
666
- Path * path ;
667
699
668
700
/*
669
701
* 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)
673
705
required_outer = rel -> lateral_relids ;
674
706
675
707
/* 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 ));
679
709
680
710
/* Consider index scans */
681
711
create_index_paths (root ,rel );
@@ -760,19 +790,6 @@ set_append_rel_pathlist(PlannerInfo *root, RelOptInfo *rel,
760
790
761
791
}
762
792
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
-
776
793
static List *
777
794
accumulate_append_subpath (List * subpaths ,Path * path )
778
795
{
@@ -827,9 +844,6 @@ on_partitions_removed(PG_FUNCTION_ARGS) {
827
844
prel = (PartRelationInfo * )
828
845
hash_search (relations , (const void * )& relid ,HASH_FIND ,0 );
829
846
830
- if (!prel )
831
- PG_RETURN_NULL ();
832
-
833
847
/* remove children relations */
834
848
switch (prel -> parttype )
835
849
{