diff options
author | Simon Rettberg | 2017-11-29 12:00:01 +0100 |
---|---|---|
committer | Simon Rettberg | 2017-11-29 12:00:01 +0100 |
commit | b07b97ab37c14c1b459ffb4297da5c449d04a8e0 (patch) | |
tree | 699dafd322e08c714d9abea691a962f600b3102e /inc/database.inc.php | |
parent | [js] Move all our fixes into one file, add browser history/URL fix for messages (diff) | |
download | slx-admin-b07b97ab37c14c1b459ffb4297da5c449d04a8e0.tar.gz slx-admin-b07b97ab37c14c1b459ffb4297da5c449d04a8e0.tar.xz slx-admin-b07b97ab37c14c1b459ffb4297da5c449d04a8e0.zip |
[inc/Database] Do EXPLAIN SELECT at shutdown so we don't interfere with SQL_CAL_FOUND_ROWS
Diffstat (limited to 'inc/database.inc.php')
-rw-r--r-- | inc/database.inc.php | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/inc/database.inc.php b/inc/database.inc.php index 150f828a..79c945b8 100644 --- a/inc/database.inc.php +++ b/inc/database.inc.php @@ -17,6 +17,7 @@ class Database private static $statements = array(); private static $returnErrors; private static $lastError = false; + private static $explainList = array(); /** * Connect to the DB if not already connected. @@ -37,6 +38,11 @@ class Database return false; Util::traceError('Connecting to the local database failed: ' . $e->getMessage()); } + if (CONFIG_DEBUG) { + register_shutdown_function(function() { + self::examineLoggedQueries(); + }); + } return true; } @@ -115,7 +121,7 @@ class Database { self::init(); if (CONFIG_DEBUG && preg_match('/^\s*SELECT/is', $query)) { - self::explainQuery($query, $args); + self::$explainList[] = [$query, $args]; } // Support passing nested arrays for IN statements, automagically refactor self::handleArrayArgument($query, $args); @@ -141,6 +147,13 @@ class Database return false; } + public static function examineLoggedQueries() + { + foreach (self::$explainList as $e) { + self::explainQuery($e[0], $e[1]); + } + } + private static function explainQuery($query, $args) { $res = self::simpleQuery('EXPLAIN ' . $query, $args, true); @@ -155,7 +168,7 @@ class Database $lens[$key] = strlen($key); } foreach ($rows as $row) { - if (!$log && preg_match('/filesort|temporary/i', $row['Extra'])) { + if (!$log && $row['rows'] > 20 && preg_match('/filesort|temporary/i', $row['Extra'])) { $log = true; } foreach ($row as $key => $col) { |