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.98.2) (envelope-from ) id 1xLU2O-00000001XRB-3H2s for pgsql-bugs@arkaria.postgresql.org; Mon, 26 Oct 2026 23:23:33 +0000 Received: from localhost ([127.0.0.1]:35816 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xLU2N-00000008MsR-1vjy for pgsql-bugs@arkaria.postgresql.org; Mon, 26 Oct 2026 23:23:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]:48102) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xLU2N-00000008MsF-0dwg for pgsql-bugs@lists.postgresql.org; Mon, 26 Oct 2026 23:23:31 +0000 Received: from fout-b6-smtp.messagingengine.com ([202.12.124.149]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xLU2F-0000000195c-3mXv for pgsql-bugs@lists.postgresql.org; Mon, 26 Oct 2026 23:23:25 +0000 Received: from phl-compute-08.internal (phl-compute-08.internal [10.202.2.48]) by mailfout.stl.internal (Postfix) with ESMTP id 520E11D003FD for ; Mon, 26 Oct 2026 19:23:22 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-08.internal (MEProxy); Mon, 26 Oct 2026 19:23:22 -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:subject :subject:to:to; s=fm2; t=1793057001; x=1793143401; bh=9r5WCgJNUP lee10bmr90uoizA3lbGWFEqxrQmx2TC/k=; b=P0qwC3Yl3paffJADMqc0KJKQjc f/fV1EExF7rD1lL9mtWhN5FdimeT1tkqsJ65MoH/Z4DAn4mKjq+dEiqpilkC0hs9 nmLS2wiL7NdpBWwGV4MyiGPiDwXUAlci0BNNXYgX133XmeDBmN+N3qoLamEWHVN9 micBCA87gw6ncFFehmNeyNR6SD+kaylRh7FkZz5BxL2lDjpQTIevZ4JwXwaM7elN jfNQzhsjKHxVb1SeLHHCqYVUaV8+TGXvasyhnnpRwgDbItQiVFvT8JVwZRSEIJGO uleUdpqySOXc5gJY8QLC+FDVoD03sM2VLwuBJgmQrrciC053uGyNF5cV+m4w== 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:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1793057001; x=1793143401; bh=9r5WCgJNUPlee10bmr90uoizA3lbGWFEqxr Qmx2TC/k=; b=LQJVDjxSZ2+AMamPZJLFLSqnWhn3AV/iaUyS8qtjXKb1ch0XC9k ydbMlk4IpwDLpEP/kUYCFAqyXqdtxX8ylHq6RPOT2o3mz+MmxqcuQXIJzgEE6AuU ZDJpKCLqRobfdRmGJR3qzWsjJMKwnAUSVKwLHdpvUWObwNli0ryfAPCaiRMrkdUp b3Ha07/otkzdFGc1EIDeNeP6fPxYU/6Oj4LheeQsqFJgvMmflCnjK4gRVUYfpCGT ebtlngGVxMZuT7MHgA0I/GHwDhCfrLccjtnb5cuNbS+FVGLY9sVZqeVY3n5zQQBk 4fhmQ64wRfOokdW08UPFFxaawLjdhPUd/Kg== X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-07; repo=github.com/dkim2wg/interop; date=2026-10-18; sw=lmtpprox; action=sign d=paquier.xyz a=rsa-sha256; DKIM2-Signature: i=1; m=1; t=1793057001; d=paquier.xyz; mf=PG1pY2hhZWxAcGFxdWllci54eXo+; rt=PHBnc3FsLWJ1Z3NAbGlzdHMucG9zdGdyZXNxbC5vcmc+; s=fm2:rsa-sha256:CZbnYcpgRmqZ9RhFOarHLlwz6cjvRRuJIjpkUnmsgqlQ5kS g4FWndLgSZfMmSxzPPP+e93kd5OXUZPDN0jpg2A8dr1/YJ5fWCZHn/dLpHTfqIRy 67r06PWTW+T0w6xpLP36HWSqgNkm4iuaE9v14H5PFdUDElwJUbt5NnAi3rY8RutY hQszwtdeUq9pccfJb8CINla0hiJS8TWFUa716DfNsWjXjGKUYApI7O0T/mavGisu hQBCOBUyzm+BP4v2q5D75IIA6AUpoerVNczfxfJC76zAkLEsWyo9QaJ9x66PKBhM yQOeqPPR0YqSFpnWnn1b+17L6buTDBUsRx+DP/Q==; X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-07; repo=github.com/dkim2wg/interop; date=2026-10-18; sw=lmtpprox; action=mi-m=1; hc=12; hn=cc,content-disposition,content-type,date,feedback-id,from, in-reply-to,message-id,mime-version,references,subject,to; Message-Instance: m=1; h=sha256:fVFrJl357y0J84XjEbeEX1srJZAbCUSr2v3W1IVOGaM=:NoJFTEv0lSfiZ9DVtKWxqPTsXiZqSE5jrIECWRtvDec=; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTFJRvNM+DT5PHkgH4cYT6IR8kmOrWcucLab/a62rn8NpL/jmwH+yCGB2JeUKSsoIf o4GeDx8xBCV9zcqpApUrNOd6dD8LEekdbVPHyYGYqstI8UyQOImaUVp5GOfvTRgURUmoRb QJR+j2NLtvx9yjr3dtos4ma7b8a/zfotJGMN1kY0FNvT10DX3JpA0dMixJNX0wBpmjDV+P i0gV1IvkvfPw4b0zk8f/gEDjh+lpcFOv6dHn2vgcBXyhxlbDqJTW+opVG/cmFmOJ8RAPun y+HhjBhx9NBtrIgyTswOFQetYv3dqNk27MpClg1dMSWClLIID+jqtlpQTOs6y8GsJM2Unu eQ3r2B5sqof2uyaP/+a7PBMA4PJviGTT0A8tKV/IdnV2PFsKcKV5Mrf4fXV0Z2TCDU3uoW A0n5KnWSQamFyUmO7D4r1BR3y5H+dYvHqK2FAV33WqCLrIPQDaYdde2WEUJ4i32VBsIKe4 Z4D22KTUT6qNC7RRMX0CtKpdsT10CDAlJjfVQcmBLDecw2ApOJWHyGlOzGbARozH+r4aRp foN1OVxIoONxiFYE39OUp+1l+yKT5wUbRtBAVDTbk0oXwbA1SoIN1oCjTASRVhDv6jkaAN LjBO0zAvzwXzV0s1DoMUszdAnCFOlW2IxteEk7oM9wyRv1n5av3IXWtn13+w X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 26 Oct 2026 19:23:20 -0400 (EDT) Date: Tue, 27 Oct 2026 08:23:17 +0900 From: Michael Paquier To: Sami Imseih Cc: Gaurav Singh , pgsql-bugs@lists.postgresql.org, Lukas Fittl Subject: Re: pg_stat_statements stores WITH HOLD cursor query with literals Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="7nhfiGEbJ20/uLDh" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --7nhfiGEbJ20/uLDh Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Oct 26, 2026 at 05:16:45PM -0500, Sami Imseih wrote: > I spent some time thinking about this today, and I can now see > its usefulness. Initially I was thinking that nesting_level is the only > thing that needs this state in pg_stat_statements and auto_explain, and > was not sure if this complexity is worth it. I was wondering a bit myself about the potential interactions between auto_explain and PGSS, especially once they're bundled together, but I did not dig much about the details of the interactions.. > Take for example a role switch between the DECLARE CURSOR and the cursor > cleanup. Maybe not very common, but perhaps applications dealing with > multi-tenancy/RLS could end up running into this without realizing. >=20 > ``` > userid | toplevel | calls | query > --------+----------+-------+---------------------------------------------- > user1 | t | 1 | DECLARE c CURSOR FOR SELECT $1 WHERE $2 =3D = $3 > user2 | t | 1 | DECLARE c CURSOR FOR SELECT 1 WHERE 1 =3D 1; > ``` Fancy. I've never seen that, but I suspect you would.. > There is also a similar shape with auto_explain. The cursors were not > sampled when they started. After raising auto_explain.sample_rate, the > later SELECT makes the new sample rate effective. Then COMMIT closes > the cursors while auto_explain thinks the current query should be > sampled. That counts as one more case here. > One could argue which behavior we want to see in the above, but I think > the point is that this QueryDesc state support could help us close some > of these issues. I don't really want to enter in the realm where we add more per-extension fields in backend structures, especially if multiple extensions have a risk of stepping on each other. > As far as v3- goes, they both look good to me, and I could not find > anything wrong with them. Okay, thanks. Let's use this infrastructure, then. I suspect that Lukas Fittl would also find uses for it, as he's a lot into monitoring and, err.. analyzing. I am adding him in CC to make him aware of this thread, at least, with QueryDesc extensibility in mind. -- Michael --7nhfiGEbJ20/uLDh Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmrf4OUACgkQnvQgOdby QH1c9hAAhnX87+3cT9r3Xq3W0JZ6Dd9TQvvp3vv/X+7kP9aDw1gOrry53eZHrdIJ P3D8A6S+0o1emlKfNihZ6uKHqdQAawHK9pvm1Ub2mgv9pfuiT+AGtgPNPKoP7YGD s2TEumC9hAhGC41dPDbVVz8C3lPZyfrikqJbFeHFMKCYUuAY+aZe05/GwDnfHfGS CyBd6oxByjBL168dCybM5/7aV4GrgKZya9IjHbC9QV21I8wRgUCpTLWa2G4Ql63q 7AwZz3UZ6iKFm3FAYtRZx+x8HdpGn8r3WqPuvjZ/7iBkuvVMNlUiPMrhPKpLoOtj 2DyPSvB7eyGwwKxvvvgIIP2N4XHPAAGVSXIo3G8vfxVSR7jRhAG4pCHDbRHAAq/3 822itE7UsVrkMYlYClf5T1/aBH48zKmpwfm7JrBlUp/8qTD4wJ5utb8jfW6BEfdS bcTTi5V9oWQVY8XQLqSNZLoP1vcWSqFcyFx4XAf8rI5eVSy34TegREHJnARVkHwZ 76r7BqynLPW/8raD3ZRPMalrvYTZqIKx5PEGZ89JAzm7mHrFWTz5cZCYbbT8/kPu gGflqOz/dBJ3UUuabhVuFnKAc8W3uARGxmgdAYM8/BR9lKw21FZxU47u7bV2rDYA qnMUc/Sm3u9mgUW88nZJ1d6K95jL7m3YIUuZ9xPaU9Occp4/N1w= =hrzQ -----END PGP SIGNATURE----- --7nhfiGEbJ20/uLDh--