Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fkgTB-0005LZ-OC for pgsql-bugs@arkaria.postgresql.org; Wed, 01 Aug 2018 02:02:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fkgT9-0005wc-MB for pgsql-bugs@arkaria.postgresql.org; Wed, 01 Aug 2018 02:02:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fkgT7-0005wR-K3; Wed, 01 Aug 2018 02:02:31 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fkgSv-0007Q3-2a; Wed, 01 Aug 2018 02:02:29 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id AC9F0210F0; Tue, 31 Jul 2018 22:02:13 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Tue, 31 Jul 2018 22:02:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:content-type:date:from:in-reply-to:message-id:mime-version :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=bLdjN6Ymf/sBY9N0VFklakxbkk+a83T42W4zQ7xvU0E=; b=o+zK/K/e WiSjhZBnSCY//8cVl5lVTLe5qFiPeqjTl0daOYldBM3i/HZL3FfsNP1sGNJ86Xhh TE35ELS+cHnf+aeAaM9ZNJi3+dA4sJTaocIpIwT90O1xhPegn1ORyAEO8ynDgy7x Zf7WBEGZfDwmsBtX1r6312q/AKF0YzteKpma0xOWuz4IktyrAjifxIri9pIxR/Rr 4M/gF3lP4YiQVeUlZPVzd0m+ow2z71C9DGcIvkS1KupXzepJb6WGGEO2NWB2LMHc 3wPiY7/QLAbZ8ZKyeSxk52uaVGvRB54vilSVPvg71GzMnZOcec+gMPwsibKlBX3L VWVpGozkktKorA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=bLdjN6Ymf/sBY9N0VFklakxbkk+a8 3T42W4zQ7xvU0E=; b=vfg4ze8mSmsuEzh43FEpLQTsn5AiD7gfhi6a7MoI71wet viwR8u7Q42rnZXjgKfhPJKXwJNQWR60U62irks5ZWkIxqf7xo/+nz/R0Hxct39ry fd+XSHA+LS1zzVp/N19ktJ+hyAPUAaeUNt7BZyT8GdRgCPdocAW/jykBsE29Suog oSpunUGj9aWlTO0oHaHSZHJNU6WfcNwckrFA4s0lsQC/otOxOwKkw5ZJFlDtyqwX VBO6K5j7loRXKlCDOR/38ZZgiyLWS84MOIZazq8EqOOcgzjY/d0pSl4XcUVaYD8p aOigau9NypaXIH2sQktNS93YfND4oagFgDlw3wupA== X-ME-Proxy: X-ME-Sender: Received: from intern.anarazel.de (c-98-210-140-171.hsd1.ca.comcast.net [98.210.140.171]) by mail.messagingengine.com (Postfix) with ESMTPA id 085FCE405A; Tue, 31 Jul 2018 22:02:13 -0400 (EDT) Date: Tue, 31 Jul 2018 19:02:11 -0700 From: Andres Freund To: Peter Geoghegan Cc: Luca Ferrari , PostgreSQL mailing lists , pgsql-general Subject: Re: could not read block 0 in file : read only 0 of 8192 bytes when doing nasty on immutable index function Message-ID: <20180801020211.fqrubprbstrdcg6p@alap3.anarazel.de> References: <20180627204439.4b7miflyolm4qtcz@alap3.anarazel.de> <20180628150209.n2qch5jtn3vt2xaa@alap3.anarazel.de> <20180709183201.zn53uwiwqozhettk@alap3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2018-07-31 18:48:23 -0700, Peter Geoghegan wrote: > On Mon, Jul 9, 2018 at 11:32 AM, Andres Freund wrote: > > I assume we'll have to backpatch this issue, so I think it'd probably a > > good idea to put a specific CacheInvalidateHeapTuple() in there > > explicitly in the back branches, and do the larger fix in 12. ISTM > > there's some risks that it'd cause issues. > > What do you think of the attached? > > The is a new CacheInvalidateRelcache() call, rather than a new call to > CacheInvalidateRelcacheByTuple(), but those two things are equivalent > (I assume that you actually meant to say > CacheInvalidateRelcacheByTuple(), not CacheInvalidateHeapTuple()). Right. > From 18ffbcc81c75525c73930ad3b5a63ae0873d2381 Mon Sep 17 00:00:00 2001 > From: Peter Geoghegan > Date: Tue, 31 Jul 2018 18:33:30 -0700 > Subject: [PATCH] Add table relcache invalidation to index builds. > > It's necessary to make sure that owning tables have a relcache > invalidation prior to advancing the command counter to make > newly-entered catalog tuples for the index visible. inval.c must be > able to roll back the local caches in the event of transaction abort. > There is only a problem when CREATE INDEX transactions abort, since > there is a generic invalidation once we reach index_update_stats(). > > This bug is of long standing. Problems were made much more likely by > the addition of parallel CREATE INDEX (commit 9da0cc35284), but it is > strongly suspected that similar problems can be triggered without > involving plan_create_index_workers(). Maybe expand a bit on this by saying that it's more likely "because plan_create_index_workers() triggers a relcache entry to be (re-)built, which previously did only happen in edge cases" or such? > Bug diagnosed by Andres Freund. > > Author: Peter Geoghegan > Reported-By: Luca Ferrari > Discussion: https://postgr.es/m/CAKoxK+5fVodiCtMsXKV_1YAKXbzwSfp7DgDqUmcUAzeAhf=HEQ@mail.gmail.com > Backpatch: 9.3- > --- > src/backend/catalog/index.c | 13 +++++++++++++ > 1 file changed, 13 insertions(+) > > diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c > index 8b276bc430..7036d72bd6 100644 > --- a/src/backend/catalog/index.c > +++ b/src/backend/catalog/index.c > @@ -1137,6 +1137,19 @@ index_create(Relation heapRelation, > InvokeObjectPostCreateHookArg(RelationRelationId, > indexRelationId, 0, is_internal); > > + /* > + * Invalidate the relcache for the owning table, so that any local > + * relcache entry for the new index built after CommandCounterIncrement > + * won't become inconsistent in the event of transaction abort. inval.c > + * must be able to roll back the local caches when aborting. Clearly it > + * isn't useful to create an index whose definition results in a relcache > + * entry for the index being allocated before commit, but the local caches > + * cannot be allowed to become inconsistent under any circumstances. > + * (There is only an issue when transactions abort because we'll reach > + * index_update_stats when they commit.) > + */ Not a fan of this comment. It doesn't really explain that well why it's needed here, but then goes on to a relatively general explanation of why cache invalidation is necessary. Why not just go for something like "register relcache invalidation on the indexes' heap relation, to maintain consistency of its index list"? I wonder if it wouldn't be more appropriately placed closer to the UpdateIndexRelation(), given that that's essentially what necessitates the relcache flush? Greetings, Andres Freund