diff --git a/ChangeLog b/ChangeLog index 93e0d4aa1..de849ed93 100755 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,12 @@ phpMyAdmin - Changelog $Id$ $Source$ +2003-04-10 Michal Cihar + * pdf_schema.php3, libraries/common.lib.php3, + libraries/display_tbl.lib.php3, libraries/get_foreign.lib.php3: Get row + count by SHOW TABLE STATUS, and by SELECT COUNT(*) only for small + (<20000 rows) tables (RFE #708533). + 2003-04-09 Michal Cihar * libraries/build_dump.lib.php3: Fixed undefined index warnings in LaTeX and XML dump. diff --git a/libraries/common.lib.php3 b/libraries/common.lib.php3 index a69f480ff..3b0a41c5f 100644 --- a/libraries/common.lib.php3 +++ b/libraries/common.lib.php3 @@ -1224,9 +1224,20 @@ h1 {font-family: sans-serif; font-size: large; font-weight: bold} */ function PMA_countRecords($db, $table, $ret = FALSE) { - $result = PMA_mysql_query('SELECT COUNT(*) AS num FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table)); - $num = ($result) ? PMA_mysql_result($result, 0, 'num') : 0; - mysql_free_result($result); + global $err_url; + if (PMA_MYSQL_INT_VERSION >= 32303) { + $local_query = 'SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\' FROM \'' . PMA_sqlAddslashes($table, TRUE) . '\''; + $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url); + $showtable = PMA_mysql_fetch_array($result); + $num = (isset($showtable['Rows']) ? $showtable['Rows'] : 0); + if ($num < 20000) unset($num); + mysql_free_result($result); + } + if (!isset($num)) { + $result = PMA_mysql_query('SELECT COUNT(*) AS num FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table)) or PMA_mysqlDie('', $local_query, '', $err_url); + $num = ($result) ? PMA_mysql_result($result, 0, 'num') : 0; + mysql_free_result($result); + } if ($ret) { return $num; } else { diff --git a/libraries/display_tbl.lib.php3 b/libraries/display_tbl.lib.php3 index f210799ef..9deb34fa6 100644 --- a/libraries/display_tbl.lib.php3 +++ b/libraries/display_tbl.lib.php3 @@ -156,10 +156,7 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) { } else if (($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1') && (!empty($db) && !empty($table))) { - $local_query = 'SELECT COUNT(*) AS total FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table); - $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url); - $the_total = PMA_mysql_result($result, 0, 'total'); - mysql_free_result($result); + $the_total = PMA_countRecords($db, $table, TRUE); } // 4. If navigation bar or sorting fields names urls should be diff --git a/libraries/get_foreign.lib.php3 b/libraries/get_foreign.lib.php3 index 53f2b0b5e..9bd083c1e 100755 --- a/libraries/get_foreign.lib.php3 +++ b/libraries/get_foreign.lib.php3 @@ -27,10 +27,7 @@ // We could also do the SELECT anyway, with a LIMIT, and ensure that // the current value of the field is one of the choices. - $count_query = 'SELECT COUNT(*) AS total FROM ' . PMA_backquote($foreign_db) . '.' . PMA_backquote($foreign_table); - $count_result = PMA_mysql_query($count_query) or PMA_mysqlDie('', $count_query, '', $err_url); - $the_total = PMA_mysql_result($count_result, 0, 'total'); - mysql_free_result($count_result); + $the_total = PMA_countRecords($db, $table, TRUE); if ($the_total < 200) { // foreign_display can be FALSE if no display field defined: diff --git a/pdf_schema.php3 b/pdf_schema.php3 index 56edf6df7..62b42a11e 100644 --- a/pdf_schema.php3 +++ b/pdf_schema.php3 @@ -1295,10 +1295,8 @@ function PMA_RT_DOC($alltables ){ $update_time = (isset($showtable['Update_time']) ? PMA_localisedDate(strtotime($showtable['Update_time'])) : ''); $check_time = (isset($showtable['Check_time']) ? PMA_localisedDate(strtotime($showtable['Check_time'])) : ''); } else { - $local_query = 'SELECT COUNT(*) AS count FROM ' . PMA_backquote($table); - $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url); $showtable = array(); - $num_rows = PMA_mysql_result($result, 0, 'count'); + $num_rows = PMA_countRecords($db, $table, TRUE); $show_comment = ''; $create_time = ''; $update_time = '';