fixed display of table statistics for information_schema

This commit is contained in:
Sebastian Mendel
2005-10-11 15:08:38 +00:00
parent c6198d6564
commit a3b332fb51
3 changed files with 92 additions and 98 deletions

View File

@@ -1,4 +1,4 @@
---------------------- ----------------------
phpMyAdmin - Changelog phpMyAdmin - Changelog
---------------------- ----------------------
@@ -19,6 +19,8 @@ $Source$
no table statistics for information_schema no table statistics for information_schema
* tbl_properties_table_info.php: * tbl_properties_table_info.php:
bug #1317655 information_schema browsing bug #1317655 information_schema browsing
* db_details_db_info.php, db_details_structure.php:
fixed display table statistics for information_schema
2005-10-09 Marc Delisle <lem9@users.sourceforge.net> 2005-10-09 Marc Delisle <lem9@users.sourceforge.net>
* tbl_properties_links.php: invalid js confirmation and operation feedback * tbl_properties_links.php: invalid js confirmation and operation feedback

View File

@@ -63,6 +63,11 @@ if ($cfg['SkipLockedTables'] == TRUE) {
$db_info_result = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . $tbl_group_sql . ';', NULL, PMA_DBI_QUERY_STORE); $db_info_result = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . $tbl_group_sql . ';', NULL, PMA_DBI_QUERY_STORE);
if ($db_info_result != FALSE && PMA_DBI_num_rows($db_info_result) > 0) { if ($db_info_result != FALSE && PMA_DBI_num_rows($db_info_result) > 0) {
while ($tmp = PMA_DBI_fetch_row($db_info_result)) { while ($tmp = PMA_DBI_fetch_row($db_info_result)) {
if ( NULL === $tmp['Rows'] ) {
$tmp['Rows'] = PMA_countRecords( $GLOBALS['db'],
$tmp['Name'], $return = true, $force_exact = true );
}
if (!isset($sot_cache[$tmp[0]])) { if (!isset($sot_cache[$tmp[0]])) {
$sts_result = PMA_DBI_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . addslashes($tmp[0]) . '\';'); $sts_result = PMA_DBI_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . addslashes($tmp[0]) . '\';');
$sts_tmp = PMA_DBI_fetch_assoc($sts_result); $sts_tmp = PMA_DBI_fetch_assoc($sts_result);
@@ -99,6 +104,11 @@ if (!isset($sot_ready)) {
$db_info_result = PMA_DBI_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . $tbl_group_sql . ';', NULL, PMA_DBI_QUERY_STORE); $db_info_result = PMA_DBI_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . $tbl_group_sql . ';', NULL, PMA_DBI_QUERY_STORE);
if ($db_info_result != FALSE && PMA_DBI_num_rows($db_info_result) > 0) { if ($db_info_result != FALSE && PMA_DBI_num_rows($db_info_result) > 0) {
while ($sts_tmp = PMA_DBI_fetch_assoc($db_info_result)) { while ($sts_tmp = PMA_DBI_fetch_assoc($db_info_result)) {
if ( NULL === $sts_tmp['Rows'] ) {
$sts_tmp['Rows'] = PMA_countRecords( $GLOBALS['db'],
$sts_tmp['Name'], $return = true, $force_exact = true );
}
if (!isset($sts_tmp['Type']) && isset($sts_tmp['Engine'])) { if (!isset($sts_tmp['Type']) && isset($sts_tmp['Engine'])) {
$sts_tmp['Type'] =& $sts_tmp['Engine']; $sts_tmp['Type'] =& $sts_tmp['Engine'];
} }

View File

@@ -34,48 +34,51 @@ if (PMA_MYSQL_INT_VERSION >= 40101) {
// Display function // Display function
function pma_TableHeader($alternate = FALSE, $record_count = TRUE) { function pma_TableHeader( $is_schema = false ) {
$cnt = 0; // Let's count the columns... $cnt = 0; // Let's count the columns...
if ( $is_schema ) {
$action_colspan = 3;
} else {
$action_colspan = 6;
}
echo ' <table border="' . $GLOBALS['cfg']['Border'] . '" cellpadding="2" cellspacing="1">' . "\n" echo ' <table border="' . $GLOBALS['cfg']['Border'] . '" cellpadding="2" cellspacing="1">' . "\n"
. ' <tr>' . "\n" . ' <tr>' . "\n"
. ' <td></td>' . "\n" . ' <td></td>' . "\n"
. ' <th>' . "\n" . ' <th>' . "\n"
. ' &nbsp;' . $GLOBALS['strTable'] . '&nbsp;' . "\n" . ' &nbsp;' . $GLOBALS['strTable'] . '&nbsp;' . "\n"
. ' </th>' . "\n" . ' </th>' . "\n"
. ' <th colspan="6">' . "\n" . ' <th colspan="' . $action_colspan . '">' . "\n"
. ' &nbsp;' . $GLOBALS['strAction'] . '&nbsp;' . "\n" . ' &nbsp;' . $GLOBALS['strAction'] . '&nbsp;' . "\n"
. ' </th>' . "\n"; . ' </th>' . "\n";
$cnt += 3; $cnt += 2 + $action_colspan;
if ($record_count) { echo ' <th>' . "\n"
. ' &nbsp;' . $GLOBALS['strRecords'] . PMA_showHint($GLOBALS['strApproximateCount']) . '&nbsp;' . "\n"
. ' </th>' . "\n";
$cnt++;
if (!($GLOBALS['cfg']['PropertiesNumColumns'] > 1)) {
echo ' <th>' . "\n" echo ' <th>' . "\n"
. ' &nbsp;' . $GLOBALS['strRecords'] . PMA_showHint($GLOBALS['strApproximateCount']) . '&nbsp;' . "\n" . ' &nbsp;' . $GLOBALS['strType'] . '&nbsp;' . "\n"
. ' </th>' . "\n"; . ' </th>' . "\n";
$cnt++; $cnt++;
} if (PMA_MYSQL_INT_VERSION >= 40100) {
if (!$alternate) {
if (!($GLOBALS['cfg']['PropertiesNumColumns'] > 1)) {
echo ' <th>' . "\n" echo ' <th>' . "\n"
. ' &nbsp;' . $GLOBALS['strType'] . '&nbsp;' . "\n" . ' &nbsp;' . $GLOBALS['strCollation'] . '&nbsp;' . "\n"
. ' </th>' . "\n"; . ' </th>' . "\n";
$cnt++; $cnt++;
if (PMA_MYSQL_INT_VERSION >= 40100) {
echo ' <th>' . "\n"
. ' &nbsp;' . $GLOBALS['strCollation'] . '&nbsp;' . "\n"
. ' </th>' . "\n";
$cnt++;
}
} }
if ($GLOBALS['cfg']['ShowStats']) {
echo ' <th>' . "\n"
. ' &nbsp;' . $GLOBALS['strSize'] . '&nbsp;' . "\n"
. ' </th>' . "\n"
. ' <th>' . "\n"
. ' &nbsp;' . $GLOBALS['strOverhead'] . '&nbsp;' . "\n"
. ' </th>' . "\n";
$cnt += 2;
}
echo "\n";
} }
if ($GLOBALS['cfg']['ShowStats']) {
echo ' <th>' . "\n"
. ' &nbsp;' . $GLOBALS['strSize'] . '&nbsp;' . "\n"
. ' </th>' . "\n"
. ' <th>' . "\n"
. ' &nbsp;' . $GLOBALS['strOverhead'] . '&nbsp;' . "\n"
. ' </th>' . "\n";
$cnt += 2;
}
echo "\n";
echo ' </tr>' . "\n"; echo ' </tr>' . "\n";
$GLOBALS['structure_tbl_col_cnt'] = $cnt; $GLOBALS['structure_tbl_col_cnt'] = $cnt;
} }
@@ -159,12 +162,13 @@ else {
} }
// rabus: disable statistics for information_schema. // rabus: disable statistics for information_schema.
if (PMA_MYSQL_INT_VERSION >= 50000 && $db == 'information_schema') { if (PMA_MYSQL_INT_VERSION >= 50002 && $db == 'information_schema') {
$cfg['ShowStats'] = FALSE; $cfg['ShowStats'] = false;
pma_TableHeader(FALSE, FALSE); $table_is_schema = true;
} else { } else {
pma_TableHeader(); $table_is_schema = false;
} }
pma_TableHeader( $table_is_schema );
$i = $sum_entries = 0; $i = $sum_entries = 0;
(double) $sum_size = 0; (double) $sum_size = 0;
@@ -232,7 +236,7 @@ else {
<td><img src="<?php echo $GLOBALS['pmaThemeImage'] . 'spacer.png'; ?>" border="0" width="10" height="1" alt="" /></td> <td><img src="<?php echo $GLOBALS['pmaThemeImage'] . 'spacer.png'; ?>" border="0" width="10" height="1" alt="" /></td>
<td valign="top"> <td valign="top">
<?php <?php
pma_TableHeader(FALSE, !(PMA_MYSQL_INT_VERSION >= 50000 && $db == 'information_schema')); pma_TableHeader();
} }
?> ?>
<tr <?php echo $on_mouse; ?>> <tr <?php echo $on_mouse; ?>>
@@ -254,7 +258,7 @@ else {
require_once('./libraries/bookmark.lib.php'); require_once('./libraries/bookmark.lib.php');
$book_sql_query = PMA_queryBookmarks($db, $cfg['Bookmark'], '\'' . PMA_sqlAddslashes($table) . '\'', 'label'); $book_sql_query = PMA_queryBookmarks($db, $cfg['Bookmark'], '\'' . PMA_sqlAddslashes($table) . '\'', 'label');
if (!empty($sts_data['Rows']) || $is_view || (PMA_MYSQL_INT_VERSION >= 50000 && $db == 'information_schema')) { if ( ! empty( $sts_data['Rows'] ) || $is_view ) {
echo '<a href="sql.php?' . $tbl_url_query . '&amp;sql_query=' echo '<a href="sql.php?' . $tbl_url_query . '&amp;sql_query='
. (isset($book_sql_query) && $book_sql_query != FALSE ? urlencode($book_sql_query) : urlencode('SELECT * FROM ' . PMA_backquote($table))) . (isset($book_sql_query) && $book_sql_query != FALSE ? urlencode($book_sql_query) : urlencode('SELECT * FROM ' . PMA_backquote($table)))
. '&amp;pos=0">' . $titles['Browse'] . '</a>'; . '&amp;pos=0">' . $titles['Browse'] . '</a>';
@@ -269,7 +273,7 @@ else {
</td> </td>
<td align="center" bgcolor="<?php echo $bgcolor; ?>"> <td align="center" bgcolor="<?php echo $bgcolor; ?>">
<?php <?php
if (!empty($sts_data['Rows']) || $is_view || (PMA_MYSQL_INT_VERSION >= 50000 && $db == 'information_schema')) { if ( ! empty($sts_data['Rows'] ) || $is_view ) {
echo '<a href="tbl_select.php?' . $tbl_url_query . '">' echo '<a href="tbl_select.php?' . $tbl_url_query . '">'
. $titles['Search'] . '</a>'; . $titles['Search'] . '</a>';
} else { } else {
@@ -277,70 +281,59 @@ else {
} }
?> ?>
</td> </td>
<td align="center" bgcolor="<?php echo $bgcolor; ?>">
<?php <?php
if (PMA_MYSQL_INT_VERSION >= 50000 && $db == 'information_schema') { if ( ! $table_is_schema ) {
// rabus: We cannot insert into information_schema tables!
echo $titles['NoInsert'];
} else {
?> ?>
<td align="center" bgcolor="<?php echo $bgcolor; ?>">
<a href="tbl_change.php?<?php echo $tbl_url_query; ?>"> <a href="tbl_change.php?<?php echo $tbl_url_query; ?>">
<?php echo $titles['Insert']; ?></a> <?php echo $titles['Insert']; ?></a>
</td>
<td align="center" bgcolor="<?php echo $bgcolor; ?>">
<?php <?php
} if ( ! empty($sts_data['Rows']) ) {
?> echo '<a href="sql.php?' . $tbl_url_query
</td> . '&amp;sql_query=';
<td align="center" bgcolor="<?php echo $bgcolor; ?>"> if (PMA_MYSQL_INT_VERSION >= 40000) {
<?php echo urlencode('TRUNCATE ' . PMA_backquote($table))
if (!empty($sts_data['Rows'])) { . '&amp;zero_rows='
echo '<a href="sql.php?' . $tbl_url_query . urlencode(sprintf($strTableHasBeenEmptied, htmlspecialchars($table)))
. '&amp;sql_query='; . '" onclick="return confirmLink(this, \'TRUNCATE ';
if (PMA_MYSQL_INT_VERSION >= 40000) { } else {
echo urlencode('TRUNCATE ' . PMA_backquote($table)) echo urlencode('DELETE FROM ' . PMA_backquote($table))
. '&amp;zero_rows=' . '&amp;zero_rows='
. urlencode(sprintf($strTableHasBeenEmptied, htmlspecialchars($table))) . urlencode(sprintf($strTableHasBeenEmptied, htmlspecialchars($table)))
. '" onclick="return confirmLink(this, \'TRUNCATE '; . '" onclick="return confirmLink(this, \'DELETE FROM ';
}
echo PMA_jsFormat($table) . '\')">' . $titles['Empty'] . '</a>';
} else { } else {
echo urlencode('DELETE FROM ' . PMA_backquote($table)) echo $titles['NoEmpty'];
. '&amp;zero_rows='
. urlencode(sprintf($strTableHasBeenEmptied, htmlspecialchars($table)))
. '" onclick="return confirmLink(this, \'DELETE FROM ';
} }
echo PMA_jsFormat($table) . '\')">' . $titles['Empty'] . '</a>'; ?>
} else {
echo $titles['NoEmpty'];
}
$drop_query = 'DROP '
. ($is_view ? 'VIEW' : 'TABLE')
. ' ' . PMA_backquote($table);
$drop_message = sprintf(($is_view ? $strViewHasBeenDropped : $strTableHasBeenDropped), htmlspecialchars($table));
?>
</td> </td>
<td align="center" bgcolor="<?php echo $bgcolor; ?>"> <td align="center" bgcolor="<?php echo $bgcolor; ?>">
<?php <?php
// rabus: We cannot drop information_schema tables! $drop_query = 'DROP '
if (PMA_MYSQL_INT_VERSION >= 50000 && $db == 'information_schema') { . ($is_view ? 'VIEW' : 'TABLE')
echo $titles['NoDrop']; . ' ' . PMA_backquote($table);
} else { $drop_message = sprintf(($is_view ? $strViewHasBeenDropped : $strTableHasBeenDropped), htmlspecialchars($table));
?> ?>
<a href="sql.php?<?php echo $tbl_url_query; ?>&amp;reload=1&amp;purge=1&amp;sql_query=<?php echo urlencode($drop_query); ?>&amp;zero_rows=<?php echo urlencode($drop_message); ?>" <a href="sql.php?<?php echo $tbl_url_query; ?>&amp;reload=1&amp;purge=1&amp;sql_query=<?php echo urlencode($drop_query); ?>&amp;zero_rows=<?php echo urlencode($drop_message); ?>"
onclick="return confirmLink(this, '<?php echo PMA_jsFormat($drop_query, FALSE); ?>')"> onclick="return confirmLink(this, '<?php echo PMA_jsFormat($drop_query, FALSE); ?>')">
<?php echo $titles['Drop']; ?></a> <?php echo $titles['Drop']; ?></a>
<?php <?php
unset($drop_query, $drop_message);
} }
?> ?>
</td> </td>
<?php <?php
unset($drop_query, $drop_message);
echo "\n";
// loic1: Patch from Joshua Nye <josh at boxcarmedia.com> to get valid // loic1: Patch from Joshua Nye <josh at boxcarmedia.com> to get valid
// statistics whatever is the table type // statistics whatever is the table type
if (isset($sts_data['Rows']) || (PMA_MYSQL_INT_VERSION >= 50000 && $db == 'information_schema')) { if ( isset( $sts_data['Rows'] ) ) {
// MyISAM, ISAM or Heap table: Row count, data size and index size // MyISAM, ISAM or Heap table: Row count, data size and index size
// is accurate. // is accurate.
if (isset($sts_data['Type']) && preg_match('@^(MyISAM|ISAM|HEAP)$@', $sts_data['Type'])) { if (isset($sts_data['Type']) && preg_match('@^(MyISAM|ISAM|HEAP|MEMORY)$@', $sts_data['Type'])) {
if ($cfg['ShowStats']) { if ($cfg['ShowStats']) {
$tblsize = doubleval($sts_data['Data_length']) + doubleval($sts_data['Index_length']); $tblsize = doubleval($sts_data['Data_length']) + doubleval($sts_data['Index_length']);
$sum_size += $tblsize; $sum_size += $tblsize;
@@ -398,16 +391,13 @@ else {
} }
$display_rows = 'unknown'; $display_rows = 'unknown';
} }
// Don't display number of rows for information_schema tables. ?>
if (!(PMA_MYSQL_INT_VERSION >= 50000 && $db == 'information_schema')) { <td align="right" bgcolor="<?php echo $bgcolor; ?>" <?php echo $click_mouse; ?>>
?> <?php
<td align="right" bgcolor="<?php echo $bgcolor; ?>" <?php echo $click_mouse; ?>> echo "\n" . ' ' . $display_rows . "\n";
<?php ?>
echo "\n" . ' ' . $display_rows . "\n"; </td>
?> <?php
</td>
<?php
}
if (!($cfg['PropertiesNumColumns'] > 1)) { if (!($cfg['PropertiesNumColumns'] > 1)) {
echo ' <td bgcolor="' . $bgcolor . '" nowrap="nowrap" ' . $click_mouse . '>' . "\n" echo ' <td bgcolor="' . $bgcolor . '" nowrap="nowrap" ' . $click_mouse . '>' . "\n"
. ' &nbsp;' . (isset($sts_data['Type']) ? $sts_data['Type'] : '&nbsp;') . '&nbsp;' . "\n" . ' &nbsp;' . (isset($sts_data['Type']) ? $sts_data['Type'] : '&nbsp;') . '&nbsp;' . "\n"
@@ -419,7 +409,7 @@ else {
} }
} }
if ($cfg['ShowStats']) { if ( $cfg['ShowStats']) {
echo "\n"; echo "\n";
?> ?>
<td align="right" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap" <?php echo $click_mouse; ?>> <td align="right" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap" <?php echo $click_mouse; ?>>
@@ -467,7 +457,7 @@ else {
} }
} else { } else {
?> ?>
<td colspan="<?php echo ($structure_tbl_col_cnt - 8) ?>" align="center" bgcolor="<?php echo $bgcolor; ?>" <?php echo $click_mouse; ?>> <td colspan="<?php echo ($structure_tbl_col_cnt - ($table_is_schema ? 5 : 8)) ?>" align="center" bgcolor="<?php echo $bgcolor; ?>" <?php echo $click_mouse; ?>>
<?php echo $strInUse . "\n"; ?> <?php echo $strInUse . "\n"; ?>
</td> </td>
<?php <?php
@@ -489,21 +479,13 @@ else {
<th align="center" nowrap="nowrap"> <th align="center" nowrap="nowrap">
&nbsp;<b><?php echo sprintf($strTables, number_format($num_tables, 0, $number_decimal_separator, $number_thousands_separator)); ?></b>&nbsp; &nbsp;<b><?php echo sprintf($strTables, number_format($num_tables, 0, $number_decimal_separator, $number_thousands_separator)); ?></b>&nbsp;
</th> </th>
<?php <th colspan="<?php echo ( $table_is_schema ? 3 : 6 ) ?>" align="center">
if (PMA_MYSQL_INT_VERSION >= 50000 && $db == 'information_schema') {
?>
<th colspan="6">&nbsp;</th>
<?php
} else {
?>
<th colspan="6" align="center">
<b><?php echo $strSum; ?></b> <b><?php echo $strSum; ?></b>
</th> </th>
<th align="right" nowrap="nowrap"> <th align="right" nowrap="nowrap">
<b><?php echo number_format($sum_entries, 0, $number_decimal_separator, $number_thousands_separator); ?></b> <b><?php echo number_format($sum_entries, 0, $number_decimal_separator, $number_thousands_separator); ?></b>
</th> </th>
<?php <?php
}
if (!($cfg['PropertiesNumColumns'] > 1)) { if (!($cfg['PropertiesNumColumns'] > 1)) {
echo ' <th align="center">' . "\n" echo ' <th align="center">' . "\n"
. ' <b>--</b>' . "\n" . ' <b>--</b>' . "\n"
@@ -633,7 +615,7 @@ if ($num_tables > 0) {
<?php <?php
} // end if } // end if
if (PMA_MYSQL_INT_VERSION < 50002 || (PMA_MYSQL_INT_VERSION >= 50002 && $db != 'information_schema')) { if ( ! $table_is_schema ) {
require('./libraries/display_create_table.lib.php'); require('./libraries/display_create_table.lib.php');
} // end if (Create Table dialog) } // end if (Create Table dialog)