Re: Cleaning up PREPARE query strings? - Mailing list pgsql-hackers

From Sami Imseih
Subject Re: Cleaning up PREPARE query strings?
Date
Msg-id CAA5RZ0sswD2h2w8FkVjToA=3oNYUb1mW-zuCD=J6DDK2zuLuZg@mail.gmail.com
Whole thread Raw
In response to Re: Cleaning up PREPARE query strings?  (Julien Rouhaud <rjuju123@gmail.com>)
Responses Re: Cleaning up PREPARE query strings?
List pgsql-hackers
I was looking a bit more here, and I found that this patch breaks if
pg_stat_statements is enabled.

```
postgres=# SELECT 'bingo'\;  PREPARE q1 AS SELECT 1 AS a \; SELECT 42;
server closed the connection unexpectedly
    This probably means the server terminated abnormally
    before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.
The connection to the server was lost. Attempting reset: Failed.
!?>
```

This is because the raw statement location is set to 0 with the patch which
breaks generate_nromalized_query when trying to deal with a multi command
statement. So, I don't think the way v1 is doing things will actually work.

I am thinking that storing the statement length and location in the entry
of prepared_queries may be the better option. Having that info, the
cleaned up query text can be generated on the fly whenever
pg_prepared_statement is called.

We may not need to call CleanQuerytext whenever, however it does
have the benefit of removing leading and trailing whitespace and the
terminating semicolon.

What do you think?

--
Sami Imseih
Amazon Web Services (AWS)



pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: code contributions for 2025, WIP version
Next
From: Andres Freund
Date:
Subject: Re: Enhancing Memory Context Statistics Reporting