[wp-trac] [WordPress Trac] #18836: ORDER BY RAND() is slow

WordPress Trac noreply at wordpress.org
Sun Apr 20 00:58:51 UTC 2025


#18836: ORDER BY RAND() is slow
-------------------------------------+--------------------------
 Reporter:  scribu                   |       Owner:  pbearne
     Type:  enhancement              |      Status:  assigned
 Priority:  normal                   |   Milestone:  6.9
Component:  Query                    |     Version:
 Severity:  minor                    |  Resolution:
 Keywords:  early changes-requested  |     Focuses:  performance
-------------------------------------+--------------------------
Changes (by SirLouen):

 * keywords:  early changes-requested close => early changes-requested


Comment:

 After hour and a half trying to understand
 [http://stackoverflow.com/a/25882872 the algorithm], I think I've come
 with a solution with the idea that @scribu was suggesting one decade ago,
 and I think I got it.

 The performance gains are slight, not as big as I thought.

 [[Image(https://i.imgur.com/co5ywlc.png)]]

 I'm still double-checking the code, but I will provide a patch tomorrow,
 just wanted to remove the `close` proposal because maybe there is an
 opportunity for optimization here.

 Test Demo: https://streamable.com/m5iklq

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/18836#comment:28>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list