@@ -45,22 +45,25 @@ static void set_plain_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblE
45
45
static void set_append_rel_pathlist (PlannerInfo * root ,RelOptInfo * rel ,Index rti ,RangeTblEntry * rte );
46
46
static List * accumulate_append_subpath (List * subpaths ,Path * path );
47
47
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
+
48
52
typedef struct
49
53
{
50
54
Oid old_varno ;
51
55
Oid new_varno ;
52
56
}change_varno_context ;
53
57
58
+ static void change_varnos_in_restrinct_info (RestrictInfo * rinfo ,Oid old_varno ,Oid new_varno );
54
59
static void change_varnos (Node * node ,Oid old_varno ,Oid new_varno );
55
60
static bool change_varno_walker (Node * node ,change_varno_context * context );
56
61
57
-
58
62
PG_FUNCTION_INFO_V1 (on_partitions_created );
59
63
PG_FUNCTION_INFO_V1 (on_partitions_updated );
60
64
PG_FUNCTION_INFO_V1 (on_partitions_removed );
61
65
62
66
63
-
64
67
/*
65
68
* Entry point
66
69
*/
@@ -181,11 +184,11 @@ my_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
181
184
182
185
// }
183
186
184
- if (length (children )> 0 )
187
+ if (list_length (children )> 0 )
185
188
{
186
189
RelOptInfo * * new_rel_array ;
187
190
RangeTblEntry * * new_rte_array ;
188
- int len = length (children );
191
+ int len = list_length (children );
189
192
190
193
/* Expand simple_rel_array and simple_rte_array */
191
194
ereport (LOG , (errmsg ("Expanding simple_rel_array" )));
@@ -322,28 +325,8 @@ append_child_relation(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEnt
322
325
new_rinfo = copyObject (node );
323
326
324
327
/* 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
+
347
330
childrel -> baserestrictinfo = lappend (childrel -> baserestrictinfo ,
348
331
new_rinfo );
349
332
}
@@ -371,7 +354,11 @@ change_varnos(Node *node, Oid old_varno, Oid new_varno)
371
354
change_varno_walker (node ,& context );
372
355
}
373
356
357
+ <<<<<<< HEAD
374
358
static bool
359
+ == == == =
360
+ bool
361
+ >>>>>>> pathman :
375
362
change_varno_walker (Node * node ,change_varno_context * context )
376
363
{
377
364
if (node == NULL )
@@ -392,6 +379,42 @@ change_varno_walker(Node *node, change_varno_context *context)
392
379
}
393
380
394
381
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
+
395
418
/*
396
419
* Recursive function to walk through conditions tree
397
420
*/
@@ -432,7 +455,6 @@ handle_binary_opexpr(const PartRelationInfo *prel, const OpExpr *expr,
432
455
HashRelation * hashrel ;
433
456
RangeRelation * rangerel ;
434
457
int int_value ;
435
- DateADT dt_value ;
436
458
Datum value ;
437
459
int i ,j ;
438
460
int startidx ,endidx ;
@@ -459,9 +481,6 @@ handle_binary_opexpr(const PartRelationInfo *prel, const OpExpr *expr,
459
481
return ALL ;
460
482
}
461
483
case PT_RANGE :
462
- // if (c->consttype == DATEOID)
463
- // value = TimeTzADTPGetDatum(date2timestamp_no_overflow(c->constvalue));
464
- // else
465
484
value = c -> constvalue ;
466
485
rangerel = (RangeRelation * )
467
486
hash_search (range_restrictions , (const void * )& prel -> oid ,HASH_FIND ,NULL );
@@ -471,9 +490,10 @@ handle_binary_opexpr(const PartRelationInfo *prel, const OpExpr *expr,
471
490
List * children = NIL ;
472
491
bool found = false;
473
492
startidx = 0 ;
474
- endidx = rangerel -> nranges - 1 ;
475
493
int counter = 0 ;
476
494
495
+ endidx = rangerel -> nranges - 1 ;
496
+
477
497
/* check boundaries */
478
498
if (rangerel -> nranges == 0 || rangerel -> ranges [0 ].min > value ||
479
499
rangerel -> ranges [rangerel -> nranges - 1 ].max < value )
@@ -553,7 +573,7 @@ handle_opexpr(const OpExpr *expr, const PartRelationInfo *prel)
553
573
Node * firstarg = NULL ;
554
574
Node * secondarg = NULL ;
555
575
556
- if (length (expr -> args )== 2 )
576
+ if (list_length (expr -> args )== 2 )
557
577
{
558
578
firstarg = (Node * )linitial (expr -> args );
559
579
secondarg = (Node * )lsecond (expr -> args );
@@ -796,10 +816,8 @@ on_partitions_created(PG_FUNCTION_ARGS) {
796
816
797
817
Datum
798
818
on_partitions_updated (PG_FUNCTION_ARGS ) {
799
- HashRelationKey key ;
800
819
Oid relid ;
801
820
PartRelationInfo * prel ;
802
- int i ;
803
821
804
822
LWLockAcquire (AddinShmemInitLock ,LW_EXCLUSIVE );
805
823
/* parent relation oid */