Simplify slow queries
This commit is contained in:
parent
72b801513b
commit
ea6d6e0d44
|
@ -270,14 +270,11 @@ if (!defined("DRIVER")) {
|
|||
// SHOW DATABASES can take a very long time so it is cached
|
||||
$return = get_session("dbs");
|
||||
if ($return === null) {
|
||||
$kill = ($flush ? kill_timeout() : 0);
|
||||
$return = @get_vals("/* Adminer $kill */ " . ($connection->server_info >= 5 // @ - may be killed
|
||||
$query = ($connection->server_info >= 5
|
||||
? "SELECT SCHEMA_NAME FROM information_schema.SCHEMATA"
|
||||
: "SHOW DATABASES"
|
||||
)); // SHOW DATABASES can be disabled by skip_show_database
|
||||
if ($flush) {
|
||||
cancel_kill_timeout();
|
||||
}
|
||||
); // SHOW DATABASES can be disabled by skip_show_database
|
||||
$return = ($flush ? slow_query($query) : get_vals($query));
|
||||
restart_session();
|
||||
set_session("dbs", $return);
|
||||
stop_session();
|
||||
|
@ -935,11 +932,10 @@ if (!defined("DRIVER")) {
|
|||
}
|
||||
|
||||
/** Get process list
|
||||
* @param bool
|
||||
* @return array ($row)
|
||||
*/
|
||||
function process_list($full = true) {
|
||||
return get_rows("SHOW" . ($full ? " FULL" : "") . " PROCESSLIST");
|
||||
function process_list() {
|
||||
return get_rows("SHOW FULL PROCESSLIST");
|
||||
}
|
||||
|
||||
/** Get status variables
|
||||
|
|
|
@ -899,13 +899,14 @@ function is_url($string) {
|
|||
return (preg_match("~^(https?)://($domain?\\.)+$domain(:\\d+)?(/.*)?(\\?.*)?(#.*)?\$~i", $string, $match) ? strtolower($match[1]) : ""); //! restrict path, query and fragment characters
|
||||
}
|
||||
|
||||
/** Launch timeout after which the query will be killed
|
||||
* @return int kill token
|
||||
/** Run query which can be killed by AJAX call after timing out
|
||||
* @param string
|
||||
* @return Min_Result
|
||||
*/
|
||||
function kill_timeout() {
|
||||
function slow_query($query) {
|
||||
global $adminer, $token;
|
||||
$kill = mt_rand();
|
||||
if (support("kill")) {
|
||||
if (support("kill") && is_object($connection2 = connect()) && (DB == "" || $connection2->select_db(DB))) {
|
||||
$kill = $connection2->result("SELECT CONNECTION_ID()"); // MySQL and MySQLi can use thread_id but it's not in PDO_MySQL
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
var timeout = setTimeout(function () {
|
||||
|
@ -914,28 +915,18 @@ var timeout = setTimeout(function () {
|
|||
}, <?php echo 1000 * $adminer->queryTimeout(); ?>);
|
||||
</script>
|
||||
<?php
|
||||
} else {
|
||||
$connection2 = null;
|
||||
}
|
||||
ob_flush();
|
||||
flush();
|
||||
return $kill;
|
||||
}
|
||||
|
||||
/** Cancel kill query timeout
|
||||
* @return null
|
||||
*/
|
||||
function cancel_kill_timeout() {
|
||||
global $connection;
|
||||
if (support("kill")) {
|
||||
$return = @get_key_vals($query, $connection2); // @ - may be killed
|
||||
if ($connection2) {
|
||||
echo "<script type='text/javascript'>clearTimeout(timeout);</script>\n";
|
||||
ob_flush();
|
||||
flush();
|
||||
if ($connection->errno == 2006) { // 2006 - CR_SERVER_GONE_ERROR
|
||||
$connection2 = connect();
|
||||
if (is_object($connection2)) {
|
||||
$connection = $connection2;
|
||||
}
|
||||
}
|
||||
}
|
||||
return array_keys($return);
|
||||
}
|
||||
|
||||
/** Callback registered to erase output buffer in AJAX calls
|
||||
|
|
|
@ -33,11 +33,7 @@ if ($_GET["script"] == "db") {
|
|||
json_row("");
|
||||
|
||||
} elseif ($_GET["script"] == "kill") {
|
||||
foreach (process_list(false) as $process) {
|
||||
if (ereg('^/\* Adminer ' . (+$_POST["kill"]) . ' \*/', $process["Info"])) {
|
||||
$connection->query("KILL $process[Id]");
|
||||
}
|
||||
}
|
||||
$connection->query("KILL " . (+$_POST["kill"]));
|
||||
|
||||
} else { // connect
|
||||
foreach (count_tables($adminer->databases()) as $db => $val) {
|
||||
|
|
|
@ -405,9 +405,7 @@ if (!$columns) {
|
|||
$found_rows = found_rows($table_status, $where);
|
||||
if ($found_rows < max(1e4, 2 * ($page + 1) * $limit)) {
|
||||
// slow with big tables
|
||||
$kill = kill_timeout();
|
||||
$found_rows = @$connection->result("/* Adminer $kill */ SELECT COUNT(*) FROM " . table($TABLE) . ($where ? " WHERE " . implode(" AND ", $where) : "")); // @ - may be kill
|
||||
cancel_kill_timeout();
|
||||
$found_rows = reset(slow_query("SELECT COUNT(*) FROM " . table($TABLE) . ($where ? " WHERE " . implode(" AND ", $where) : "")));
|
||||
} else {
|
||||
$exact_count = false;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue