mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-18 07:31:32 +02:00
[ticket/15941] Replace MAX to speed up query in update_post_information
Replace MAX SQL function with faster query using order by and limit. The ajacent query could also be optimized to eliminate the usage of MAX. Note that adding a compound key as suggested by EXPLAIN SQL yields an improvement, but not nearly as fast as ORDER + LIMIT. PHPBB3-15941
This commit is contained in:
@@ -202,11 +202,13 @@ function update_post_information($type, $ids, $return_update_sql = false)
|
||||
|
||||
if (count($ids) == 1)
|
||||
{
|
||||
$sql = 'SELECT MAX(p.post_id) as last_post_id
|
||||
$sql = 'SELECT p.post_id as last_post_id
|
||||
FROM ' . POSTS_TABLE . " p $topic_join
|
||||
WHERE " . $db->sql_in_set('p.' . $type . '_id', $ids) . "
|
||||
$topic_condition
|
||||
AND p.post_visibility = " . ITEM_APPROVED;
|
||||
AND p.post_visibility = " . ITEM_APPROVED . "
|
||||
ORDER BY p.post_id DESC";
|
||||
$result = $db->sql_query_limit($sql, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -216,8 +218,8 @@ function update_post_information($type, $ids, $return_update_sql = false)
|
||||
$topic_condition
|
||||
AND p.post_visibility = " . ITEM_APPROVED . "
|
||||
GROUP BY p.{$type}_id";
|
||||
}
|
||||
$result = $db->sql_query($sql);
|
||||
}
|
||||
|
||||
$last_post_ids = array();
|
||||
while ($row = $db->sql_fetchrow($result))
|
||||
|
Reference in New Issue
Block a user