mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-12-21 08:29:39 +08:00
Avoid extra AggCheckCallContext() checks in ordered-set aggregates.
In the transition functions, we don't really need to recheck this after the first call. I had been feeling paranoid about possibly getting a non-null argument value in some other context; but it's probably game over anyway if we have a non-null "internal" value that's not what we are expecting. In the final functions, the general convention in pre-existing final functions seems to be that an Assert() is good enough, so do it like that here too. This seems to save a few tenths of a percent of overall query runtime, which isn't much, but still it's just overhead if there's not a plausible case where the checks would fire.
This commit is contained in:
parent
e6336b8b57
commit
847e46abc9
@ -122,8 +122,8 @@ ordered_set_startup(FunctionCallInfo fcinfo, bool use_tuples)
|
|||||||
int numSortCols;
|
int numSortCols;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check we're called as aggregate, and get the Agg node's
|
* Check we're called as aggregate (and not a window function), and
|
||||||
* group-lifespan context
|
* get the Agg node's group-lifespan context
|
||||||
*/
|
*/
|
||||||
if (AggCheckCallContext(fcinfo, &gcontext) != AGG_CONTEXT_AGGREGATE)
|
if (AggCheckCallContext(fcinfo, &gcontext) != AGG_CONTEXT_AGGREGATE)
|
||||||
elog(ERROR, "ordered-set aggregate called in non-aggregate context");
|
elog(ERROR, "ordered-set aggregate called in non-aggregate context");
|
||||||
@ -356,12 +356,7 @@ ordered_set_transition(PG_FUNCTION_ARGS)
|
|||||||
if (PG_ARGISNULL(0))
|
if (PG_ARGISNULL(0))
|
||||||
osastate = ordered_set_startup(fcinfo, false);
|
osastate = ordered_set_startup(fcinfo, false);
|
||||||
else
|
else
|
||||||
{
|
|
||||||
/* safety check */
|
|
||||||
if (AggCheckCallContext(fcinfo, NULL) != AGG_CONTEXT_AGGREGATE)
|
|
||||||
elog(ERROR, "ordered-set aggregate called in non-aggregate context");
|
|
||||||
osastate = (OSAPerGroupState *) PG_GETARG_POINTER(0);
|
osastate = (OSAPerGroupState *) PG_GETARG_POINTER(0);
|
||||||
}
|
|
||||||
|
|
||||||
/* Load the datum into the tuplesort object, but only if it's not null */
|
/* Load the datum into the tuplesort object, but only if it's not null */
|
||||||
if (!PG_ARGISNULL(1))
|
if (!PG_ARGISNULL(1))
|
||||||
@ -389,12 +384,7 @@ ordered_set_transition_multi(PG_FUNCTION_ARGS)
|
|||||||
if (PG_ARGISNULL(0))
|
if (PG_ARGISNULL(0))
|
||||||
osastate = ordered_set_startup(fcinfo, true);
|
osastate = ordered_set_startup(fcinfo, true);
|
||||||
else
|
else
|
||||||
{
|
|
||||||
/* safety check */
|
|
||||||
if (AggCheckCallContext(fcinfo, NULL) != AGG_CONTEXT_AGGREGATE)
|
|
||||||
elog(ERROR, "ordered-set aggregate called in non-aggregate context");
|
|
||||||
osastate = (OSAPerGroupState *) PG_GETARG_POINTER(0);
|
osastate = (OSAPerGroupState *) PG_GETARG_POINTER(0);
|
||||||
}
|
|
||||||
|
|
||||||
/* Form a tuple from all the other inputs besides the transition value */
|
/* Form a tuple from all the other inputs besides the transition value */
|
||||||
slot = osastate->qstate->tupslot;
|
slot = osastate->qstate->tupslot;
|
||||||
@ -435,9 +425,7 @@ percentile_disc_final(PG_FUNCTION_ARGS)
|
|||||||
bool isnull;
|
bool isnull;
|
||||||
int64 rownum;
|
int64 rownum;
|
||||||
|
|
||||||
/* safety check */
|
Assert(AggCheckCallContext(fcinfo, NULL) == AGG_CONTEXT_AGGREGATE);
|
||||||
if (AggCheckCallContext(fcinfo, NULL) != AGG_CONTEXT_AGGREGATE)
|
|
||||||
elog(ERROR, "ordered-set aggregate called in non-aggregate context");
|
|
||||||
|
|
||||||
/* Get and check the percentile argument */
|
/* Get and check the percentile argument */
|
||||||
if (PG_ARGISNULL(1))
|
if (PG_ARGISNULL(1))
|
||||||
@ -542,9 +530,7 @@ percentile_cont_final_common(FunctionCallInfo fcinfo,
|
|||||||
double proportion;
|
double proportion;
|
||||||
bool isnull;
|
bool isnull;
|
||||||
|
|
||||||
/* safety check */
|
Assert(AggCheckCallContext(fcinfo, NULL) == AGG_CONTEXT_AGGREGATE);
|
||||||
if (AggCheckCallContext(fcinfo, NULL) != AGG_CONTEXT_AGGREGATE)
|
|
||||||
elog(ERROR, "ordered-set aggregate called in non-aggregate context");
|
|
||||||
|
|
||||||
/* Get and check the percentile argument */
|
/* Get and check the percentile argument */
|
||||||
if (PG_ARGISNULL(1))
|
if (PG_ARGISNULL(1))
|
||||||
@ -752,9 +738,7 @@ percentile_disc_multi_final(PG_FUNCTION_ARGS)
|
|||||||
bool isnull = true;
|
bool isnull = true;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* safety check */
|
Assert(AggCheckCallContext(fcinfo, NULL) == AGG_CONTEXT_AGGREGATE);
|
||||||
if (AggCheckCallContext(fcinfo, NULL) != AGG_CONTEXT_AGGREGATE)
|
|
||||||
elog(ERROR, "ordered-set aggregate called in non-aggregate context");
|
|
||||||
|
|
||||||
/* If there were no regular rows, the result is NULL */
|
/* If there were no regular rows, the result is NULL */
|
||||||
if (PG_ARGISNULL(0))
|
if (PG_ARGISNULL(0))
|
||||||
@ -875,9 +859,7 @@ percentile_cont_multi_final_common(FunctionCallInfo fcinfo,
|
|||||||
bool isnull;
|
bool isnull;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* safety check */
|
Assert(AggCheckCallContext(fcinfo, NULL) == AGG_CONTEXT_AGGREGATE);
|
||||||
if (AggCheckCallContext(fcinfo, NULL) != AGG_CONTEXT_AGGREGATE)
|
|
||||||
elog(ERROR, "ordered-set aggregate called in non-aggregate context");
|
|
||||||
|
|
||||||
/* If there were no regular rows, the result is NULL */
|
/* If there were no regular rows, the result is NULL */
|
||||||
if (PG_ARGISNULL(0))
|
if (PG_ARGISNULL(0))
|
||||||
@ -1045,9 +1027,7 @@ mode_final(PG_FUNCTION_ARGS)
|
|||||||
FmgrInfo *equalfn;
|
FmgrInfo *equalfn;
|
||||||
bool shouldfree;
|
bool shouldfree;
|
||||||
|
|
||||||
/* safety check */
|
Assert(AggCheckCallContext(fcinfo, NULL) == AGG_CONTEXT_AGGREGATE);
|
||||||
if (AggCheckCallContext(fcinfo, NULL) != AGG_CONTEXT_AGGREGATE)
|
|
||||||
elog(ERROR, "ordered-set aggregate called in non-aggregate context");
|
|
||||||
|
|
||||||
/* If there were no regular rows, the result is NULL */
|
/* If there were no regular rows, the result is NULL */
|
||||||
if (PG_ARGISNULL(0))
|
if (PG_ARGISNULL(0))
|
||||||
@ -1173,9 +1153,7 @@ hypothetical_rank_common(FunctionCallInfo fcinfo, int flag,
|
|||||||
TupleTableSlot *slot;
|
TupleTableSlot *slot;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* safety check */
|
Assert(AggCheckCallContext(fcinfo, NULL) == AGG_CONTEXT_AGGREGATE);
|
||||||
if (AggCheckCallContext(fcinfo, NULL) != AGG_CONTEXT_AGGREGATE)
|
|
||||||
elog(ERROR, "ordered-set aggregate called in non-aggregate context");
|
|
||||||
|
|
||||||
/* If there were no regular rows, the rank is always 1 */
|
/* If there were no regular rows, the rank is always 1 */
|
||||||
if (PG_ARGISNULL(0))
|
if (PG_ARGISNULL(0))
|
||||||
@ -1305,9 +1283,7 @@ hypothetical_dense_rank_final(PG_FUNCTION_ARGS)
|
|||||||
MemoryContext tmpcontext;
|
MemoryContext tmpcontext;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* safety check */
|
Assert(AggCheckCallContext(fcinfo, NULL) == AGG_CONTEXT_AGGREGATE);
|
||||||
if (AggCheckCallContext(fcinfo, NULL) != AGG_CONTEXT_AGGREGATE)
|
|
||||||
elog(ERROR, "ordered-set aggregate called in non-aggregate context");
|
|
||||||
|
|
||||||
/* If there were no regular rows, the rank is always 1 */
|
/* If there were no regular rows, the rank is always 1 */
|
||||||
if (PG_ARGISNULL(0))
|
if (PG_ARGISNULL(0))
|
||||||
|
Loading…
Reference in New Issue
Block a user