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

From Sami Imseih
Subject Re: Cleaning up PREPARE query strings?
Date
Msg-id CAA5RZ0tO7KXtOSGLGzhGijneTs5+v32PqOxhQ0bSj9Q8stLPyw@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 think that you have a misunderstanding of how memory context works in
> postgres.

No, I understand how memory contexts work, but I skipped over the fact that the
cleaned up query text is copied into CachedPlanSource memory context during

CreateCachedPlan:
```
plansource->query_string = pstrdup(query_string);

```
Which is long-lived and will remain until DEALLOCATE.

while pstate->p_sourcetext and new_query are in the current execution's
memory context.

The patch is indeed better from a memory perspective. My apologies.

However, the error reporting does break with the patch. Notice with the patch
the cursor for the error reporting shifts incorrectly. This is due to the fact
rawstmt->stmt_location/length are no longer representative of the original
qurey text.

## unpatched
```
postgres=# SELECT 1    \; PREPARE stmt AS SELECT nonexistent_column
FROM users\; SELECT 2;
 ?column?
----------
        1
(1 row)

ERROR:  relation "users" does not exist
LINE 1: ... ; PREPARE stmt AS SELECT nonexistent_column FROM users; SEL...

                                       ^
```

## patched
```
postgres=# SELECT 1    \; PREPARE stmt AS SELECT nonexistent_column
FROM users\; SELECT 2;
 ?column?
----------
        1
(1 row)

ERROR:  relation "users" does not exist
LINE 1: ...LECT 1    ; PREPARE stmt AS SELECT nonexistent_column FROM u...

                                   ^
```

--
Sami Imseih
Amazon Web Services (AWS)



pgsql-hackers by date:

Previous
From: wenhui qiu
Date:
Subject: Re: Can we change pg_rewind used without wal_log_hints and data_checksums
Next
From: Tatsuo Ishii
Date:
Subject: Re: Row pattern recognition