Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qvnvw-007W8C-M6 for pgsql-hackers@arkaria.postgresql.org; Thu, 26 Oct 2023 00:09:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qvnvt-00A0oc-3R for pgsql-hackers@arkaria.postgresql.org; Thu, 26 Oct 2023 00:09:05 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qvnvs-00A0oS-52 for pgsql-hackers@lists.postgresql.org; Thu, 26 Oct 2023 00:09:04 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qvnvj-002p93-Vh for pgsql-hackers@postgresql.org; Thu, 26 Oct 2023 00:09:03 +0000 Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailout.nyi.internal (Postfix) with ESMTP id 0FB945C0218; Wed, 25 Oct 2023 20:08:53 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Wed, 25 Oct 2023 20:08:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm3; t=1698278933; x=1698365333; bh=gg jgnMQTAAAVGtTo6gpmcD8JYetSNVb8TR8yFCLb8y0=; b=q/vNLcJJrr4RIoLkTF nFZ37urLCsdDdfKy4BnaWij30jEnp8aTu5pUBfO1yNOlKgEJcG9dxlW1+R9HBcLy NvU/Hx9CveM3lIvFE6Im4rdVOnUCd07/TzzrGGpmtWRc8lPMy+N49zHewiZcFN5y aqCBmt7xpqH+P3q1IGtAJprPhxpW45oqdhWgdAzrLXX0h+7WnZ243Y/FWJK9EOgX R+44GuSRAdeLVpF3KzMC4b8QTQauHGZGXxWUCP+cCrq5cIRHIIdPTne9yVWBy1wV 2vMDL1komBjxfK3TWN68G258H5NpygTwl+4Xh6vnTrPgKPFOJMWEpdfPPKXrCUct vRBA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; t=1698278933; x=1698365333; bh=ggjgnMQTAAAVG tTo6gpmcD8JYetSNVb8TR8yFCLb8y0=; b=aK1jDlePWbWZGWq5SP4dZAhX3Qyvg wGZbxgQCKut8W3CuAFD7UNngYrVzgS0pxbGc0K+4BNV3x+4slOuQ2j+hI6cCM7rx +4kTD0s8WvQsP/JWODRdCmxmW8GxHZsGavf1xwcdrJ5XVMuI1X2LiW9ySJf2WGIb JL0C1jzmUt2RXzlkhJOU7Y+DDSyjjBiB+A8vnEBOSrG7ECeBpwvkyfmdajjqz1Zh AkjuD7kdaoq/tjxU+XIB9hGzgXflkJqubcd6LwAyBhj/HNBalzUPJp7Sb4QLxZAn OXTwV010bNhFHwb0IS9+3epWMP/+goqY1pG4aQaTJz8yE5Z+arU4EIgmw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrledugdeftdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenfg hrlhcuvffnffculdejtddmnecujfgurhepfffhvfevuffkfhggtggujgesghdtreertddt vdenucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrhcuoehmihgthhgrvghlsehprg hquhhivghrrdighiiiqeenucggtffrrghtthgvrhhnpeetleeifedufffhhfdtteelgeeg geffhfekueevteeigfduudevudetgfegiedvjeenucevlhhushhtvghrufhiiigvpedtne curfgrrhgrmhepmhgrihhlfhhrohhmpehmihgthhgrvghlsehprghquhhivghrrdighiii X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 25 Oct 2023 20:08:46 -0400 (EDT) Date: Thu, 26 Oct 2023 09:08:42 +0900 From: Michael Paquier To: Dmitry Dolgov <9erthalion6@gmail.com> Cc: Nathan Bossart , "Gregory Stark (as CFM)" , David Geier , Sergei Kornilov , Alvaro Herrera , Marcos Pegoraro , vignesh C , Robert Haas , Zhihong Yu , David Steele , PostgreSQL-development , Pavel Trukhanov , Tom Lane Subject: Re: pg_stat_statements and "IN" conditions Message-ID: References: <8702fa3e-5aac-dcf0-161b-faa2b9eadad6@gmail.com> <20230226104619.jfmwrpd5zrkmp3eu@erthalion.local> <20230314190432.l4oe3wa3pvt5b7hx@erthalion.local> <20230319122734.xkba536kut3g4gcy@erthalion.local> <20230704044611.GA3373000@nathanxps13> <20230704190256.arszjcwvrjekxj25@ddolgov.remote.csb> <20231013133519.yf26oncodrvemfjw@ddolgov.remote.csb> <20231017081541.octf6qghtjllwtvj@erthalion.local> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="R4+ZdJWw003cTinA" Content-Disposition: inline In-Reply-To: <20231017081541.octf6qghtjllwtvj@erthalion.local> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --R4+ZdJWw003cTinA Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Oct 17, 2023 at 10:15:41AM +0200, Dmitry Dolgov wrote: > In the current patch version I didn't add anything yet to address the > question of having more parameters to tune constants merging. The main > obstacle as I see it is that the information for that has to be > collected when jumbling various query nodes. Anything except information > about the ArrayExpr itself would have to be acquired when jumbling some > other parts of the query, not directly related to the ArrayExpr. It > seems to me this interdependency between otherwise unrelated nodes > outweigh the value it brings, and would require some more elaborate (and > more invasive for the purpose of this patch) mechanism to implement. typedef struct ArrayExpr { + pg_node_attr(custom_query_jumble) + Hmm. I am not sure that this is the best approach implementation-wise. Wouldn't it be better to invent a new pg_node_attr (these can include parameters as well!), say query_jumble_merge or query_jumble_agg_location that aggregates all the parameters of a list to be considered as a single element. To put it short, we could also apply the same property to other parts of a parsed tree, and not only an ArrayExpr's list. /* GUC parameters */ extern PGDLLIMPORT int compute_query_id; - +extern PGDLLIMPORT bool query_id_const_merge; Not much a fan of this addition as well for an in-core GUC. I would suggest pushing the GUC layer to pg_stat_statements, maintaining the computation method to use as a field of JumbleState as I suspect that this is something we should not enforce system-wide, but at extension-level instead. + /* + * Indicates the constant represents the beginning or the end of a merged + * constants interval. + */ + bool merged; Not sure that this is the best thing to do either. Instead of this extra boolean flag, could it be simpler if we switch LocationLen so as we track the start position and the end position of a constant in a query string, so as we'd use one LocationLen for a whole set of Const nodes in an ArrayExpr? Perhaps this could just be a refactoring piece of its own? + /* + * If the first expression is a constant, verify if the following elements + * are constants as well. If yes, the list is eligible for merging, and the + * order of magnitude need to be calculated. + */ + if (IsA(firstExpr, Const)) + { + foreach(temp, elements) + if (!IsA(lfirst(temp), Const)) + return false; This path should be benchmarked, IMO. -- Michael --R4+ZdJWw003cTinA Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmU5rgoACgkQnvQgOdby QH02+RAApCDE10kpHcgog5D1e7YKI/+u477UK4mFgWvh1GlxA3QZgYefC5XKiNlk LhSW/cXgAMFhSU2UrlygGnzSFOHmh+6k9KftQmgAfq9bxNYTNh7JqMTtsWefR7J7 PXNuPuZ7beac27IDfcIomJJc4ZcGqnbS+jYraRyvJBPBXdJit8pmahpo6G5z4mej tGMRlWEpi8m0I+sZZZYVmuIemNKR/Mk5ekQuSURSQIi1SzZQDzT3ydmx3QHpS9tz dnH5FYKUYUnKfVrVG0ETVaWJrv1naQDZOK2/fhzSP32fj9Nk8ZtCzvbXqexOPHXW kdUrjFlgrQTTPndKZoBsww7NwcEx3yGf53PCoTSGZCUAqI7gtaNAKfyXQZNRfSHP Lk2eXLjrdFgg6Eq1DFgD7FN2IYBUVqFsmMYCnN9OS0bQ55RW2ExkxcjJ0ej0Ank4 iosZb1sMj3wjh+aUv76VRhW/tgQUvVnsz2pa2c9IzragMPE32YcHqhK4nzzEF1uC fCltDNNUwd40mfzhNPRFKK2T539LJrZ5A7CDghJCuM5CDpXAozXQkbISHJwgLU1l h8aGwWxDuv8BgYzTyNYgEA3BA0W+QdS5wTyikjcEmHj8v7zwnGwzHjOxXosshyGI tuye5KbBblgYehCLCLo0Rfnp5S7T5RFwwaNzSGrWY93NRIoFiGA= =QF6K -----END PGP SIGNATURE----- --R4+ZdJWw003cTinA--