Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d38so-0007UW-IG for pgsql-hackers@arkaria.postgresql.org; Tue, 25 Apr 2017 22:24:30 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1d38so-0000rE-50 for pgsql-hackers@arkaria.postgresql.org; Tue, 25 Apr 2017 22:24:30 +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 1d38sd-0000bu-P9 for pgsql-hackers@postgresql.org; Tue, 25 Apr 2017 22:24:19 +0000 Received: from 173-164-140-181-sfba.hfc.comcastbusiness.net ([173.164.140.181] helo=fetter.org) by magus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d38sY-0000LH-Mu for pgsql-hackers@postgresql.org; Tue, 25 Apr 2017 22:24:19 +0000 Received: by fetter.org (Postfix, from userid 1000) id 795E8E387F; Tue, 25 Apr 2017 15:24:08 -0700 (PDT) Date: Tue, 25 Apr 2017 15:24:08 -0700 From: David Fetter To: Konstantin Knizhnik Cc: pgsql-hackers@postgresql.org Subject: Re: Cached plans and statement generalization Message-ID: <20170425222408.GF32130@fetter.org> References: <8e76d8fc-8b8c-14bd-d4d1-e9cf193a74f5@postgrespro.ru> <20170424184353.u2krt2eiw2l6e2af@alap3.anarazel.de> <20170425165421.GD32130@fetter.org> <58FFB309.5040209@postgrespro.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <58FFB309.5040209@postgrespro.ru> User-Agent: Mutt/1.8.0 (2017-02-23) X-Pg-Spam-Score: -0.9 (/) 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 On Tue, Apr 25, 2017 at 11:35:21PM +0300, Konstantin Knizhnik wrote: > On 04/25/2017 07:54 PM, David Fetter wrote: > > On Tue, Apr 25, 2017 at 06:11:09PM +0300, Konstantin Knizhnik wrote: > > > On 24.04.2017 21:43, Andres Freund wrote: > > > > Hi, > > > > > > > > On 2017-04-24 11:46:02 +0300, Konstantin Knizhnik wrote: > > > > > So what I am thinking now is implicit query caching. If the same query with > > > > > different literal values is repeated many times, then we can try to > > > > > generalize this query and replace it with prepared query with > > > > > parameters. > > > > That's not actuall all that easy: > > > > - You pretty much do parse analysis to be able to do an accurate match. > > > > How much overhead is parse analysis vs. planning in your cases? > > > > - The invalidation infrastructure for this, if not tied to to fully > > > > parse-analyzed statements, is going to be hell. > > > > - Migrating to parameters can actually cause significant slowdowns, not > > > > nice if that happens implicitly. > > > Well, first of all I want to share results I already get: pgbench with > > > default parameters, scale 10 and one connection: > > > > > > protocol > > > TPS > > > simple > > > 3492 > > > extended > > > 2927 > > > prepared > > > 6865 > > > simple + autoprepare > > > 6844 > > If this is string mashing on the unparsed query, as it appears to be, > > it's going to be a perennial source of security issues. > > Sorry, may be I missed something, but I can not understand how > security can be violated by extracting string literals from query. I > am just copying bytes from one buffer to another. I do not try to > somehow interpret this parameters. What I am doing is very similar > with standard prepared statements. And moreover query is parsed! > Only query which was already parsed and executed (but with different > values of parameters) can be autoprepared. I don't have an exploit yet. What concerns me is attackers' access to what is in essence the ability to poke at RULEs when they only have privileges to read. Best, David. -- David Fetter http://fetter.org/ Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter Skype: davidfetter XMPP: david(dot)fetter(at)gmail(dot)com Remember to vote! Consider donating to Postgres: http://www.postgresql.org/about/donate -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers