Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d3SkJ-0006yM-Lq for pgsql-hackers@arkaria.postgresql.org; Wed, 26 Apr 2017 19:37:04 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1d3SkI-0000yU-LB for pgsql-hackers@arkaria.postgresql.org; Wed, 26 Apr 2017 19:37:02 +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.84_2) (envelope-from ) id 1d3Sim-0006lk-BV for pgsql-hackers@postgresql.org; Wed, 26 Apr 2017 19:35:28 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by magus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d3Sii-0000zi-PZ for pgsql-hackers@postgresql.org; Wed, 26 Apr 2017 19:35:27 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id EB35221C2A87; Wed, 26 Apr 2017 22:35:22 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru Message-ID: <5900F679.8000100@postgrespro.ru> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1493235322; bh=Hxg3FJ8B+IAk1cBTwsT6HBo1svij+KX4JnV9vDv9xUg=; h=Date:From:To:CC:Subject:References:In-Reply-To; b=JwRFtMO43ZtxSmZ8sG82rd/PH/JTLsC25jOzpOrov3RQ5BwwpDcAiG1pvm7H9ID/q 05ms1blLuNEz5tskktw48reYSPOXUA3iwGIwfOVM9uwi/1aiR26B5FjCgB72wqkaWB 2wCAxZ5ggzYRuvBGQvt7zOOQdo9qqgnNBmNzpiyI= Date: Wed, 26 Apr 2017 22:35:21 +0300 From: Konstantin Knizhnik User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 MIME-Version: 1.0 To: Doug Doole , Andres Freund CC: Serge Rielau , Pg Hackers Subject: Re: Cached plans and statement generalization References: <1f4c1a22-ecbe-811d-4695-ee4701b8f6c7@postgrespro.ru> <58FFB391.5080101@postgrespro.ru> <58FFB5F0.2020900@postgrespro.ru> <20170425214746.3mngxgbo7yndfgax@alap3.anarazel.de> <20170425223448.amnhdludwondarph@alap3.anarazel.de> In-Reply-To: Content-Type: multipart/alternative; boundary="------------090305080000060005020101" X-Pg-Spam-Score: -2.0 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org This is a multi-part message in MIME format. --------------090305080000060005020101 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 04/26/2017 08:08 PM, Doug Doole wrote: > > A naive option would be to invalidate anything that depends on table or view *.FOOBAR. You could probably make it a bit smarter by also requiring that schema A appear in the path. > > > This has been rumbling around in my head. I wonder if you could solve this problem by registering dependencies on objects which don't yet exist. Consider: > > CREATE TABLE C.T1(...); > CREATE TABLE C.T2(...); > SET search_path='A,B,C,D'; > SELECT * FROM C.T1, T2; > > For T1, you'd register a hard dependency on C.T1 and no virtual dependencies since the table is explicitly qualified. > > For T2, you'd register a hard dependency on C.T2 since that is the table that was selected for the query. You'd also register virtual dependencies on A.T2 and B.T2 since if either of those tables (or views) are created you need to recompile the > statement. (Note that no virtual dependency is created on D.T2() since that table would never be selected by the compiler.) > > The catch is that virtual dependencies would have to be recorded and searched as strings, not OIDs since the objects don't exist. Virtual dependencies only have to be checked during CREATE processing though, so that might not be too bad. > > But this is getting off topic - I just wanted to capture the idea while it was rumbling around. I think that it will be enough to handle modification of search path and invalidate prepared statements cache in this case. -- Konstantin Knizhnik Postgres Professional: http://www.postgrespro.com The Russian Postgres Company --------------090305080000060005020101 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit
On 04/26/2017 08:08 PM, Doug Doole wrote:
A naive option would be to invalidate anything that depends on table or view *.FOOBAR. You could probably make it a bit smarter by also requiring that schema A appear in the path.

This has been rumbling around in my head. I wonder if you could solve this problem by registering dependencies on objects which don't yet exist. Consider:

CREATE TABLE C.T1(...);
CREATE TABLE C.T2(...);
SET search_path='A,B,C,D';
SELECT * FROM C.T1, T2;

For T1, you'd register a hard dependency on C.T1 and no virtual dependencies since the table is explicitly qualified.

For T2, you'd register a hard dependency on C.T2 since that is the table that was selected for the query. You'd also register virtual dependencies on A.T2 and B.T2 since if either of those tables (or views) are created you need to recompile the statement. (Note that no virtual dependency is created on D.T2() since that table would never be selected by the compiler.)

The catch is that virtual dependencies would have to be recorded and searched as strings, not OIDs since the objects don't exist. Virtual dependencies only have to be checked during CREATE processing though, so that might not be too bad.

But this is getting off topic - I just wanted to capture the idea while it was rumbling around.

I think that it will be enough to handle modification of search path and invalidate prepared statements cache in this case.

-- 
Konstantin Knizhnik
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company
--------------090305080000060005020101--