1. Check existence of mb_string, mysql and xml extensions before installation.
[openemr.git] / phpmyadmin / libraries / Partition.class.php
blob12220232b460e78af7f189605b2e7c0f5e8c2698
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Library for extracting information about the partitions
6 * @package PhpMyAdmin
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 /**
13 * Represents a sub partition of a table
15 * @package PhpMyAdmin
17 class PMA_SubPartition
19 /**
20 * @var string the database
22 protected $db;
23 /**
24 * @var string the table
26 protected $table;
27 /**
28 * @var string partition name
30 protected $name;
31 /**
32 * @var integer ordinal
34 protected $ordinal;
35 /**
36 * @var string partition method
38 protected $method;
39 /**
40 * @var string partition expression
42 protected $expression;
43 /**
44 * @var integer no of table rows in the partition
46 protected $rows;
47 /**
48 * @var integer data length
50 protected $dataLength;
51 /**
52 * @var integer index length
54 protected $indexLength;
55 /**
56 * @var string partition comment
58 protected $comment;
60 /**
61 * Constructs a partition
63 * @param array $row fetched row from information_schema.PARTITIONS
65 public function __construct($row)
67 $this->db = $row['TABLE_SCHEMA'];
68 $this->table = $row['TABLE_NAME'];
69 $this->loadData($row);
72 /**
73 * Loads data from the fetched row from information_schema.PARTITIONS
75 * @param array $row fetched row
77 * @return void
79 protected function loadData($row)
81 $this->name = $row['SUBPARTITION_NAME'];
82 $this->ordinal = $row['SUBPARTITION_ORDINAL_POSITION'];
83 $this->method = $row['SUBPARTITION_METHOD'];
84 $this->expression = $row['SUBPARTITION_EXPRESSION'];
85 $this->loadCommonData($row);
88 /**
89 * Loads some data that is common to both partitions and sub partitions
91 * @param array $row fetched row
93 * @return void
95 protected function loadCommonData($row)
97 $this->rows = $row['TABLE_ROWS'];
98 $this->dataLength = $row['DATA_LENGTH'];
99 $this->indexLength = $row['INDEX_LENGTH'];
100 $this->comment = $row['PARTITION_COMMENT'];
104 * Return the partition name
106 * @return string partition name
108 public function getName()
110 return $this->name;
114 * Return the ordinal of the partition
116 * @return number the ordinal
118 public function getOrdinal()
120 return $this->ordinal;
124 * Returns the partition method
126 * @return string partition method
128 public function getMethod()
130 return $this->method;
134 * Returns the partition expression
136 * @return string partition expression
138 public function getExpression()
140 return $this->expression;
144 * Returns the number of data rows
146 * @return integer number of rows
148 public function getRows()
150 return $this->rows;
154 * Returns the data length
156 * @return integer data length
158 public function getDataLength()
160 return $this->dataLength;
164 * Returns the index length
166 * @return integer index length
168 public function getIndexLength()
170 return $this->indexLength;
174 * Returns the partition comment
176 * @return string partition comment
178 public function getComment()
180 return $this->comment;
185 * base Partition Class
187 * @package PhpMyAdmin
189 class PMA_Partition extends PMA_SubPartition
192 * @var string partition description
194 protected $description;
196 * @var PMA_SubPartition[] sub partitions
198 protected $subPartitions = array();
201 * Loads data from the fetched row from information_schema.PARTITIONS
203 * @param array $row fetched row
205 * @return void
207 protected function loadData($row)
209 $this->name = $row['PARTITION_NAME'];
210 $this->ordinal = $row['PARTITION_ORDINAL_POSITION'];
211 $this->method = $row['PARTITION_METHOD'];
212 $this->expression = $row['PARTITION_EXPRESSION'];
213 $this->description = $row['PARTITION_DESCRIPTION'];
214 // no sub partitions, load all data to this object
215 if (empty($row['SUBPARTITION_NAME'])) {
216 $this->loadCommonData($row);
221 * Returns the partiotion description
223 * @return string partition description
225 public function getDescription()
227 return $this->description;
231 * Add a sub partition
233 * @param PMA_SubPartition $partition Sub partition
235 * @return void
237 public function addSubPartition(PMA_SubPartition $partition)
239 $this->subPartitions[] = $partition;
243 * Whether there are sub partitions
245 * @return boolean
247 public function hasSubPartitions()
249 return ! empty($this->subPartitions);
253 * Returns the number of data rows
255 * @return integer number of rows
257 public function getRows()
259 if (empty($this->subPartitions)) {
260 return $this->rows;
261 } else {
262 $rows = 0;
263 foreach ($this->subPartitions as $subPartition) {
264 $rows += $subPartition->rows;
266 return $rows;
271 * Returns the total data length
273 * @return integer data length
275 public function getDataLength()
277 if (empty($this->subPartitions)) {
278 return $this->dataLength;
279 } else {
280 $dataLength = 0;
281 foreach ($this->subPartitions as $subPartition) {
282 $dataLength += $subPartition->dataLength;
284 return $dataLength;
289 * Returns the tatal index length
291 * @return integer index length
293 public function getIndexLength()
295 if (empty($this->subPartitions)) {
296 return $this->indexLength;
297 } else {
298 $indexLength = 0;
299 foreach ($this->subPartitions as $subPartition) {
300 $indexLength += $subPartition->indexLength;
302 return $indexLength;
307 * Returns the list of sub partitions
309 * @return PMA_SubPartition[]
311 public function getSubPartitions()
313 return $this->subPartitions;
317 * Returns array of partitions for a specific db/table
319 * @param string $db database name
320 * @param string $table table name
322 * @access public
323 * @return PMA_Partition[]
325 static public function getPartitions($db, $table)
327 if (PMA_Partition::havePartitioning()) {
328 $result = $GLOBALS['dbi']->fetchResult(
329 "SELECT * FROM `information_schema`.`PARTITIONS`"
330 . " WHERE `TABLE_SCHEMA` = '" . PMA_Util::sqlAddSlashes($db)
331 . "' AND `TABLE_NAME` = '" . PMA_Util::sqlAddSlashes($table) . "'"
333 if ($result) {
334 $partitionMap = array();
335 foreach ($result as $row) {
336 if (isset($partitionMap[$row['PARTITION_NAME']])) {
337 $partition = $partitionMap[$row['PARTITION_NAME']];
338 } else {
339 $partition = new PMA_Partition($row);
340 $partitionMap[$row['PARTITION_NAME']] = $partition;
343 if (! empty($row['SUBPARTITION_NAME'])) {
344 $parentPartition = $partition;
345 $partition = new PMA_SubPartition($row);
346 $parentPartition->addSubPartition($partition);
349 return array_values($partitionMap);
351 return array();
352 } else {
353 return array();
358 * returns array of partition names for a specific db/table
360 * @param string $db database name
361 * @param string $table table name
363 * @access public
364 * @return array of partition names
366 static public function getPartitionNames($db, $table)
368 if (PMA_Partition::havePartitioning()) {
369 return $GLOBALS['dbi']->fetchResult(
370 "SELECT `PARTITION_NAME` FROM `information_schema`.`PARTITIONS`"
371 . " WHERE `TABLE_SCHEMA` = '" . PMA_Util::sqlAddSlashes($db)
372 . "' AND `TABLE_NAME` = '" . PMA_Util::sqlAddSlashes($table) . "'"
374 } else {
375 return array();
380 * returns the partition method used by the table.
382 * @param string $db database name
383 * @param string $table table name
385 * @return string partition method
387 static public function getPartitionMethod($db, $table)
389 if (PMA_Partition::havePartitioning()) {
390 $partition_method = $GLOBALS['dbi']->fetchResult(
391 "SELECT `PARTITION_METHOD` FROM `information_schema`.`PARTITIONS`"
392 . " WHERE `TABLE_SCHEMA` = '" . PMA_Util::sqlAddSlashes($db) . "'"
393 . " AND `TABLE_NAME` = '" . PMA_Util::sqlAddSlashes($table) . "'"
395 if (! empty($partition_method)) {
396 return $partition_method[0];
399 return null;
403 * checks if MySQL server supports partitioning
405 * @static
406 * @staticvar boolean $have_partitioning
407 * @staticvar boolean $already_checked
408 * @access public
409 * @return boolean
411 static public function havePartitioning()
413 static $have_partitioning = false;
414 static $already_checked = false;
416 if (! $already_checked) {
417 if (PMA_MYSQL_INT_VERSION < 50600) {
418 if ($GLOBALS['dbi']->fetchValue(
419 "SELECT @@have_partitioning;"
420 )) {
421 $have_partitioning = true;
423 } else {
424 // see http://dev.mysql.com/doc/refman/5.6/en/partitioning.html
425 $plugins = $GLOBALS['dbi']->fetchResult("SHOW PLUGINS");
426 foreach ($plugins as $value) {
427 if ($value['Name'] == 'partition') {
428 $have_partitioning = true;
429 break;
433 $already_checked = true;
435 return $have_partitioning;