Fix RAND() implementation and add plugin compatibility layer#340
Open
wp-fuse wants to merge 1 commit intoWordPress:trunkfrom
Open
Fix RAND() implementation and add plugin compatibility layer#340wp-fuse wants to merge 1 commit intoWordPress:trunkfrom
wp-fuse wants to merge 1 commit intoWordPress:trunkfrom
Conversation
- Translate parameter-less RAND() natively to SQLite for better performance - Fix seeded RAND(N) to correctly delegate to the PHP UDF, resolving a TypeError - Update rand() UDF to return a float (0.0-1.0) and support optional seeds - Add plugin compatibility integration (integrations/plugin-compatibility/) to strip FOR UPDATE/SKIP LOCKED/NOWAIT and rewrite Action Scheduler queries - Update RAND() test metadata to reflect correct DOUBLE return type
90063a9 to
e835807
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix RAND() implementation and add plugin compatibility layer
Summary
This PR fixes bugs in the
RAND()implementation and adds a new plugin compatibility integration (following the existingintegrations/query-monitor/pattern) to handle third-party plugin queries that are incompatible with SQLite.Changes
RAND() fixes (
wp-includes/sqlite-ast/class-wp-pdo-mysql-on-sqlite.php)RAND()natively to(ABS(RANDOM()) / 9223372036854775808.0)for better performance (avoids PHP UDF overhead per row).RAND(N)calls correctly fall through to the PHP UDF viatranslate_sequence(), fixing aTypeErrorwhere the function returned no value.UDF fix (
wp-includes/sqlite/class-wp-sqlite-pdo-user-defined-functions.php)rand()to accept an optional$seedparameter and return afloat(0.0–1.0) instead of anint, matching MySQL behavior.Plugin compatibility layer (
integrations/plugin-compatibility/)New integration module (same pattern as
integrations/query-monitor/) that sanitizes third-party plugin queries before they reach the AST parser:FOR UPDATE,SKIP LOCKED, andNOWAITglobally (including inside subqueries), since SQLite doesn't support row-level locking.UPDATE ... JOINsyntax toUPDATE ... WHERE IN (...), escapes the unquotedgroupkeyword, and fixes missingINTOinINSERTstatements.Test updates (
tests/WP_SQLite_Driver_Tests.php)RAND()to reflect the correctDOUBLEreturn type.Boot integration (
wp-includes/sqlite/db.php)require_oncefor the new plugin compatibility boot file.Testing