Commits on Aug 21, 2026
-
Clean up PREPARE query strings in multi-statement contexts
When PREPARE is executed as part of a multi-statement query string, the stored query text previously included the entire multi-statement string. This caused the extra queries to be stored in the prepared statement cache, consuming unnecessary memory, and made them visible when querying pg_prepared_statements. It also caused issues with query normalization in extensions like pg_stat_statements. This commit modifies PrepareQuery() to extract only the relevant PREPARE statement using CleanQuerytext() before storing it in the CachedPlanSource. The stmt_location in the Query tree is reset to 0 since the query text stored in the plan cache now contains only the PREPARE statement, which starts at position 0. This ensures that downstream consumers like pg_stat_statements can correctly normalize the query text. Author: Julien Rouhaud <rjuju123@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/aUwKEWGge5jWtaRX%40jrouhaud