From: Michael Paquier <michael@paquier.xyz>
To: Anthonin Bonnefoy <anthonin.bonnefoy@datadoghq.com>
Cc: Fujii Masao <masao.fujii@oss.nttdata.com>
Cc: Dilip Kumar <dilipbalaut@gmail.com>
Cc: a.kozhemyakin@postgrespro.ru
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #18947: TRAP: failed Assert("len_to_wrt >= 0") in pg_stat_statements
Date: Tue, 10 Jun 2025 20:14:40 +0900
Message-ID: <aEgToLnBX9W43ne-@paquier.xyz> (raw)
In-Reply-To: <CAO6_Xqoxsm_Y5dxc_4YmrhRACTBe-Y8Q=PP6Xv-svo6eud1-Mg@mail.gmail.com>
References: <18947-cdd2668beffe02bf@postgresql.org>
<CAFiTN-tGux5MZ9Hk2wKv5sVhk7eDq2AHaT79LxnQbVamxoRn9Q@mail.gmail.com>
<aET38DIyBht33bIP@paquier.xyz>
<9171ecda-e1f4-4390-ae54-98bc441b98e3@oss.nttdata.com>
<aEfGl9bNPR5C76W2@paquier.xyz>
<CAO6_Xqoxsm_Y5dxc_4YmrhRACTBe-Y8Q=PP6Xv-svo6eud1-Mg@mail.gmail.com>
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
Attachments:
[application/pgp-signature] signature.asc (832B, ../aEgToLnBX9W43ne-@paquier.xyz/2-signature.asc)
download
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: michael@paquier.xyz, anthonin.bonnefoy@datadoghq.com, masao.fujii@oss.nttdata.com, dilipbalaut@gmail.com, a.kozhemyakin@postgrespro.ru, pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #18947: TRAP: failed Assert("len_to_wrt >= 0") in pg_stat_statements
In-Reply-To: <aEgToLnBX9W43ne-@paquier.xyz>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox