From 04c0b4f99df7c303f93d5f6c0aac15df64aa6dfa Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Tue, 7 Nov 2006 23:43:59 +0000 Subject: [PATCH] GROUP BY is hella faster than DISTINCT. git-svn-id: https://develop.svn.wordpress.org/trunk@4450 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/query.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/wp-includes/query.php b/wp-includes/query.php index fb13aa519d..fa8e704e48 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -583,6 +583,7 @@ class WP_Query { $limits = ''; $join = ''; $search = ''; + $groupby = ''; if ( !isset($q['post_type']) ) $q['post_type'] = 'post'; @@ -801,12 +802,10 @@ class WP_Query { $out_cats = " AND ID NOT IN ($out_posts)"; } $whichcat = $in_cats . $out_cats; - $distinct = 'DISTINCT'; + $groupby = "{$wpdb->posts}.ID"; } // Category stuff for nice URLs - - global $cache_categories; if ('' != $q['category_name']) { $reqcat = get_category_by_path($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 = substr($whichcat, 0, -2); $whichcat .= ")"; - $distinct = 'DISTINCT'; + $groupby = "{$wpdb->posts}.ID"; } // Author/user stuff @@ -975,7 +974,6 @@ class WP_Query { // Apply post-paging filters on where and join. Only plugins that // manipulate paging queries should use these hooks. $where = apply_filters('posts_where_paged', $where); - $groupby = ''; $groupby = apply_filters('posts_groupby', $groupby); if ( ! empty($groupby) ) $groupby = 'GROUP BY ' . $groupby;