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

Commit05ca21b

Browse files
committed
Fix type checking for support functions of parallel VARIADIC aggregates.
The impact of VARIADIC on the combine/serialize/deserialize supportfunctions of an aggregate wasn't thought through carefully. There isactually no impact, because variadicity isn't passed through to thesefunctions (and it doesn't seem like it would need to be). However,lookup_agg_function was mistakenly told to check things as though it werepassed through. The net result was that it was impossible to declare anaggregate that had both VARIADIC input and parallelism support functions.In passing, fix a runtime check in nodeAgg.c for the combine function'sstrictness to make its error message agree with the creation-time check.The previous message was actually backwards, and it doesn't seem likethere's a good reason to have two versions of this message text anyway.Back-patch to 9.6 where parallel aggregation was introduced.Alexey Bashtanov; message fix by meDiscussion:https://postgr.es/m/f86dde87-fef4-71eb-0480-62754aaca01b@imap.cc
1 parent185f4f8 commit05ca21b

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

‎src/backend/catalog/pg_aggregate.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -410,16 +410,17 @@ AggregateCreate(const char *aggName,
410410
OidcombineType;
411411

412412
/*
413-
* Combine function must have 2argument, each of which is the trans
414-
* type
413+
* Combine function must have 2arguments, each of which is the trans
414+
* type. VARIADIC doesn't affect it.
415415
*/
416416
fnArgs[0]=aggTransType;
417417
fnArgs[1]=aggTransType;
418418

419-
combinefn=lookup_agg_function(aggcombinefnName,2,fnArgs,
420-
variadicArgType,&combineType);
419+
combinefn=lookup_agg_function(aggcombinefnName,2,
420+
fnArgs,InvalidOid,
421+
&combineType);
421422

422-
/* Ensure the return type matches theaggregates trans type */
423+
/* Ensure the return type matches theaggregate's trans type */
423424
if (combineType!=aggTransType)
424425
ereport(ERROR,
425426
(errcode(ERRCODE_DATATYPE_MISMATCH),
@@ -429,25 +430,26 @@ AggregateCreate(const char *aggName,
429430

430431
/*
431432
* A combine function to combine INTERNAL states must accept nulls and
432-
* ensure that the returned state is in the correct memory context.
433+
* ensure that the returned state is in the correct memory context. We
434+
* cannot directly check the latter, but we can check the former.
433435
*/
434436
if (aggTransType==INTERNALOID&&func_strict(combinefn))
435437
ereport(ERROR,
436438
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
437439
errmsg("combine function with transition type %s must not be declared STRICT",
438440
format_type_be(aggTransType))));
439-
440441
}
441442

442443
/*
443444
* Validate the serialization function, if present.
444445
*/
445446
if (aggserialfnName)
446447
{
448+
/* signature is always serialize(internal) returns bytea */
447449
fnArgs[0]=INTERNALOID;
448450

449451
serialfn=lookup_agg_function(aggserialfnName,1,
450-
fnArgs,variadicArgType,
452+
fnArgs,InvalidOid,
451453
&rettype);
452454

453455
if (rettype!=BYTEAOID)
@@ -463,11 +465,12 @@ AggregateCreate(const char *aggName,
463465
*/
464466
if (aggdeserialfnName)
465467
{
468+
/* signature is always deserialize(bytea, internal) returns internal */
466469
fnArgs[0]=BYTEAOID;
467470
fnArgs[1]=INTERNALOID;/* dummy argument for type safety */
468471

469472
deserialfn=lookup_agg_function(aggdeserialfnName,2,
470-
fnArgs,variadicArgType,
473+
fnArgs,InvalidOid,
471474
&rettype);
472475

473476
if (rettype!=INTERNALOID)
@@ -770,7 +773,11 @@ AggregateCreate(const char *aggName,
770773

771774
/*
772775
* lookup_agg_function
773-
* common code for finding transfn, invtransfn, finalfn, and combinefn
776+
* common code for finding aggregate support functions
777+
*
778+
* fnName: possibly-schema-qualified function name
779+
* nargs, input_types: expected function argument types
780+
* variadicArgType: type of variadic argument if any, else InvalidOid
774781
*
775782
* Returns OID of function, and stores its return type into *rettype
776783
*

‎src/backend/executor/nodeAgg.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2940,8 +2940,8 @@ build_pertrans_for_aggref(AggStatePerTrans pertrans,
29402940
if (pertrans->transfn.fn_strict&&aggtranstype==INTERNALOID)
29412941
ereport(ERROR,
29422942
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
2943-
errmsg("combine functionfor aggregate %u must be declared as STRICT",
2944-
aggref->aggfnoid)));
2943+
errmsg("combine functionwith transition type %s mustnotbe declared STRICT",
2944+
format_type_be(aggtranstype))));
29452945
}
29462946
else
29472947
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp