169 bool is_borrowed_rel);
197 int n_total_subplans);
295 while (dispatch != NULL)
320 if (partdesc->
nparts == 0 ||
329 (
errcode(ERRCODE_CHECK_VIOLATION),
330 errmsg(
"no partition of relation \"%s\" found for row",
333 errdetail(
"Partition key of the failing row contains %s.",
338 is_leaf = partdesc->
is_leaf[partidx];
359 partdesc->
oids[partidx],
378 rootResultRelInfo, partidx);
402 dispatch = pd[dispatch->
indexes[partidx]];
415 partdesc->
oids[partidx],
422 dispatch = subdispatch;
437 if (tempslot != NULL)
512 bool found_whole_row;
538 if (partrel->rd_rel->relhasindex &&
539 leaf_part_rri->ri_IndexRelationDescs == NULL)
604 wcoExprs =
lappend(wcoExprs, wcoExpr);
607 leaf_part_rri->ri_WithCheckOptions = wcoList;
608 leaf_part_rri->ri_WithCheckOptionExprs = wcoExprs;
644 if (part_attmap == NULL)
649 returningList = (
List *)
657 leaf_part_rri->ri_returningList = returningList;
669 leaf_part_rri->ri_projectReturning =
676 leaf_part_rri, partidx,
false);
700 foreach(lc, childIdxs)
710 arbiterIndexes =
lappend_oid(arbiterIndexes, childIdx);
723 elog(
ERROR,
"invalid arbiter index list");
724 leaf_part_rri->ri_onConflictArbiterIndexes = arbiterIndexes;
739 leaf_part_rri->ri_onConflict = onconfl;
786 if (part_attmap == NULL)
791 onconflset = (
List *)
798 onconflset = (
List *)
885 if (part_attmap == NULL)
891 if (
unlikely(!leaf_part_rri->ri_projectNewInfoValid))
894 foreach(lc, firstMergeActionList)
907 list = &leaf_part_rri->ri_matchedMergeAction;
909 list = &leaf_part_rri->ri_notMatchedMergeAction;
912 switch (
action->commandType)
923 leaf_part_rri->ri_newTupleSlot,
943 leaf_part_rri->ri_newTupleSlot,
950 elog(
ERROR,
"unknown action in MERGE WHEN clause");
966 return leaf_part_rri;
982 bool is_borrowed_rel)
1069 dispatch->
indexes[partidx] = rri_index;
1122 partdesc->
nparts *
sizeof(int));
1127 if (parent_pd != NULL)
1208 parent_pd->
indexes[partidx] = dispatchidx;
1318 if (partexpr_item == NULL)
1319 elog(
ERROR,
"wrong number of partition key expressions");
1329 if (partexpr_item != NULL)
1330 elog(
ERROR,
"wrong number of partition key expressions");
1338 #define PARTITION_CACHED_FIND_THRESHOLD 16
1383 int bound_offset = -1;
1384 int part_index = -1;
1402 switch (
key->strategy)
1447 Datum lastDatum = boundinfo->
datums[last_datum_offset][0];
1452 key->partcollation[0],
1457 return boundinfo->
indexes[last_datum_offset];
1466 if (bound_offset >= 0 &&
equal)
1467 part_index = boundinfo->
indexes[bound_offset];
1474 range_partkey_has_null =
false;
1481 for (
i = 0;
i <
key->partnatts;
i++)
1485 range_partkey_has_null =
true;
1491 if (range_partkey_has_null)
1497 Datum *lastDatums = boundinfo->
datums[last_datum_offset];
1514 return boundinfo->
indexes[last_datum_offset + 1];
1516 if (cmpval < 0 && last_datum_offset + 1 < boundinfo->
ndatums)
1519 lastDatums = boundinfo->
datums[last_datum_offset + 1];
1520 kind = boundinfo->
kind[last_datum_offset + 1];
1529 return boundinfo->
indexes[last_datum_offset + 1];
1547 part_index = boundinfo->
indexes[bound_offset + 1];
1552 elog(
ERROR,
"unexpected partition strategy: %d",
1553 (
int)
key->strategy);
1571 Assert(bound_offset >= 0);
1624 for (
i = 0;
i < partnatts;
i++)
1644 for (
i = 0;
i < partnatts;
i++)
1657 &foutoid, &typisvarlena);
1665 vallen = strlen(
val);
1666 if (vallen <= maxfieldlen)
1717 if (parentattrno <= 0 ||
1718 parentattrno > attrMap->
maplen ||
1719 attrMap->
attnums[parentattrno - 1] == 0)
1720 elog(
ERROR,
"unexpected attno %d in target column list",
1723 attrMap->
attnums[parentattrno - 1]);
1792 int n_total_subplans,
1813 Assert(n_total_subplans > 0);
1815 n_total_subplans - 1);
1832 *initially_valid_subplans,
1861 int n_part_hierarchies;
1872 Assert(n_part_hierarchies > 0);
1903 int npartrelpruneinfos =
list_length(partrelpruneinfos);
1915 foreach(lc2, partrelpruneinfos)
1955 sizeof(
int) * pinfo->
nparts);
1961 #ifdef USE_ASSERT_CHECKING
1962 for (
int k = 0; k < pinfo->
nparts; k++)
1964 Assert(partdesc->
oids[k] == pinfo->relid_map[k] ||
1965 pinfo->subplan_map[k] == -1);
1991 for (pp_idx = 0; pp_idx < partdesc->
nparts; pp_idx++)
1994 while (pd_idx < pinfo->nparts &&
1998 if (pd_idx < pinfo->nparts &&
1999 pinfo->relid_map[pd_idx] == partdesc->
oids[pp_idx])
2003 pinfo->subplan_map[pd_idx];
2005 pinfo->subpart_map[pd_idx];
2023 if (pd_idx != pinfo->
nparts)
2024 elog(
ERROR,
"could not match partition child tables to plan elements");
2041 partdesc, partkey, planstate,
2052 partdesc, partkey, planstate,
2078 List *pruning_steps,
2108 foreach(lc, pruning_steps)
2121 foreach(lc2, step->
exprs)
2139 if (planstate == NULL)
2169 int n_total_subplans)
2171 int *new_subplan_indexes;
2181 new_subplan_indexes = (
int *)
palloc0(
sizeof(
int) * n_total_subplans);
2187 new_subplan_indexes[
i] = newidx++;
2209 int nparts = pprune->
nparts;
2216 for (k = 0; k < nparts; k++)
2231 Assert(oldidx < n_total_subplans);
2232 pprune->
subplan_map[k] = new_subplan_indexes[oldidx] - 1;
2234 if (new_subplan_indexes[oldidx] > 0)
2256 new_other_subplans = NULL;
2260 new_subplan_indexes[
i] - 1);
2265 pfree(new_subplan_indexes);
2380 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_if_req(TupleDesc indesc, TupleDesc outdesc, bool missing_ok)
AttrMap * build_attrmap_by_name(TupleDesc indesc, TupleDesc outdesc, bool missing_ok)
#define InvalidAttrNumber
int bms_next_member(const Bitmapset *a, int prevbit)
void bms_free(Bitmapset *a)
int bms_num_members(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)
Bitmapset * bms_add_range(Bitmapset *a, int lower, int upper)
static Datum values[MAXATTR]
#define FLEXIBLE_ARRAY_MEMBER
#define OidIsValid(objectId)
elog(ERROR, "%s: %s", p2, msg)
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 * ExecInitExprWithParams(Expr *node, ParamListInfo ext_params)
ProjectionInfo * ExecBuildUpdateProjection(List *targetList, bool evalTargetList, List *targetColnos, TupleDesc relDesc, ExprContext *econtext, TupleTableSlot *slot, PlanState *parent)
ExprState * ExecInitQual(List *qual, PlanState *parent)
ExprState * ExecInitExpr(Expr *node, PlanState *parent)
ProjectionInfo * ExecBuildProjectionInfo(List *targetList, ExprContext *econtext, TupleTableSlot *slot, PlanState *parent, TupleDesc inputDesc)
List * ExecPrepareExprList(List *nodes, EState *estate)
void ExecCloseIndices(ResultRelInfo *resultRelInfo)
void ExecOpenIndices(ResultRelInfo *resultRelInfo, bool speculative)
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)
void CheckValidResultRel(ResultRelInfo *resultRelInfo, CmdType operation)
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)
Bitmapset * ExecFindMatchingSubPlans(PartitionPruneState *prunestate, bool initial_prune)
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
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)
PartitionTupleRouting * ExecSetupPartitionTupleRouting(EState *estate, Relation rel)
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
const TupleTableSlotOps TTSOpsVirtual
void ExecDropSingleTupleTableSlot(TupleTableSlot *slot)
TupleTableSlot * MakeSingleTupleTableSlot(TupleDesc tupdesc, const TupleTableSlotOps *tts_ops)
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Relation ExecGetRangeTableRelation(EState *estate, Index rti)
TupleConversionMap * ExecGetRootToChildMap(ResultRelInfo *resultRelInfo, EState *estate)
TupleConversionMap * ExecGetChildToRootMap(ResultRelInfo *resultRelInfo)
#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)
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)
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 pfree(void *pointer)
void * palloc0(Size size)
MemoryContext CurrentMemoryContext
void * repalloc(void *pointer, Size size)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
#define CHECK_FOR_INTERRUPTS()
void ExecInitMergeTupleSlots(ModifyTableState *mtstate, ResultRelInfo *resultRelInfo)
ResultRelInfo * ExecLookupResultRelByOid(ModifyTableState *node, Oid resultoid, bool missing_ok, bool update_cache)
#define IsA(nodeptr, _type_)
#define castNode(_type_, nodeptr)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
@ 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, 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_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)
void check_stack_depth(void)
static int32 DatumGetInt32(Datum X)
#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 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 * 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
PartitionBoundInfo boundinfo
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 TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
static Datum slot_getattr(TupleTableSlot *slot, int attnum, bool *isnull)
#define IsolationUsesXactSnapshot()