Skip to content

[AST] Support MySQL locking clauses (FOR UPDATE, SKIP LOCKED, etc.)#342

Open
wp-fuse wants to merge 3 commits intoWordPress:trunkfrom
wp-fuse:feature/pr-1-locking-clauses
Open

[AST] Support MySQL locking clauses (FOR UPDATE, SKIP LOCKED, etc.)#342
wp-fuse wants to merge 3 commits intoWordPress:trunkfrom
wp-fuse:feature/pr-1-locking-clauses

Conversation

@wp-fuse
Copy link
Copy Markdown

@wp-fuse wp-fuse commented Mar 30, 2026

Goal:
Support MySQL queries that utilize locking clauses (e.g., FOR UPDATE, LOCK IN SHARE MODE, SKIP LOCKED, NOWAIT) by ensuring they are safely ignored during translation to SQLite.

Why is this necessary?
SQLite does not support row-level locking syntax in SELECT statements. In environments like WordPress, plugins such as Action Scheduler frequently use these clauses for concurrency control. Since SQLite manages concurrency through database-level locking during write transactions, these clauses are redundant at the SQL level but would cause syntax errors if not stripped.

What was changed:

  • Added the lockingClause rule to the AST translator (class-wp-pdo-mysql-on-sqlite.php).
  • The rule now returns null, safely removing the clause from the final SQL string.
  • Added a detailed comment explaining that while this ensures syntax compatibility, the specific row-level locking semantics of MySQL are not preserved.

Verification:

  • Validated via the driver test suite (WP_SQLite_Driver_Tests.php), which includes complex queries and emulated Action Scheduler scenarios with FOR UPDATE.
  • Confirmed that queries with joins and subqueries containing FOR UPDATE are correctly translated into valid SQLite SQL.

wp-fuse added 3 commits March 30, 2026 19:33
Goal:
Support MySQL queries that utilize locking clauses (e.g., FOR UPDATE, LOCK IN SHARE MODE, SKIP LOCKED, NOWAIT) by ensuring they are safely ignored during translation to SQLite.

Why is this necessary?
SQLite does not support row-level locking syntax in SELECT statements. In environments like WordPress, plugins such as Action Scheduler frequently use these clauses for concurrency control. Since SQLite manages concurrency through database-level locking during write transactions, these clauses are redundant at the SQL level but would cause syntax errors if not stripped.

What was changed:
- Added the lockingClause rule to the AST translator (class-wp-pdo-mysql-on-sqlite.php).
- The rule now returns null, safely removing the clause from the final SQL string.
- Added a detailed comment explaining that while this ensures syntax compatibility, the specific row-level locking semantics of MySQL are not preserved.

Verification:
- Validated via the driver test suite (WP_SQLite_Driver_Tests.php), which includes complex queries and emulated Action Scheduler scenarios with FOR UPDATE.
- Confirmed that queries with joins and subqueries containing FOR UPDATE are correctly translated into valid SQLite SQL.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant