Re: BUG #18947: TRAP: failed Assert("len_to_wrt >= 0") in pg_stat_statements

From: Anthonin Bonnefoy <anthonin(dot)bonnefoy(at)datadoghq(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Fujii Masao <masao(dot)fujii(at)oss(dot)nttdata(dot)com>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>, a(dot)kozhemyakin(at)postgrespro(dot)ru, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #18947: TRAP: failed Assert("len_to_wrt >= 0") in pg_stat_statements
Date: 2025-06-11 09:04:36
Message-ID: CAO6_XqpxskZZdhgNJ0xQ1cyX3Br=11iSAb_1GLQHO1=OziKNoQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Here's a v2 for the attempted fix. This is using the mentioned approach:
- SelectStmt's location is set to Select's position when the node if built
- If there are surrounding parentheses, we include them and move the
start of the statement to the outermost '('

The Statement length is only set for:
- COPY: We use the PreparableStatement's surrounding '()' to set both
location and length (setting location should be redundant here though)
- CTAS: we set the statement's length if there's a tailing 'WITH (NO) DATA'.
- Other than those, the statement length will fallback to use the top
RawStmt's remaining length.

I haven't done it for Views and JSON_ARRAY. Their nested queries
aren't currently tracked and reported by pgss so there's no way to
test those. This could be done but there's no available way to test
this is correct AFAIK?

Attachment Content-Type Size
v02-0001-Fix-location-and-length-tracking-of-select-state.patch application/octet-stream 19.9 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2025-06-11 11:22:23 BUG #18954: Error "could not reserve shared memory region ... error code 487" on Windows
Previous Message Richard Guo 2025-06-11 08:33:54 Re: BUG #18953: Planner fails to build plan for complex query with LATERAL references