aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2014-01-08 14:33:52 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2014-01-08 14:33:52 -0500
commit847e46abc92333a5a948d8fa886604832c1db238 (patch)
tree3dca81d89dc74fb412e5e01f05d1cff8a268d534
parente6336b8b5772b9856d65ef967e0b9f748f0f7b0b (diff)
downloadpostgresql-847e46abc92333a5a948d8fa886604832c1db238.tar.gz
postgresql-847e46abc92333a5a948d8fa886604832c1db238.zip
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.
-rw-r--r--src/backend/utils/adt/orderedsetaggs.c42
1 files changed, 9 insertions, 33 deletions
diff --git a/src/backend/utils/adt/orderedsetaggs.c b/src/backend/utils/adt/orderedsetaggs.c
index d98f5a807c8..216c498a2f1 100644
--- a/src/backend/utils/adt/orderedsetaggs.c
+++ b/src/backend/utils/adt/orderedsetaggs.c
@@ -122,8 +122,8 @@ ordered_set_startup(FunctionCallInfo fcinfo, bool use_tuples)
int numSortCols;
/*
- * Check we're called as aggregate, and get the Agg node's
- * group-lifespan context
+ * Check we're called as aggregate (and not a window function), and
+ * get the Agg node's group-lifespan context
*/
if (AggCheckCallContext(fcinfo, &gcontext) != AGG_CONTEXT_AGGREGATE)
elog(ERROR, "ordered-set aggregate called in non-aggregate context");
@@ -356,12 +356,7 @@ ordered_set_transition(PG_FUNCTION_ARGS)
if (PG_ARGISNULL(0))
osastate = ordered_set_startup(fcinfo, false);
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);
- }
/* Load the datum into the tuplesort object, but only if it's not null */
if (!PG_ARGISNULL(1))
@@ -389,12 +384,7 @@ ordered_set_transition_multi(PG_FUNCTION_ARGS)
if (PG_ARGISNULL(0))
osastate = ordered_set_startup(fcinfo, true);
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);
- }
/* Form a tuple from all the other inputs besides the transition value */
slot = osastate->qstate->tupslot;
@@ -435,9 +425,7 @@ percentile_disc_final(PG_FUNCTION_ARGS)
bool isnull;
int64 rownum;
- /* safety check */
- if (AggCheckCallContext(fcinfo, NULL) != AGG_CONTEXT_AGGREGATE)
- elog(ERROR, "ordered-set aggregate called in non-aggregate context");
+ Assert(AggCheckCallContext(fcinfo, NULL) == AGG_CONTEXT_AGGREGATE);
/* Get and check the percentile argument */
if (PG_ARGISNULL(1))
@@ -542,9 +530,7 @@ percentile_cont_final_common(FunctionCallInfo fcinfo,
double proportion;
bool isnull;
- /* safety check */
- if (AggCheckCallContext(fcinfo, NULL) != AGG_CONTEXT_AGGREGATE)
- elog(ERROR, "ordered-set aggregate called in non-aggregate context");
+ Assert(AggCheckCallContext(fcinfo, NULL) == AGG_CONTEXT_AGGREGATE);
/* Get and check the percentile argument */
if (PG_ARGISNULL(1))
@@ -752,9 +738,7 @@ percentile_disc_multi_final(PG_FUNCTION_ARGS)
bool isnull = true;
int i;
- /* safety check */
- if (AggCheckCallContext(fcinfo, NULL) != AGG_CONTEXT_AGGREGATE)
- elog(ERROR, "ordered-set aggregate called in non-aggregate context");
+ Assert(AggCheckCallContext(fcinfo, NULL) == AGG_CONTEXT_AGGREGATE);
/* If there were no regular rows, the result is NULL */
if (PG_ARGISNULL(0))
@@ -875,9 +859,7 @@ percentile_cont_multi_final_common(FunctionCallInfo fcinfo,
bool isnull;
int i;
- /* safety check */
- if (AggCheckCallContext(fcinfo, NULL) != AGG_CONTEXT_AGGREGATE)
- elog(ERROR, "ordered-set aggregate called in non-aggregate context");
+ Assert(AggCheckCallContext(fcinfo, NULL) == AGG_CONTEXT_AGGREGATE);
/* If there were no regular rows, the result is NULL */
if (PG_ARGISNULL(0))
@@ -1045,9 +1027,7 @@ mode_final(PG_FUNCTION_ARGS)
FmgrInfo *equalfn;
bool shouldfree;
- /* safety check */
- if (AggCheckCallContext(fcinfo, NULL) != AGG_CONTEXT_AGGREGATE)
- elog(ERROR, "ordered-set aggregate called in non-aggregate context");
+ Assert(AggCheckCallContext(fcinfo, NULL) == AGG_CONTEXT_AGGREGATE);
/* If there were no regular rows, the result is NULL */
if (PG_ARGISNULL(0))
@@ -1173,9 +1153,7 @@ hypothetical_rank_common(FunctionCallInfo fcinfo, int flag,
TupleTableSlot *slot;
int i;
- /* safety check */
- if (AggCheckCallContext(fcinfo, NULL) != AGG_CONTEXT_AGGREGATE)
- elog(ERROR, "ordered-set aggregate called in non-aggregate context");
+ Assert(AggCheckCallContext(fcinfo, NULL) == AGG_CONTEXT_AGGREGATE);
/* If there were no regular rows, the rank is always 1 */
if (PG_ARGISNULL(0))
@@ -1305,9 +1283,7 @@ hypothetical_dense_rank_final(PG_FUNCTION_ARGS)
MemoryContext tmpcontext;
int i;
- /* safety check */
- if (AggCheckCallContext(fcinfo, NULL) != AGG_CONTEXT_AGGREGATE)
- elog(ERROR, "ordered-set aggregate called in non-aggregate context");
+ Assert(AggCheckCallContext(fcinfo, NULL) == AGG_CONTEXT_AGGREGATE);
/* If there were no regular rows, the rank is always 1 */
if (PG_ARGISNULL(0))