Skip to content

Commit 409a43c

Browse files
committed
Use bit-shift math in unseeded RAND() compile path
Replace the literal `0x001FFFFFFFFFFFFF` / `9007199254740992.0` with `(1 << 53) - 1` and `(1 << 53)` written directly in the SQL. SQLite's query optimizer folds them at prepare time, so there's no runtime cost, and the math is now self-documenting. Per review feedback on #363.
1 parent 9e0d046 commit 409a43c

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

packages/mysql-on-sqlite/src/sqlite/class-wp-pdo-mysql-on-sqlite.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4418,7 +4418,7 @@ private function translate_function_call( WP_Parser_Node $node ): string {
44184418
* The UDF also handles RAND(NULL) as RAND(0), matching MySQL.
44194419
*/
44204420
if ( 0 === count( $args ) ) {
4421-
return '((RANDOM() & 0x001FFFFFFFFFFFFF) / 9007199254740992.0)';
4421+
return '((RANDOM() & ((1 << 53) - 1)) / ((1 << 53) * 1.0))';
44224422
}
44234423
return $this->translate_sequence( $node->get_children() );
44244424
case 'DATE_FORMAT':

0 commit comments

Comments
 (0)