]> granicus.if.org Git - postgresql/commit
Fix slot type handling for Agg nodes performing internal sorts.
authorAndres Freund <andres@anarazel.de>
Thu, 25 Jul 2019 21:22:52 +0000 (14:22 -0700)
committerAndres Freund <andres@anarazel.de>
Thu, 25 Jul 2019 21:29:26 +0000 (14:29 -0700)
commit8677c62eaeea002712dd71dc678a7a0566e59858
tree7ae9b0df6e51dd34d874275b7d88e824296f3544
parentb2453704673469ffd34ed13a642e3edc936f5a24
Fix slot type handling for Agg nodes performing internal sorts.

Since 15d8f8312 we assert that - and since 7ef04e4d2cb24da597edf1
rely on - the slot type for an expression's
ecxt_{outer,inner,scan}tuple not changing, unless explicitly flagged
as such. That allows to either skip deforming (for a virtual tuple
slot) or optimize the code for JIT accelerated deforming
appropriately (for other known slot types).

This assumption was sometimes violated for grouping sets, when
nodeAgg.c internally uses tuplesorts, and the child node doesn't
return a TTSOpsMinimalTuple type slot. Detect that case, and flag that
the outer slot might not be "fixed".

It's probably worthwhile to optimize this further in the future, and
more granularly determine whether the slot is fixed. As we already
instantiate per-phase transition and equal expressions, we could
cheaply set the slot type appropriately for each phase.  But that's a
separate change from this bugfix.

This commit does include a very minor optimization by avoiding to
create a slot for handling tuplesorts, if no such sorts are
performed. Previously we created that slot unnecessarily in the common
case of computing all grouping sets via hashing. The code looked too
confusing without that, as the conditions for needing a sort slot and
flagging that the slot type isn't fixed, are the same.

Reported-By: Ashutosh Sharma
Author: Andres Freund
Discussion: https://postgr.es/m/CAE9k0PmNaMD2oHTEAhRyxnxpaDaYkuBYkLa1dpOpn=RS0iS2AQ@mail.gmail.com
Backpatch: 12-, where the bug was introduced in 15d8f8312
src/backend/executor/nodeAgg.c
src/test/regress/expected/groupingsets.out
src/test/regress/sql/groupingsets.sql