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

Commit17083ab

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 parent8cbd679 commit17083ab

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
@@ -409,16 +409,17 @@ AggregateCreate(const char *aggName,
409409
OidcombineType;
410410

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

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

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

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

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

448450
serialfn=lookup_agg_function(aggserialfnName,1,
449-
fnArgs,variadicArgType,
451+
fnArgs,InvalidOid,
450452
&rettype);
451453

452454
if (rettype!=BYTEAOID)
@@ -462,11 +464,12 @@ AggregateCreate(const char *aggName,
462464
*/
463465
if (aggdeserialfnName)
464466
{
467+
/* signature is always deserialize(bytea, internal) returns internal */
465468
fnArgs[0]=BYTEAOID;
466469
fnArgs[1]=INTERNALOID;/* dummy argument for type safety */
467470

468471
deserialfn=lookup_agg_function(aggdeserialfnName,2,
469-
fnArgs,variadicArgType,
472+
fnArgs,InvalidOid,
470473
&rettype);
471474

472475
if (rettype!=INTERNALOID)
@@ -768,7 +771,11 @@ AggregateCreate(const char *aggName,
768771

769772
/*
770773
* lookup_agg_function
771-
* common code for finding transfn, invtransfn, finalfn, and combinefn
774+
* common code for finding aggregate support functions
775+
*
776+
* fnName: possibly-schema-qualified function name
777+
* nargs, input_types: expected function argument types
778+
* variadicArgType: type of variadic argument if any, else InvalidOid
772779
*
773780
* Returns OID of function, and stores its return type into *rettype
774781
*

‎src/backend/executor/nodeAgg.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3556,8 +3556,8 @@ build_pertrans_for_aggref(AggStatePerTrans pertrans,
35563556
if (pertrans->transfn.fn_strict&&aggtranstype==INTERNALOID)
35573557
ereport(ERROR,
35583558
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
3559-
errmsg("combine functionfor aggregate %u must be declared as STRICT",
3560-
aggref->aggfnoid)));
3559+
errmsg("combine functionwith transition type %s mustnotbe declared STRICT",
3560+
format_type_be(aggtranstype))));
35613561
}
35623562
else
35633563
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp