]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix misapplication of pgstat_count_truncate to wrong relation.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 7 Dec 2018 17:12:00 +0000 (12:12 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 7 Dec 2018 17:12:00 +0000 (12:12 -0500)
commit4d5cfb91156d1cc8ede245b8b363468efedf1975
treec0ca3b53bbbd7d14856e01240a339398e2d5a256
parenta40ee75c1e2c16802d9d1b5473d9dcea20263653
Fix misapplication of pgstat_count_truncate to wrong relation.

The stanza of ExecuteTruncate[Guts] that truncates a target table's toast
relation re-used the loop local variable "rel" to reference the toast rel.
This was safe enough when written, but commit d42358efb added code below
that that supposed "rel" still pointed to the parent table.  Therefore,
the stats counter update was applied to the wrong relcache entry (the
toast rel not the user rel); and if we were unlucky and that relcache
entry had been flushed during reindex_relation, very bad things could
ensue.

(I'm surprised that CLOBBER_CACHE_ALWAYS testing hasn't found this.
I'm even more surprised that the problem wasn't detected during the
development of d42358efb; it must not have been tested in any case
with a toast table, as the incorrect stats counts are very obvious.)

To fix, replace use of "rel" in that code branch with a more local
variable.  Adjust test cases added by d42358efb so that some of them
use tables with toast tables.

Per bug #15540 from Pan Bian.  Back-patch to 9.5 where d42358efb came in.

Discussion: https://postgr.es/m/15540-01078812338195c0@postgresql.org
src/backend/commands/tablecmds.c
src/test/regress/expected/stats.out
src/test/regress/sql/stats.sql