[wp-trac] [WordPress Trac] #15068: merging query objects/arrays

WordPress Trac wp-trac at lists.automattic.com
Fri Oct 8 14:41:31 UTC 2010


#15068: merging query objects/arrays
----------------------------+-----------------------------------------------
 Reporter:  youngmicroserf  |       Owner:                
     Type:  enhancement     |      Status:  new           
 Priority:  normal          |   Milestone:  Future Release
Component:  Query           |     Version:  3.0.1         
 Severity:  normal          |    Keywords:                
----------------------------+-----------------------------------------------
Changes (by Denis-de-Bernardy):

  * milestone:  Awaiting Review => Future Release


Comment:

 Replying to [comment:2 scribu]:
 > Can you do a global sort on UNIONs ?

 Yes, with a subquery.

 {{{
 SELECT *
 FROM (
   SELECT ...
   UNION
   SELECT ...
 ) as stmt
 ORDER BY ...
 LIMIT N
 }}}

 It's a bit slow, since it'll need to quick sort or heap sort the result,
 but it'll still be faster and more reliable than pulling the X results of
 N queries, in order to drop dups and use php to sort the top X results out
 of the resulting merged set. Better let SQL do it than re-invent the union
 statement... As a bonus, using an SQL UNION allows to extract stats, i.e.
 the total number of rows.

 Pushing this to future pending a patch, though, because it's an extremely
 messy proposition -- even with an ORM.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/15068#comment:3>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list