aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/search
diff options
context:
space:
mode:
authorMeik Sievertsen <acydburn@phpbb.com>2009-04-11 13:49:32 +0000
committerMeik Sievertsen <acydburn@phpbb.com>2009-04-11 13:49:32 +0000
commit0319733ea8e9dd5225fc9169bb3a063bf29bcd9c (patch)
tree92f0a6be76547b6f624d177fafe12b43446e4c21 /phpBB/includes/search
parent77fcc367e2ec60a1ca9a891d6cbcbf48be05badb (diff)
downloadforums-0319733ea8e9dd5225fc9169bb3a063bf29bcd9c.tar
forums-0319733ea8e9dd5225fc9169bb3a063bf29bcd9c.tar.gz
forums-0319733ea8e9dd5225fc9169bb3a063bf29bcd9c.tar.bz2
forums-0319733ea8e9dd5225fc9169bb3a063bf29bcd9c.tar.xz
forums-0319733ea8e9dd5225fc9169bb3a063bf29bcd9c.zip
[Change] Performance improvements for native fulltext search (patch by Paul)
(This has been tested for 2 weeks in a live environment) git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9440 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes/search')
-rw-r--r--phpBB/includes/search/fulltext_native.php22
1 files changed, 19 insertions, 3 deletions
diff --git a/phpBB/includes/search/fulltext_native.php b/phpBB/includes/search/fulltext_native.php
index ee36039454..5a9f34a261 100644
--- a/phpBB/includes/search/fulltext_native.php
+++ b/phpBB/includes/search/fulltext_native.php
@@ -650,8 +650,12 @@ class fulltext_native extends search_backend
case 'mysql4':
case 'mysqli':
+ $sql_array_copy = $sql_array;
+
// 3.x does not support SQL_CALC_FOUND_ROWS
- $sql_array['SELECT'] = 'SQL_CALC_FOUND_ROWS ' . $sql_array['SELECT'];
+ // $sql_array['SELECT'] = 'SQL_CALC_FOUND_ROWS ' . $sql_array['SELECT'];
+ $sql_array_copy['SELECT'] = 'SQL_CALC_FOUND_ROWS p.post_id ';
+
$is_mysql = true;
break;
@@ -730,8 +734,14 @@ class fulltext_native extends search_backend
}
// if we use mysql and the total result count is not cached yet, retrieve it from the db
- if (!$total_results && $is_mysql)
+ if (!$total_results && $is_mysql && !empty($sql_array_copy))
{
+ $sql = $db->sql_build_query('SELECT', $sql_array_copy);
+ unset($sql_array_copy);
+
+ $db->sql_query($sql);
+ $db->sql_freeresult($result);
+
$sql = 'SELECT FOUND_ROWS() as total_results';
$result = $db->sql_query($sql);
$total_results = (int) $db->sql_fetchfield('total_results');
@@ -855,7 +865,7 @@ class fulltext_native extends search_backend
{
case 'mysql4':
case 'mysqli':
- $select = 'SQL_CALC_FOUND_ROWS ' . $select;
+// $select = 'SQL_CALC_FOUND_ROWS ' . $select;
$is_mysql = true;
break;
@@ -948,6 +958,12 @@ class fulltext_native extends search_backend
if (!$total_results && $is_mysql)
{
+ // Count rows for the executed queries. Replace $select within $sql with SQL_CALC_FOUND_ROWS, and run it.
+ $sql = str_replace('SELECT ' . $select, 'SELECT DISTINCT SQL_CALC_FOUND_ROWS p.post_id', $sql);
+
+ $db->sql_query($sql);
+ $db->sql_freeresult($result);
+
$sql = 'SELECT FOUND_ROWS() as total_results';
$result = $db->sql_query($sql);
$total_results = (int) $db->sql_fetchfield('total_results');