Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9d229f3

Browse files
committed
Provide moving-aggregate support for a bunch of numerical aggregates.
First installment of the promised moving-aggregate support in built-inaggregates: count(), sum(), avg(), stddev() and variance() forassorted datatypes, though not for float4/float8.In passing, remove a 2001-vintage kluge in interval_accum(): intervalarray elements have been properly aligned since around 2003, butnobody remembered to take out this workaround. Also, fix a thinkoin the opr_sanity tests for moving-aggregate catalog entries.David Rowley and Florian Pflug, reviewed by Dean Rasheed
1 parenta9d9acb commit9d229f3

File tree

13 files changed

+1230
-222
lines changed

13 files changed

+1230
-222
lines changed

‎src/backend/utils/adt/int8.c

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -717,13 +717,58 @@ int8inc(PG_FUNCTION_ARGS)
717717
}
718718
}
719719

720+
Datum
721+
int8dec(PG_FUNCTION_ARGS)
722+
{
723+
/*
724+
* When int8 is pass-by-reference, we provide this special case to avoid
725+
* palloc overhead for COUNT(): when called as an aggregate, we know that
726+
* the argument is modifiable local storage, so just update it in-place.
727+
* (If int8 is pass-by-value, then of course this is useless as well as
728+
* incorrect, so just ifdef it out.)
729+
*/
730+
#ifndefUSE_FLOAT8_BYVAL/* controls int8 too */
731+
if (AggCheckCallContext(fcinfo,NULL))
732+
{
733+
int64*arg= (int64*)PG_GETARG_POINTER(0);
734+
int64result;
735+
736+
result=*arg-1;
737+
/* Overflow check */
738+
if (result>0&&*arg<0)
739+
ereport(ERROR,
740+
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
741+
errmsg("bigint out of range")));
742+
743+
*arg=result;
744+
PG_RETURN_POINTER(arg);
745+
}
746+
else
747+
#endif
748+
{
749+
/* Not called as an aggregate, so just do it the dumb way */
750+
int64arg=PG_GETARG_INT64(0);
751+
int64result;
752+
753+
result=arg-1;
754+
/* Overflow check */
755+
if (result>0&&arg<0)
756+
ereport(ERROR,
757+
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
758+
errmsg("bigint out of range")));
759+
760+
PG_RETURN_INT64(result);
761+
}
762+
}
763+
764+
720765
/*
721-
* These functions are exactly like int8inc but are used for aggregates that
722-
* count only non-null values.Since the functions are declared strict,
723-
* the null checks happen before we ever get here, and all we need do is
724-
* increment the state value. We could actually make these pg_proc entries
725-
* point right at int8inc, but then the opr_sanity regression test would
726-
* complain about mismatched entries for a built-in function.
766+
* These functions are exactly like int8inc/int8dec but are used for
767+
*aggregates thatcount only non-null values.Since the functions are
768+
*declared strict,the null checks happen before we ever get here, and all we
769+
*need do isincrement the state value. We could actually make these pg_proc
770+
*entriespoint right at int8inc/int8dec, but then the opr_sanity regression
771+
*test wouldcomplain about mismatched entries for a built-in function.
727772
*/
728773

729774
Datum
@@ -738,6 +783,12 @@ int8inc_float8_float8(PG_FUNCTION_ARGS)
738783
returnint8inc(fcinfo);
739784
}
740785

786+
Datum
787+
int8dec_any(PG_FUNCTION_ARGS)
788+
{
789+
returnint8dec(fcinfo);
790+
}
791+
741792

742793
Datum
743794
int8larger(PG_FUNCTION_ARGS)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp