166 bool is_borrowed_rel);
194 int n_total_subplans);
292 while (dispatch != NULL)
317 if (partdesc->
nparts == 0 ||
326 (
errcode(ERRCODE_CHECK_VIOLATION),
327 errmsg(
"no partition of relation \"%s\" found for row",
330 errdetail(
"Partition key of the failing row contains %s.",
335 is_leaf = partdesc->
is_leaf[partidx];
356 partdesc->
oids[partidx],
375 rootResultRelInfo, partidx);
399 dispatch = pd[dispatch->
indexes[partidx]];
412 partdesc->
oids[partidx],
419 dispatch = subdispatch;
434 if (tempslot != NULL)
509 bool found_whole_row;
535 if (partrel->rd_rel->relhasindex &&
536 leaf_part_rri->ri_IndexRelationDescs == NULL)
601 wcoExprs =
lappend(wcoExprs, wcoExpr);
604 leaf_part_rri->ri_WithCheckOptions = wcoList;
605 leaf_part_rri->ri_WithCheckOptionExprs = wcoExprs;
643 if (part_attmap == NULL)
648 returningList = (
List *)
656 leaf_part_rri->ri_returningList = returningList;
668 leaf_part_rri->ri_projectReturning =
675 leaf_part_rri, partidx,
false);
699 foreach(lc, childIdxs)
709 arbiterIndexes =
lappend_oid(arbiterIndexes, childIdx);
722 elog(
ERROR,
"invalid arbiter index list");
723 leaf_part_rri->ri_onConflictArbiterIndexes = arbiterIndexes;
738 leaf_part_rri->ri_onConflict = onconfl;
785 if (part_attmap == NULL)
790 onconflset = (
List *)
797 onconflset = (
List *)
885 if (part_attmap == NULL)
891 if (
unlikely(!leaf_part_rri->ri_projectNewInfoValid))
902 leaf_part_rri->ri_MergeJoinCondition =
905 foreach(lc, firstMergeActionList)
916 leaf_part_rri->ri_MergeActions[
action->matchKind] =
920 switch (
action->commandType)
931 leaf_part_rri->ri_newTupleSlot,
951 leaf_part_rri->ri_newTupleSlot,
958 elog(
ERROR,
"unknown action in MERGE WHEN clause");
974 return leaf_part_rri;
990 bool is_borrowed_rel)
1077 dispatch->
indexes[partidx] = rri_index;
1130 partdesc->
nparts *
sizeof(int));
1135 if (parent_pd != NULL)
1216 parent_pd->
indexes[partidx] = dispatchidx;
1326 if (partexpr_item == NULL)
1327 elog(
ERROR,
"wrong number of partition key expressions");
1337 if (partexpr_item != NULL)
1338 elog(
ERROR,
"wrong number of partition key expressions");
1346#define PARTITION_CACHED_FIND_THRESHOLD 16
1391 int bound_offset = -1;
1392 int part_index = -1;
1410 switch (
key->strategy)
1455 Datum lastDatum = boundinfo->
datums[last_datum_offset][0];
1460 key->partcollation[0],
1465 return boundinfo->
indexes[last_datum_offset];
1474 if (bound_offset >= 0 &&
equal)
1475 part_index = boundinfo->
indexes[bound_offset];
1482 range_partkey_has_null =
false;
1489 for (
i = 0;
i <
key->partnatts;
i++)
1493 range_partkey_has_null =
true;
1499 if (range_partkey_has_null)
1505 Datum *lastDatums = boundinfo->
datums[last_datum_offset];
1522 return boundinfo->
indexes[last_datum_offset + 1];
1524 if (cmpval < 0 && last_datum_offset + 1 < boundinfo->
ndatums)
1527 lastDatums = boundinfo->
datums[last_datum_offset + 1];
1528 kind = boundinfo->
kind[last_datum_offset + 1];
1537 return boundinfo->
indexes[last_datum_offset + 1];
1555 part_index = boundinfo->
indexes[bound_offset + 1];
1560 elog(
ERROR,
"unexpected partition strategy: %d",
1561 (
int)
key->strategy);
1579 Assert(bound_offset >= 0);
1632 for (
i = 0;
i < partnatts;
i++)
1652 for (
i = 0;
i < partnatts;
i++)
1665 &foutoid, &typisvarlena);
1673 vallen = strlen(
val);
1674 if (vallen <= maxfieldlen)
1725 if (parentattrno <= 0 ||
1726 parentattrno > attrMap->
maplen ||
1727 attrMap->
attnums[parentattrno - 1] == 0)
1728 elog(
ERROR,
"unexpected attno %d in target column list",
1731 attrMap->
attnums[parentattrno - 1]);
1800 int n_total_subplans,
1821 Assert(n_total_subplans > 0);
1823 n_total_subplans - 1);
1840 *initially_valid_subplans,
1869 int n_part_hierarchies;
1880 Assert(n_part_hierarchies > 0);
1911 int npartrelpruneinfos =
list_length(partrelpruneinfos);
1923 foreach(lc2, partrelpruneinfos)
1964 memcmp(partdesc->
oids, pinfo->relid_map,
1965 sizeof(
int) * partdesc->
nparts) == 0)
1969 sizeof(
int) * pinfo->
nparts);
1989 for (pp_idx = 0; pp_idx < partdesc->
nparts; pp_idx++)
1992 while (pd_idx < pinfo->nparts &&
1997 if (pd_idx < pinfo->nparts &&
1998 pinfo->relid_map[pd_idx] == partdesc->
oids[pp_idx])
2002 pinfo->subplan_map[pd_idx];
2004 pinfo->subpart_map[pd_idx];
2029 for (
int pd_idx2 = pd_idx + 1; pd_idx2 < pinfo->
nparts; pd_idx2++)
2031 if (pd_idx2 >= pinfo->
nparts)
2033 if (pinfo->relid_map[pd_idx2] == partdesc->
oids[pp_idx])
2059 partdesc, partkey, planstate,
2070 partdesc, partkey, planstate,
2096 List *pruning_steps,
2120 context->planstate = planstate;
2121 context->exprcontext = econtext;
2126 foreach(lc, pruning_steps)
2138 for (keyno = 0; keyno < partnatts; keyno++)
2161 if (planstate == NULL)
2162 context->exprstates[stateidx] =
2166 context->exprstates[stateidx] =
2192 int n_total_subplans)
2194 int *new_subplan_indexes;
2204 new_subplan_indexes = (
int *)
palloc0(
sizeof(
int) * n_total_subplans);
2210 new_subplan_indexes[
i] = newidx++;
2232 int nparts = pprune->
nparts;
2239 for (k = 0; k < nparts; k++)
2254 Assert(oldidx < n_total_subplans);
2255 pprune->
subplan_map[k] = new_subplan_indexes[oldidx] - 1;
2257 if (new_subplan_indexes[oldidx] > 0)
2279 new_other_subplans = NULL;
2283 new_subplan_indexes[
i] - 1);
2288 pfree(new_subplan_indexes);
2403 initial_prune, validsubplans);
AclResult pg_attribute_aclcheck(Oid table_oid, AttrNumber attnum, Oid roleid, AclMode mode)
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
AttrMap * build_attrmap_by_name(TupleDesc indesc, TupleDesc outdesc, bool missing_ok)
AttrMap * build_attrmap_by_name_if_req(TupleDesc indesc, TupleDesc outdesc, bool missing_ok)
#define InvalidAttrNumber
int bms_next_member(const Bitmapset *a, int prevbit)
Bitmapset * bms_add_range(Bitmapset *a, int lower, int upper)
void bms_free(Bitmapset *a)
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_copy(const Bitmapset *a)
static Datum values[MAXATTR]
#define Assert(condition)
#define FLEXIBLE_ARRAY_MEMBER
#define OidIsValid(objectId)
int errdetail(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
bool equal(const void *a, const void *b)
ExprState * ExecInitExpr(Expr *node, PlanState *parent)
ProjectionInfo * ExecBuildProjectionInfo(List *targetList, ExprContext *econtext, TupleTableSlot *slot, PlanState *parent, TupleDesc inputDesc)
ExprState * ExecInitQual(List *qual, PlanState *parent)
ExprState * ExecInitExprWithParams(Expr *node, ParamListInfo ext_params)
ProjectionInfo * ExecBuildUpdateProjection(List *targetList, bool evalTargetList, List *targetColnos, TupleDesc relDesc, ExprContext *econtext, TupleTableSlot *slot, PlanState *parent)
List * ExecPrepareExprList(List *nodes, EState *estate)
void ExecCloseIndices(ResultRelInfo *resultRelInfo)
void ExecOpenIndices(ResultRelInfo *resultRelInfo, bool speculative)
void CheckValidResultRel(ResultRelInfo *resultRelInfo, CmdType operation, List *mergeActions)
bool ExecPartitionCheck(ResultRelInfo *resultRelInfo, TupleTableSlot *slot, EState *estate, bool emitError)
void InitResultRelInfo(ResultRelInfo *resultRelInfo, Relation resultRelationDesc, Index resultRelationIndex, ResultRelInfo *partition_root_rri, int instrument_options)
Bitmapset * ExecFindMatchingSubPlans(PartitionPruneState *prunestate, bool initial_prune)
static PartitionDispatch ExecInitPartitionDispatchInfo(EState *estate, PartitionTupleRouting *proute, Oid partoid, PartitionDispatch parent_pd, int partidx, ResultRelInfo *rootResultRelInfo)
static PartitionPruneState * CreatePartitionPruneState(PlanState *planstate, PartitionPruneInfo *pruneinfo)
static ResultRelInfo * ExecInitPartitionInfo(ModifyTableState *mtstate, EState *estate, PartitionTupleRouting *proute, PartitionDispatch dispatch, ResultRelInfo *rootResultRelInfo, int partidx)
static void ExecInitRoutingInfo(ModifyTableState *mtstate, EState *estate, PartitionTupleRouting *proute, PartitionDispatch dispatch, ResultRelInfo *partRelInfo, int partidx, bool is_borrowed_rel)
static char * ExecBuildSlotPartitionKeyDescription(Relation rel, Datum *values, bool *isnull, int maxfieldlen)
static void FormPartitionKeyDatum(PartitionDispatch pd, TupleTableSlot *slot, EState *estate, Datum *values, bool *isnull)
static void PartitionPruneFixSubPlanMap(PartitionPruneState *prunestate, Bitmapset *initially_valid_subplans, int n_total_subplans)
#define PARTITION_CACHED_FIND_THRESHOLD
PartitionTupleRouting * ExecSetupPartitionTupleRouting(EState *estate, Relation rel)
static List * adjust_partition_colnos(List *colnos, ResultRelInfo *leaf_part_rri)
static List * adjust_partition_colnos_using_map(List *colnos, AttrMap *attrMap)
ResultRelInfo * ExecFindPartition(ModifyTableState *mtstate, ResultRelInfo *rootResultRelInfo, PartitionTupleRouting *proute, TupleTableSlot *slot, EState *estate)
static void InitPartitionPruneContext(PartitionPruneContext *context, List *pruning_steps, PartitionDesc partdesc, PartitionKey partkey, PlanState *planstate, ExprContext *econtext)
struct PartitionDispatchData PartitionDispatchData
static void find_matching_subplans_recurse(PartitionPruningData *prunedata, PartitionedRelPruningData *pprune, bool initial_prune, Bitmapset **validsubplans)
static int get_partition_for_tuple(PartitionDispatch pd, Datum *values, bool *isnull)
PartitionPruneState * ExecInitPartitionPruning(PlanState *planstate, int n_total_subplans, PartitionPruneInfo *pruneinfo, Bitmapset **initially_valid_subplans)
void ExecCleanupTupleRouting(ModifyTableState *mtstate, PartitionTupleRouting *proute)
struct PartitionDispatchData * PartitionDispatch
struct PartitionedRelPruningData PartitionedRelPruningData
TupleTableSlot * MakeSingleTupleTableSlot(TupleDesc tupdesc, const TupleTableSlotOps *tts_ops)
const TupleTableSlotOps TTSOpsVirtual
void ExecDropSingleTupleTableSlot(TupleTableSlot *slot)
TupleConversionMap * ExecGetRootToChildMap(ResultRelInfo *resultRelInfo, EState *estate)
TupleConversionMap * ExecGetChildToRootMap(ResultRelInfo *resultRelInfo)
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Relation ExecGetRangeTableRelation(EState *estate, Index rti)
#define GetPerTupleExprContext(estate)
#define EXEC_FLAG_EXPLAIN_GENERIC
#define ResetExprContext(econtext)
#define GetPerTupleMemoryContext(estate)
static Datum ExecEvalExprSwitchContext(ExprState *state, ExprContext *econtext, bool *isNull)
Datum FunctionCall2Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
char * OidOutputFunctionCall(Oid functionId, Datum val)
List * lappend(List *list, void *datum)
List * lappend_int(List *list, int datum)
List * lappend_oid(List *list, Oid datum)
void list_free(List *list)
bool list_member_oid(const List *list, Oid datum)
void getTypeOutputInfo(Oid type, Oid *typOutput, bool *typIsVarlena)
int pg_mbcliplen(const char *mbstr, int len, int limit)
void MemoryContextReset(MemoryContext context)
void * repalloc(void *pointer, Size size)
void pfree(void *pointer)
void * palloc0(Size size)
MemoryContext CurrentMemoryContext
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
#define CHECK_FOR_INTERRUPTS()
ResultRelInfo * ExecLookupResultRelByOid(ModifyTableState *node, Oid resultoid, bool missing_ok, bool update_cache)
void ExecInitMergeTupleSlots(ModifyTableState *mtstate, ResultRelInfo *resultRelInfo)
#define IsA(nodeptr, _type_)
#define castNode(_type_, nodeptr)
@ PARTITION_STRATEGY_HASH
@ PARTITION_STRATEGY_LIST
@ PARTITION_STRATEGY_RANGE
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, const Oid *partcollation, const Datum *values, const 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_accepts_nulls(bi)
PartitionKey RelationGetPartitionKey(Relation rel)
static int16 get_partition_col_attnum(PartitionKey key, int col)
static int get_partition_natts(PartitionKey key)
static Oid get_partition_col_typid(PartitionKey key, int col)
PartitionDirectory CreatePartitionDirectory(MemoryContext mcxt, bool omit_detached)
PartitionDesc PartitionDirectoryLookup(PartitionDirectory pdir, Relation rel)
List * get_partition_ancestors(Oid relid)
Bitmapset * get_matching_partitions(PartitionPruneContext *context, List *pruning_steps)
#define PruneCxtStateIdx(partnatts, step_id, keyno)
#define PARTITION_MAX_KEYS
#define lfirst_node(type, lc)
static int list_length(const List *l)
static ListCell * list_head(const List *l)
static ListCell * lnext(const List *l, const ListCell *c)
static int32 DatumGetInt32(Datum X)
MemoryContextSwitchTo(old_ctx)
#define RelationGetForm(relation)
#define RelationGetRelid(relation)
#define RelationGetDescr(relation)
#define RelationGetRelationName(relation)
List * RelationGetIndexList(Relation relation)
int errtable(Relation rel)
Node * map_variable_attnos(Node *node, int target_varno, int sublevels_up, const AttrMap *attno_map, Oid to_rowtype, bool *found_whole_row)
int check_enable_rls(Oid relid, Oid checkAsUser, bool noError)
char * pg_get_partkeydef_columns(Oid relid, bool pretty)
void check_stack_depth(void)
void appendStringInfo(StringInfo str, const char *fmt,...)
void appendBinaryStringInfo(StringInfo str, const void *data, int datalen)
void appendStringInfoString(StringInfo str, const char *s)
void appendStringInfoChar(StringInfo str, char ch)
void initStringInfo(StringInfo str)
List * es_tuple_routing_result_relations
MemoryContext es_query_cxt
PartitionDirectory es_partition_directory
ParamListInfo ecxt_param_list_info
TupleTableSlot * ecxt_scantuple
struct EState * ecxt_estate
EndForeignInsert_function EndForeignInsert
BeginForeignInsert_function BeginForeignInsert
ExecForeignBatchInsert_function ExecForeignBatchInsert
GetForeignModifyBatchSize_function GetForeignModifyBatchSize
ProjectionInfo * mas_proj
ResultRelInfo * resultRelInfo
ResultRelInfo * rootResultRelInfo
List * mergeJoinConditions
List * withCheckOptionLists
OnConflictAction onConflictAction
TupleTableSlot * oc_ProjSlot
TupleTableSlot * oc_Existing
ExprState * oc_WhereClause
ProjectionInfo * oc_ProjInfo
PartitionRangeDatumKind ** kind
int last_found_datum_index
PartitionBoundInfo boundinfo
int last_found_part_index
int indexes[FLEXIBLE_ARRAY_MEMBER]
PartitionStrategy strategy
ExprContext * exprcontext
Bitmapset * other_subplans
PartitionPruningData * partprunedata[FLEXIBLE_ARRAY_MEMBER]
Bitmapset * other_subplans
MemoryContext prune_context
PartitionedRelPruningData partrelprunedata[FLEXIBLE_ARRAY_MEMBER]
PartitionDispatch * partition_dispatch_info
ResultRelInfo ** partitions
ResultRelInfo ** nonleaf_partitions
Bitmapset * present_parts
List * initial_pruning_steps
List * exec_pruning_steps
List * exec_pruning_steps
PartitionPruneContext exec_context
PartitionPruneContext initial_context
Bitmapset * present_parts
List * initial_pruning_steps
ExprContext * ps_ExprContext
TupleTableSlot * ps_ResultTupleSlot
TupleTableSlot * ri_PartitionTupleSlot
OnConflictSetState * ri_onConflict
List * ri_onConflictArbiterIndexes
struct CopyMultiInsertBuffer * ri_CopyMultiInsertBuffer
struct FdwRoutine * ri_FdwRoutine
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
TupleTableSlot * table_slot_create(Relation relation, List **reglist)
TupleTableSlot * execute_attr_map_slot(AttrMap *attrMap, TupleTableSlot *in_slot, TupleTableSlot *out_slot)
static Datum slot_getattr(TupleTableSlot *slot, int attnum, bool *isnull)
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
#define IsolationUsesXactSnapshot()