Problem/Motivation
The pgsql driver connects and then runs SET NAMES 'UTF8' as a separate statement in Connection::__construct(). This adds one network round trip to every connection. Drupal opens a new database connection on every request, so every request pays this cost.
libpq can set session settings in the connection startup packet through the options DSN parameter. SET NAMES 'UTF8' is equivalent to SET client_encoding TO 'UTF8'. The encoding can be set with options='-c client_encoding=UTF8' in the DSN, with no extra round trip.
Steps to reproduce
Enable statement logging on PostgreSQL. Load any page. The log shows SET NAMES 'UTF8' after each connection start.
Proposed resolution
Append options='-c client_encoding=UTF8' to the DSN in Connection::open(). Remove the exec() call from the constructor.
Remaining tasks
Create a merge request. Review.
API changes
None.
Data model changes
None.
For the committer
The changes to the .gitlab-ci.yml file need to be removed before merging!
Issue fork drupal-3615187
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3615187-set-names-to
changes, plain diff MR !16579
Comments
Comment #3
daffie commentedAdded the fix and testing.
Comment #4
daffie commentedDisclosure: I have used AI on the PR and the IS.
Comment #5
daffie commentedComment #6
smustgrave commentedFor 1 comment on the MR.
Comment #7
daffie commentedComment #8
longwaveAdded a suggestion to the MR.
Comment #9
daffie commentedRebased the PR and set the updated comment back to the original comment.
Comment #10
smustgrave commentedNot a postgresql expert but believe all feedback on this one has been addressed.
Comment #13
longwaveCommitted and pushed 9b33c68d4b3 to main and f7b68ec152a to 11.x. Thanks!
Debated about backporting it but not sure it's worth it or a change we should be making in a patch release, it's technically not a bug fix.