postgresql/src/backend/commands
Tom Lane 5deadfef28 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
2018-12-07 12:11:59 -05:00
..
aggregatecmds.c Improve spelling of new FINALFUNC_MODIFY aggregate attribute. 2018-05-21 11:41:42 -04:00
alter.c Remove WITH OIDS support, change oid catalog column visibility. 2018-11-20 16:00:17 -08:00
amcmds.c Remove WITH OIDS support, change oid catalog column visibility. 2018-11-20 16:00:17 -08:00
analyze.c Introduce notion of different types of slots (without implementing them). 2018-11-15 22:00:30 -08:00
async.c Update copyright for 2018 2018-01-02 23:30:12 -05:00
cluster.c Remove WITH OIDS support, change oid catalog column visibility. 2018-11-20 16:00:17 -08:00
collationcmds.c Merge catalog/pg_foo_fn.h headers back into pg_foo.h headers. 2018-04-08 14:35:29 -04:00
comment.c Update copyright for 2018 2018-01-02 23:30:12 -05:00
constraint.c Introduce notion of different types of slots (without implementing them). 2018-11-15 22:00:30 -08:00
conversioncmds.c Merge catalog/pg_foo_fn.h headers back into pg_foo.h headers. 2018-04-08 14:35:29 -04:00
copy.c Remove WITH OIDS support, change oid catalog column visibility. 2018-11-20 16:00:17 -08:00
createas.c Remove WITH OIDS support, change oid catalog column visibility. 2018-11-20 16:00:17 -08:00
dbcommands.c Remove WITH OIDS support, change oid catalog column visibility. 2018-11-20 16:00:17 -08:00
define.c Update copyright for 2018 2018-01-02 23:30:12 -05:00
discard.c Rename TransactionChain functions 2018-03-16 13:18:06 -04:00
dropcmds.c Fix more wrong paths in header comments 2018-07-11 17:57:04 +03:00
event_trigger.c Remove WITH OIDS support, change oid catalog column visibility. 2018-11-20 16:00:17 -08:00
explain.c Remove WITH OIDS support, change oid catalog column visibility. 2018-11-20 16:00:17 -08:00
extension.c Integrate recovery.conf into postgresql.conf 2018-11-25 16:33:40 +01:00
foreigncmds.c Remove WITH OIDS support, change oid catalog column visibility. 2018-11-20 16:00:17 -08:00
functioncmds.c Remove WITH OIDS support, change oid catalog column visibility. 2018-11-20 16:00:17 -08:00
indexcmds.c Don't mark partitioned indexes invalid unnecessarily 2018-12-05 13:31:51 -03:00
lockcmds.c Post-feature-freeze pgindent run. 2018-04-26 14:47:16 -04:00
Makefile Implement multivariate n-distinct coefficients 2017-03-24 14:06:10 -03:00
matview.c Remove WITH OIDS support, change oid catalog column visibility. 2018-11-20 16:00:17 -08:00
opclasscmds.c Remove WITH OIDS support, change oid catalog column visibility. 2018-11-20 16:00:17 -08:00
operatorcmds.c Change PROCEDURE to FUNCTION in CREATE OPERATOR syntax 2018-08-22 14:44:49 +02:00
policy.c Remove WITH OIDS support, change oid catalog column visibility. 2018-11-20 16:00:17 -08:00
portalcmds.c Post-feature-freeze pgindent run. 2018-04-26 14:47:16 -04:00
prepare.c Remove WITH OIDS support, change oid catalog column visibility. 2018-11-20 16:00:17 -08:00
proclang.c Remove WITH OIDS support, change oid catalog column visibility. 2018-11-20 16:00:17 -08:00
publicationcmds.c Clean up sloppy coding in publicationcmds.c's OpenTableList(). 2018-12-07 11:02:39 -05:00
schemacmds.c Remove WITH OIDS support, change oid catalog column visibility. 2018-11-20 16:00:17 -08:00
seclabel.c Remove duplicated words split across lines in comments 2018-09-08 12:24:19 -07:00
sequence.c Remove WITH OIDS support, change oid catalog column visibility. 2018-11-20 16:00:17 -08:00
statscmds.c Remove WITH OIDS support, change oid catalog column visibility. 2018-11-20 16:00:17 -08:00
subscriptioncmds.c Remove WITH OIDS support, change oid catalog column visibility. 2018-11-20 16:00:17 -08:00
tablecmds.c Fix misapplication of pgstat_count_truncate to wrong relation. 2018-12-07 12:11:59 -05:00
tablespace.c Remove WITH OIDS support, change oid catalog column visibility. 2018-11-20 16:00:17 -08:00
trigger.c Remove WITH OIDS support, change oid catalog column visibility. 2018-11-20 16:00:17 -08:00
tsearchcmds.c Remove WITH OIDS support, change oid catalog column visibility. 2018-11-20 16:00:17 -08:00
typecmds.c Remove WITH OIDS support, change oid catalog column visibility. 2018-11-20 16:00:17 -08:00
user.c Remove WITH OIDS support, change oid catalog column visibility. 2018-11-20 16:00:17 -08:00
vacuum.c Remove WITH OIDS support, change oid catalog column visibility. 2018-11-20 16:00:17 -08:00
vacuumlazy.c Remove WITH OIDS support, change oid catalog column visibility. 2018-11-20 16:00:17 -08:00
variable.c Remove WITH OIDS support, change oid catalog column visibility. 2018-11-20 16:00:17 -08:00
view.c Remove WITH OIDS support, change oid catalog column visibility. 2018-11-20 16:00:17 -08:00