From: Tom Lane <tgl@sss.pgh.pa.us>
To: Michael Paquier <michael.paquier@gmail.com>
Cc: Andres Freund <andres@2ndquadrant.com>
Cc: cg@osss.net
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #11638: Transaction safety fails when constraints are dropped and analyze is done
Date: Tue, 21 Oct 2014 22:12:29 -0400
Message-ID: <20648.1413943949@sss.pgh.pa.us> (raw)
In-Reply-To: <CAB7nPqR5mpKM6HWh1jE9crWa-8mjri_J9exD3AyYuEEnW0cTQg@mail.gmail.com>
References: <20141010181433.25463.5856@wrigleys.postgresql.org>
<20141010191401.GA18020@awork2.anarazel.de>
<CAB7nPqRsXPPNaFXDHZPbBESYR_EJPvQP6eKmhp-p13mJDpGgXw@mail.gmail.com>
<20141015051254.GC7242@alap3.anarazel.de>
<CAB7nPqTsZUnDNYgLZ8OO5T4rQY+=XSe7uomiv=OVQnJvVzzHJg@mail.gmail.com>
<20141015061815.GF7242@alap3.anarazel.de>
<CAB7nPqR5mpKM6HWh1jE9crWa-8mjri_J9exD3AyYuEEnW0cTQg@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
Michael Paquier <michael.paquier@gmail.com> writes:
> On Wed, Oct 15, 2014 at 3:18 PM, Andres Freund <andres@2ndquadrant.com>
>> On 2014-10-15 15:02:43 +0900, Michael Paquier wrote:
>>> Btw, I have just put my hands on this code and made the attached to
>>> make vac_update_relstats able to do a transactional update. It looks
>>> to work fine with only a check on the flags of vacuum statement.
I think the original reasoning why this would be okay even for ANALYZE
was that if we are doing an ANALYZE inside a transaction that has done
DDL on the table, it would be okay to modify the pg_class row in-place
because it would be a tuple that the transaction itself has written
and so it would be invalidated if the transaction rolled back. The flaw
in this reasoning is that the DDL might not actually have changed the
pg_class row, and so it might still be the original pre-transaction
version that's visible to other transactions. Thus the risk is confined
to cases like DROP INDEX that don't modify pg_class. I'm not entirely
sure, but this reasoning might have been perfectly correct at the time
and have been invalidated by later optimizations to suppress "unnecessary"
physical updates of pg_class in favor of just sending sinval events.
(Note that DROP INDEX certainly must send a relcache inval to ensure that
other sessions stop using the index, and at one time the only trigger for
such an inval was to physically update pg_class and/or pg_attribute.)
>> Imo this is complex enough to deserve a regression test. Can you add
>> one?
> Definitely makes sense. Here is an updated version.
I don't much care for this patch. Aside from cosmetic issues like having
named the new argument backwards and failed to update the function header
comment that the patch largely invalidates, it seems to me to be likely
to have unforeseen side effects, in that there may now be assumptions
elsewhere that we don't force a pg_class update for this type of change.
The implications are particularly ticklish for pg_class itself...
I think that a better answer is to continue to do this update
nontransactionally, but to not let the code clear relhasindex etc
if we're inside a transaction block. It is certainly safe to put
off clearing those flags if we're not sure that we're seeing a
committed state of the table's schema.
An interesting question is whether it is ever possible for this function
to be told to *set* relhasindex when it was clear (or likewise for the
other flags). Offhand I would say that that should never happen, because
certainly neither VACUUM nor ANALYZE should be creating indexes etc.
Should we make it throw an error if that happens, or just go ahead and
apply the update, assuming that it's correcting somehow-corrupted data?
regards, tom lane
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, michael.paquier@gmail.com, andres@2ndquadrant.com, cg@osss.net
Subject: Re: BUG #11638: Transaction safety fails when constraints are dropped and analyze is done
In-Reply-To: <20648.1413943949@sss.pgh.pa.us>
References: <20141010181433.25463.5856@wrigleys.postgresql.org> <20141010191401.GA18020@awork2.anarazel.de> <CAB7nPqRsXPPNaFXDHZPbBESYR_EJPvQP6eKmhp-p13mJDpGgXw@mail.gmail.com> <20141015051254.GC7242@alap3.anarazel.de> <CAB7nPqTsZUnDNYgLZ8OO5T4rQY+=XSe7uomiv=OVQnJvVzzHJg@mail.gmail.com> <20141015061815.GF7242@alap3.anarazel.de> <CAB7nPqR5mpKM6HWh1jE9crWa-8mjri_J9exD3AyYuEEnW0cTQg@mail.gmail.com> <20648.1413943949@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox