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

Commita55888e

Browse files
committed
Fix nodeAgg coredump in case where lower-level plan has
an empty targetlist *and* fails to return any tuples, as will happenfor example with 'SELECT COUNT(1) FROM table WHERE ...' if the where-clause selects no tuples. It's so nice to make a fix by diking out code,instead of adding more...
1 parent04f150e commita55888e

File tree

1 file changed

+14
-27
lines changed

1 file changed

+14
-27
lines changed

‎src/backend/executor/nodeAgg.c

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* SQL aggregates. (Do not expect POSTQUEL semantics.) -- ay 2/95
1212
*
1313
* IDENTIFICATION
14-
* $Header: /cvsroot/pgsql/src/backend/executor/nodeAgg.c,v 1.55 1999/09/26 21:21:09 tgl Exp $
14+
* $Header: /cvsroot/pgsql/src/backend/executor/nodeAgg.c,v 1.56 1999/09/28 02:03:19 tgl Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -373,7 +373,8 @@ ExecAgg(Agg *node)
373373
elog(ERROR,"ExecAgg: no valid transition functions??");
374374

375375
/*
376-
* Release any per-group working storage.
376+
* Release any per-group working storage, unless we're passing
377+
* it back as the result of the aggregate.
377378
*/
378379
if (OidIsValid(peraggstate->xfn1_oid)&&
379380
!peraggstate->value1IsNull&&
@@ -411,34 +412,20 @@ ExecAgg(Agg *node)
411412
aggstate->agg_done= true;
412413

413414
/*
414-
* When the outerPlan doesn't return a single tuple,
415-
* create a dummy input tuple anyway because we still need
416-
* to return a valid aggregate tuple. (XXX isn't this wasted
417-
* effort? Since we're not in GROUP BY mode, it shouldn't be
418-
* possible for the projected result to refer to any raw input
419-
* columns??) The values returned for the aggregates will be
420-
* the initial values of the transition functions.
415+
* We used to create a dummy all-nulls input tuple here if
416+
* inputTuple == NULL (ie, the outerPlan didn't return anything).
417+
* However, now that we don't return a bogus tuple in Group mode,
418+
* we can only get here with inputTuple == NULL in non-Group mode.
419+
* So, if the parser has done its job right, the projected output
420+
* tuple's targetList must not contain any direct references to
421+
* input columns, and so it's a waste of time to create an
422+
* all-nulls input tuple. We just let the tuple slot get set
423+
* to NULL instead. The values returned for the aggregates will
424+
* be the initial values of the transition functions.
421425
*/
422-
if (inputTuple==NULL)
423-
{
424-
TupleDesctupType;
425-
Datum*tupValue;
426-
char*null_array;
427-
AttrNumberattnum;
428-
429-
tupType=aggstate->csstate.css_ScanTupleSlot->ttc_tupleDescriptor;
430-
tupValue=projInfo->pi_tupValue;
431-
432-
/* set all the values to NULL */
433-
null_array=palloc(sizeof(char)*tupType->natts);
434-
for (attnum=0;attnum<tupType->natts;attnum++)
435-
null_array[attnum]='n';
436-
inputTuple=heap_formtuple(tupType,tupValue,null_array);
437-
pfree(null_array);
438-
}
439426

440427
/*
441-
* Store the representative input tuple (orfaked-up null tuple)
428+
* Store the representative input tuple (orNULL, if none)
442429
* in the tuple table slot reserved for it.
443430
*/
444431
ExecStoreTuple(inputTuple,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp