cache table information
This commit is contained in:
@@ -8,8 +8,11 @@
|
|||||||
/**
|
/**
|
||||||
* @todo make use of PMA_Message and PMA_Error
|
* @todo make use of PMA_Message and PMA_Error
|
||||||
*/
|
*/
|
||||||
class PMA_Table {
|
class PMA_Table
|
||||||
|
{
|
||||||
|
|
||||||
|
static $cache = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string table name
|
* @var string table name
|
||||||
*/
|
*/
|
||||||
@@ -240,7 +243,10 @@ class PMA_Table {
|
|||||||
// from the result set are NULL except Name and Comment.
|
// from the result set are NULL except Name and Comment.
|
||||||
// MySQL from 5.0.0 to 5.0.12 returns 'view',
|
// MySQL from 5.0.0 to 5.0.12 returns 'view',
|
||||||
// from 5.0.13 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:
|
// use substr() because the comment might contain something like:
|
||||||
// (VIEW 'BASE2.VTEST' REFERENCES INVALID TABLE(S) OR COLUMN(S) OR FUNCTION)
|
// (VIEW 'BASE2.VTEST' REFERENCES INVALID TABLE(S) OR COLUMN(S) OR FUNCTION)
|
||||||
return (substr($comment, 0, 4) == 'VIEW');
|
return (substr($comment, 0, 4) == 'VIEW');
|
||||||
@@ -380,17 +386,17 @@ class PMA_Table {
|
|||||||
{
|
{
|
||||||
$row_count = false;
|
$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) {
|
if (null === $is_view) {
|
||||||
$is_view = PMA_Table::isView($db, $table);
|
$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
|
// for a VIEW, $row_count is always false at this point
|
||||||
if (false === $row_count || $row_count < $GLOBALS['cfg']['MaxExactCount']) {
|
if (false === $row_count || $row_count < $GLOBALS['cfg']['MaxExactCount']) {
|
||||||
if (! $is_view) {
|
if (! $is_view) {
|
||||||
@@ -421,6 +427,7 @@ class PMA_Table {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
PMA_Table::$cache[$db][$table]['Rows'] = $row_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($ret) {
|
if ($ret) {
|
||||||
|
@@ -201,6 +201,7 @@ function PMA_DBI_get_tables($database, $link = null)
|
|||||||
* PMA_DBI_get_tables_full('my_database', 'my_tables_', 'comment'));
|
* PMA_DBI_get_tables_full('my_database', 'my_tables_', 'comment'));
|
||||||
* </code>
|
* </code>
|
||||||
*
|
*
|
||||||
|
* @todo move into PMA_Table
|
||||||
* @uses PMA_DBI_fetch_result()
|
* @uses PMA_DBI_fetch_result()
|
||||||
* @uses PMA_escape_mysql_wildcards()
|
* @uses PMA_escape_mysql_wildcards()
|
||||||
* @uses PMA_backquote()
|
* @uses PMA_backquote()
|
||||||
@@ -219,6 +220,8 @@ function PMA_DBI_get_tables($database, $link = null)
|
|||||||
function PMA_DBI_get_tables_full($database, $table = false,
|
function PMA_DBI_get_tables_full($database, $table = false,
|
||||||
$tbl_is_group = false, $link = null, $limit_offset = 0, $limit_count = false)
|
$tbl_is_group = false, $link = null, $limit_offset = 0, $limit_count = false)
|
||||||
{
|
{
|
||||||
|
require_once './libraries/Table.class.php';
|
||||||
|
|
||||||
if (true === $limit_count) {
|
if (true === $limit_count) {
|
||||||
$limit_count = $GLOBALS['cfg']['MaxTableList'];
|
$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)) . '%\'';
|
.' LIKE \'' . PMA_escape_mysql_wildcards(addslashes($table)) . '%\'';
|
||||||
} else {
|
} else {
|
||||||
$sql = 'SHOW TABLE STATUS FROM '
|
$sql = 'SHOW TABLE STATUS FROM '
|
||||||
. PMA_backquote($each_database) . ';';
|
. PMA_backquote($each_database);
|
||||||
}
|
}
|
||||||
|
|
||||||
$each_tables = PMA_DBI_fetch_result($sql, 'Name', null, $link);
|
$each_tables = PMA_DBI_fetch_result($sql, 'Name', null, $link);
|
||||||
@@ -372,6 +375,10 @@ function PMA_DBI_get_tables_full($database, $table = false,
|
|||||||
uksort($tables[$key], 'strnatcasecmp');
|
uksort($tables[$key], 'strnatcasecmp');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cache table data
|
||||||
|
// so PMA_Table does not require to issue SHOW TABLE STATUS again
|
||||||
|
PMA_Table::$cache = $tables;
|
||||||
|
|
||||||
if (! is_array($database)) {
|
if (! is_array($database)) {
|
||||||
if (isset($tables[$database])) {
|
if (isset($tables[$database])) {
|
||||||
|
Reference in New Issue
Block a user