156 List *source_stepids,
252 foreach(
lc, subpaths)
359 pruneinfo->other_subplans = other_subplans;
477 List *initial_pruning_steps;
478 List *exec_pruning_steps;
571 initial_pruning_steps = context.
steps;
573 initial_pruning_steps =
NIL;
591 exec_pruning_steps = context.
steps;
601 exec_pruning_steps =
NIL;
606 exec_pruning_steps =
NIL;
610 if (initial_pruning_steps || exec_pruning_steps)
648 int *leafpart_rti_map;
656 subplan_map = (
int *)
palloc(nparts *
sizeof(
int));
657 memset(subplan_map, -1, nparts *
sizeof(
int));
658 subpart_map = (
int *)
palloc(nparts *
sizeof(
int));
659 memset(subpart_map, -1, nparts *
sizeof(
int));
661 leafpart_rti_map = (
int *)
palloc0(nparts *
sizeof(
int));
662 present_parts =
NULL;
696 if (partrel->
nparts == -1)
697 leafpart_rti_map[
i] = (
int) partrel->
relid;
716 pinfo->subplan_map = subplan_map;
717 pinfo->subpart_map = subpart_map;
719 pinfo->leafpart_rti_map = leafpart_rti_map;
815 context.
strategy = rel->part_scheme->strategy;
816 context.
partnatts = rel->part_scheme->partnatts;
820 context.
partsupfunc = rel->part_scheme->partsupfunc;
884 results[step->step_id] =
891 elog(
ERROR,
"invalid pruning step type: %d",
1020 foreach(
lc, clauses)
1031 (((
Const *) clause)->constisnull ||
1128 result =
lappend(result, step);
1287 false,
NIL,
NIL, nullkeys);
1288 result =
lappend(result, step);
1305 result =
lappend(result, step);
1327 result =
lappend(result,
final);
1359 opstep->nullkeys = nullkeys;
1375 List *source_stepids,
1381 cstep->combineOp = combineOp;
1382 cstep->source_stepids = source_stepids;
1479 elog(
ERROR,
"invalid clause for hash partitioning");
1485 elog(
ERROR,
"invalid partition strategy: %c",
1573 for (keyno = 0; keyno <
pc->keyno; keyno++)
1585 if (
eqpc->keyno == keyno)
1610 if (
lepc->keyno == keyno)
1636 if (
gepc->keyno == keyno)
1766 elog(
ERROR,
"invalid partition strategy: %c",
1783#define PartCollMatchesExprColl(partcoll, exprcoll) \
1784 ((partcoll) == InvalidOid || (partcoll) == (exprcoll))
2136 elog(
ERROR,
"invalid partition strategy: %c",
2214 &lefttype, &righttype);
2317 if (arr->constisnull)
2322 &
elemlen, &elembyval, &elemalign);
2325 elemlen, elembyval, elemalign,
2326 &elem_values, &elem_nulls,
2328 for (
i = 0;
i < num_elems;
i++)
2346 elem_values[
i],
false, elembyval);
2633 Assert(context->
rel->part_scheme->strategy
2636 context->
rel->part_scheme->partnatts);
2660 result =
lappend(result, step);
2720 for (
i = 0;
i < partnatts;
i++)
2778 bool inclusive =
false;
2811 maxoff = boundinfo->
ndatums - 1;
2910 if (off > boundinfo->
ndatums - 1)
2924 if (off >= 0 &&
is_equal && !inclusive)
2940 elog(
ERROR,
"invalid strategy number %d", opstrategy);
2944 Assert(minoff >= 0 && maxoff >= 0);
2992 bool inclusive =
false;
2995 Assert(nvalues <= partnatts);
3038 if (nvalues < partnatts)
3053 if (nvalues == partnatts)
3082 boundinfo->
datums[off - 1],
3083 boundinfo->
kind[off - 1],
3094 boundinfo->
kind[off],
3105 if (boundinfo->
kind[off][nvalues] ==
3122 boundinfo->
datums[off + 1],
3123 boundinfo->
kind[off + 1],
3134 boundinfo->
kind[off],
3144 Assert(minoff >= 0 && maxoff >= 0);
3187 if (
is_equal && nvalues < partnatts)
3207 nextoff = inclusive ? off - 1 : off + 1;
3224 boundinfo->
kind[off],
3227 minoff = inclusive ? off : off + 1;
3263 if (
is_equal && nvalues < partnatts)
3270 nextoff = inclusive ? off + 1 : off - 1;
3286 boundinfo->
kind[off],
3289 maxoff = inclusive ? off + 1 : off;
3317 elog(
ERROR,
"invalid strategy number %d", opstrategy);
3361 Assert(minoff >= 0 && maxoff >= 0);
3362 if (minoff <= maxoff)
3426 execparamids =
bms_join(execparamids,
3431 return execparamids;
3467 for (keyno = 0; keyno < context->
partnatts; keyno++)
3493 opstep->step.step_id, keyno);
3573 elog(
ERROR,
"unexpected partition strategy: %d",
3614 switch (
cstep->combineOp)
3617 foreach(
lc1,
cstep->source_stepids)
3628 if (step_id >=
cstep->step.step_id)
3629 elog(
ERROR,
"invalid pruning combine step argument");
3647 foreach(
lc1,
cstep->source_stepids)
3652 if (step_id >=
cstep->step.step_id)
3653 elog(
ERROR,
"invalid pruning combine step argument");
3725 switch (
btest->booltesttype)
3796 *
value = con->constvalue;
3797 *isnull = con->constisnull;
AppendRelInfo ** find_appinfos_by_relids(PlannerInfo *root, Relids relids, int *nappinfos)
Node * adjust_appendrel_attrs(PlannerInfo *root, Node *node, int nappinfos, AppendRelInfo **appinfos)
Node * adjust_appendrel_attrs_multilevel(PlannerInfo *root, Node *node, RelOptInfo *childrel, RelOptInfo *parentrel)
#define DatumGetArrayTypeP(X)
void deconstruct_array(const ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
Bitmapset * bms_make_singleton(int x)
Bitmapset * bms_int_members(Bitmapset *a, const Bitmapset *b)
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
int bms_next_member(const Bitmapset *a, int prevbit)
Bitmapset * bms_del_members(Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_add_range(Bitmapset *a, int lower, int upper)
Bitmapset * bms_del_member(Bitmapset *a, int x)
int bms_num_members(const Bitmapset *a)
bool bms_is_member(int x, const Bitmapset *a)
Bitmapset * bms_add_member(Bitmapset *a, int x)
Bitmapset * bms_add_members(Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_join(Bitmapset *a, Bitmapset *b)
Bitmapset * bms_copy(const Bitmapset *a)
static Datum values[MAXATTR]
#define Assert(condition)
#define OidIsValid(objectId)
bool contain_volatile_functions(Node *clause)
bool enable_partition_pruning
bool equal(const void *a, const void *b)
static Datum ExecEvalExprSwitchContext(ExprState *state, ExprContext *econtext, bool *isNull)
#define palloc_object(type)
#define palloc0_array(type, count)
#define palloc0_object(type)
void fmgr_info_cxt(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt)
void fmgr_info_copy(FmgrInfo *dstinfo, FmgrInfo *srcinfo, MemoryContext destcxt)
#define HASHEXTENDED_PROC
List * lappend(List *list, void *datum)
List * list_concat(List *list1, const List *list2)
List * list_concat_copy(const List *list1, const List *list2)
List * list_copy(const List *oldlist)
List * lappend_int(List *list, int datum)
List * lappend_oid(List *list, Oid datum)
void list_free(List *list)
void get_op_opfamily_properties(Oid opno, Oid opfamily, bool ordering_op, int *strategy, Oid *lefttype, Oid *righttype)
void get_typlenbyvalalign(Oid typid, int16 *typlen, bool *typbyval, char *typalign)
Oid get_opfamily_proc(Oid opfamily, Oid lefttype, Oid righttype, int16 procnum)
char op_volatile(Oid opno)
bool op_in_opfamily(Oid opno, Oid opfamily)
Oid get_negator(Oid opno)
Oid get_commutator(Oid opno)
Expr * makeBoolExpr(BoolExprType boolop, List *args, int location)
Node * makeBoolConst(bool value, bool isnull)
Expr * make_opclause(Oid opno, Oid opresulttype, bool opretset, Expr *leftop, Expr *rightop, Oid opcollid, Oid inputcollid)
Const * makeConst(Oid consttype, int32 consttypmod, Oid constcollid, int constlen, Datum constvalue, bool constisnull, bool constbyval)
void pfree(void *pointer)
void * palloc0(Size size)
MemoryContext CurrentMemoryContext
static bool is_andclause(const void *clause)
static bool is_orclause(const void *clause)
static Node * get_rightop(const void *clause)
#define expression_tree_walker(n, w, c)
static bool is_notclause(const void *clause)
static Expr * get_notclausearg(const void *notclause)
static Node * get_leftop(const void *clause)
#define IsA(nodeptr, _type_)
#define castNode(_type_, nodeptr)
@ PARTITION_STRATEGY_HASH
@ PARTITION_STRATEGY_LIST
@ PARTITION_STRATEGY_RANGE
@ PARTITION_RANGE_DATUM_MAXVALUE
@ PARTITION_RANGE_DATUM_MINVALUE
int32 partition_rbound_datum_cmp(FmgrInfo *partsupfunc, Oid *partcollation, const Datum *rb_datums, PartitionRangeDatumKind *rb_kind, const Datum *tuple_datums, int n_tuple_datums)
uint64 compute_partition_hash_value(int partnatts, FmgrInfo *partsupfunc, const Oid *partcollation, const Datum *values, const bool *isnull)
int partition_range_datum_bsearch(FmgrInfo *partsupfunc, Oid *partcollation, PartitionBoundInfo boundinfo, int nvalues, const Datum *values, bool *is_equal)
int partition_list_bsearch(FmgrInfo *partsupfunc, Oid *partcollation, PartitionBoundInfo boundinfo, Datum value, bool *is_equal)
#define partition_bound_has_default(bi)
#define partition_bound_accepts_nulls(bi)
Bitmapset * get_matching_partitions(PartitionPruneContext *context, List *pruning_steps)
static PruneStepResult * get_matching_range_bounds(PartitionPruneContext *context, StrategyNumber opstrategy, const Datum *values, int nvalues, FmgrInfo *partsupfunc, Bitmapset *nullkeys)
int make_partition_pruneinfo(PlannerInfo *root, RelOptInfo *parentrel, List *subpaths, List *prunequal)
@ PARTCLAUSE_MATCH_CONTRADICT
@ PARTCLAUSE_MATCH_CLAUSE
@ PARTCLAUSE_MATCH_NULLNESS
static List * add_part_relids(List *allpartrelids, Bitmapset *partrelids)
static PartitionPruneStep * gen_prune_step_combine(GeneratePruningStepsContext *context, List *source_stepids, PartitionPruneCombineOp combineOp)
static List * make_partitionedrel_pruneinfo(PlannerInfo *root, RelOptInfo *parentrel, List *prunequal, Bitmapset *partrelids, int *relid_subplan_map, Bitmapset **matchedsubplans)
static Bitmapset * get_partkey_exec_paramids(List *steps)
static PartClauseMatchStatus match_clause_to_partition_key(GeneratePruningStepsContext *context, Expr *clause, Expr *partkey, int partkeyidx, bool *clause_is_not_null, PartClauseInfo **pc, List **clause_steps)
static PruneStepResult * get_matching_list_bounds(PartitionPruneContext *context, StrategyNumber opstrategy, Datum value, int nvalues, FmgrInfo *partsupfunc, Bitmapset *nullkeys)
static PartClauseMatchStatus match_boolean_partition_clause(Oid partopfamily, Expr *clause, Expr *partkey, Expr **outconst, bool *notclause)
Bitmapset * prune_append_rel_partitions(RelOptInfo *rel)
static List * get_steps_using_prefix(GeneratePruningStepsContext *context, StrategyNumber step_opstrategy, bool step_op_is_ne, Expr *step_lastexpr, Oid step_lastcmpfn, Bitmapset *step_nullkeys, List *prefix)
static List * gen_partprune_steps_internal(GeneratePruningStepsContext *context, List *clauses)
static void gen_partprune_steps(RelOptInfo *rel, List *clauses, PartClauseTarget target, GeneratePruningStepsContext *context)
static void partkey_datum_from_expr(PartitionPruneContext *context, Expr *expr, int stateidx, Datum *value, bool *isnull)
static List * gen_prune_steps_from_opexps(GeneratePruningStepsContext *context, List **keyclauses, Bitmapset *nullkeys)
#define PartCollMatchesExprColl(partcoll, exprcoll)
static PruneStepResult * perform_pruning_base_step(PartitionPruneContext *context, PartitionPruneStepOp *opstep)
static PruneStepResult * perform_pruning_combine_step(PartitionPruneContext *context, PartitionPruneStepCombine *cstep, PruneStepResult **step_results)
static List * get_steps_using_prefix_recurse(GeneratePruningStepsContext *context, StrategyNumber step_opstrategy, bool step_op_is_ne, Expr *step_lastexpr, Oid step_lastcmpfn, Bitmapset *step_nullkeys, List *prefix, ListCell *start, List *step_exprs, List *step_cmpfns)
static Bitmapset * pull_exec_paramids(Expr *expr)
static PartitionPruneStep * gen_prune_step_op(GeneratePruningStepsContext *context, StrategyNumber opstrategy, bool op_is_ne, List *exprs, List *cmpfns, Bitmapset *nullkeys)
static PruneStepResult * get_matching_hash_bounds(PartitionPruneContext *context, StrategyNumber opstrategy, const Datum *values, int nvalues, FmgrInfo *partsupfunc, Bitmapset *nullkeys)
static bool pull_exec_paramids_walker(Node *node, Bitmapset **context)
#define PruneCxtStateIdx(partnatts, step_id, keyno)
#define IS_PARTITIONED_REL(rel)
#define planner_rt_fetch(rti, root)
@ RELOPT_OTHER_MEMBER_REL
#define PARTITION_MAX_KEYS
static int list_length(const List *l)
#define list_make1_oid(x1)
#define for_each_cell(cell, lst, initcell)
static ListCell * list_head(const List *l)
static ListCell * lnext(const List *l, const ListCell *c)
#define list_make2(x1, x2)
@ PARTPRUNE_COMBINE_INTERSECT
@ PARTPRUNE_COMBINE_UNION
static bool DatumGetBool(Datum X)
bool predicate_refuted_by(List *predicate_list, List *clause_list, bool weak)
Node * negate_clause(Node *node)
RelOptInfo * find_base_rel(PlannerInfo *root, int relid)
void check_stack_depth(void)
#define HTMaxStrategyNumber
#define BTGreaterStrategyNumber
#define BTMaxStrategyNumber
#define HTEqualStrategyNumber
#define BTLessStrategyNumber
#define BTEqualStrategyNumber
#define BTLessEqualStrategyNumber
#define BTGreaterEqualStrategyNumber
PartitionRangeDatumKind ** kind
ExprContext * exprcontext
PartitionBoundInfo boundinfo
Bitmapset * present_parts
List * initial_pruning_steps
List * exec_pruning_steps
Bitmapset * bound_offsets
bool contain_var_clause(Node *node)