Skip to content

Commit

Permalink
Fast number of rows with big tables in PostgreSQL (thanks to juzna)
Browse files Browse the repository at this point in the history
  • Loading branch information
vrana committed Jul 29, 2011
1 parent 2e1d38a commit c828299
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 2 deletions.
4 changes: 4 additions & 0 deletions adminer/drivers/mssql.inc.php
Expand Up @@ -490,6 +490,10 @@ function explain($connection, $query) {
return $return;
}

function found_rows($table_status, $where) {
return false;
}

function foreign_keys($table) {
$return = array();
foreach (get_rows("EXEC sp_fkeys @fktable_name = " . q($table)) as $row) {
Expand Down
9 changes: 9 additions & 0 deletions adminer/drivers/mysql.inc.php
Expand Up @@ -822,6 +822,15 @@ function explain($connection, $query) {
return $connection->query("EXPLAIN $query");
}

/** Get approximate number of rows
* @param array
* @param array
* @return int or null if approximate number can't be retrieved
*/
function found_rows($table_status, $where) {
return ($where || $table_status["Engine"] != "InnoDB" ? null : $table_status["Rows"]);
}

/** Get user defined types
* @return array
*/
Expand Down
4 changes: 4 additions & 0 deletions adminer/drivers/oracle.inc.php
Expand Up @@ -275,6 +275,10 @@ function explain($connection, $query) {
return $connection->query("SELECT * FROM plan_table");
}

function found_rows($table_status, $where) {
return false;
}

function alter_table($table, $name, $fields, $foreign, $comment, $engine, $collation, $auto_increment, $partitioning) {
$alter = $drop = array();
foreach ($fields as $field) {
Expand Down
12 changes: 12 additions & 0 deletions adminer/drivers/pgsql.inc.php
Expand Up @@ -511,6 +511,18 @@ function explain($connection, $query) {
return $connection->query("EXPLAIN $query");
}

function found_rows($table_status, $where) {
global $connection;
if (ereg(
" rows=([0-9]+)",
$connection->result("EXPLAIN SELECT * FROM " . idf_escape($table_status["Name"]) . ($where ? " WHERE " . implode(" AND ", $where) : "")),
$regs
)) {
return $regs[1];
}
return false;
}

function types() {
return get_vals("SELECT typname
FROM pg_type
Expand Down
4 changes: 4 additions & 0 deletions adminer/drivers/sqlite.inc.php
Expand Up @@ -503,6 +503,10 @@ function explain($connection, $query) {
return $connection->query("EXPLAIN $query");
}

function found_rows($table_status, $where) {
return false;
}

function types() {
return array();
}
Expand Down
4 changes: 2 additions & 2 deletions adminer/select.inc.php
Expand Up @@ -373,8 +373,8 @@
if ($rows || $page) {
$exact_count = true;
if ($_GET["page"] != "last" && +$limit && count($group) >= count($select) && ($found_rows >= $limit || $page)) {
$found_rows = $table_status["Rows"];
if (!isset($found_rows) || $where || ($table_status["Engine"] == "InnoDB" && $found_rows < max(1e4, 2 * ($page + 1) * $limit))) {
$found_rows = found_rows($table_status, $where);
if ($found_rows < max(1e4, 2 * ($page + 1) * $limit)) {
// slow with big tables
ob_flush(); //! doesn't work with AJAX
flush();
Expand Down
1 change: 1 addition & 0 deletions changes.txt
@@ -1,5 +1,6 @@
Adminer 3.3.2-dev:
Don't scroll with AJAX select order and alter move column
Fast number of rows with big tables (PostgreSQL)

Adminer 3.3.1 (released 2011-07-27):
Fix XSS introduced in Adminer 3.2.0
Expand Down

0 comments on commit c828299

Please sign in to comment.