cache table information

This commit is contained in:
Sebastian Mendel
2008-05-09 13:38:03 +00:00
parent 9658a0bca5
commit df216c95ec
2 changed files with 24 additions and 10 deletions

View File

@@ -8,7 +8,10 @@
/**
* @todo make use of PMA_Message and PMA_Error
*/
class PMA_Table {
class PMA_Table
{
static $cache = array();
/**
* @var string table name
@@ -240,7 +243,10 @@ class PMA_Table {
// from the result set are NULL except Name and Comment.
// MySQL from 5.0.0 to 5.0.12 returns 'view',
// from 5.0.13 returns 'VIEW'.
$comment = strtoupper(PMA_DBI_fetch_value('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . $table . '\'', 0, 'Comment'));
if (! isset(PMA_Table::$cache[$db][$table]['Comment'])) {
PMA_Table::$cache[$db][$table] = PMA_DBI_fetch_single_row('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . $table . '\'');
}
$comment = strtoupper(PMA_Table::$cache[$db][$table]['Comment']);
// use substr() because the comment might contain something like:
// (VIEW 'BASE2.VTEST' REFERENCES INVALID TABLE(S) OR COLUMN(S) OR FUNCTION)
return (substr($comment, 0, 4) == 'VIEW');
@@ -380,17 +386,17 @@ class PMA_Table {
{
$row_count = false;
if (! $force_exact) {
$row_count = PMA_DBI_fetch_value(
'SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \''
. PMA_sqlAddslashes($table, true) . '\';',
0, 'Rows');
}
if (null === $is_view) {
$is_view = PMA_Table::isView($db, $table);
}
if (! $force_exact) {
if (! isset(PMA_Table::$cache[$db][$table]['Rows']) && ! $is_view) {
PMA_Table::$cache[$db][$table] = PMA_DBI_fetch_single_row('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . PMA_sqlAddslashes($table, true) . '\'');
}
$row_count = PMA_Table::$cache[$db][$table]['Rows'];
}
// for a VIEW, $row_count is always false at this point
if (false === $row_count || $row_count < $GLOBALS['cfg']['MaxExactCount']) {
if (! $is_view) {
@@ -421,6 +427,7 @@ class PMA_Table {
}
}
}
PMA_Table::$cache[$db][$table]['Rows'] = $row_count;
}
if ($ret) {

View File

@@ -201,6 +201,7 @@ function PMA_DBI_get_tables($database, $link = null)
* PMA_DBI_get_tables_full('my_database', 'my_tables_', 'comment'));
* </code>
*
* @todo move into PMA_Table
* @uses PMA_DBI_fetch_result()
* @uses PMA_escape_mysql_wildcards()
* @uses PMA_backquote()
@@ -219,6 +220,8 @@ function PMA_DBI_get_tables($database, $link = null)
function PMA_DBI_get_tables_full($database, $table = false,
$tbl_is_group = false, $link = null, $limit_offset = 0, $limit_count = false)
{
require_once './libraries/Table.class.php';
if (true === $limit_count) {
$limit_count = $GLOBALS['cfg']['MaxTableList'];
}
@@ -301,7 +304,7 @@ function PMA_DBI_get_tables_full($database, $table = false,
.' LIKE \'' . PMA_escape_mysql_wildcards(addslashes($table)) . '%\'';
} else {
$sql = 'SHOW TABLE STATUS FROM '
. PMA_backquote($each_database) . ';';
. PMA_backquote($each_database);
}
$each_tables = PMA_DBI_fetch_result($sql, 'Name', null, $link);
@@ -373,6 +376,10 @@ function PMA_DBI_get_tables_full($database, $table = false,
}
}
// cache table data
// so PMA_Table does not require to issue SHOW TABLE STATUS again
PMA_Table::$cache = $tables;
if (! is_array($database)) {
if (isset($tables[$database])) {
return $tables[$database];