From 44a4cfebcdc692ee54315bc4a18d7335d9847083 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Mon, 15 Jun 2009 19:28:55 +0000 Subject: [PATCH] - Patch #243093 by catch, killes: improved indices on comment table. --- modules/comment/comment.install | 18 ++++++++++++++---- modules/comment/comment.module | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/modules/comment/comment.install b/modules/comment/comment.install index 119e96a9cd0..d98ba0ce807 100644 --- a/modules/comment/comment.install +++ b/modules/comment/comment.install @@ -153,6 +153,18 @@ function comment_update_7002() { return $ret; } +/** + * Improve indexes on the comment table. + */ +function comment_update_7003() { + $ret = array(); + db_drop_index($ret, 'comment', 'status'); + db_drop_index($rest, 'comment', 'pid'); + db_add_index($ret, 'comment', 'comment_pid_status', array('pid', 'status')); + db_add_index($ret, 'comment', 'comment_num_new', array('nid', 'timestamp', 'status')); + return $ret; +} + /** * @} End of "defgroup updates-6.x-to-7.x" * The next series of updates should start at 8000. @@ -255,10 +267,8 @@ function comment_schema() { ) ), 'indexes' => array( - 'pid' => array('pid'), - 'nid' => array('nid'), - // This index is probably unused. - 'status' => array('status'), + 'comment_status_pid' => array('pid', 'status'), + 'comment_num_new' => array('nid', 'timestamp', 'status'), ), 'primary key' => array('cid'), 'foreign keys' => array( diff --git a/modules/comment/comment.module b/modules/comment/comment.module index a1e36a90f6a..3e6fb15eb5f 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -1335,7 +1335,7 @@ function comment_num_new($nid, $timestamp = 0) { $timestamp = ($timestamp > NODE_NEW_LIMIT ? $timestamp : NODE_NEW_LIMIT); // Use the timestamp to retrieve the number of new comments. - return db_query('SELECT COUNT(c.cid) FROM {node} n INNER JOIN {comment} c ON n.nid = c.nid WHERE n.nid = :nid AND timestamp > :timestamp AND c.status = :status', array( + return db_query('SELECT COUNT(cid) FROM {comment} WHERE nid = :nid AND timestamp > :timestamp AND status = :status', array( ':nid' => $nid, ':timestamp' => $timestamp, ':status' => COMMENT_PUBLISHED,