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:
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.