@@ -160,6 +160,7 @@ my_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
160160if (prel != NULL )
161161{
162162List * children = NIL ;
163+ List * ranges ;
163164ListCell * lc ;
164165int childOID = -1 ;
165166int i ;
@@ -168,22 +169,33 @@ my_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
168169rte -> inh = true;
169170
170171dsm_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 ));
174177
175178/* Run over restrictions and collect children partitions */
176179ereport (LOG , (errmsg ("Checking restrictions" )));
177180foreach (lc ,rel -> baserestrictinfo )
178181{
179182RestrictInfo * 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+ }
181192
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 ]);
187199}
188200
189201// if (children == NIL)
@@ -339,6 +351,9 @@ append_child_relation(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEnt
339351
340352childrel -> baserestrictinfo = lappend (childrel -> baserestrictinfo ,
341353new_rinfo );
354+
355+ /* TODO: temporarily commented out */
356+ // reconstruct_restrictinfo((Node *) new_rinfo, prel, childOID);
342357}
343358
344359/* Build an AppendRelInfo for this parent and child */
@@ -477,14 +492,20 @@ handle_binary_opexpr(const PartRelationInfo *prel, const OpExpr *expr,
477492{
478493int_value = DatumGetInt32 (c -> constvalue );
479494key .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+ // }
488509}
489510case PT_RANGE :
490511value = c -> constvalue ;
@@ -493,7 +514,7 @@ handle_binary_opexpr(const PartRelationInfo *prel, const OpExpr *expr,
493514if (rangerel != NULL )
494515{
495516RangeEntry * re ;
496- List * children = NIL ;
517+ // List *children = NIL;
497518bool found = false;
498519startidx = 0 ;
499520int counter = 0 ;
@@ -557,21 +578,24 @@ handle_binary_opexpr(const PartRelationInfo *prel, const OpExpr *expr,
557578startidx = 0 ;
558579endidx = i ;
559580break ;
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 :
563586startidx = i ;
564587endidx = rangerel -> nranges - 1 ;
565588break ;
566589case OP_STRATEGY_GT :
567590startidx = (re -> max == value ) ?i + 1 :i ;
568591endidx = rangerel -> nranges - 1 ;
569592}
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);
573595* all = false;
574- return children ;
596+ return list_make1_int (make_range (startidx ,endidx ));
597+
598+ // return children;
575599}
576600}
577601}
@@ -630,22 +654,46 @@ handle_boolexpr(const BoolExpr *expr, const PartRelationInfo *prel)
630654b = walk_expr_tree ((Expr * )lfirst (lc ),prel );
631655switch (expr -> boolop )
632656{
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+
633690case 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);
645693break ;
646694case AND_EXPR :
647- ret = list_intersection_int (ret ,b );
648- list_free (b );
695+ ret = intersect_ranges (ret ,b );
696+ // list_free(b);
649697break ;
650698default :
651699break ;
@@ -695,13 +743,14 @@ handle_arrexpr(const ScalarArrayOpExpr *expr, const PartRelationInfo *prel)
695743for (i = 0 ;i < num_elems ;i ++ )
696744{
697745key .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);
701749
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);
704752
753+ oids = list_append_unique_int (oids ,make_range (key .hash ,key .hash ));
705754}
706755
707756/* free resources */
@@ -829,7 +878,7 @@ accumulate_append_subpath(List *subpaths, Path *path)
829878 */
830879Datum
831880on_partitions_created (PG_FUNCTION_ARGS ) {
832- Oid relid ;
881+ // Oid relid;
833882
834883LWLockAcquire (load_config_lock ,LW_EXCLUSIVE );
835884
@@ -866,7 +915,6 @@ on_partitions_updated(PG_FUNCTION_ARGS) {
866915Datum
867916on_partitions_removed (PG_FUNCTION_ARGS ) {
868917Oid relid ;
869- int i ;
870918
871919LWLockAcquire (load_config_lock ,LW_EXCLUSIVE );
872920