Improve partition support

Signed-off-by: Madhura Jayaratne <madhura.cj@gmail.com>
This commit is contained in:
Madhura Jayaratne 2015-08-13 18:26:15 +05:30
parent 9cf71d9169
commit 4acdbebe18

View File

@ -16,6 +16,160 @@ if (! defined('PHPMYADMIN')) {
*/
class PMA_Partition
{
/**
* @var string the database
*/
protected $db;
/**
* @var string the table
*/
protected $table;
/**
* @var string partition name
*/
protected $name;
/**
* @var int ordinal
*/
protected $ordinal;
/**
* @var string partition method
*/
protected $method;
/**
* @var string partition expression
*/
protected $expression;
/**
* @var string partition description
*/
protected $description;
/**
* @var integer no of table rows in the parition
*/
protected $rows;
/**
* @var PMA_Partition[] sub partitions
*/
protected $subPartitions = array();
/**
* Constructs a partition
*
* @param string $db database name
* @param string $table table name
* @param string $name parition name
* @param int $ordinal ordinal
* @param string $method partition method
* @param string $expression partition expression
*/
public function __construct($db, $table, $name, $ordinal, $method, $expression)
{
$this->db = $db;
$this->table = $table;
$this->name = $name;
$this->ordinal = $ordinal;
$this->method = $method;
$this->expression = $expression;
}
/**
* Sets the partition description
*
* @param string $description parition description
*
* @return void
*/
public function setDescription($description)
{
$this->description = $description;
}
/**
* Sets the number of rows in the parition
*
* @param integer $rows number of rows
*
* @return void
*/
public function setRows($rows)
{
$this->rows = $rows;
}
/**
* Add a sub parition
*
* @param PMA_Partition $parition
*
* @return void
*/
public function addSubPartition(PMA_Partition $parition)
{
$this->subPartitions[] = $parition;
}
/**
* Returns array of partitions for a specific db/table
*
* @param string $db database name
* @param string $table table name
*
* @access public
* @return PMA_Partition[]
*/
static public function getParititions($db, $table)
{
if (PMA_Partition::havePartitioning()) {
$result = $GLOBALS['dbi']->fetchResult(
"SELECT * FROM `information_schema`.`PARTITIONS`"
. " WHERE `TABLE_SCHEMA` = '" . PMA_Util::sqlAddSlashes($db)
. "' AND `TABLE_NAME` = '" . PMA_Util::sqlAddSlashes($table) . "'"
);
if ($result) {
$partitionMap = array();
foreach ($result as $row) {
if (isset($partitionMap[$row['PARTITION_NAME']])) {
$tempPartition = $partitionMap[$row['PARTITION_NAME']];
} else {
$tempPartition = new PMA_Partition(
$db,
$table,
$row['PARTITION_NAME'],
$row['PARTITION_ORDINAL_POSITION'],
$row['PARTITION_METHOD'],
$row['PARTITION_EXPRESSION']
);
$tempPartition->setDescription($row['PARTITION_DESCRIPTION']);
$partitionMap[$row['PARTITION_NAME']] = $tempPartition;
}
if (! empty($row['SUBPARTITION_NAME'])) {
$parentPartition = $tempPartition;
$partition = new PMA_Partition(
$db,
$table,
$row['SUBPARTITION_NAME'],
$row['SUBPARTITION_ORDINAL_POSITION'],
$row['SUBPARTITION_METHOD'],
$row['SUBPARTITION_EXPRESSION']
);
$parentPartition->addSubPartition($parition);
} else {
$partition = $tempPartition;
}
$partition->setRows($row['TABLE_ROWS']);
}
return array_values($partitionMap);
}
return array();
} else {
return array();
}
}
/**
* returns array of partition names for a specific db/table
*