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 1tiwrG-004748-Ej for pgsql-hackers@arkaria.postgresql.org; Fri, 14 Feb 2025 14:39:58 +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 1tiwrE-00Ah1u-F8 for pgsql-hackers@arkaria.postgresql.org; Fri, 14 Feb 2025 14:39:57 +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 1tiwrE-00Ah1l-5F for pgsql-hackers@lists.postgresql.org; Fri, 14 Feb 2025 14:39:56 +0000 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tiwrD-000mMK-0d for pgsql-hackers@postgresql.org; Fri, 14 Feb 2025 14:39:55 +0000 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-21f44e7eae4so40870745ad.2 for ; Fri, 14 Feb 2025 06:39:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739543994; x=1740148794; darn=postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=cIhoMc6Zhbqe23O7EcUOlx/9dkhq/mmHUBDdg0nYT0Y=; b=L9Srvx02vAtzrHdl0P7mQHBJvJwJ91ci1i1qbAh+HwJRGZRKNmETHFVOq2DLH+5v6K xP5D0WJkHM4TB2O5eFoRm04WU0CScbiSkLgCM/bfxGUImAbtphK4iEnH5XfQudtcHIFF 0iDwD/DRZ+IBdW9iO6q5xYkK0oOogtjGKGRLcNjC3nnZg3PhuBVP7SLakO3GClvdF8ZV gc4eSBey3C/zYjkHQ2qdT9Cx4vJQQdLmiH6nKOunraTdriLIm+0Y04HGh7autNBsIcR1 SUFpkco0J+s0Pop4jS5jorWeSxqDlVhphYhBDevxKtPoJ9fUouVH+dYzWstk6h+ecyMW WkgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739543994; x=1740148794; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=cIhoMc6Zhbqe23O7EcUOlx/9dkhq/mmHUBDdg0nYT0Y=; b=tZpXlg3rs7lnx1ylVN/NLbfKr/u+d1QtwFgOkYX/J+vdCPSatCuXGpchmuZQLimlrg V+nYMrGEby7wVT0Je+ZbJ39OnwRVzweqPc8oQcJBj7+19fawyGu8XG9bTlyF+sydxjlb F//QnhM1sDYYyq3XFFFWheiMPRxc4aoZoX8ZQekle6neXmKVNOrJ7TkaibrW8a8GvoNS ggRWpMPCx39VLy+sKTEys6GQ2ux2ew/giJ3Vlq+K8YqvcUsOPPpU++XFJrp+NBJI4tKd xcdD8Fozqd9/UqOS7ZkD5kJNxJ/v4qPE1EvP/IKq57YyuHZk+YZc4kcWD0ayy2WpmkXq Wv2A== X-Forwarded-Encrypted: i=1; AJvYcCXYm9Z6gEpOOU/pleyK/8kXrzq7yNfq8yr2Lyjk96bG9AiAcQWR3rMTf7yQgqGtkqcnl5Jmq5kPEILKjeIT@postgresql.org X-Gm-Message-State: AOJu0YwTK2esmbDcOGC4YudPGP8RyqkT38u6D54fr9SnXzKq0osL0NRe k5XOqSwksnzMuFQChTLY6Sw2Rfd5W5+SISWXh8eQvDmrGqw+fX6Q X-Gm-Gg: ASbGncsQzrzRtQH/M+rLklifp+osC0u93UepkflrAdhSN4W/oEifvzyMYKbelKGombo wfAP11LVq0OQf7p9CYnab4UaNIERT+0P9PqrECoMRRIYrmcMFhEYSwzodn+ZG4v1M0xSJAod0rl MhT1CY78VpDN0giI6161X0xTa8gfUoYiB19HlUiEdzKDLU8yh43U32T4769ODNIcTdnoJKaKRoK TFnbgYwLDUx9jpUKMQfH3IStySwxgBz42hbjLz16pMmWt1U9rdzlPOiMZFEI6KPEXG5Ki6PHaao PRP3zf0= X-Google-Smtp-Source: AGHT+IGCqzoAmjYNBtLyTzUuhM8hQhPRCVBNLMRJEGfbRfCBCTPJHyRCE27gwbvTFhAl7fEMpSsaRA== X-Received: by 2002:a05:6a21:178a:b0:1ee:7d95:c674 with SMTP id adf61e73a8af0-1ee7d95d438mr7019267637.39.1739543994066; Fri, 14 Feb 2025 06:39:54 -0800 (PST) Received: from jrouhaud ([115.43.41.38]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7324d5d4608sm1728073b3a.129.2025.02.14.06.39.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2025 06:39:53 -0800 (PST) Date: Fri, 14 Feb 2025 22:39:45 +0800 From: Julien Rouhaud To: Dmitry Dolgov <9erthalion6@gmail.com> Cc: Sami Imseih , =?iso-8859-1?Q?=C1lvaro?= Herrera , 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: References: <202502140936.lni5gtrycnzf@alvherre.pgsql> <7vjscmc3ybcibtyetdufrevyyl2hxpcpnofn2eygnne46owmql@gofozgqyq722> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, Feb 14, 2025 at 03:20:24PM +0100, Dmitry Dolgov wrote: > > Btw, there was another mistake in the last version introducing > "$1 /*, ... */" format, the constant position has to be of course > calculated as usual. I'm not sure what you mean here, but just in case: > +SELECT * FROM test_merge WHERE id IN (1, 2, 3, 4, 5, 6, 7, 8, 9) AND data = 2; > + id | data > +----+------ > +(0 rows) > + > +SELECT * FROM test_merge WHERE id IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) AND data = 2; > + id | data > +----+------ > +(0 rows) > + > +SELECT * FROM test_merge WHERE id IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) AND data = 2; > + id | data > +----+------ > +(0 rows) > + > +SELECT query, calls FROM pg_stat_statements ORDER BY query COLLATE "C"; > + query | calls > +--------------------------------------------------------------------+------- > + SELECT * FROM test_merge WHERE id IN ($1 /*, ... */) AND data = $3 | 3 > + SELECT pg_stat_statements_reset() IS NOT NULL AS t | 1 > +(2 rows) There seems to be an off-by-1 error in parameter numbering when merging them. Note that the query text as-is can still be successfully be used in an EXPLAIN (GENERIC_PLAN), but it might cause problem to third party tools that try to do something smarter about the parameters.