diff --git a/libraries/Index.class.php b/libraries/Index.class.php index bf97de36f..e02950b78 100644 --- a/libraries/Index.class.php +++ b/libraries/Index.class.php @@ -290,6 +290,40 @@ class PMA_Index return $this->_type; } + /** + * Return a list of all index types + * + * @return array index types + */ + static public function getTypes() + { + return array( + 'PRIMARY', + 'INDEX', + 'UNIQUE', + 'FULLTEXT', + ); + } + + public function getTypeSelector() + { + $html_options = ''; + + foreach (PMA_Index::getTypes() as $each_index_type) { + if ($each_index_type === 'PRIMARY' + && $this->_name !== 'PRIMARY' + && PMA_Index::getPrimary($this->_table, $this->_schema)) { + // skip PRIMARY if there is already one in the table + continue; + } + $html_options .= '' . "\n"; + } + + return $html_options; + } + public function getPacked() { return $this->_packed; @@ -364,9 +398,9 @@ class PMA_Index * @return array Index collection array * @author Garvin Hicking (pma@supergarv.de) */ - static public function getView($table, $db, $print_mode = false) + static public function getView($table, $schema, $print_mode = false) { - $indexes = PMA_Index::getFromTable($table, $db); + $indexes = PMA_Index::getFromTable($table, $schema); if (count($indexes) < 1) { return PMA_Message::warning('strNoIndex')->getDisplay(); @@ -459,11 +493,76 @@ class PMA_Index $r .= ''; if (! $print_mode) { - //$r .= PMA_check_indexes($ret_keys); + $r .= PMA_Index::findDuplicates($table, $schema); } return $r; } + + public function getCompareData() + { + $data = array( + // 'Non_unique' => $this->_non_unique, + 'Packed' => $this->_packed, + 'Index_type' => $this->_type, + ); + + foreach ($this->_columns as $column) { + $data['columns'][] = $column->getCompareData(); + } + + return $data; + } + + /** + * Function to check over array of indexes and look for common problems + * + * @uses $GLOBALS['strIndexesSeemEqual'] + * @uses is_string() + * @uses is_array() + * @uses count() + * @uses array_pop() + * @uses reset() + * @uses current() + * @access public + * @param string name of table + * @return string Output HTML + */ + function findDuplicates($table, $schema) + { + $indexes = PMA_Index::getFromTable($table, $schema); + + $output = ''; + + // count($indexes) < 2: + // there is no need to check if there less than two indexes + if (count($indexes) < 2) { + return $output; + } + + // remove last index from stack and ... + while ($while_index = array_pop($indexes)) { + // ... compare with every remaining index in stack + foreach ($indexes as $each_index) { + if ($each_index->getCompareData() !== $while_index->getCompareData()) { + continue; + } + + // did not find any difference + // so it makes no sense to have this two equal indexes + + $message = PMA_Message::warning('strIndexesSeemEqual'); + $message->addParam($each_index->getName()); + $message->addParam($while_index->getName()); + $output .= $message->getDisplay(); + + // there is no need to check any further indexes if we have already + // found that this one has a duplicate + continue 2; + } + } + return $output; + } } class PMA_Index_Column @@ -566,5 +665,16 @@ class PMA_Index_Column { return $this->_sub_part; } + + public function getCompareData() + { + return array( + 'Column_name' => $this->_name, + 'Seq_in_index' => $this->_seq_in_index, + 'Collation' => $this->_collation, + 'Sub_part' => $this->_sub_part, + 'Null' => $this->_null, + ); + } } ?> \ No newline at end of file diff --git a/libraries/display_tbl.lib.php b/libraries/display_tbl.lib.php index 58f6f2698..580794270 100644 --- a/libraries/display_tbl.lib.php +++ b/libraries/display_tbl.lib.php @@ -10,6 +10,7 @@ * */ require_once './libraries/Table.class.php'; +require_once './libraries/Index.class.php'; /** * Defines the display mode to use for the results of a SQL query @@ -483,40 +484,10 @@ function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $ isset($analyzed_sql[0]['table_ref']) && count($analyzed_sql[0]['table_ref']) == 1) { // grab indexes data: - PMA_DBI_select_db($db); - if (!defined('PMA_IDX_INCLUDED')) { - $ret_keys = PMA_get_indexes($table); - } - - $prev_index = ''; - foreach ($ret_keys as $row) { - - if ($row['Key_name'] != $prev_index){ - $indexes[] = $row['Key_name']; - $prev_index = $row['Key_name']; - } - $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index']; - $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique']; - if (isset($row['Cardinality'])) { - $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality']; - } - // I don't know what does the following column mean.... - // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed']; - $indexes_info[$row['Key_name']]['Comment'] = (isset($row['Comment'])) - ? $row['Comment'] - : ''; - $indexes_info[$row['Key_name']]['Index_type'] = (isset($row['Index_type'])) - ? $row['Index_type'] - : ''; - - $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name']; - if (isset($row['Sub_part'])) { - $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part']; - } - } // end while + $indexes = PMA_Index::getFromTable($table, $db); // do we have any index? - if (isset($indexes_data)) { + if ($indexes) { if ($_SESSION['userconf']['disp_direction'] == 'horizontal' || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') { @@ -535,30 +506,28 @@ function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $ } echo '
' . "\n"; } } diff --git a/libraries/tbl_indexes.lib.php b/libraries/tbl_indexes.lib.php deleted file mode 100644 index d08bb6d22..000000000 --- a/libraries/tbl_indexes.lib.php +++ /dev/null @@ -1,177 +0,0 @@ - $each_index) { - if (count($while_index) !== count($each_index)) { - // number of fields are not equal - continue; - } - - // compare some key elements of every column in this two indexes - foreach ($each_index as $col_name => $each_index_column) { - if (! isset($while_index[$col_name]) - // the position - || $while_index[$col_name]['Seq_in_index'] !== $each_index_column['Seq_in_index'] - // the order, ASC or DESC - || $while_index[$col_name]['Collation'] !== $each_index_column['Collation'] - // the length - || $while_index[$col_name]['Sub_part'] !== $each_index_column['Sub_part'] - // BTREE or HASH - || $while_index[$col_name]['Index_type'] !== $each_index_column['Index_type']) { - continue 2; - } - } - - // did not find any difference - // so it makes no sense to have this two equal indexes - - // use first column from index to fetch index name - reset($while_index); - $first_column = current($while_index); - - $message = PMA_Message::warning('strIndexesSeemEqual'); - $message->addParam($each_index_name); - $message->addParam($first_column['Key_name']); - $output .= $message->getDisplay(); - - // there is no need to check any further indexes if we have already - // found that this one has a duplicate - continue 2; - } - } - - if ($output) { - $output = '- |