aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/functions_posting.php
diff options
context:
space:
mode:
authorjasonmarlin <jason.marlin@gmail.com>2019-01-15 11:31:38 -0500
committerjasonmarlin <jason.marlin@gmail.com>2019-01-15 11:31:38 -0500
commitcffdc8efff9f0c66e6640a42fc375b4662b44180 (patch)
treebc219294c4ba2dc207c04811fb1db91983f5dcf8 /phpBB/includes/functions_posting.php
parent5e302c7e15a2f683755eb500d162866484a898f6 (diff)
downloadforums-cffdc8efff9f0c66e6640a42fc375b4662b44180.tar
forums-cffdc8efff9f0c66e6640a42fc375b4662b44180.tar.gz
forums-cffdc8efff9f0c66e6640a42fc375b4662b44180.tar.bz2
forums-cffdc8efff9f0c66e6640a42fc375b4662b44180.tar.xz
forums-cffdc8efff9f0c66e6640a42fc375b4662b44180.zip
[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
Diffstat (limited to 'phpBB/includes/functions_posting.php')
-rw-r--r--phpBB/includes/functions_posting.php8
1 files changed, 5 insertions, 3 deletions
diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php
index c7d691287c..3640f543d9 100644
--- a/phpBB/includes/functions_posting.php
+++ b/phpBB/includes/functions_posting.php
@@ -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);
}
- $result = $db->sql_query($sql);
$last_post_ids = array();
while ($row = $db->sql_fetchrow($result))