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 1n6mfF-0005yW-Sd for pgsql-hackers@arkaria.postgresql.org; Mon, 10 Jan 2022 04:52:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1n6mfD-0006J3-SS for pgsql-hackers@arkaria.postgresql.org; Mon, 10 Jan 2022 04:52:11 +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 1n6mfD-0006Is-G0 for pgsql-hackers@lists.postgresql.org; Mon, 10 Jan 2022 04:52:11 +0000 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1n6mf4-0000ji-7E for pgsql-hackers@lists.postgresql.org; Mon, 10 Jan 2022 04:52:10 +0000 Received: by mail-pj1-x1029.google.com with SMTP id hv15so5065549pjb.5 for ; Sun, 09 Jan 2022 20:52:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=qOS4hUNhrmBPLPQ2DhkVzTcmkM5kf5B5mW3LAu32Lzs=; b=ncCdHJH3d7ekKtD77GR3tlg79LXaaedqX9gQI1IhtmauIfj+UdS7v4XnTSFg3pEMFC 9Z+nhKQuqo6BE8gPWRz/ebYprlFSd5BetNj92Q0f48nxHNb+PJXcRy6pKEyPMv+yetuZ LfjWn3PjQkK/csacwRC3/VCbQZi6oVFfYmXsDYqhOZZyHKsxsOGtVtxoM3uRyjlS6yj3 M3DiUIYMpOYGCYuY0I60SK0jtYcr8OLwuNMwLD+I7bWOqnvuWPz3WNK52t8m9aV+U9/E JTy39BGi5IP0uqzJTWCgjnMsIyE9V7qlUAxe9kQl+NF/QZutzWsUXB9SyMad1H3fVOaS XnVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=qOS4hUNhrmBPLPQ2DhkVzTcmkM5kf5B5mW3LAu32Lzs=; b=gQaNG1r8uqyGfR/aFvE4gP+9BidFGEQjTCNNXmAKGc6+AoIeNrbU1xeNVFLVg0oF81 rxE/abSCMkbgy9jkKZyY6n/44HqaClkU5cingRLhAb5QasTzdwm39BDrlHoLKdYsV572 ByC+Trq5ZpC0xfY/hL0TZnf2IgDv9EwrberFO0QWZMA/PcQx0g1E0NeCRiIB2UOFYf05 zG8TXdZXrWNSd0fIRv1koJxtWcm/hI+V+Pj8wkfeavbVu31+l02js75mCAyUVesFVj0d PyvUcCuqSv4zQZt4gz7a6zpUe11CgkUOIgOM9KTYbjjElZMDg+KOEN4Z0UQP5AXXa9WT akng== X-Gm-Message-State: AOAM530jYht8ZnPDLbbg92D9znFEnf3HaccfWXjalyozrd4UTdialuDI zT/EJDawvprhOdkfBAB/YN0= X-Google-Smtp-Source: ABdhPJwaAuhuA2gV9Jahi41W18wJRSw6Bu1J126daF7oc8qalvYcgQlXdJZPFQjLloGFnqeWoUWT1Q== X-Received: by 2002:a17:902:cec2:b0:149:7fa3:3fe3 with SMTP id d2-20020a170902cec200b001497fa33fe3mr62551561plg.161.1641790320728; Sun, 09 Jan 2022 20:52:00 -0800 (PST) Received: from jrouhaud (1-171-174-202.dynamic-ip.hinet.net. [1.171.174.202]) by smtp.gmail.com with ESMTPSA id h2sm5240629pfh.55.2022.01.09.20.51.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jan 2022 20:52:00 -0800 (PST) Date: Mon, 10 Jan 2022 12:51:55 +0800 From: Julien Rouhaud To: "Andrey V. Lepikhov" Cc: PostgreSQL Hackers , Tom Lane Subject: Re: Multiple Query IDs for a rewritten parse tree Message-ID: References: <1606733.1641689399@sss.pgh.pa.us> <20220109121321.3d74krhjbr5mp4zv@jrouhaud> <1ea9d518-becb-1c3d-dc6c-e0045d3101de@postgrespro.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1ea9d518-becb-1c3d-dc6c-e0045d3101de@postgrespro.ru> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, Jan 10, 2022 at 09:10:59AM +0500, Andrey V. Lepikhov wrote: > On 1/9/22 5:13 PM, Julien Rouhaud wrote: > > For now the queryid mixes two different things: fingerprinting and query text > > normalization. Should each calculation method be allowed to do a different > > normalization too, and if yes where should be stored the state data needed for > > that? If not, we would need some kind of primary hash for that purpose. > > > Do You mean JumbleState? Yes, or some other abstraction. For instance with the proposed patch to handle differently the IN clauses, you needs a to change JumbleState. > I think, registering queryId generator we should store also a pointer (void > **args) to an additional data entry, as usual. Well, yes but only if you need to produce different versions of the normalized query text, and I'm not convinced that's really necessary. > > Looking at Andrey's use case for wanting multiple hashes, I don't think that > > adaptive optimization needs a normalized query string. The only use would be > > to output some statistics, but this could be achieved by storing a list of > > "primary queryid" for each adaptive entry. That's probably also true for > > anything that's not monitoring intended. Also, all monitoring consumers should > > probably agree on the same queryid, both fingerprint and normalized string, as > > otherwise it's impossible to cross-reference metric data. > > > 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.