GROUP BY is hella faster than DISTINCT.

git-svn-id: http://svn.automattic.com/wordpress/trunk@4450 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2006-11-07 23:43:59 +00:00
parent 66aab7b56d
commit 1977863614
1 changed files with 3 additions and 5 deletions

View File

@ -583,6 +583,7 @@ class WP_Query {
$limits = ''; $limits = '';
$join = ''; $join = '';
$search = ''; $search = '';
$groupby = '';
if ( !isset($q['post_type']) ) if ( !isset($q['post_type']) )
$q['post_type'] = 'post'; $q['post_type'] = 'post';
@ -801,12 +802,10 @@ class WP_Query {
$out_cats = " AND ID NOT IN ($out_posts)"; $out_cats = " AND ID NOT IN ($out_posts)";
} }
$whichcat = $in_cats . $out_cats; $whichcat = $in_cats . $out_cats;
$distinct = 'DISTINCT'; $groupby = "{$wpdb->posts}.ID";
} }
// Category stuff for nice URLs // Category stuff for nice URLs
global $cache_categories;
if ('' != $q['category_name']) { if ('' != $q['category_name']) {
$reqcat = get_category_by_path($q['category_name']); $reqcat = get_category_by_path($q['category_name']);
$q['category_name'] = str_replace('%2F', '/', urlencode(urldecode($q['category_name']))); $q['category_name'] = str_replace('%2F', '/', urlencode(urldecode($q['category_name'])));
@ -836,7 +835,7 @@ class WP_Query {
$whichcat .= get_category_children($q['cat'], '', ', '); $whichcat .= get_category_children($q['cat'], '', ', ');
$whichcat = substr($whichcat, 0, -2); $whichcat = substr($whichcat, 0, -2);
$whichcat .= ")"; $whichcat .= ")";
$distinct = 'DISTINCT'; $groupby = "{$wpdb->posts}.ID";
} }
// Author/user stuff // Author/user stuff
@ -975,7 +974,6 @@ class WP_Query {
// Apply post-paging filters on where and join. Only plugins that // Apply post-paging filters on where and join. Only plugins that
// manipulate paging queries should use these hooks. // manipulate paging queries should use these hooks.
$where = apply_filters('posts_where_paged', $where); $where = apply_filters('posts_where_paged', $where);
$groupby = '';
$groupby = apply_filters('posts_groupby', $groupby); $groupby = apply_filters('posts_groupby', $groupby);
if ( ! empty($groupby) ) if ( ! empty($groupby) )
$groupby = 'GROUP BY ' . $groupby; $groupby = 'GROUP BY ' . $groupby;