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 1tuFmd-006OQl-45 for pgsql-hackers@arkaria.postgresql.org; Mon, 17 Mar 2025 19:05:55 +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 1tuFma-000Ews-7D for pgsql-hackers@arkaria.postgresql.org; Mon, 17 Mar 2025 19:05:52 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tuFmZ-000Ewe-7I for pgsql-hackers@lists.postgresql.org; Mon, 17 Mar 2025 19:05:51 +0000 Received: from fhigh-b6-smtp.messagingengine.com ([202.12.124.157]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tuFmV-003N3e-2I for pgsql-hackers@postgresql.org; Mon, 17 Mar 2025 19:05:50 +0000 Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfhigh.stl.internal (Postfix) with ESMTP id C7D932540234; Mon, 17 Mar 2025 15:05:46 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Mon, 17 Mar 2025 15:05:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1742238346; x=1742324746; bh=S DIYMqKbEka1sLr6ZY0lsuAiaIcq1ghTC9fsFR5KuYA=; b=XBxgNX3A/3n6Kc5P8 mT9R96b+M7nzb04ASTF6o3Jwh/D/LXCnvCNS6u7htIUU9hxXdRfqT6eaC6dE4zXI pwtmEdkH9h4QX+7X8u9KcGoKcOjz6E8RN/3kajAb//d1hqLVA7/wqRKxnK7X7HSQ ZpFtE3DdHGwp5ZHY8+HJK1prEOO4ap68rwOZCQlev2CawfBSg3YhDxlq0bztyVI0 HRJVoy6a/aJCBQ/c1MbBwCRbgN/O1jDYd8vpNCZpfZzcEr9LVsg+J0pX1wYdfc0v FTGWv+ao/NCnSeNpmYGthuZRse2TT9jdNdrNsSruJhz09fuyDSMDiJjnE9cFvt2L 1NA/Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddugedtfedvucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhepfffhvfevuffkgggtugfgjgesmhekreertddt jeenucfhrhhomheplmhlvhgrrhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlh hvhhdrnhhoqdhiphdrohhrgheqnecuggftrfgrthhtvghrnheptefgffeljeeggfelheet ueevgffgvedvheehkeehtdeufeevteehvefhhedvkefhnecuffhomhgrihhnpehgihhthh husgdrtghomhdptghirhhruhhsqdgtihdrtghomhdpvghnthgvrhhprhhishgvuggsrdgt ohhmnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprg hlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrghdpnhgspghrtghpthhtohepudel pdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehkohhusegtlhgvrghrqdgtohguvg drtghomhdprhgtphhtthhopehmrghrtghoshesfhdutddrtghomhdrsghrpdhrtghpthht oheplegvrhhthhgrlhhiohhnieesghhmrghilhdrtghomhdprhgtphhtthhopehgvghiug grvhdrphhgsehgmhgrihhlrdgtohhmpdhrtghpthhtohepnhgrthhhrghnuggsohhsshgr rhhtsehgmhgrihhlrdgtohhmpdhrtghpthhtohepphgrvhgvlhdrthhruhhkhhgrnhhovh esghhmrghilhdrtghomhdprhgtphhtthhopehrvghshhhkvghkihhrihhllhesghhmrghi lhdrtghomhdprhgtphhtthhopehrjhhujhhuuddvfeesghhmrghilhdrtghomhdprhgtph htthhopehrohgsvghrthhmhhgrrghssehgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 17 Mar 2025 15:05:44 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1742238342; bh=GY2VBa7ih/SLbo1hPmxcQt1iQ1fEwGnD1zo35nQ7Jp0=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=Ll7nIzHvNffCyuIH7kzrgN3D2NIyXCOokfw58BnoVFYI47qpQoBxuqrxhM7r7K6Yl vpwNAj42iE6AGhg7hn54cVhgI2+9BLo+Brun4RL0bw7+V+BGDjVzJNeSihiVCknojP mNuB4k3oTmGXyVaJiyx20UlOHAqpsPSsQO0K9p6NVemSCCfxRgEs2thX/asmV9NLl9 apSm2+boIekD0y1Iwan39xKrZcZywqD6U6N7hvqL9tDXEJuLt/CC9jfQmF2BdTTC+d gPVO1X/HVGtHpLA0yYzVsUMU8mlidC18v/K3HlEmx0LTfsXM/OjKw7KdjJuEdSLIeM xE43g2y8YKbGQ== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id 1F68A87; Mon, 17 Mar 2025 20:05:42 +0100 (CET) Date: Mon, 17 Mar 2025 20:05:42 +0100 From: =?utf-8?Q?=C3=81lvaro?= Herrera To: Dmitry Dolgov <9erthalion6@gmail.com> Cc: Julien Rouhaud , Sami Imseih , Kirill Reshke , Sergei Kornilov , yasuo.honda@gmail.com, tgl@sss.pgh.pa.us, smithpb2250@gmail.com, vignesh21@gmail.com, michael@paquier.xyz, nathandbossart@gmail.com, stark.cfm@gmail.com, geidav.pg@gmail.com, marcos@f10.com.br, robertmhaas@gmail.com, david@pgmasters.net, pgsql-hackers@postgresql.org, pavel.trukhanov@gmail.com, Sutou Kouhei Subject: Re: pg_stat_statements and "IN" conditions Message-ID: <202503171905.usybbg5hfoxp@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="xulb2npnegtuim3q" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --xulb2npnegtuim3q Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit On 2025-Feb-14, Dmitry Dolgov wrote: > This should do it. The last patch for today, otherwise I'll probably add > more bugs than features :) Thank you. I've spent some time with this patch in the last few days, and I propose a few changes. I renamed everything from "merge" to "squash"; apart from that, it's mostly docs and code comments changes, but I also removed the addition of a boolean argument to JUMBLE_LOCATION which AFAICS is unnecessary, and did away with the business of checking for function immutability. I also changed the code layout of generate_normalized_query(); no functional changes, I just reordered the code blocks (which caused a couple of lines to appear repeated that weren't before). You can see my patch on top of yours here: https://github.com/alvherre/postgres/commits/query_id_squash_values/ and the CI run here: https://cirrus-ci.com/build/5660053472018432 In addition, here I attach the complete patch on top of current master. Unless there's some opposition to this, I intend to push this tomorrow. I have to admit that looking at this part of the test, +SELECT * FROM test_squash_cast WHERE data IN + (1::int4::casttesttype, 2::int4::casttesttype, 3::int4::casttesttype, + 4::int4::casttesttype, 5::int4::casttesttype, 6::int4::casttesttype, + 7::int4::casttesttype, 8::int4::casttesttype, 9::int4::casttesttype, + 10::int4::casttesttype, 11::int4::casttesttype); + id | data +----+------ +(0 rows) + +SELECT query, calls FROM pg_stat_statements ORDER BY query COLLATE "C"; + query | calls +----------------------------------------------------+------- + SELECT * FROM test_squash_cast WHERE data IN +| 1 + ($1 /*, ... */::int4::casttesttype) | + SELECT pg_stat_statements_reset() IS NOT NULL AS t | 1 +(2 rows) and +SELECT * FROM test_squash WHERE id IN (1::oid, 2::oid, 3::oid, 4::oid, 5::oid, 6::oid, 7::oid, 8::oid, 9::oid); + id | data +----+------ +(0 rows) + +SELECT query, calls FROM pg_stat_statements ORDER BY query COLLATE "C"; + query | calls +------------------------------------------------------------+------- + SELECT * FROM test_squash WHERE id IN ($1 /*, ... */::oid) | 1 I am tempted to say that explicit casts should also be considered squashable (that is, in IsSquashableConst() also allow the case of func->funcformat == COERCE_EXPLICIT_CAST). That would also squash queries such as this one: +SELECT * FROM test_squash_bigint WHERE data IN + (1::bigint, 2::bigint, 3::bigint, 4::bigint, 5::bigint, 6::bigint, + 7::bigint, 8::bigint, 9::bigint, 10::bigint, 11::bigint); + id | data +----+------ +(0 rows) + +SELECT query, calls FROM pg_stat_statements ORDER BY query COLLATE "C"; + query | calls +----------------------------------------------------------------------------------+------- + SELECT * FROM test_squash_bigint WHERE data IN +| 1 + ($1::bigint, $2::bigint, $3::bigint, $4::bigint, $5::bigint, $6::bigint,+| + $7::bigint, $8::bigint, $9::bigint, $10::bigint, $11::bigint) | I, frankly, see little argument for making a distinction here. We can still discuss whether we prefer it one way or the other; we don't need that decision to prevent me from pushing the patch I here attach, I think. -- Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/ "The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom." (Isaac Asimov) --xulb2npnegtuim3q Content-Type: text/x-diff; charset=utf-8 Content-Disposition: attachment; filename="v29-0001-Prevent-jumbling-of-every-element-in-ArrayExpr.patch"