Re: pgsql: Avoid corrupting tables when ANALYZE inside a transaction is rol

From: Noah Misch <noah(at)leadboat(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-committers(at)postgresql(dot)org
Subject: Re: pgsql: Avoid corrupting tables when ANALYZE inside a transaction is rol
Date: 2014-10-30 04:09:36
Message-ID: 20141030040936.GA407655@tornado.leadboat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

On Wed, Oct 29, 2014 at 10:12:44PM +0000, Tom Lane wrote:
> Avoid corrupting tables when ANALYZE inside a transaction is rolled back.
>
> VACUUM and ANALYZE update the target table's pg_class row in-place, that is
> nontransactionally. This is OK, more or less, for the statistical columns,
> which are mostly nontransactional anyhow. It's not so OK for the DDL hint
> flags (relhasindex etc), which might get changed in response to
> transactional changes that could still be rolled back. This isn't a
> problem for VACUUM, since it can't be run inside a transaction block nor
> in parallel with DDL on the table. However, we allow ANALYZE inside a
> transaction block, so if the transaction had earlier removed the last
> index, rule, or trigger from the table, and then we roll back the
> transaction after ANALYZE, the table would be left in a corrupted state
> with the hint flags not set though they should be.
>
> To fix, suppress the hint-flag updates if we are InTransactionBlock().

Shouldn't this use IsInTransactionChain(), to catch the other ways ANALYZE can
share a transaction with DDL?

In response to

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2014-10-30 14:10:13 Re: Re: pgsql: Avoid corrupting tables when ANALYZE inside a transaction is rol
Previous Message Peter Eisentraut 2014-10-30 00:06:56 pgsql: Remove use of TAP subtests