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 1uOwwW-00EDZj-Kn for pgsql-bugs@arkaria.postgresql.org; Tue, 10 Jun 2025 11:15:00 +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 1uOwwU-003XCm-MX for pgsql-bugs@arkaria.postgresql.org; Tue, 10 Jun 2025 11:14:59 +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 1uOwwT-003XCd-V2 for pgsql-bugs@lists.postgresql.org; Tue, 10 Jun 2025 11:14:59 +0000 Received: from fhigh-b6-smtp.messagingengine.com ([202.12.124.157]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uOwwR-001E4B-2v for pgsql-bugs@lists.postgresql.org; Tue, 10 Jun 2025 11:14:58 +0000 Received: from phl-compute-09.internal (phl-compute-09.phl.internal [10.202.2.49]) by mailfhigh.stl.internal (Postfix) with ESMTP id 94C702540105; Tue, 10 Jun 2025 07:14:52 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-09.internal (MEProxy); Tue, 10 Jun 2025 07:14:52 -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=fm1; t=1749554092; x=1749640492; bh=6HLLPZyWOC S21nZvCwkjn37CdMHs4yTQfL9EuZhtE24=; b=eQdcUnWTGfxT6opKBqz7h1BpiM bM+iPhNyU7lV83vKfEOO9jDXhvCg2bT1dLRuRSeF7bMpGoz4j0Ua0rSXWG9SS+T3 57v7kfsFFMBt+VK8L6/7rHFginlz5mC0Cla/7GL0ZkliGacfu9Ama1lMkm0VgLD7 fDSF/sohyu2Y4uQqX5o/yh521ZsK+EAhr7h40zC7J+Q+rjW/l6TxaFCsvXWHiH08 U5TkC6nP2lBJNkdLmBXGfCH6LwoCXZdNZumdQ1Lp2LFGM8i3YEBHecZMe6gu9AZP gk0sP0yCd0Wtg/9mSxCRDyvjXcqdoqfjVCxeFFhJlytHv+48XiN6zInXrhVw== 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=fm1; t= 1749554092; x=1749640492; bh=6HLLPZyWOCS21nZvCwkjn37CdMHs4yTQfL9 EuZhtE24=; b=iRxy90QAba/o7mqw+u/fnMZSLmuIyT5rywRL3QTPEOX8NaZT2sd iy2M6CFEw9Z00lGyC7ppGZtijS74p/XbFkMV74MapX5lPtzKIVhqifValDOYdgBx NjgFwSKjnHDXGB0JV2DOmhhXD1y9/vNHUvxDVc5eCq/41H4QUW8kIozUDrZa4vci cgWF2+Fj9mpjCwdZ8bojaekAt1AGAbRJ2r9xhoLdW9P/fTZtViOIylv1bNeCBi7P 3AgzNL3BHWa1gk28YaYRPArQPgD+EOPT+acg4Pdsozy7ETUfIyETEfGV3trTc7GD 9/P2+jP46ns8cJLUge1u9MHM/OCKMCn3AQg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtddugddutdeiiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenfghrlhcuvffnffculdejtddmnecujfgurhepfffhvfevuffk fhggtggujgesghdtreertddtvdenucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrh cuoehmihgthhgrvghlsehprghquhhivghrrdighiiiqeenucggtffrrghtthgvrhhnpeet leeifedufffhhfdtteelgeeggeffhfekueevteeigfduudevudetgfegiedvjeenucevlh hushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehmihgthhgrvghl sehprghquhhivghrrdighiiipdhnsggprhgtphhtthhopeehpdhmohguvgepshhmthhpoh huthdprhgtphhtthhopegrnhhthhhonhhinhdrsghonhhnvghfohihsegurghtrgguohhg hhhqrdgtohhmpdhrtghpthhtohepmhgrshgrohdrfhhujhhiihesohhsshdrnhhtthgurg htrgdrtghomhdprhgtphhtthhopeguihhlihhpsggrlhgruhhtsehgmhgrihhlrdgtohhm pdhrtghpthhtoheprgdrkhhoiihhvghmhigrkhhinhesphhoshhtghhrvghsphhrohdrrh hupdhrtghpthhtohepphhgshhqlhdqsghughhssehlihhsthhsrdhpohhsthhgrhgvshhq lhdrohhrgh X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 10 Jun 2025 07:14:48 -0400 (EDT) Date: Tue, 10 Jun 2025 20:14:40 +0900 From: Michael Paquier To: Anthonin Bonnefoy Cc: Fujii Masao , Dilip Kumar , a.kozhemyakin@postgrespro.ru, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18947: TRAP: failed Assert("len_to_wrt >= 0") in pg_stat_statements Message-ID: References: <18947-cdd2668beffe02bf@postgresql.org> <9171ecda-e1f4-4390-ae54-98bc441b98e3@oss.nttdata.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="goS2+RL7rMT6GWge" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --goS2+RL7rMT6GWge Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Jun 10, 2025 at 12:02:06PM +0200, Anthonin Bonnefoy wrote: > One wrong assumption I made was that parenthesis aren't part of the > select statement, which is definitely wrong with queries like '(SELECT > 1) limit 1;'. As we don't have end location tracking, we don't have > the possibility to get the length of the select statement. Yeah. > I've joined a possible (and very rough, this would definitely require > more tests) fix: > - SelectStmt's location is now the outermost '(' position > - Don't track the length anymore in 'select_no_parens' > - Nodes that are embedding a SelectStatement would need to update its > length if necessary. For COPY, this is straightforward as we can use > the parenthesis location surrounding the statement. With CTAS, > SelectStmt's length should be updated if there's an existing > opt_with_data. Hmm. I am wondering whether this would be enough; these are not the only places where we use select_no_parens and select_with_parens. I'd be curious to see what you think a fully-bloomed fix should look like. -- Michael --goS2+RL7rMT6GWge Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmhIE6AACgkQnvQgOdby QH3qTQ/6AiYHkAmrP3XzQGjZJWdjesNYreoQxgdudYxmbMKEEXEoS4+Z3NDcIwV6 iWYZkinIuD/O0cMqDtULXPFgF+GC+RnVK+yk3PzN75HbCi8bHgwUfHjkUezv8eMl 5ReYUp7Gsx9J/fq8aVRej2479cTG2Ht4C4/YWFvH7iJw+GZ7GoHzmkN5tj76Ef5L dZXGOSnAj5E01dF20Zg11sxlvzyo97jd+iXIgPXwdg1yfi0PwrlSBR+G3smaxWfm wZXgPYiZoRc1V42BOr5M9fuORaATRJs58l8O21oU1khCgzbARG8kRzla0lcMAxk2 W+BsiuDA4k+E7Qbg9grBh3ro93ZAOUqFeIj0PqY0mAIG5GLgCN1vSvY/dcG75CyO o6BA/AuoAOgJTRzh5YvIThwNhlTqIYxOD9JxCjR+ar09MKLrxQ5jL8JeGLmiwl4R BUYInekvhU4IBYaTT8tStO+n32rC2ho7csVpRcqCfDC6GI8CbLZ0n+GQs+ocAJkY bNsyGBRE/LvCqxwq376LLOt9Wd8fOxcwosy9+11WSUgOyLm4WUAgnkU2S+d8TXm3 IbmUSznU1peL40oZOc0rrlA81rxdHcSzRhXZdSb2UrUTulvHEpMnt/YWWYO/e2kv +W81XTO8lTrRFdIosG/CJccT60KG6NPxQCkFhh7plHYqABkv39M= =Gazb -----END PGP SIGNATURE----- --goS2+RL7rMT6GWge--