146 int *relid_subplan_map,
157 List *source_stepids,
162 Expr *clause,
Expr *partkey,
int partkeyidx,
163 bool *clause_is_not_null,
206 Expr *expr,
int stateidx,
230 int *relid_subplan_map;
250 foreach(lc, subpaths)
281 if (prel == parentrel)
296 relid_subplan_map[pathrel->
relid] =
i;
307 foreach(lc, allpartrelids)
320 if (pinfolist !=
NIL)
322 prunerelinfos =
lappend(prunerelinfos, pinfolist);
323 allmatchedsubplans =
bms_join(matchedsubplans,
328 pfree(relid_subplan_map);
334 if (prunerelinfos ==
NIL)
404 foreach(lc, allpartrelids)
409 if (targetpart == currtarget)
413 lfirst(lc) = currpartrelids;
414 return allpartrelids;
418 return lappend(allpartrelids, partrelids);
443 int *relid_subplan_map,
448 bool doruntimeprune =
false;
449 int *relid_subpart_map;
472 List *initial_pruning_steps;
473 List *exec_pruning_steps;
485 Assert(rti < root->simple_rel_array_size);
486 relid_subpart_map[rti] =
i++;
495 targetpart = subpart;
520 partprunequal = prunequal;
529 partprunequal = (
List *)
566 initial_pruning_steps = context.
steps;
568 initial_pruning_steps =
NIL;
586 exec_pruning_steps = context.
steps;
596 exec_pruning_steps =
NIL;
601 exec_pruning_steps =
NIL;
605 if (initial_pruning_steps || exec_pruning_steps)
606 doruntimeprune =
true;
616 pinfolist =
lappend(pinfolist, pinfo);
622 pfree(relid_subpart_map);
634 foreach(lc, pinfolist)
639 int nparts = subpart->
nparts;
650 subplan_map = (
int *)
palloc(nparts *
sizeof(
int));
651 memset(subplan_map, -1, nparts *
sizeof(
int));
652 subpart_map = (
int *)
palloc(nparts *
sizeof(
int));
653 memset(subpart_map, -1, nparts *
sizeof(
int));
655 present_parts = NULL;
666 subplan_map[
i] = subplanidx = relid_subplan_map[partrel->
relid] - 1;
667 subpart_map[
i] = subpartidx = relid_subpart_map[partrel->
relid] - 1;
676 else if (subpartidx >= 0)
695 pfree(relid_subpart_map);
697 *matchedsubplans = subplansfound;
781 pruning_steps = gcontext.
steps;
784 if (pruning_steps ==
NIL)
845 foreach(lc, pruning_steps)
858 results[step->step_id] =
865 elog(
ERROR,
"invalid pruning step type: %d",
875 final_result = results[num_steps - 1];
876 Assert(final_result != NULL);
884 Assert(i < context->boundinfo->nindexes);
970 bool generate_opsteps =
false;
993 memset(keyclauses, 0,
sizeof(keyclauses));
1005 (((
Const *) clause)->constisnull ||
1026 bool all_args_contradictory =
true;
1042 bool arg_contradictory;
1051 if (arg_contradictory)
1057 all_args_contradictory =
false;
1059 if (argsteps !=
NIL)
1090 if (all_args_contradictory)
1096 if (arg_stepids !=
NIL)
1102 result =
lappend(result, step);
1129 if (argsteps !=
NIL)
1149 bool clause_is_not_null =
false;
1155 &clause_is_not_null,
1156 &pc, &clause_steps))
1170 generate_opsteps =
true;
1171 keyclauses[
i] =
lappend(keyclauses[
i], pc);
1175 if (!clause_is_not_null)
1182 keyclauses[
i] !=
NIL)
1261 false,
NIL,
NIL, nullkeys);
1262 result =
lappend(result, step);
1264 else if (generate_opsteps)
1279 result =
lappend(result, step);
1301 result =
lappend(result,
final);
1331 opstep->
exprs = exprs;
1349 List *source_stepids,
1395 memset(btree_clauses, 0,
sizeof(btree_clauses));
1396 memset(hash_clauses, 0,
sizeof(hash_clauses));
1399 List *clauselist = keyclauses[
i];
1400 bool consider_next_key =
true;
1419 foreach(lc, clauselist)
1448 consider_next_key =
false;
1453 elog(
ERROR,
"invalid clause for hash partitioning");
1459 elog(
ERROR,
"invalid partition strategy: %c",
1469 if (!consider_next_key)
1504 foreach(lc, btree_clauses[strat])
1513 bool prefix_valid =
true;
1514 bool pk_has_clauses;
1548 for (keyno = 0; keyno < pc->
keyno; keyno++)
1550 pk_has_clauses =
false;
1560 if (eqpc->
keyno == keyno)
1562 prefix =
lappend(prefix, eqpc);
1563 pk_has_clauses =
true;
1585 if (lepc->
keyno == keyno)
1587 prefix =
lappend(prefix, lepc);
1588 pk_has_clauses =
true;
1611 if (gepc->
keyno == keyno)
1613 prefix =
lappend(prefix, gepc);
1614 pk_has_clauses =
true;
1629 if (!pk_has_clauses)
1631 prefix_valid =
false;
1676 if (eq_clauses !=
NIL)
1690 pc =
llast(eq_clauses);
1697 last_keyno = pc->
keyno;
1698 foreach(lc, eq_clauses)
1701 if (pc->
keyno == last_keyno)
1743 elog(
ERROR,
"invalid partition strategy: %c",
1760 #define PartCollMatchesExprColl(partcoll, exprcoll) \
1761 ((partcoll) == InvalidOid || (partcoll) == (exprcoll))
1796 Expr *clause,
Expr *partkey,
int partkeyidx,
1798 List **clause_steps)
1817 partclause->
keyno = partkeyidx;
1819 partclause->
opno = BooleanEqualOperator;
1821 partclause->
expr = expr;
1842 bool is_opne_listp =
false;
1851 opno = opclause->
opno;
1854 if (
equal(leftop, partkey))
1856 else if (
equal(rightop, partkey))
1897 &op_strategy, &op_lefttype,
1910 &op_strategy, &op_lefttype,
1913 is_opne_listp =
true;
2043 op_righttype, op_righttype,
2048 elog(
ERROR,
"invalid partition strategy: %c",
2062 partclause->
keyno = partkeyidx;
2066 partclause->
opno = negator;
2072 partclause->
opno = opno;
2076 partclause->
expr = expr;
2077 partclause->
cmpfn = cmpfn;
2098 if (!
equal(leftop, partkey) ||
2126 &lefttype, &righttype);
2196 if (
op_volatile(saop_op) != PROVOLATILE_IMMUTABLE)
2234 &elemlen, &elembyval, &elemalign);
2237 elemlen, elembyval, elemalign,
2238 &elem_values, &elem_nulls,
2240 for (
i = 0;
i < num_elems;
i++)
2258 elem_values[
i],
false, elembyval);
2259 elem_exprs =
lappend(elem_exprs, elem_expr);
2290 foreach(lc1, elem_exprs)
2298 elem_clauses =
lappend(elem_clauses, elem_clause);
2312 else if (*clause_steps ==
NIL)
2347 return boolmatchstatus;
2376 Expr *step_lastexpr,
2382 Assert(step_nullkeys == NULL ||
2428 Expr *step_lastexpr,
2447 if (cur_keyno < step_lastkeyno - 1)
2462 if (pc->
keyno > cur_keyno)
2474 if (pc->
keyno == cur_keyno)
2542 step_exprs1 =
lappend(step_exprs1, step_lastexpr);
2547 step_cmpfns1 =
lappend_oid(step_cmpfns1, step_lastcmpfn);
2550 step_opstrategy, step_op_is_ne,
2551 step_exprs1, step_cmpfns1,
2553 result =
lappend(result, step);
2590 int *partindices = boundinfo->
indexes;
2595 int greatest_modulus;
2613 for (
i = 0;
i < partnatts;
i++)
2619 greatest_modulus = boundinfo->
nindexes;
2620 if (partindices[rowHash % greatest_modulus] >= 0)
2671 bool inclusive =
false;
2704 maxoff = boundinfo->
ndatums - 1;
2732 if (off >= 0 && is_equal)
2765 if (off >= 0 && is_equal)
2785 if (!is_equal || !inclusive)
2803 if (off > boundinfo->
ndatums - 1)
2817 if (off >= 0 && is_equal && !inclusive)
2833 elog(
ERROR,
"invalid strategy number %d", opstrategy);
2837 Assert(minoff >= 0 && maxoff >= 0);
2880 int *partindices = boundinfo->
indexes;
2885 bool inclusive =
false;
2888 Assert(nvalues <= partnatts);
2914 if (partindices[minoff] < 0)
2916 if (partindices[maxoff] < 0)
2920 Assert(partindices[minoff] >= 0 &&
2921 partindices[maxoff] >= 0);
2931 if (nvalues < partnatts)
2944 if (off >= 0 && is_equal)
2946 if (nvalues == partnatts)
2954 int saved_off = off;
2975 boundinfo->
datums[off - 1],
2976 boundinfo->
kind[off - 1],
2987 boundinfo->
kind[off],
2998 if (boundinfo->
kind[off][nvalues] ==
3009 while (off < boundinfo->ndatums - 1)
3015 boundinfo->
datums[off + 1],
3016 boundinfo->
kind[off + 1],
3027 boundinfo->
kind[off],
3037 Assert(minoff >= 0 && maxoff >= 0);
3080 if (is_equal && nvalues < partnatts)
3095 while (off >= 1 && off < boundinfo->ndatums - 1)
3100 nextoff = inclusive ? off - 1 : off + 1;
3104 boundinfo->
datums[nextoff],
3105 boundinfo->
kind[nextoff],
3117 boundinfo->
kind[off],
3120 minoff = inclusive ? off : off + 1;
3156 if (is_equal && nvalues < partnatts)
3158 while (off >= 1 && off < boundinfo->ndatums - 1)
3163 nextoff = inclusive ? off + 1 : off - 1;
3166 boundinfo->
datums[nextoff],
3167 boundinfo->
kind[nextoff],
3179 boundinfo->
kind[off],
3182 maxoff = inclusive ? off + 1 : off;
3194 else if (!is_equal || inclusive)
3210 elog(
ERROR,
"invalid strategy number %d", opstrategy);
3214 Assert(minoff >= 0 && minoff <= boundinfo->ndatums);
3215 Assert(maxoff >= 0 && maxoff <= boundinfo->ndatums);
3223 if (minoff < boundinfo->ndatums && partindices[minoff] < 0)
3225 int lastkey = nvalues - 1;
3227 if (boundinfo->
kind[minoff][lastkey] ==
3242 if (maxoff >= 1 && partindices[maxoff] < 0)
3244 int lastkey = nvalues - 1;
3246 if (boundinfo->
kind[maxoff - 1][lastkey] ==
3254 Assert(minoff >= 0 && maxoff >= 0);
3255 if (minoff <= maxoff)
3314 foreach(lc2, step->
exprs)
3320 execparamids =
bms_join(execparamids,
3325 return execparamids;
3361 for (keyno = 0; keyno < context->
partnatts; keyno++)
3467 elog(
ERROR,
"unexpected partition strategy: %d",
3523 elog(
ERROR,
"invalid pruning combine step argument");
3524 step_result = step_results[step_id];
3525 Assert(step_result != NULL);
3547 elog(
ERROR,
"invalid pruning combine step argument");
3548 step_result = step_results[step_id];
3549 Assert(step_result != NULL);
3599 if (!IsBooleanOpfamily(partopfamily))
3611 leftop = btest->
arg;
3615 if (
equal(leftop, partkey))
3634 if (
equal(leftop, partkey))
3635 *outconst = is_not_clause ?
3664 Expr *expr,
int stateidx,
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, Relids child_relids, Relids top_parent_relids)
#define DatumGetArrayTypeP(X)
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
Bitmapset * bms_join(Bitmapset *a, Bitmapset *b)
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
int bms_next_member(const Bitmapset *a, int prevbit)
int bms_num_members(const Bitmapset *a)
bool bms_is_member(int x, const Bitmapset *a)
Bitmapset * bms_make_singleton(int x)
Bitmapset * bms_add_member(Bitmapset *a, int x)
Bitmapset * bms_add_members(Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_del_members(Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_int_members(Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_del_member(Bitmapset *a, int x)
bool bms_is_empty(const Bitmapset *a)
Bitmapset * bms_copy(const Bitmapset *a)
Bitmapset * bms_add_range(Bitmapset *a, int lower, int upper)
static Datum values[MAXATTR]
#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)
void fmgr_info_cxt(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt)
void fmgr_info_copy(FmgrInfo *dstinfo, FmgrInfo *srcinfo, MemoryContext destcxt)
#define HASHEXTENDED_PROC
Assert(fmt[strlen(fmt) - 1] !='\n')
List * lappend(List *list, void *datum)
List * lappend_int(List *list, int datum)
List * lappend_oid(List *list, Oid datum)
List * list_copy(const List *oldlist)
void list_free(List *list)
List * list_concat(List *list1, const List *list2)
List * list_concat_copy(const List *list1, const List *list2)
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 * 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)
Expr * makeBoolExpr(BoolExprType boolop, List *args, int location)
Node * makeBoolConst(bool value, bool isnull)
void pfree(void *pointer)
void * palloc0(Size size)
MemoryContext CurrentMemoryContext
bool expression_tree_walker(Node *node, bool(*walker)(), void *context)
static bool is_andclause(const void *clause)
static Expr * get_notclausearg(const void *notclause)
static bool is_orclause(const void *clause)
static Node * get_rightop(const void *clause)
static bool is_notclause(const void *clause)
static Node * get_leftop(const void *clause)
#define IsA(nodeptr, _type_)
@ T_PartitionPruneStepCombine
#define castNode(_type_, nodeptr)
#define PARTITION_STRATEGY_LIST
@ PARTITION_RANGE_DATUM_MAXVALUE
@ PARTITION_RANGE_DATUM_MINVALUE
#define PARTITION_STRATEGY_RANGE
#define PARTITION_STRATEGY_HASH
int32 partition_rbound_datum_cmp(FmgrInfo *partsupfunc, Oid *partcollation, Datum *rb_datums, PartitionRangeDatumKind *rb_kind, Datum *tuple_datums, int n_tuple_datums)
uint64 compute_partition_hash_value(int partnatts, FmgrInfo *partsupfunc, Oid *partcollation, Datum *values, bool *isnull)
int partition_range_datum_bsearch(FmgrInfo *partsupfunc, Oid *partcollation, PartitionBoundInfo boundinfo, int nvalues, 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)
@ PARTCLAUSE_MATCH_CONTRADICT
@ PARTCLAUSE_MATCH_CLAUSE
@ PARTCLAUSE_MATCH_NULLNESS
static List * add_part_relids(List *allpartrelids, Bitmapset *partrelids)
static List * get_steps_using_prefix(GeneratePruningStepsContext *context, StrategyNumber step_opstrategy, bool step_op_is_ne, Expr *step_lastexpr, Oid step_lastcmpfn, int step_lastkeyno, Bitmapset *step_nullkeys, List *prefix)
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)
Bitmapset * get_matching_partitions(PartitionPruneContext *context, List *pruning_steps)
struct PruneStepResult PruneStepResult
PartitionPruneInfo * make_partition_pruneinfo(PlannerInfo *root, RelOptInfo *parentrel, List *subpaths, List *prunequal)
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)
Bitmapset * prune_append_rel_partitions(RelOptInfo *rel)
static List * get_steps_using_prefix_recurse(GeneratePruningStepsContext *context, StrategyNumber step_opstrategy, bool step_op_is_ne, Expr *step_lastexpr, Oid step_lastcmpfn, int step_lastkeyno, Bitmapset *step_nullkeys, List *prefix, ListCell *start, List *step_exprs, List *step_cmpfns)
static PruneStepResult * get_matching_list_bounds(PartitionPruneContext *context, StrategyNumber opstrategy, Datum value, int nvalues, FmgrInfo *partsupfunc, Bitmapset *nullkeys)
static PruneStepResult * get_matching_hash_bounds(PartitionPruneContext *context, StrategyNumber opstrategy, Datum *values, int nvalues, FmgrInfo *partsupfunc, Bitmapset *nullkeys)
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 PartClauseMatchStatus match_boolean_partition_clause(Oid partopfamily, Expr *clause, Expr *partkey, Expr **outconst)
static List * gen_prune_steps_from_opexps(GeneratePruningStepsContext *context, List **keyclauses, Bitmapset *nullkeys)
static PruneStepResult * get_matching_range_bounds(PartitionPruneContext *context, StrategyNumber opstrategy, Datum *values, int nvalues, FmgrInfo *partsupfunc, 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)
struct GeneratePruningStepsContext GeneratePruningStepsContext
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)
struct PartClauseInfo PartClauseInfo
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)
@ PARTPRUNE_COMBINE_INTERSECT
@ PARTPRUNE_COMBINE_UNION
void check_stack_depth(void)
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)
#define HTMaxStrategyNumber
#define BTGreaterStrategyNumber
#define BTMaxStrategyNumber
#define HTEqualStrategyNumber
#define BTLessStrategyNumber
#define BTEqualStrategyNumber
#define BTLessEqualStrategyNumber
#define BTGreaterEqualStrategyNumber
BoolTestType booltesttype
NullTestType nulltesttype
PartitionRangeDatumKind ** kind
ExprContext * exprcontext
PartitionBoundInfo boundinfo
Bitmapset * other_subplans
PartitionPruneCombineOp combineOp
StrategyNumber opstrategy
struct FmgrInfo * partsupfunc
Bitmapset * present_parts
List * initial_pruning_steps
List * exec_pruning_steps
ExprContext * ps_ExprContext
int simple_rel_array_size
struct AppendRelInfo ** append_rel_array
Bitmapset * bound_offsets
struct PartitionBoundInfoData * boundinfo
PartitionScheme part_scheme
struct RelOptInfo ** part_rels
bool contain_var_clause(Node *node)