[wp-trac] [WordPress Trac] #18836: ORDER BY RAND() is slow
    WordPress Trac 
    noreply at wordpress.org
       
    Sat Apr 19 00:32:45 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:  needs-testing has-unit-tests has-    |     Focuses:
  patch early                                    |  performance
-------------------------------------------------+-------------------------
Comment (by SirLouen):
 I've passed my WP-Query benchmarking template and here are the results:
 [[Image(https://i.imgur.com/0RPY1sg.png)]]
 These are the 3 queries benchmarked in a pool of 10K posts,
 `$post_per_page` = 1K, 10 iterations each
 {{{#!php
 new WP_Query([
     'post_type' => 'post',
     'posts_per_page' => $posts_per_page,
     'orderby' => 'rand',
     'no_found_rows' => true,
     'cache_results' => false
 ]);
 new WP_Query([
     'post_type' => 'post',
     'posts_per_page' => $posts_per_page,
     'orderby' => 'date',
     'order' => 'DESC',
     'no_found_rows' => true,
     'cache_results' => false
 ]);
 new WP_Query([
     'post_type' => 'post',
     'posts_per_page' => $posts_per_page,
     'orderby' => 'title',
     'order' => 'DESC',
     'no_found_rows' => true,
     'cache_results' => false
 ]);
 }}}
 Tomorrow I will be checking the new implementation pushed by @pbearne to
 see if it actually improves the rand implementation and create a proper
 Patch testing report.
-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/18836#comment:25>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
    
    
More information about the wp-trac
mailing list