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!

CommentFileSizeAuthor
#6 Screenshot 2026-08-10 at 08.21.11.png828.69 KBdaffie

Issue fork drupal-3615415

Command icon 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

daffie created an issue. See original summary.

daffie’s picture

Issue summary: View changes
daffie’s picture

Status: Active » Needs review

Ready for a review.

smustgrave’s picture

Can't tell if the pipeline errors are from a previous run or this one? But seeing failures?

daffie’s picture

StatusFileSize
new828.69 KB

@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: screenshot

daffie’s picture

The CI pipeline no longer starts with PostgreSQL on PHP 8.6

smustgrave’s picture

Disclosure 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?

daffie’s picture

Disclosure: I have used AI on the PR, the IS and the CR.

smustgrave’s picture

@daffie I can mark it if you think coverage for Combine is good?

mradcliffe’s picture

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

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Short slack talk and @daffie feels good about that coverage for Combine which works for me. Going to mark it.