]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix edge case leading to agg transitions skipping ExecAggTransReparent() calls.
authorAndres Freund <andres@anarazel.de>
Tue, 21 Jan 2020 07:26:51 +0000 (23:26 -0800)
committerAndres Freund <andres@anarazel.de>
Tue, 21 Jan 2020 07:30:47 +0000 (23:30 -0800)
commit8bb006a412e4022f60cf7a71ebdc45a12d6c61c4
tree4827f1c7003c5886f30dd3ba1e323c52078ce834
parent1ef7332b78f55f0503a8c882886d2979c2f94c62
Fix edge case leading to agg transitions skipping ExecAggTransReparent() calls.

The code checking whether an aggregate transition value needs to be
reparented into the current context has always only compared the
transition return value with the previous transition value by datum,
i.e. without regard for NULLness.  This normally works, because when
the transition function returns NULL (via fcinfo->isnull), it'll
return a value that won't be the same as its input value.

But there's no hard requirement that that's the case. And it turns
out, it's possible to hit this case (see discussion or reproducers),
leading to a non-null transition value not being reparented, followed
by a crash caused by that.

Instead of adding another comparison of NULLness, instead have
ExecAggTransReparent() ensure that pergroup->transValue ends up as 0
when the new transition value is NULL. That avoids having to add an
additional branch to the much more common cases of the transition
function returning the old transition value (which is a pointer in
this case), and when the new value is different, but not NULL.

In branches since 69c3936a149, also deduplicate the reparenting code
between the expression evaluation based transitions, and the path for
ordered aggregates.

Reported-By: Teodor Sigaev, Nikita Glukhov
Author: Andres Freund
Discussion: https://postgr.es/m/bd34e930-cfec-ea9b-3827-a8bc50891393@sigaev.ru
Backpatch: 9.4-, this issue has existed since at least 7.4
src/backend/executor/nodeAgg.c