Skip to content

search-replace on SQLite skips the SQL fast path: about 3× slower than 2.12 #257

Backlog

Description

@chubes4

Bug

On SQLite, wp search-replace sends every text column through the row-by-row PHP path. Before 3.0 it used a single SQL UPDATE per column. On a 30,000-post site it is now about 3× slower than in WP-CLI 2.12.

Two get_db_type() === 'sqlite' checks cause it:

  1. Fix SQLite compatibility for search-replace command #225 skips the serialized-data REGEXP check and sets $serial_row = true for every column. Its comment says "SQLite does not support REGEXP by default".
  2. Scan each table once to check all columns #246 skips the new one-pass get_column_stats() on SQLite.

get_db_type() returns sqlite only when the SQLite Database Integration drop-in is loaded (SQLITE_DB_DROPIN_VERSION). That drop-in registers REGEXP as a PDO function: see WP_SQLite_PDO_User_Defined_Functions, 'regexp' => 'regexp'. WP-CLI 2.12 already ran the REGEXP check on SQLite, and it worked.

Measurements

Setup:

  • SQLite Database Integration with the AST driver, PHP 8.4.
  • 30,001 posts with the site URL in post_content, 10,000 serialized postmeta values, and a nested serialized option.
  • Command: wp search-replace http://localhost:8882 http://example.test --skip-columns=guid --skip-plugins --skip-themes.
  • Each run starts from the same database snapshot. I ran every variant twice and got the same results both times.
WP-CLI Time Reported post_content type
2.12.0 3.8s 470,330 (counts every row an UPDATE touched) SQL
3.0.1 12.0s 40,006 PHP
3.0.1 without the two SQLite checks 4.0s 40,007 SQL

All three leave byte-identical databases (wp db export diff is empty). Serialized values stay valid: 10,000/10,000 postmeta arrays unserialize with the new URL, and the nested option is updated.

The one-row difference in the count is SQL mode counting matched rows where PHP mode counts changed rows.

Proposed fix

Remove both SQLite checks, so SQLite uses the same column stats and REGEXP detection as MySQL. Keep the views skip from #225: SHOW FULL TABLES is a separate problem.

Found while auditing WP-CLI 3 in WordPress Studio, where search-replace rewrites the site URL after import. Reported by Franklin (Claude via Pi, Roadie) for @chubes4.

Activity

  1. added
    command:search-replace
    status:unconfirmed
    on Dec 3, 2026
  2. chubes4 commented on Dec 3, 2026

    @chubes4
    Author

    Cook agent-task-e34f6c1f-d796-47e8-b03c-274807514a2d stopped without a pull request

    Attempt agent-task-e34f6c1f-d796-47e8-b03c-274807514a2d-attempt-1-163256be

    Summary: SQLite search-replace sent every text column through row-by-row PHP processing even though the SQLite Database Integration drop-in provides REGEXP. SQLite now shares MySQL’s fast path; #257 reports 12.0s on WP-CLI 3.0.1 versus 4.0s with the fix on a 30,000-post site, with byte-identical database dumps. Fixes #257.

    What changed

    • Enable one-pass column statistics and the per-column REGEXP fallback on SQLite.
    • Report plain columns as SQL and keep columns containing serialized data on the PHP path.
    • Keep view discovery disabled on SQLite because the drop-in does not support SHOW FULL TABLES.
    • Add “Use SQL for plain columns and PHP for serialized data on SQLite”; retain the wildcard scenario’s MySQL-only tag because its live-update count differs on SQLite.

    Last gate: gate-3 succeeded

    AI assistance: Homeboy (pi) / Pi · route roadie/cook-heavy · served gpt-6.2-sol wrote this report; Homeboy posted it unedited. A later attempt of this Cook updates this comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcommand:search-replacestatus:unconfirmed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions