MCPcopy Create free account
hub / github.com/apache/cloudberry / ExecPartitionCheck

Function ExecPartitionCheck

src/backend/executor/execMain.c:2959–3006  ·  view source on GitHub ↗

* ExecPartitionCheck --- check that tuple meets the partition constraint. * * Returns true if it meets the partition constraint. If the constraint * fails and we're asked to emit an error, do so and don't return; otherwise * return false. */

Source from the content-addressed store, hash-verified

2957 * return false.
2958 */
2959bool
2960ExecPartitionCheck(ResultRelInfo *resultRelInfo, TupleTableSlot *slot,
2961 EState *estate, bool emitError)
2962{
2963 ExprContext *econtext;
2964 bool success;
2965
2966 /*
2967 * If first time through, build expression state tree for the partition
2968 * check expression. (In the corner case where the partition check
2969 * expression is empty, ie there's a default partition and nothing else,
2970 * we'll be fooled into executing this code each time through. But it's
2971 * pretty darn cheap in that case, so we don't worry about it.)
2972 */
2973 if (resultRelInfo->ri_PartitionCheckExpr == NULL)
2974 {
2975 /*
2976 * Ensure that the qual tree and prepared expression are in the
2977 * query-lifespan context.
2978 */
2979 MemoryContext oldcxt = MemoryContextSwitchTo(estate->es_query_cxt);
2980 List *qual = RelationGetPartitionQual(resultRelInfo->ri_RelationDesc);
2981
2982 resultRelInfo->ri_PartitionCheckExpr = ExecPrepareCheck(qual, estate);
2983 MemoryContextSwitchTo(oldcxt);
2984 }
2985
2986 /*
2987 * We will use the EState's per-tuple context for evaluating constraint
2988 * expressions (creating it if it's not already there).
2989 */
2990 econtext = GetPerTupleExprContext(estate);
2991
2992 /* Arrange for econtext's scan tuple to be the tuple under test */
2993 econtext->ecxt_scantuple = slot;
2994
2995 /*
2996 * As in case of the catalogued constraints, we treat a NULL result as
2997 * success here, not a failure.
2998 */
2999 success = ExecCheck(resultRelInfo->ri_PartitionCheckExpr, econtext);
3000
3001 /* if asked to emit error, don't actually return on failure */
3002 if (!success && emitError)
3003 ExecPartitionCheckEmitError(resultRelInfo, slot, estate);
3004
3005 return success;
3006}
3007
3008/*
3009 * ExecPartitionCheckEmitError - Form and emit an error message after a failed

Callers 8

ExecBRInsertTriggersFunction · 0.85
CopyFromFunction · 0.85
ExecSimpleRelationInsertFunction · 0.85
ExecSimpleRelationUpdateFunction · 0.85
ExecInsertFunction · 0.85
ExecUpdateFunction · 0.85
ExecFindPartitionFunction · 0.85

Calls 5

MemoryContextSwitchToFunction · 0.85
RelationGetPartitionQualFunction · 0.85
ExecPrepareCheckFunction · 0.85
ExecCheckFunction · 0.85

Tested by

no test coverage detected