Get row count by SHOW TABLE STATUS, and by SELECT COUNT(*) only for small (<20000 rows) tables (RFE #708533).

This commit is contained in:
Michal Čihař
2003-04-10 16:23:45 +00:00
parent 03a6ff4124
commit 5e95ec6944
5 changed files with 23 additions and 14 deletions

View File

@@ -5,6 +5,12 @@ phpMyAdmin - Changelog
$Id$ $Id$
$Source$ $Source$
2003-04-10 Michal Cihar <nijel@users.sourceforge.net>
* 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 <nijel@users.sourceforge.net> 2003-04-09 Michal Cihar <nijel@users.sourceforge.net>
* libraries/build_dump.lib.php3: Fixed undefined index warnings in LaTeX * libraries/build_dump.lib.php3: Fixed undefined index warnings in LaTeX
and XML dump. and XML dump.

View File

@@ -1224,9 +1224,20 @@ h1 {font-family: sans-serif; font-size: large; font-weight: bold}
*/ */
function PMA_countRecords($db, $table, $ret = FALSE) function PMA_countRecords($db, $table, $ret = FALSE)
{ {
$result = PMA_mysql_query('SELECT COUNT(*) AS num FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table)); global $err_url;
$num = ($result) ? PMA_mysql_result($result, 0, 'num') : 0; if (PMA_MYSQL_INT_VERSION >= 32303) {
mysql_free_result($result); $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) { if ($ret) {
return $num; return $num;
} else { } else {

View File

@@ -156,10 +156,7 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) {
} }
else if (($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1') else if (($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1')
&& (!empty($db) && !empty($table))) { && (!empty($db) && !empty($table))) {
$local_query = 'SELECT COUNT(*) AS total FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table); $the_total = PMA_countRecords($db, $table, TRUE);
$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);
} }
// 4. If navigation bar or sorting fields names urls should be // 4. If navigation bar or sorting fields names urls should be

View File

@@ -27,10 +27,7 @@
// We could also do the SELECT anyway, with a LIMIT, and ensure that // We could also do the SELECT anyway, with a LIMIT, and ensure that
// the current value of the field is one of the choices. // 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); $the_total = PMA_countRecords($db, $table, TRUE);
$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);
if ($the_total < 200) { if ($the_total < 200) {
// foreign_display can be FALSE if no display field defined: // foreign_display can be FALSE if no display field defined:

View File

@@ -1295,10 +1295,8 @@ function PMA_RT_DOC($alltables ){
$update_time = (isset($showtable['Update_time']) ? PMA_localisedDate(strtotime($showtable['Update_time'])) : ''); $update_time = (isset($showtable['Update_time']) ? PMA_localisedDate(strtotime($showtable['Update_time'])) : '');
$check_time = (isset($showtable['Check_time']) ? PMA_localisedDate(strtotime($showtable['Check_time'])) : ''); $check_time = (isset($showtable['Check_time']) ? PMA_localisedDate(strtotime($showtable['Check_time'])) : '');
} else { } 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(); $showtable = array();
$num_rows = PMA_mysql_result($result, 0, 'count'); $num_rows = PMA_countRecords($db, $table, TRUE);
$show_comment = ''; $show_comment = '';
$create_time = ''; $create_time = '';
$update_time = ''; $update_time = '';