1
1
#include "pathman.h"
2
2
#include "postgres.h"
3
3
#include "fmgr.h"
4
+ #include "nodes/nodeFuncs.h"
4
5
#include "nodes/pg_list.h"
5
6
#include "nodes/relation.h"
6
7
#include "nodes/primnodes.h"
@@ -59,6 +60,7 @@ static void change_varnos_in_restrinct_info(RestrictInfo *rinfo, Oid old_varno,
59
60
static void change_varnos (Node * node ,Oid old_varno ,Oid new_varno );
60
61
static bool change_varno_walker (Node * node ,change_varno_context * context );
61
62
63
+ /* callbacks */
62
64
PG_FUNCTION_INFO_V1 (on_partitions_created );
63
65
PG_FUNCTION_INFO_V1 (on_partitions_updated );
64
66
PG_FUNCTION_INFO_V1 (on_partitions_removed );
@@ -173,15 +175,15 @@ my_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
173
175
// // children = lappend_int(children, prel->children[i]);
174
176
// children = lappend_int(children, dsm_arr[i]);
175
177
176
- ranges = list_make1_int (make_range (0 ,prel -> children_count - 1 ));
178
+ ranges = list_make1_int (make_irange (0 ,prel -> children_count - 1 , false ));
177
179
178
180
/* Run over restrictions and collect children partitions */
179
181
ereport (LOG , (errmsg ("Checking restrictions" )));
180
182
foreach (lc ,rel -> baserestrictinfo )
181
183
{
182
184
RestrictInfo * rinfo = (RestrictInfo * )lfirst (lc );
183
185
List * ret = walk_expr_tree (rinfo -> clause ,prel ,& all );
184
- ranges = intersect_ranges (ranges ,ret );
186
+ ranges = irange_list_intersect (ranges ,ret );
185
187
186
188
// if (!all)
187
189
// {
@@ -194,7 +196,7 @@ my_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
194
196
{
195
197
int i ;
196
198
IndexRange range = (IndexRange )lfirst (lc );
197
- for (i = range_min (range );i <= range_max (range );i ++ )
199
+ for (i = irange_lower (range );i <= irange_upper (range );i ++ )
198
200
children = lappend_int (children ,dsm_arr [i ]);
199
201
}
200
202
@@ -341,7 +343,7 @@ append_child_relation(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEnt
341
343
childrel -> baserestrictinfo = NIL ;
342
344
foreach (lc ,rel -> baserestrictinfo )
343
345
{
344
- RestrictInfo * new_rinfo ;
346
+ Node * new_rinfo ;
345
347
346
348
node = (Node * )lfirst (lc );
347
349
new_rinfo = copyObject (node );
@@ -351,9 +353,6 @@ append_child_relation(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEnt
351
353
352
354
childrel -> baserestrictinfo = lappend (childrel -> baserestrictinfo ,
353
355
new_rinfo );
354
-
355
- /* TODO: temporarily commented out */
356
- // reconstruct_restrictinfo((Node *) new_rinfo, prel, childOID);
357
356
}
358
357
359
358
/* Build an AppendRelInfo for this parent and child */
@@ -435,7 +434,6 @@ change_varnos_in_restrinct_info(RestrictInfo *rinfo, Oid old_varno, Oid new_varn
435
434
}
436
435
}
437
436
438
-
439
437
/*
440
438
* Recursive function to walk through conditions tree
441
439
*/
@@ -473,12 +471,15 @@ handle_binary_opexpr(const PartRelationInfo *prel, const OpExpr *expr,
473
471
const Var * v ,const Const * c )
474
472
{
475
473
HashRelationKey key ;
476
- HashRelation * hashrel ;
477
474
RangeRelation * rangerel ;
478
475
int int_value ;
479
476
Datum value ;
480
- int i ,j ;
481
- int startidx ,endidx ;
477
+ int i ,
478
+ startidx ,
479
+ endidx ;
480
+ FmgrInfo * cmp_func ;
481
+
482
+ * all = false;
482
483
483
484
/* determine operator type */
484
485
TypeCacheEntry * tce = lookup_type_cache (v -> vartype ,
@@ -493,7 +494,7 @@ handle_binary_opexpr(const PartRelationInfo *prel, const OpExpr *expr,
493
494
int_value = DatumGetInt32 (c -> constvalue );
494
495
key .hash = make_hash (prel ,int_value );
495
496
496
- return list_make1_int ( make_range (key .hash ,key .hash ));
497
+ return list_make1_irange ( make_irange (key .hash ,key .hash , true ));
497
498
498
499
// key.parent_oid = prel->oid;
499
500
// hashrel = (HashRelation *)
@@ -572,7 +573,7 @@ handle_binary_opexpr(const PartRelationInfo *prel, const OpExpr *expr,
572
573
{
573
574
case OP_STRATEGY_LT :
574
575
startidx = 0 ;
575
- endidx = ( re -> min == value ) ?i - 1 :i ;
576
+ endidx = check_eq ( cmp_func , re -> min , value ) ?i - 1 :i ;
576
577
break ;
577
578
case OP_STRATEGY_LE :
578
579
startidx = 0 ;
@@ -581,19 +582,19 @@ handle_binary_opexpr(const PartRelationInfo *prel, const OpExpr *expr,
581
582
case BTEqualStrategyNumber :
582
583
// return list_make1_int(re->child_oid);
583
584
// return list_make1_int(make_range(prel->oid, prel->oid));
584
- return list_make1_int ( make_range (i ,i ));
585
+ return list_make1_irange ( make_irange (i ,i , true ));
585
586
case BTGreaterEqualStrategyNumber :
586
587
startidx = i ;
587
588
endidx = rangerel -> nranges - 1 ;
588
589
break ;
589
- case OP_STRATEGY_GT :
590
- startidx = ( re -> max == value ) ?i + 1 :i ;
590
+ case BTGreaterStrategyNumber :
591
+ startidx = check_eq ( cmp_func , re -> max , value ) ?i + 1 :i ;
591
592
endidx = rangerel -> nranges - 1 ;
592
593
}
593
594
// for (j=startidx; j<=endidx; j++)
594
595
// children = lappend_int(children, ranges[j].child_oid);
595
596
* all = false;
596
- return list_make1_int ( make_range (startidx ,endidx ));
597
+ return list_make1_irange ( make_irange (startidx ,endidx , true ));
597
598
598
599
// return children;
599
600
}
@@ -650,7 +651,7 @@ handle_boolexpr(const BoolExpr *expr, const PartRelationInfo *prel)
650
651
List * b = ALL ;
651
652
652
653
if (expr -> boolop == AND_EXPR )
653
- ret = list_make1_int ( make_range (0 ,RANGE_INFINITY ));
654
+ ret = list_make1_irange ( make_irange (0 ,RANGE_INFINITY , false ));
654
655
655
656
foreach (lc ,expr -> args )
656
657
{
@@ -691,11 +692,11 @@ handle_boolexpr(const BoolExpr *expr, const PartRelationInfo *prel)
691
692
// break;
692
693
693
694
case OR_EXPR :
694
- ret = unite_ranges (ret ,b );
695
+ ret = irange_list_union (ret ,b );
695
696
// list_free(b);
696
697
break ;
697
698
case AND_EXPR :
698
- ret = intersect_ranges (ret ,b );
699
+ ret = irange_list_intersect (ret ,b );
699
700
// list_free(b);
700
701
break ;
701
702
default :
@@ -715,7 +716,6 @@ handle_arrexpr(const ScalarArrayOpExpr *expr, const PartRelationInfo *prel)
715
716
Node * varnode = (Node * )linitial (expr -> args );
716
717
Node * arraynode = (Node * )lsecond (expr -> args );
717
718
HashRelationKey key ;
718
- HashRelation * hashrel ;
719
719
720
720
if (varnode == NULL || !IsA (varnode ,Var ))
721
721
return ALL ;
@@ -730,8 +730,8 @@ handle_arrexpr(const ScalarArrayOpExpr *expr, const PartRelationInfo *prel)
730
730
int num_elems ;
731
731
Datum * elem_values ;
732
732
bool * elem_nulls ;
733
- int i ;
734
- List * oids = NIL ;
733
+ int i ;
734
+ List * ret = NIL ;
735
735
736
736
/* extract values from array */
737
737
arrayval = DatumGetArrayTypeP (((Const * )arraynode )-> constvalue );
@@ -743,7 +743,7 @@ handle_arrexpr(const ScalarArrayOpExpr *expr, const PartRelationInfo *prel)
743
743
& elem_values ,& elem_nulls ,& num_elems );
744
744
745
745
/* construct OIDs list */
746
- for (i = 0 ;i < num_elems ;i ++ )
746
+ for (i = 0 ;i < num_elems ;i ++ )
747
747
{
748
748
key .hash = make_hash (prel ,elem_values [i ]);
749
749
// key.parent_oid = prel->oid;
@@ -753,14 +753,15 @@ handle_arrexpr(const ScalarArrayOpExpr *expr, const PartRelationInfo *prel)
753
753
// if (hashrel != NULL)
754
754
// oids = list_append_unique_int(oids, hashrel->child_oid);
755
755
756
- oids = list_append_unique_int (oids , make_range (key .hash ,key .hash ));
756
+ ret = list_append_unique_int (ret , make_irange (key .hash ,key .hash , true ));
757
757
}
758
758
759
759
/* free resources */
760
760
pfree (elem_values );
761
761
pfree (elem_nulls );
762
762
763
- return oids ;
763
+ * all = false;
764
+ return ret ;
764
765
}
765
766
return ALL ;
766
767
}