Time out long running select count

This commit is contained in:
Jakub Vrana 2012-08-19 19:38:53 -07:00
parent 1f53cd3386
commit 6a7021db28
3 changed files with 22 additions and 15 deletions

View file

@ -905,6 +905,7 @@ function is_url($string) {
function kill_timeout() { function kill_timeout() {
global $adminer, $token; global $adminer, $token;
$kill = mt_rand(); $kill = mt_rand();
if (support("kill")) {
?> ?>
<script type="text/javascript"> <script type="text/javascript">
var timeout = setTimeout(function () { var timeout = setTimeout(function () {
@ -913,6 +914,7 @@ var timeout = setTimeout(function () {
}, <?php echo 1000 * $adminer->queryTimeout(); ?>); }, <?php echo 1000 * $adminer->queryTimeout(); ?>);
</script> </script>
<?php <?php
}
ob_flush(); ob_flush();
flush(); flush();
return $kill; return $kill;
@ -923,6 +925,7 @@ var timeout = setTimeout(function () {
*/ */
function cancel_kill_timeout() { function cancel_kill_timeout() {
global $connection; global $connection;
if (support("kill")) {
echo "<script type='text/javascript'>clearTimeout(timeout);</script>\n"; echo "<script type='text/javascript'>clearTimeout(timeout);</script>\n";
ob_flush(); ob_flush();
flush(); flush();
@ -933,3 +936,4 @@ function cancel_kill_timeout() {
} }
} }
} }
}

View file

@ -393,25 +393,28 @@ if (!$columns) {
$found_rows = found_rows($table_status, $where); $found_rows = found_rows($table_status, $where);
if ($found_rows < max(1e4, 2 * ($page + 1) * $limit)) { if ($found_rows < max(1e4, 2 * ($page + 1) * $limit)) {
// slow with big tables // slow with big tables
ob_flush(); $kill = kill_timeout();
flush(); $found_rows = @$connection->result("/* Adminer $kill */ SELECT COUNT(*) FROM " . table($TABLE) . ($where ? " WHERE " . implode(" AND ", $where) : "")); // @ - may be kill
$found_rows = $connection->result("SELECT COUNT(*) FROM " . table($TABLE) . ($where ? " WHERE " . implode(" AND ", $where) : "")); cancel_kill_timeout();
} else { } else {
$exact_count = false; $exact_count = false;
} }
} }
echo "<p class='pages'>"; echo "<p class='pages'>";
if (+$limit && $found_rows > $limit) { if (+$limit && ($found_rows === false || $found_rows > $limit)) {
// display first, previous 4, next 4 and last page // display first, previous 4, next 4 and last page
$max_page = floor(($found_rows - 1) / $limit); $max_page = ($found_rows === false
? $page + (count($rows) >= $limit ? 2 : 1)
: floor(($found_rows - 1) / $limit)
);
echo '<a href="' . h(remove_from_uri("page")) . "\" onclick=\"pageClick(this.href, +prompt('" . lang('Page') . "', '" . ($page + 1) . "'), event); return false;\">" . lang('Page') . "</a>:"; echo '<a href="' . h(remove_from_uri("page")) . "\" onclick=\"pageClick(this.href, +prompt('" . lang('Page') . "', '" . ($page + 1) . "'), event); return false;\">" . lang('Page') . "</a>:";
echo pagination(0, $page) . ($page > 5 ? " ..." : ""); echo pagination(0, $page) . ($page > 5 ? " ..." : "");
for ($i = max(1, $page - 4); $i < min($max_page, $page + 5); $i++) { for ($i = max(1, $page - 4); $i < min($max_page, $page + 5); $i++) {
echo pagination($i, $page); echo pagination($i, $page);
} }
echo ($page + 5 < $max_page ? " ..." : "") . ($exact_count ? pagination($max_page, $page) : ' <a href="' . h(remove_from_uri() . "&page=last") . '">' . lang('last') . "</a>"); echo ($page + 5 < $max_page ? " ..." : "") . ($exact_count && $found_rows !== false ? pagination($max_page, $page) : ' <a href="' . h(remove_from_uri() . "&page=last") . '">' . lang('last') . "</a>");
} }
echo " (" . ($exact_count ? "" : "~ ") . lang('%d row(s)', $found_rows) . ") " . checkbox("all", 1, 0, lang('whole result')) . "\n"; echo ($found_rows !== false ? " (" . ($exact_count ? "" : "~ ") . lang('%d row(s)', $found_rows) . ")" : "") . " " . checkbox("all", 1, 0, lang('whole result')) . "\n";
if ($adminer->selectCommandPrint()) { if ($adminer->selectCommandPrint()) {
?> ?>

View file

@ -1,6 +1,6 @@
Adminer 3.5.2-dev: Adminer 3.5.2-dev:
Edit strings with \n in textarea Edit strings with \n in textarea
Time out long running database list Time out long running database list and select count
Use VALUES() in INSERT+UPDATE export Use VALUES() in INSERT+UPDATE export
Style logout button as link Style logout button as link