@@ -45,22 +45,25 @@ static void set_plain_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblE
4545static void set_append_rel_pathlist (PlannerInfo * root ,RelOptInfo * rel ,Index rti ,RangeTblEntry * rte );
4646static List * accumulate_append_subpath (List * subpaths ,Path * path );
4747
48+ PG_FUNCTION_INFO_V1 (on_partitions_created );
49+ PG_FUNCTION_INFO_V1 (on_partitions_updated );
50+ PG_FUNCTION_INFO_V1 (on_partitions_removed );
51+
4852typedef struct
4953{
5054Oid old_varno ;
5155Oid new_varno ;
5256}change_varno_context ;
5357
58+ static void change_varnos_in_restrinct_info (RestrictInfo * rinfo ,Oid old_varno ,Oid new_varno );
5459static void change_varnos (Node * node ,Oid old_varno ,Oid new_varno );
5560static bool change_varno_walker (Node * node ,change_varno_context * context );
5661
57-
5862PG_FUNCTION_INFO_V1 (on_partitions_created );
5963PG_FUNCTION_INFO_V1 (on_partitions_updated );
6064PG_FUNCTION_INFO_V1 (on_partitions_removed );
6165
6266
63-
6467/*
6568 * Entry point
6669 */
@@ -181,11 +184,11 @@ my_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
181184
182185// }
183186
184- if (length (children )> 0 )
187+ if (list_length (children )> 0 )
185188{
186189RelOptInfo * * new_rel_array ;
187190RangeTblEntry * * new_rte_array ;
188- int len = length (children );
191+ int len = list_length (children );
189192
190193/* Expand simple_rel_array and simple_rte_array */
191194ereport (LOG , (errmsg ("Expanding simple_rel_array" )));
@@ -322,28 +325,8 @@ append_child_relation(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEnt
322325new_rinfo = copyObject (node );
323326
324327/* replace old relids with new ones */
325- change_varnos (new_rinfo -> clause ,rel -> relid ,childrel -> relid );
326- if (new_rinfo -> left_em )
327- change_varnos (new_rinfo -> left_em -> em_expr ,rel -> relid ,childrel -> relid );
328- if (new_rinfo -> right_em )
329- change_varnos (new_rinfo -> right_em -> em_expr ,rel -> relid ,childrel -> relid );
330-
331- /* TODO: find some elegant way to do this */
332- if (bms_is_member (rel -> relid ,new_rinfo -> clause_relids ))
333- {
334- bms_del_member (new_rinfo -> clause_relids ,rel -> relid );
335- bms_add_member (new_rinfo -> clause_relids ,childrel -> relid );
336- }
337- if (bms_is_member (rel -> relid ,new_rinfo -> left_relids ))
338- {
339- bms_del_member (new_rinfo -> left_relids ,rel -> relid );
340- bms_add_member (new_rinfo -> left_relids ,childrel -> relid );
341- }
342- if (bms_is_member (rel -> relid ,new_rinfo -> right_relids ))
343- {
344- bms_del_member (new_rinfo -> right_relids ,rel -> relid );
345- bms_add_member (new_rinfo -> right_relids ,childrel -> relid );
346- }
328+ change_varnos_in_restrinct_info (new_rinfo ,rel -> relid ,childrel -> relid );
329+
347330childrel -> baserestrictinfo = lappend (childrel -> baserestrictinfo ,
348331new_rinfo );
349332}
@@ -371,7 +354,11 @@ change_varnos(Node *node, Oid old_varno, Oid new_varno)
371354change_varno_walker (node ,& context );
372355}
373356
357+ <<<<<<< HEAD
374358static bool
359+ == == == =
360+ bool
361+ >>>>>>> pathman :
375362change_varno_walker (Node * node ,change_varno_context * context )
376363{
377364if (node == NULL )
@@ -392,6 +379,42 @@ change_varno_walker(Node *node, change_varno_context *context)
392379}
393380
394381
382+ void
383+ change_varnos_in_restrinct_info (RestrictInfo * rinfo ,Oid old_varno ,Oid new_varno )
384+ {
385+ ListCell * lc ;
386+
387+ change_varnos ((Node * )rinfo -> clause ,old_varno ,new_varno );
388+ if (rinfo -> left_em )
389+ change_varnos ((Node * )rinfo -> left_em -> em_expr ,old_varno ,new_varno );
390+ if (rinfo -> right_em )
391+ change_varnos ((Node * )rinfo -> right_em -> em_expr ,old_varno ,new_varno );
392+ if (rinfo -> orclause )
393+ foreach (lc , ((BoolExpr * )rinfo -> orclause )-> args )
394+ {
395+ RestrictInfo * rinfo2 = (RestrictInfo * )lfirst (lc );
396+ change_varnos_in_restrinct_info (rinfo2 ,old_varno ,new_varno );
397+ }
398+
399+ /* TODO: find some elegant way to do this */
400+ if (bms_is_member (old_varno ,rinfo -> clause_relids ))
401+ {
402+ bms_del_member (rinfo -> clause_relids ,old_varno );
403+ bms_add_member (rinfo -> clause_relids ,new_varno );
404+ }
405+ if (bms_is_member (old_varno ,rinfo -> left_relids ))
406+ {
407+ bms_del_member (rinfo -> left_relids ,old_varno );
408+ bms_add_member (rinfo -> left_relids ,new_varno );
409+ }
410+ if (bms_is_member (old_varno ,rinfo -> right_relids ))
411+ {
412+ bms_del_member (rinfo -> right_relids ,old_varno );
413+ bms_add_member (rinfo -> right_relids ,new_varno );
414+ }
415+ }
416+
417+
395418/*
396419 * Recursive function to walk through conditions tree
397420 */
@@ -432,7 +455,6 @@ handle_binary_opexpr(const PartRelationInfo *prel, const OpExpr *expr,
432455HashRelation * hashrel ;
433456RangeRelation * rangerel ;
434457int int_value ;
435- DateADT dt_value ;
436458Datum value ;
437459int i ,j ;
438460int startidx ,endidx ;
@@ -459,9 +481,6 @@ handle_binary_opexpr(const PartRelationInfo *prel, const OpExpr *expr,
459481return ALL ;
460482}
461483case PT_RANGE :
462- // if (c->consttype == DATEOID)
463- // value = TimeTzADTPGetDatum(date2timestamp_no_overflow(c->constvalue));
464- // else
465484value = c -> constvalue ;
466485rangerel = (RangeRelation * )
467486hash_search (range_restrictions , (const void * )& prel -> oid ,HASH_FIND ,NULL );
@@ -471,9 +490,10 @@ handle_binary_opexpr(const PartRelationInfo *prel, const OpExpr *expr,
471490List * children = NIL ;
472491bool found = false;
473492startidx = 0 ;
474- endidx = rangerel -> nranges - 1 ;
475493int counter = 0 ;
476494
495+ endidx = rangerel -> nranges - 1 ;
496+
477497/* check boundaries */
478498if (rangerel -> nranges == 0 || rangerel -> ranges [0 ].min > value ||
479499rangerel -> ranges [rangerel -> nranges - 1 ].max < value )
@@ -553,7 +573,7 @@ handle_opexpr(const OpExpr *expr, const PartRelationInfo *prel)
553573Node * firstarg = NULL ;
554574Node * secondarg = NULL ;
555575
556- if (length (expr -> args )== 2 )
576+ if (list_length (expr -> args )== 2 )
557577{
558578firstarg = (Node * )linitial (expr -> args );
559579secondarg = (Node * )lsecond (expr -> args );
@@ -796,10 +816,8 @@ on_partitions_created(PG_FUNCTION_ARGS) {
796816
797817Datum
798818on_partitions_updated (PG_FUNCTION_ARGS ) {
799- HashRelationKey key ;
800819Oid relid ;
801820PartRelationInfo * prel ;
802- int i ;
803821
804822LWLockAcquire (AddinShmemInitLock ,LW_EXCLUSIVE );
805823/* parent relation oid */