20
22
protected static $_registry = array();
23
25
* @var string The name of the schema
25
27
protected $_schema = '';
28
30
* @var string The name of the table
30
32
protected $_table = '';
33
35
* @var string The name of the index
35
37
protected $_name = '';
42
44
protected $_columns = array();
45
47
* The index method used (BTREE, FULLTEXT, HASH, RTREE).
56
58
protected $_choice = '';
63
65
protected $_remarks = '';
66
* Any comment provided for the index with a COMMENT attribute when the
68
* Any comment provided for the index with a COMMENT attribute when the
67
69
* index was created.
71
73
protected $_comment = '';
74
* @var integer 0 if the index cannot contain duplicates, 1 if it can.
76
* @var integer 0 if the index cannot contain duplicates, 1 if it can.
76
78
protected $_non_unique = 0;
79
81
* Indicates how the key is packed. NULL if it is not.
83
85
protected $_packed = null;
120
122
static public function getFromTable($table, $schema)
122
124
PMA_Index::_loadIndexes($table, $schema);
124
126
if (isset(PMA_Index::$_registry[$schema][$table])) {
125
127
return PMA_Index::$_registry[$schema][$table];
132
134
* return primary if set, false otherwise
140
142
static public function getPrimary($table, $schema)
142
144
PMA_Index::_loadIndexes($table, $schema);
144
146
if (isset(PMA_Index::$_registry[$schema][$table]['PRIMARY'])) {
145
147
return PMA_Index::$_registry[$schema][$table]['PRIMARY'];
152
154
* Load index data for table
165
167
if (isset(PMA_Index::$_registry[$schema][$table])) {
169
171
$_raw_indexes = PMA_DBI_fetch_result('SHOW INDEX FROM ' . PMA_backquote($schema) . '.' . PMA_backquote($table));
170
172
foreach ($_raw_indexes as $_each_index) {
171
173
$_each_index['Schema'] = $schema;
274
276
$this->_choice = 'INDEX';
278
280
public function getColumnCount()
280
282
return count($this->_columns);
283
285
public function getComment()
285
287
return $this->_comment;
288
290
public function getRemarks()
290
292
return $this->_remarks;
293
295
public function getComments()
295
297
$comments = $this->getRemarks();
297
299
$comments .= "\n";
299
301
$comments .= $this->getComment();
301
303
return $comments;
304
306
public function getType()
306
308
return $this->_type;
310
* Return a list of all index choices
312
* Return a list of all index choices
312
* @return array index choices
314
* @return array index choices
314
316
static public function getIndexChoices()
388
390
return $r[$this->_non_unique];
391
393
public function getName()
393
395
return $this->_name;
396
398
public function setName($name)
398
400
$this->_name = (string) $name;
401
403
public function getColumns()
403
405
return $this->_columns;
407
409
* Show index data
421
423
if (count($indexes) < 1) {
422
424
return PMA_Message::warning('strNoIndex')->getDisplay();
427
$r .= '<h2>' . $GLOBALS['strIndexes'] . ': ';
429
$r .= '<h2>' . $GLOBALS['strIndexes'] . ': ';
428
430
$r .= PMA_showMySQLDocu('optimization', 'optimizing-database-structure');
446
448
$r .= '</thead>';
450
452
foreach ($indexes as $index) {
451
453
$row_span = ' rowspan="' . $index->getColumnCount() . '" ';
453
455
$r .= '<tr class="' . ($odd_row ? 'odd' : 'even') . '">';
455
457
if (! $print_mode) {
456
458
$this_params = $GLOBALS['url_params'];
457
459
$this_params['index'] = $index->getName();
459
461
. ' <a href="tbl_indexes.php' . PMA_generate_common_url($this_params)
460
462
. '">' . PMA_getIcon('b_edit.png', $GLOBALS['strEdit']) . '</a>'
461
463
. '</td>' . "\n";
463
465
$this_params = $GLOBALS['url_params'];
464
466
if ($index->getName() == 'PRIMARY') {
465
467
$this_params['sql_query'] = 'ALTER TABLE ' . PMA_backquote($table) . ' DROP PRIMARY KEY';
470
472
$this_params['zero_rows'] = sprintf($GLOBALS['strIndexHasBeenDropped'], $index->getName());
471
473
$js_msg = PMA_jsFormat('ALTER TABLE ' . $table . ' DROP INDEX ' . $index->getName());
474
476
$r .= '<td ' . $row_span . '>'
475
477
. ' <a href="sql.php' . PMA_generate_common_url($this_params)
476
. '" onclick="return confirmLink(this, \'' . $js_msg . '\')">'
478
. '" onclick="return confirmLink(this, \'' . $js_msg . '\')">'
477
479
. PMA_getIcon('b_drop.png', $GLOBALS['strDrop']) . '</a>'
478
480
. '</td>' . "\n";
481
483
$r .= '<th ' . $row_span . '>' . htmlspecialchars($index->getName()) . '</th>';
482
484
$r .= '<td ' . $row_span . '>' . htmlspecialchars($index->getType()) . '</td>';
483
485
$r .= '<td ' . $row_span . '>' . $index->isUnique(true) . '</td>';
484
486
$r .= '<td ' . $row_span . '>' . $index->isPacked(true) . '</td>';
486
488
foreach ($index->getColumns() as $column) {
487
489
if ($column->getSeqInIndex() > 1) {
488
490
$r .= '<tr class="' . ($odd_row ? 'odd' : 'even') . '">';
497
499
$r .= '<td>' . htmlspecialchars($column->getNull()) . '</td>';
499
501
if ($column->getSeqInIndex() == 1) {
500
$r .= '<td ' . $row_span . '>'
502
$r .= '<td ' . $row_span . '>'
501
503
. htmlspecialchars($index->getComments()) . '</td>';
504
506
} // end foreach $index['Sequences']
506
508
$odd_row = ! $odd_row;
508
510
$r .= '</tbody>';
509
511
$r .= '</table>';
511
513
if (! $print_mode) {
512
514
$r .= PMA_Index::findDuplicates($table, $schema);
518
520
public function getCompareData()
522
524
'Packed' => $this->_packed,
523
525
'Index_type' => $this->_type,
526
528
foreach ($this->_columns as $column) {
527
529
$data['columns'][] = $column->getCompareData();
534
536
* Function to check over array of indexes and look for common problems
547
549
static public function findDuplicates($table, $schema)
549
551
$indexes = PMA_Index::getFromTable($table, $schema);
553
555
// count($indexes) < 2:
554
556
// there is no need to check if there less than two indexes
555
557
if (count($indexes) < 2) {
559
561
// remove last index from stack and ...
560
562
while ($while_index = array_pop($indexes)) {
561
563
// ... compare with every remaining index in stack
563
565
if ($each_index->getCompareData() !== $while_index->getCompareData()) {
567
569
// did not find any difference
568
570
// so it makes no sense to have this two equal indexes
570
572
$message = PMA_Message::warning('strIndexesSeemEqual');
571
573
$message->addParam($each_index->getName());
572
574
$message->addParam($while_index->getName());
573
575
$output .= $message->getDisplay();
575
577
// there is no need to check any further indexes if we have already
576
578
// found that this one has a duplicate
587
* @package phpMyAdmin
584
589
class PMA_Index_Column
587
592
* @var string The column name
589
594
protected $_name = '';
592
* @var integer The column sequence number in the index, starting with 1.
597
* @var integer The column sequence number in the index, starting with 1.
594
599
protected $_seq_in_index = 1;
597
* @var string How the column is sorted in the index. “A” (Ascending) or NULL (Not sorted)
602
* @var string How the column is sorted in the index. “A” (Ascending) or NULL (Not sorted)
599
604
protected $_collation = null;
602
* The number of indexed characters if the column is only partly indexed,
603
* NULL if the entire column is indexed.
607
* The number of indexed characters if the column is only partly indexed,
608
* NULL if the entire column is indexed.
607
612
protected $_sub_part = null;
610
* Contains YES if the column may contain NULL.
611
* If not, the column contains NO.
615
* Contains YES if the column may contain NULL.
616
* If not, the column contains NO.
615
620
protected $_null = '';
618
* An estimate of the number of unique values in the index. This is updated
619
* by running ANALYZE TABLE or myisamchk -a. Cardinality is counted based on
620
* statistics stored as integers, so the value is not necessarily exact even
621
* for small tables. The higher the cardinality, the greater the chance that
622
* MySQL uses the index when doing joins.
623
* An estimate of the number of unique values in the index. This is updated
624
* by running ANALYZE TABLE or myisamchk -a. Cardinality is counted based on
625
* statistics stored as integers, so the value is not necessarily exact even
626
* for small tables. The higher the cardinality, the greater the chance that
627
* MySQL uses the index when doing joins.
626
631
protected $_cardinality = 0;
628
633
public function __construct($params = array())
630
635
$this->set($params);
633
638
public function set($params)
635
640
if (isset($params['Column_name'])) {
651
656
$this->_null = $params['Null'];
655
660
public function getName()
657
662
return $this->_name;
660
665
public function getCollation()
662
667
return $this->_collation;
665
670
public function getCardinality()
667
672
return $this->_cardinality;
670
675
public function getNull()
672
677
return $this->_null;
675
680
public function getSeqInIndex()
677
682
return $this->_seq_in_index;
680
685
public function getSubPart()
682
687
return $this->_sub_part;