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 1n6rrF-0002Pj-Q7 for pgsql-hackers@arkaria.postgresql.org; Mon, 10 Jan 2022 10:24:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1n6rrE-0004zp-HU for pgsql-hackers@arkaria.postgresql.org; Mon, 10 Jan 2022 10:24:56 +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 1n6rrE-0004zc-1l for pgsql-hackers@lists.postgresql.org; Mon, 10 Jan 2022 10:24:56 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by makus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1n6rr9-0003Eq-6r for pgsql-hackers@lists.postgresql.org; Mon, 10 Jan 2022 10:24:54 +0000 Received: from [172.20.10.3] (unknown [85.140.23.18]) (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 589F121C3880; Mon, 10 Jan 2022 13:24:48 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1641810289; bh=cepDu5Yh8XJPxeUPyyV/ss2Li1+7DXqzYl4o9+/0uJU=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=W5ijwlBUKnqheil+f7V84SdX2lFafJp8DH51fFNMnKImz3/dQ3k5w4S56M6gRCGK2 mQsOJP1axrEVfdaNHKaJe/wkxOLiSXr2eNwUEOoCxs2aSSYlXv6Ui3DKBA88QsLnr7 NFRNUMvsOs2ou/OR6PgE8jv/pL/EI8dMg8sldHFw= Message-ID: Date: Mon, 10 Jan 2022 15:24:46 +0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.4.1 Subject: Re: Multiple Query IDs for a rewritten parse tree Content-Language: en-US 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 Lepikhov Organization: Postgres Professional In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 10/1/2022 13:56, Julien Rouhaud wrote: > On Mon, Jan 10, 2022 at 12:37:34PM +0500, Andrey V. Lepikhov wrote: >> 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. > > I don't know the details of that extension, but I think that it should work as > long as you have the constants information in the jumble state, whatever the > resulting normalized query string is right? Yes. the same input query string doesn't prove that frozen query plan can be used, because rewrite rules could be changed. So we use only a query tree. Here we must have custom jumbling implementation. queryId in this extension defines two aspects: 1. How many input queries will be compared with a query tree template of the frozen statement. 2. As a result, performance overheads on unsuccessful comparings. > >> 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. > > But then, if generating 2 queryid is a better for performance, does the > extension really need an additional jumble state and/or normalized query > string? Additional Jumble state isn't necessary, but it would be better for performance to collect pointers to all constant nodes during a process of hash generation. -- regards, Andrey Lepikhov Postgres Professional