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 1fcaxG-0004RI-Du for pgsql-general@arkaria.postgresql.org; Mon, 09 Jul 2018 18:32:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fcaxE-0001pj-L6 for pgsql-general@arkaria.postgresql.org; Mon, 09 Jul 2018 18:32:08 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fcaxE-0001pY-60; Mon, 09 Jul 2018 18:32:08 +0000 Received: from wout1-smtp.messagingengine.com ([64.147.123.24]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fcaxB-0004Yz-9L; Mon, 09 Jul 2018 18:32:06 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id B523835A; Mon, 9 Jul 2018 14:32:03 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Mon, 09 Jul 2018 14:32:04 -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=ml2iN5LJL/Bdva2+HOkBwmBqGDLpE6aYrvL99p/MM98=; b=HEj9wWv0 gBgC/6CJiXIDcl+IwL2vdnFl0wY/ReggdSGhNRZLIgZCoCKvToLr7lYU5OrC0i8f g2N+wC/feP7XFEAhlYrvXP+O4WQ3bAHYgEA0u5UIgTQJKJnEJzXhXftCC75dciKs YU5eJAwxssgn7bghVY6g/yxXKe1gxSGbPNx4bdlRMO2iiW6kE0Hs/7vA0l29QOwJ qxL7QhnNEIZNItFF2RzjR989ciGKRTfmViZVhiKaEcFoFyEyB+nWpfuTNmWjd78K QmKy0N/hg+k7WI1V9SuOPyh9NSp9LCEPV8UJUB/fc7xoK2J8R8U8iGYmSFQjM85N nGYqcekum1xvDg== 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=ml2iN5LJL/Bdva2+HOkBwmBqGDLpE 6aYrvL99p/MM98=; b=pkKSd9tTp0BkqUbyx9gP6nBiEjb1XDUpNws5KP1+FmOf1 XO1Ge7W+Gb6Q7Nq4l2ScDczGF8RJHNz1Ra03A1uYiY3EICofzulZDxoVCim6yAhA dt/MIzgPLU8W6TbdNVpahFwFZ2iZz8l6juekuDIoeMKktkxsflH7pRX6IE+C1/eS FeUDS2R3jdO16WPKKw6JaAnJdtrMb2VC26/A9kjXUL60UoO6Oz8A9cJnmU+a1LyM T7Zz7sLr2sUIi/gR1Cbjc0vntAb+buABwL3c2FME6BZcAl8PkHaSRCbqHP00FaL5 4AIpNw/c8HrdG4iKcbmsmcKfO0dh+KbABXhl8FHdw== 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 85E3CE4439; Mon, 9 Jul 2018 14:32:02 -0400 (EDT) Date: Mon, 9 Jul 2018 11:32:01 -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: <20180709183201.zn53uwiwqozhettk@alap3.anarazel.de> References: <20180627204439.4b7miflyolm4qtcz@alap3.anarazel.de> <20180628150209.n2qch5jtn3vt2xaa@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 Hi, On 2018-07-09 09:59:58 -0700, Peter Geoghegan wrote: > On Thu, Jun 28, 2018 at 8:02 AM, Andres Freund wrote: > > I believe this happens because there's currently no relcache > > invalidation registered for the main relation, until *after* the index > > is built. Normally it'd be the CacheInvalidateRelcacheByTuple(tuple) in > > index_update_stats(), which is called at the bottom of index_build(). > > But we never get there, because the earlier error. That's bad, because > > any relcache entry built *after* the CommandCounterIncrement() in > > CommandCounterIncrement() will now be outdated. > > > > In the olden days we most of the time didn't build a relcache entry > > until after the index was built - but plan_create_index_workers() now > > does. I'm suspect there's other ways to trigger that earlier, too. > > Note that there is a kludge within plan_create_index_workers() that > has us treat the heap relation as an inheritance parent, just to get a > RelOptInfo for the heap relation without running into similar trouble > with the index in get_relation_info(). Perhaps there's an argument to > be made for refactoring plan_create_index_workers() as a fix for this. Maybe I'm missing something, but what has this got to do with the issue at hand? > > Putting in a CacheInvalidateRelcache(heapRelation); before the CCI in > > index_create() indeed makes the "borked relcache" problem go away. > > > > > > I wonder why we don't just generally trigger invalidations to an > > indexes' "owning" relation in CacheInvalidateHeapTuple()? > > I don't know, but that seems like a good question. 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. Will you tackle this? Greetings, Andres Freund