Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gUxnT-00026m-69 for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Dec 2018 17:50:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gUxnQ-0000Xh-QC for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Dec 2018 17:50:44 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1gUxnQ-0000XN-JG for pgsql-hackers@lists.postgresql.org; Thu, 06 Dec 2018 17:50:44 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gUxnN-0005VL-0h for pgsql-hackers@postgresql.org; Thu, 06 Dec 2018 17:50:43 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id wB6HoW6r017423; Thu, 6 Dec 2018 12:50:32 -0500 From: Tom Lane To: Robert Haas cc: Andres Freund , Pavel Stehule , "pgsql-hackers@postgresql.org" Subject: Re: slow queries over information schema.tables In-reply-to: References: <5978.1544030694@sss.pgh.pa.us> <20181205175657.s7mt6as356kwvrji@alap3.anarazel.de> <8210.1544034143@sss.pgh.pa.us> <20181205182555.x4wtnzffmhwsc3c7@alap3.anarazel.de> <8843.1544035292@sss.pgh.pa.us> <20577.1544113962@sss.pgh.pa.us> <21728.1544115813@sss.pgh.pa.us> Comments: In-reply-to Robert Haas message dated "Thu, 06 Dec 2018 12:12:17 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <17421.1544118632.1@sss.pgh.pa.us> Date: Thu, 06 Dec 2018 12:50:32 -0500 Message-ID: <17422.1544118632@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Robert Haas writes: > On Thu, Dec 6, 2018 at 12:03 PM Tom Lane wrote: >> [ further experimentation... ] It looks like if you prepare >> a query and then just execute it repeatedly in one transaction, >> you'd not reach AIM (as long as you were getting generic plans). >> Possibly that's a gap worth closing. > If we called it at the start of every query, couldn't we dispense with > the call in relation_openrv_extended()? No. You need to do AIM *after* obtaining the lock, else you still have the race condition that you can execute a query on a table without being aware of recent DDL on it. What we could possibly do to close the gap cited above is to have plancache.c's CheckCachedPlan force an AIM call if it notices that the plan it wants to re-use has a non-empty PlanInvalItems list. If it does not, then there is nothing that AIM would cause invalidation for anyway. This still leaves us with a query-duration-sized race condition window for DDL on functions and domains, but not any larger than that. regards, tom lane