Problem/Motivation
Connection::prepareStatement() in the pgsql driver runs preg_replace() on the full SQL of every prepared statement. The rewrite adds a ::text type-cast to fields used with the ILIKE and regex operators. This costs time for every statement, also for the many queries that use neither operator. A regex on the final SQL can also match inside expressions or string literals.
Proposed resolution
Add the cast when a condition is compiled instead. A new field_suffix directive in the condition operator map appends SQL to the field. The pgsql driver sets 'field_suffix' => '::text' for the LIKE and regex operators. Identity entries cover ILIKE and ~*, which the Views string filters use directly.
For SQL passed as a raw string, Connection::prepareStatement() keeps the rewrite behind a stripos() guard and triggers a deprecation. The rewrite is removed in Drupal 13.
Steps to reproduce
Profile any page on PostgreSQL. Connection::prepareStatement() runs the preg_replace() for every query.
Remaining tasks
Create the change record for the deprecation. Review.
API changes
Condition operator directives support a new field_suffix key. A new public method Connection::getConditionFieldSuffix() returns the suffix for an operator. Relying on the driver to cast fields in raw SQL strings is deprecated.
Data model changes
None.
For the committer
The changes to the .gitlab-ci.yml file need to be removed before merging!
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | Screenshot 2026-08-10 at 08.21.11.png | 828.69 KB | daffie |
Issue fork drupal-3615415
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 commentedComment #4
daffie commentedReady for a review.
Comment #5
smustgrave commentedCan't tell if the pipeline errors are from a previous run or this one? But seeing failures?
Comment #6
daffie commented@smustgrave: THe CI pipeline is green for MySQL and for PostgreSQL on PHP 8.5. It is failing for PostgreSQL on PHP 8.6. See:
Comment #7
daffie commentedThe CI pipeline no longer starts with PostgreSQL on PHP 8.6
Comment #8
smustgrave commentedDisclosure am using AI to help with review as I don't know postgresql that much but want to help keep it moving.
1 think flagged was there was no additional test coverage for the changes made to Combine or is that covered by testCompileWithFieldSuffixOperator?
Comment #9
daffie commentedDisclosure: I have used AI on the PR, the IS and the CR.
Comment #10
smustgrave commented@daffie I can mark it if you think coverage for Combine is good?
Comment #11
mradcliffeI reviewed the merge request, and this is done better. I didn’t find any injections.
I think the existing functional tests passing is enough for the changes in Combine so I think it is RTBC.
Comment #12
smustgrave commentedShort slack talk and @daffie feels good about that coverage for Combine which works for me. Going to mark it.