@@ -160,6 +160,7 @@ my_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
160
160
if (prel != NULL )
161
161
{
162
162
List * children = NIL ;
163
+ List * ranges ;
163
164
ListCell * lc ;
164
165
int childOID = -1 ;
165
166
int i ;
@@ -168,22 +169,33 @@ my_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
168
169
rte -> inh = true;
169
170
170
171
dsm_arr = (Oid * )dsm_array_get_pointer (& prel -> children );
171
- for (i = 0 ;i < prel -> children_count ;i ++ )
172
- // children = lappend_int(children, prel->children[i]);
173
- children = lappend_int (children ,dsm_arr [i ]);
172
+ // for (i=0; i<prel->children_count; i++)
173
+ // // children = lappend_int(children, prel->children[i]);
174
+ // children = lappend_int(children, dsm_arr[i]);
175
+
176
+ ranges = list_make1_int (make_range (0 ,prel -> children_count - 1 ));
174
177
175
178
/* Run over restrictions and collect children partitions */
176
179
ereport (LOG , (errmsg ("Checking restrictions" )));
177
180
foreach (lc ,rel -> baserestrictinfo )
178
181
{
179
182
RestrictInfo * rinfo = (RestrictInfo * )lfirst (lc );
180
- List * ret = walk_expr_tree (rinfo -> clause ,prel );
183
+ List * ret = walk_expr_tree (rinfo -> clause ,prel ,& all );
184
+ ranges = intersect_ranges (ranges ,ret );
185
+
186
+ // if (!all)
187
+ // {
188
+ // children = list_intersection_int(children, ret);
189
+ // list_free(ret);
190
+ // }
191
+ }
181
192
182
- if (ret != ALL )
183
- {
184
- children = list_intersection_int (children ,ret );
185
- list_free (ret );
186
- }
193
+ foreach (lc ,ranges )
194
+ {
195
+ int i ;
196
+ IndexRange range = (IndexRange )lfirst (lc );
197
+ for (i = range_min (range );i <=range_max (range );i ++ )
198
+ children = lappend_int (children ,dsm_arr [i ]);
187
199
}
188
200
189
201
// if (children == NIL)
@@ -339,6 +351,9 @@ append_child_relation(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEnt
339
351
340
352
childrel -> baserestrictinfo = lappend (childrel -> baserestrictinfo ,
341
353
new_rinfo );
354
+
355
+ /* TODO: temporarily commented out */
356
+ // reconstruct_restrictinfo((Node *) new_rinfo, prel, childOID);
342
357
}
343
358
344
359
/* Build an AppendRelInfo for this parent and child */
@@ -477,14 +492,20 @@ handle_binary_opexpr(const PartRelationInfo *prel, const OpExpr *expr,
477
492
{
478
493
int_value = DatumGetInt32 (c -> constvalue );
479
494
key .hash = make_hash (prel ,int_value );
480
- key .parent_oid = prel -> oid ;
481
- hashrel = (HashRelation * )
482
- hash_search (hash_restrictions , (const void * )& key ,HASH_FIND ,NULL );
483
-
484
- if (hashrel != NULL )
485
- return list_make1_int (hashrel -> child_oid );
486
- else
487
- return ALL ;
495
+
496
+ return list_make1_int (make_range (key .hash ,key .hash ));
497
+
498
+ // key.parent_oid = prel->oid;
499
+ // hashrel = (HashRelation *)
500
+ // hash_search(hash_restrictions, (const void *)&key, HASH_FIND, NULL);
501
+
502
+ // if (hashrel != NULL)
503
+ // return list_make1_int(hashrel->child_oid);
504
+ // else
505
+ // {
506
+ // *all = true;
507
+ // return NIL;
508
+ // }
488
509
}
489
510
case PT_RANGE :
490
511
value = c -> constvalue ;
@@ -493,7 +514,7 @@ handle_binary_opexpr(const PartRelationInfo *prel, const OpExpr *expr,
493
514
if (rangerel != NULL )
494
515
{
495
516
RangeEntry * re ;
496
- List * children = NIL ;
517
+ // List *children = NIL;
497
518
bool found = false;
498
519
startidx = 0 ;
499
520
int counter = 0 ;
@@ -557,21 +578,24 @@ handle_binary_opexpr(const PartRelationInfo *prel, const OpExpr *expr,
557
578
startidx = 0 ;
558
579
endidx = i ;
559
580
break ;
560
- case OP_STRATEGY_EQ :
561
- return list_make1_int (re -> child_oid );
562
- case OP_STRATEGY_GE :
581
+ case BTEqualStrategyNumber :
582
+ // return list_make1_int(re->child_oid);
583
+ // return list_make1_int(make_range(prel->oid, prel->oid));
584
+ return list_make1_int (make_range (i ,i ));
585
+ case BTGreaterEqualStrategyNumber :
563
586
startidx = i ;
564
587
endidx = rangerel -> nranges - 1 ;
565
588
break ;
566
589
case OP_STRATEGY_GT :
567
590
startidx = (re -> max == value ) ?i + 1 :i ;
568
591
endidx = rangerel -> nranges - 1 ;
569
592
}
570
- for (j = startidx ;j <=endidx ;j ++ )
571
- children = lappend_int (children ,ranges [j ].child_oid );
572
-
593
+ // for (j=startidx; j<=endidx; j++)
594
+ // children = lappend_int(children, ranges[j].child_oid);
573
595
* all = false;
574
- return children ;
596
+ return list_make1_int (make_range (startidx ,endidx ));
597
+
598
+ // return children;
575
599
}
576
600
}
577
601
}
@@ -630,22 +654,46 @@ handle_boolexpr(const BoolExpr *expr, const PartRelationInfo *prel)
630
654
b = walk_expr_tree ((Expr * )lfirst (lc ),prel );
631
655
switch (expr -> boolop )
632
656
{
657
+ // case OR_EXPR:
658
+ // if (sub_all)
659
+ // {
660
+ // list_free(ret);
661
+ // ret = NIL;
662
+
663
+ // /*
664
+ // * if at least one subexpr returns all partitions then
665
+ // * the whole OR-expression does
666
+ // */
667
+ // *all = true;
668
+
669
+ // /* so we just could return here */
670
+ // return ret;
671
+ // }
672
+ // else
673
+ // {
674
+ // ret = list_concat_unique_int(ret, b);
675
+ // list_free(b);
676
+ // }
677
+ // break;
678
+ // case AND_EXPR:
679
+ // ret = list_intersection_int(ret, b);
680
+ // list_free(b);
681
+
682
+ // /*
683
+ // * if even one subexpr doesn't return all partitions then
684
+ // * the whole AND-expression doesn't.
685
+ // */
686
+ // if (!sub_all)
687
+ // all = false;
688
+ // break;
689
+
633
690
case OR_EXPR :
634
- if (b == ALL )
635
- {
636
- list_free (ret );
637
- ret = ALL ;
638
- }
639
- else
640
- {
641
- ret = list_concat_unique_int (ret ,b );
642
- list_free (b );
643
- b = ALL ;
644
- }
691
+ ret = unite_ranges (ret ,b );
692
+ // list_free(b);
645
693
break ;
646
694
case AND_EXPR :
647
- ret = list_intersection_int (ret ,b );
648
- list_free (b );
695
+ ret = intersect_ranges (ret ,b );
696
+ // list_free(b);
649
697
break ;
650
698
default :
651
699
break ;
@@ -695,13 +743,14 @@ handle_arrexpr(const ScalarArrayOpExpr *expr, const PartRelationInfo *prel)
695
743
for (i = 0 ;i < num_elems ;i ++ )
696
744
{
697
745
key .hash = make_hash (prel ,elem_values [i ]);
698
- key .parent_oid = prel -> oid ;
699
- hashrel = (HashRelation * )
700
- hash_search (hash_restrictions , (const void * )& key ,HASH_FIND ,NULL );
746
+ // key.parent_oid = prel->oid;
747
+ // hashrel = (HashRelation *)
748
+ // hash_search(hash_restrictions, (const void *)&key, HASH_FIND, NULL);
701
749
702
- if (hashrel != NULL )
703
- oids = list_append_unique_int (oids ,hashrel -> child_oid );
750
+ // if (hashrel != NULL)
751
+ // oids = list_append_unique_int(oids, hashrel->child_oid);
704
752
753
+ oids = list_append_unique_int (oids ,make_range (key .hash ,key .hash ));
705
754
}
706
755
707
756
/* free resources */
@@ -829,7 +878,7 @@ accumulate_append_subpath(List *subpaths, Path *path)
829
878
*/
830
879
Datum
831
880
on_partitions_created (PG_FUNCTION_ARGS ) {
832
- Oid relid ;
881
+ // Oid relid;
833
882
834
883
LWLockAcquire (load_config_lock ,LW_EXCLUSIVE );
835
884
@@ -866,7 +915,6 @@ on_partitions_updated(PG_FUNCTION_ARGS) {
866
915
Datum
867
916
on_partitions_removed (PG_FUNCTION_ARGS ) {
868
917
Oid relid ;
869
- int i ;
870
918
871
919
LWLockAcquire (load_config_lock ,LW_EXCLUSIVE );
872
920