Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XjGZb-0001cq-Jy for pgsql-bugs@arkaria.postgresql.org; Tue, 28 Oct 2014 23:53:11 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XjGZb-0006p8-0G for pgsql-bugs@arkaria.postgresql.org; Tue, 28 Oct 2014 23:53:11 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XjGZZ-0006p1-Ty for pgsql-bugs@postgresql.org; Tue, 28 Oct 2014 23:53:10 +0000 Received: from mout.kundenserver.de ([212.227.126.130]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XjGZS-00089F-HN for pgsql-bugs@postgresql.org; Tue, 28 Oct 2014 23:53:07 +0000 Received: from anarazel.de (p5DDC5260.dip0.t-ipconnect.de [93.220.82.96]) by mrelayeu.kundenserver.de (node=mreue004) with ESMTP (Nemesis) id 0M4miX-1Y0FgS3k0z-00yy8S; Wed, 29 Oct 2014 00:52:58 +0100 Received: by anarazel.de (Postfix, from userid 1000) id 092F910048F; Wed, 29 Oct 2014 00:52:56 +0100 (CET) Date: Wed, 29 Oct 2014 00:52:56 +0100 From: Andres Freund To: Tom Lane Cc: Michael Paquier , cg@osss.net, pgsql-bugs@postgresql.org Subject: Re: BUG #11638: Transaction safety fails when constraints are dropped and analyze is done Message-ID: <20141028235256.GJ5873@awork2.anarazel.de> References: <20141010181433.25463.5856@wrigleys.postgresql.org> <20141010191401.GA18020@awork2.anarazel.de> <20141015051254.GC7242@alap3.anarazel.de> <20141015061815.GF7242@alap3.anarazel.de> <20648.1413943949@sss.pgh.pa.us> <20972.1414538885@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20972.1414538885@sss.pgh.pa.us> X-Provags-ID: V02:K0:7Oa3AKTyl+1IDajvfJqMw8Ap9uL0FIZi1NhLOeZbtyu 4hC40uuXvo7apFIv3ruh/l2xuLOUyPWCp0rvBSY25RKyCLQqY/ bdhKASxdAn9LZhcDSAh+t0m8ktGeEgFwQCHwLEHqI2CTWQegkL 3K9hlvMCcI4lSWlzhDgNWNtfd/bsfJVXYB7bMMjIvzdL6smCWU 51T5zr7v5Twg+K49tMTMF6x48yPnNVGtXs6j8sIpihskP4S+1H zeUWNxfvYXYOnkPGLgAtdSSNKZ7PQt8fm2fL3tKO4gWx9lhn8p 5qAc5iCSkEWe574itejSnnLf5DeMjcyqHTk+mg5nT5m+eYpJcE dMtaWgPrWzioyhHdIBiw1l+3VP06rtpYhH21V4ilh X-UI-Out-Filterresults: notjunk:1; X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org On 2014-10-28 19:28:05 -0400, Tom Lane wrote: > I wrote: > > 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. > > Attached is a proposed patch to do it that way. I borrowed Michael's > test case. I still think it'd be better to use a transactional update. But I also *do* agree that this is the safer way forward for now. So +1 from me. > + * In addition to fundamentally nontransactional statistics such as > + * relpages and relallvisible, we try to maintain certain lazily-updated > + * DDL flags such as relhasindex, by clearing them if no longer correct. > + * It's safe to do this in VACUUM, which can't run in parallel with > + * CREATE INDEX/RULE/TRIGGER and can't be part of a transaction block. > + * However, it's *not* safe to do it in an ANALYZE that's within a > + * transaction block, because the current transaction might've dropped > + * the last index; we'd think relhasindex should be cleared, but if the > + * transaction later rolls back this would be wrong. So we refrain from > + * updating the DDL flags if we're inside a transaction block. This is > + * OK since postponing the flag maintenance is always allowable. > + * Absolutely minor nitpick: It nearly sounds like this is only a concern for relhasindex - but it's just as much a problem for other relhas* stuff. Not sure if it's worth complicating the text for that. Maybe a 'e.g.'. Greetings, Andres Freund -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs