Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n6pFo-0004C7-S9 for pgsql-hackers@arkaria.postgresql.org; Mon, 10 Jan 2022 07:38:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1n6pFm-0006Ds-G9 for pgsql-hackers@arkaria.postgresql.org; Mon, 10 Jan 2022 07:38:06 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n6pFm-0006Di-3S for pgsql-hackers@lists.postgresql.org; Mon, 10 Jan 2022 07:38:06 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by makus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1n6pFY-00024C-Kq for pgsql-hackers@lists.postgresql.org; Mon, 10 Jan 2022 07:38:04 +0000 Received: from [192.168.129.212] (unknown [91.205.25.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id 0B42921C2D85; Mon, 10 Jan 2022 10:37:49 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1641800270; bh=vRR3TIWzFh+R/kt8MbXSp0b37e+9d5oqrhFLGX2XyF4=; h=Subject:To:Cc:References:From:Date:In-Reply-To; b=bjlXgM5Q2tX1vIWK1TeXuma26RTcBx0QCnglaCpZQfOFa8kNSUjkaPhWwtuJEih6R h1FQmN3M6ASxEgeuQxHcWXzaetYT3jcQUWqn9VP8Zax3Rv0n8hg0K9VUGQnW2Bmase wajjvu0s5G5C+eUEceS3FbV4pZn9hUeJ7IXJiMmE= Subject: Re: Multiple Query IDs for a rewritten parse tree To: Julien Rouhaud Cc: PostgreSQL Hackers , Tom Lane References: <1606733.1641689399@sss.pgh.pa.us> <20220109121321.3d74krhjbr5mp4zv@jrouhaud> <1ea9d518-becb-1c3d-dc6c-e0045d3101de@postgrespro.ru> From: "Andrey V. Lepikhov" Organization: Postgres Professional Message-ID: Date: Mon, 10 Jan 2022 12:37:34 +0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 1/10/22 9:51 AM, Julien Rouhaud wrote: > On Mon, Jan 10, 2022 at 09:10:59AM +0500, Andrey V. Lepikhov wrote: >> I can add one more use case. >> Our extension for freezing query plan uses query tree comparison technique >> to prove, that the plan can be applied (and we don't need to execute >> planning procedure at all). >> The procedure of a tree equality checking is expensive and we use cheaper >> queryId comparison to identify possible candidates. So here, for the better >> performance and queries coverage, we need to use query tree normalization - >> queryId should be stable to some modifications in a query text which do not >> change semantics. >> As an example, query plan with external parameters can be used to execute >> constant query if these constants correspond by place and type to the >> parameters. So, queryId calculation technique returns also pointers to all >> constants and parameters found during the calculation. > > I'm also working on a similar extension, and yes you can't accept any > fingerprinting approach for that. I don't know what are the exact heuristics > of your cheaper queryid calculation are, but is it reasonable to use it with > something like pg_stat_statements? If yes, you don't really need two queryid > approach for the sake of this single extension and therefore don't need to > store multiple jumble state or similar per statement. Especially since > requiring another one would mean a performance drop as soon as you want to use > something as common as pg_stat_statements. > I think, pg_stat_statements can live with an queryId generator of the sr_plan extension. But It replaces all constants with $XXX parameter at the query string. In our extension user defines which plan is optimal and which constants can be used as parameters in the plan. One drawback I see here - creating or dropping of my extension changes behavior of pg_stat_statements that leads to distortion of the DB load profile. Also, we haven't guarantees, that another extension will work correctly (or in optimal way) with such queryId. -- regards, Andrey Lepikhov Postgres Professional