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 1htTRo-0001LF-M3 for pgsql-hackers@arkaria.postgresql.org; Fri, 02 Aug 2019 09:02:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1htTRn-0002AV-Dh for pgsql-hackers@arkaria.postgresql.org; Fri, 02 Aug 2019 09:01:59 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1htTRn-00029b-2D for pgsql-hackers@lists.postgresql.org; Fri, 02 Aug 2019 09:01:59 +0000 Received: from www.ikoffice.de ([85.214.51.201] helo=ikoffice.de) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1htTRk-0001oY-FB for pgsql-hackers@lists.postgresql.org; Fri, 02 Aug 2019 09:01:57 +0000 Received: from exchangeserver.ikoffice.de by ikoffice.de with esmtps (TLS1.0:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1htTRh-0002as-BZ; Fri, 02 Aug 2019 11:01:53 +0200 Received: from [192.168.9.10] (192.168.1.106) by EXCHANGESERVER.ikoffice.de (192.168.1.108) with Microsoft SMTP Server (TLS) id 14.3.468.0; Fri, 2 Aug 2019 11:01:52 +0200 Subject: Re: [HACKERS] Cached plans and statement generalization To: Konstantin Knizhnik , References: <6ea1db86-b300-b57c-0f9d-a55dd3966175@postgrespro.ru> <9A6E5062D5D4DB458C80C2B2920BD71D6820CB@g01jpexmbkw23> <554d0730-f6fc-d1be-fe78-e63973ec621f@postgrespro.ru> <35be0423-36bc-cadc-bef8-02d475751f7d@postgrespro.ru> <7603a101-6b79-2328-2b4b-3bc3217992e5@postgrespro.ru> <3304c34b-4a9c-909c-4ee1-d8e7f6dcb2de@postgrespro.ru> <66f47595-1b93-ef67-fdd6-c5414e0f94c3@postgrespro.ru> <6c91d4ba-1a77-ba64-39ee-fda26dcfc9bd@postgrespro.ru> <3ab03f54-b2bd-4b19-d8fb-19579df67caa@ikoffice.de> From: Daniel Migowski Message-ID: Date: Fri, 2 Aug 2019 11:01:47 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -1.0 X-Spam-Bar: - X-Spam-Score-Int: -9 X-Spam-Flag: NO List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Am 02.08.2019 um 10:57 schrieb Konstantin Knizhnik: > On 02.08.2019 11:25, Daniel Migowski wrote: >> >> I have two suggestions however: >> >> 1. Please allow to gather information about the autoprepared >> statements by returning them in pg_prepared_statements view. I would >> love to monitor usage of them as well as the memory consumption that >> occurs. I suggested a patch to display that in >> https://www.postgresql.org/message-id/41ED3F5450C90F4D8381BC4D8DF6BBDCF02E10B4@EXCHANGESERVER.ikoffice.de >> >> > Sorry, but there is pg_autoprepared_statements view. I think that it > will be better to distinguish explicitly and implicitly prepared > statements, will not it? > Do you want to add more information to this view? Right now it shows > query string, types of parameters and number of this query execution. My sorry, I didn't notice it in the patch. If there is another view for those that's perfectly fine. >> 2. Please not only use a LRU list, but maybe something which would >> prefer statements that get reused at all. We often create ad hoc >> statements with parameters which don't really need to be kept. Maybe >> I can suggest an implementation of an LRU list where a reusal of a >> statement not only pulls it to the top of the list but also increases >> a reuse counter. When then a statement would drop off the end of the >> list one checks if the reusal count is non-zero, and only really >> drops it if the resual count is zero. Else the reusal count is >> decremented (or halved) and the element is also placed at the start >> of the LRU list, so it is kept a bit longer. >> > There are many variations of LRU and alternatives: clock, segmented > LRU, ... > I agree that classical LRU may be not the best replacement policy for > autoprepare. > Application is either use static queries, either constructing them > dynamically. It will be better to distinguish queries executed at > least twice from one-shot queries. > So may be SLRU will be the best choice. But actually situation you > have described (We often create ad hoc statements with parameters > which don't really need to be kept) > is not applicable to atutoprepare. Autoprepare deals only with > statements which are actually executed. > > We have another patch which limits number of stored prepared plans to > avoid memory overflow (in case of using stored procedures which > implicitly prepare all issued queries). > Here choice of replacement policy is more critical. Alright, just wanted to have something better than a LRU, so it is not a stepback from the implementation in the JDBC driver for us. Kind regards, Daniel Migowski