diff --git a/ChangeLog b/ChangeLog index f7c9eabc0..35992c683 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,7 @@ $HeadURL$ + [import] support handling of DELIMITER to mimic mysql CLI, thanks to fb1 - bug #1674914 [structure] changing definition of a TIMESTAMP field - bug #1615530 [upload] added more specific error message if field upload fails +- bug #1627210, #1083301, #1482401 [data] warning on duplicate indexes - [gui] avoid displaying a wide selector in server selection + [core] added PMA_fatalError() and made use of it . [i18n] use generic $strOptions diff --git a/libraries/tbl_indexes.lib.php b/libraries/tbl_indexes.lib.php index 93449b8b1..65d1be38d 100644 --- a/libraries/tbl_indexes.lib.php +++ b/libraries/tbl_indexes.lib.php @@ -1,8 +1,9 @@ $w_count) { - if (isset($idx_collection['PRIMARY'][$w_keyname]) && (isset($idx_collection['INDEX'][$w_keyname]) || isset($idx_collection['UNIQUE'][$w_keyname]))) { - $output .= PMA_index_warning(sprintf($GLOBALS['strIndexWarningPrimary'], htmlspecialchars($w_keyname)), $table); - } elseif (isset($idx_collection['UNIQUE'][$w_keyname]) && isset($idx_collection['INDEX'][$w_keyname])) { - $output .= PMA_index_warning(sprintf($GLOBALS['strIndexWarningUnique'], htmlspecialchars($w_keyname)), $table); - } + // count($idx_collection) < 2: + // there is no need to check if there less than two indexes + if (! is_array($idx_collection) || count($idx_collection) < 2) { + return false; + } - foreach ($index_types AS $index_type) { - if (isset($idx_collection[$index_type][$w_keyname]) && $idx_collection[$index_type][$w_keyname] > 1) { - $output .= PMA_index_warning(sprintf($GLOBALS['strIndexWarningMultiple'], $index_type, htmlspecialchars($w_keyname)), $table); + $indexes = array(); + foreach ($idx_collection as $index_field) { + $indexes[$index_field['Key_name']][$index_field['Column_name']] + = $index_field; + } + + $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_name => $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); + + $output .= '
'; + $output .= $GLOBALS['strIndexesSeemEqual']; + $output .= $each_index_name . ', ' . $first_column['Key_name']; + $output .= '
'; + + // 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 = '' . $output . ''; + } + return $output; } @@ -90,8 +137,9 @@ function PMA_check_indexes($idx_collection, $table = true) { * @return boolean void * @author Garvin Hicking (pma@supergarv.de) */ -function PMA_extract_indexes(&$ret_keys, &$indexes, &$indexes_info, &$indexes_data) { - if (!is_array($ret_keys)) { +function PMA_extract_indexes(&$ret_keys, &$indexes, &$indexes_info, &$indexes_data) +{ + if (! is_array($ret_keys)) { return false; } @@ -141,7 +189,9 @@ function PMA_extract_indexes(&$ret_keys, &$indexes, &$indexes_info, &$indexes_da * @return array Index collection array * @author Garvin Hicking (pma@supergarv.de) */ -function PMA_show_indexes($table, &$indexes, &$indexes_info, &$indexes_data, $display_html = true, $print_mode = false) { +function PMA_show_indexes($table, &$indexes, &$indexes_info, &$indexes_data, + $display_html = true, $print_mode = false) +{ $idx_collection = array(); $odd_row = true; foreach ($indexes as $index_name) { @@ -175,7 +225,9 @@ function PMA_show_indexes($table, &$indexes, &$indexes_info, &$indexes_data, $di if (!$print_mode) { echo ' ' . "\n" - . ' ' . $GLOBALS['edit_link_text'] . '' . "\n" + . ' ' . $GLOBALS['edit_link_text'] . '' . "\n" . ' ' . "\n"; if ($index_name == 'PRIMARY') { @@ -189,7 +241,10 @@ function PMA_show_indexes($table, &$indexes, &$indexes_info, &$indexes_data, $di } echo ' ' . "\n" - . ' ' . $GLOBALS['drop_link_text'] . '' . "\n" + . ' ' . $GLOBALS['drop_link_text'] . '' . "\n" . ' ' . "\n"; } } @@ -237,22 +292,4 @@ function PMA_show_indexes($table, &$indexes, &$indexes_info, &$indexes_data, $di return $idx_collection; } -/** - * Function to emit a index warning - * - * @author Garvin Hicking (pma@supergarv.de) - * @access public - * @param string $string Message string - * @param boolean $table Whether to output HTML in table layout - * @return string Output HTML - */ -function PMA_index_warning($string, $table = true) { - $output = '
' . $string . '
'; - - if ( $table ) { - $output = '' . $output . ''; - } - - return $output . "\n"; -} ?> diff --git a/sql.php b/sql.php index c7e6e3c2c..d746d7119 100644 --- a/sql.php +++ b/sql.php @@ -724,15 +724,9 @@ else { // BEGIN INDEX CHECK See if indexes should be checked. if (isset($query_type) && $query_type == 'check_tbl' && isset($selected) && is_array($selected)) { - foreach ($selected AS $idx => $tbl_name) { - $indexes = $indexes_info = $indexes_data = array(); - $tbl_ret_keys = PMA_get_indexes(urldecode($tbl_name), $err_url_0); - - PMA_extract_indexes($tbl_ret_keys, $indexes, $indexes_info, $indexes_data); - - $idx_collection = PMA_show_indexes(urldecode($tbl_name), $indexes, $indexes_info, $indexes_data, false); - $check = PMA_check_indexes($idx_collection); - if (!empty($check)) { + foreach ($selected as $idx => $tbl_name) { + $check = PMA_check_indexes($tbl_name); + if (! empty($check)) { ?> diff --git a/tbl_indexes.php b/tbl_indexes.php index 810e170c1..176c6d4dd 100644 --- a/tbl_indexes.php +++ b/tbl_indexes.php @@ -1,18 +1,16 @@ @@ -412,7 +406,7 @@ elseif (!defined('PMA_IDX_INCLUDED') 0) { + if (count($ret_keys) > 0) { $edit_link_text = ''; $drop_link_text = ''; @@ -446,7 +440,7 @@ elseif (!defined('PMA_IDX_INCLUDED')