]> git.joonet.de Git - adminer.git/commitdiff
Fast number of rows with big tables in PostgreSQL (thanks to juzna)
authorJakub Vrana <jakub@vrana.cz>
Fri, 29 Jul 2011 15:08:06 +0000 (17:08 +0200)
committerJakub Vrana <jakub@vrana.cz>
Fri, 29 Jul 2011 15:08:06 +0000 (17:08 +0200)
adminer/drivers/mssql.inc.php
adminer/drivers/mysql.inc.php
adminer/drivers/oracle.inc.php
adminer/drivers/pgsql.inc.php
adminer/drivers/sqlite.inc.php
adminer/select.inc.php
changes.txt

index 84b085340608dda5bb12baa746d7afe4b598104d..9fa19c6f95a1953bce9e7fbd92e0e20816fc9c95 100644 (file)
@@ -490,6 +490,10 @@ WHERE OBJECT_NAME(i.object_id) = " . q($table)
                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) {
index 29575ccb5e8e7d91995afca58d2da36f5ff07e8c..9932a7cb433d4c68ad0b10e02b581fd05da99e00 100644 (file)
@@ -822,6 +822,15 @@ if (!defined("DRIVER")) {
                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
        */
index 878d5e3c9f31f8f4a7091a6a35cdc3c344d38bd7..afe60ccc9fc10e23a4f64703541a185b8711d3d9 100644 (file)
@@ -275,6 +275,10 @@ ORDER BY uc.constraint_type, uic.column_position", $connection2) as $row) {
                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) {
index c36fbb67d3407ae3f683a4adbd0370eec64d3f3b..bab11b8368c6db104a23477e21f55fa78691745e 100644 (file)
@@ -511,6 +511,18 @@ ORDER BY p.proname');
                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
index c7213e484ca9329e386d69a3e7691fdc51afd20c..053f02f80ce38a07c7607f0189c5680b0e815a23 100644 (file)
@@ -503,6 +503,10 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
                return $connection->query("EXPLAIN $query");
        }
        
+       function found_rows($table_status, $where) {
+               return false;
+       }
+       
        function types() {
                return array();
        }
index 56f45dd33f8e2fb19c9a847aa887adc740daf365..81bf6ffefe9db17bbb1bf44116653e101fc4b115 100644 (file)
@@ -373,8 +373,8 @@ if (!$columns) {
                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();
index 9209e3dd09acb02cae6a3e42669a7a1bc3793098..c2a4bdbce0214c054839bec9b45577cb757de93d 100644 (file)
@@ -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