GROUP BY is hella faster than DISTINCT.

git-svn-id: https://develop.svn.wordpress.org/trunk@4450 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2006-11-07 23:43:59 +00:00
parent a6f7f58d47
commit 04c0b4f99d
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;