Merge branch 'index'

This commit is contained in:
Madhura Jayaratne 2015-01-28 13:59:34 +05:30
commit 94dd60d387
11 changed files with 145 additions and 70 deletions

View File

@ -24,6 +24,7 @@ phpMyAdmin - ChangeLog
+ rfe #1597 Fast filter improvement: remove "x other results found"
- bug #4720 No error message on Missing extension mbstring
+ rfe #801 Builtin transformations and relations
+ rfe #767 USING BTREE support for HEAP/MEMORY tables
4.3.9.0 (not yet released)
- bug #4728 Incorrect headings in routine editor

View File

@ -3219,10 +3219,10 @@ function checkIndexName(form_id)
// Gets the elements pointers
var $the_idx_name = $("#input_index_name");
var $the_idx_type = $("#select_index_type");
var $the_idx_choice = $("#select_index_choice");
// Index is a primary key
if ($the_idx_type.find("option:selected").val() == 'PRIMARY') {
if ($the_idx_choice.find("option:selected").val() == 'PRIMARY') {
$the_idx_name.val('PRIMARY');
$the_idx_name.prop("disabled", true);
}

View File

@ -14,6 +14,10 @@
*/
function checkIndexType()
{
/**
* @var Object Dropdown to select the index choice.
*/
$select_index_choice = $('#select_index_choice');
/**
* @var Object Dropdown to select the index type.
*/
@ -35,7 +39,7 @@ function checkIndexType()
*/
$add_more = $('#index_frm .tblFooters');
if ($select_index_type.val() == 'SPATIAL') {
if ($select_index_choice.val() == 'SPATIAL') {
// Disable and hide the size column
$size_header.hide();
$size_inputs.each(function () {
@ -78,22 +82,29 @@ function checkIndexType()
// Show controllers to add more columns
$add_more.show();
}
if ($select_index_choice.val() == 'SPATIAL' ||
$select_index_choice.val() == 'FULLTEXT') {
$select_index_type.val('').prop('disabled', true);
} else {
$select_index_type.prop('disabled', false)
}
}
/**
* Sets current index information into form parameters.
*
* @param array source_array Array containing index columns
* @param string index_type Type of index
* @param string index_choice Choice of index
*
* @return void
*/
function PMA_setIndexFormParameters(source_array, index_type)
function PMA_setIndexFormParameters(source_array, index_choice)
{
if (index_type == 'index') {
if (index_choice == 'index') {
$('input[name="indexes"]').val(JSON.stringify(source_array));
} else {
$('input[name="' + index_type + '_indexes"]').val(JSON.stringify(source_array));
$('input[name="' + index_choice + '_indexes"]').val(JSON.stringify(source_array));
}
}
@ -153,12 +164,12 @@ function PMA_removeColumnFromIndex(col_index)
*
* @param array source_array Array holding corresponding indexes
* @param string array_index Index of an INDEX in array
* @param string index_type Type of Index
* @param string index_choice Choice of Index
* @param string col_index Index of column on form
*
* @return void
*/
function PMA_addColumnToIndex(source_array, array_index, index_type, col_index)
function PMA_addColumnToIndex(source_array, array_index, index_choice, col_index)
{
// Remove column from other indexes (if any).
PMA_removeColumnFromIndex(col_index);
@ -179,20 +190,20 @@ function PMA_addColumnToIndex(source_array, array_index, index_type, col_index)
source_array[array_index] = {
'Key_name': index_name,
'Index_comment': index_comment,
'Index_type': index_type.toUpperCase(),
'Index_choice': index_choice.toUpperCase(),
'columns': columns
};
// Update index details on form.
$('select[name="field_key[' + col_index + ']"]')
.attr('data-index', index_type + ',' + array_index);
PMA_setIndexFormParameters(source_array, index_type.toLowerCase());
.attr('data-index', index_choice + ',' + array_index);
PMA_setIndexFormParameters(source_array, index_choice.toLowerCase());
}
/**
* Get choices list for a column to create a composite index with.
*
* @param string index_type Type of index
* @param string index_choice Choice of index
* @param array source_array Array hodling columns for particular index
*
* @return jQuery Object
@ -288,7 +299,7 @@ function PMA_showAddIndexDialog(source_array, array_index, target_columns, col_i
PMA_addColumnToIndex(
source_array,
array_index,
index.Index_type,
index.Index_choice,
col_index
);
} else {
@ -354,21 +365,21 @@ function PMA_showAddIndexDialog(source_array, array_index, target_columns, col_i
* Creates a advanced index type selection dialog.
*
* @param array source_array Array holding a particular type of indexes
* @param string index_type Type of index
* @param string index_choice Choice of index
* @param string col_index Index of new column on form
*
* @return void
*/
function PMA_indexTypeSelectionDialog(source_array, index_type, col_index)
function PMA_indexTypeSelectionDialog(source_array, index_choice, col_index)
{
var $single_column_radio = $('<input type="radio" id="single_column" name="index_type"' +
var $single_column_radio = $('<input type="radio" id="single_column" name="index_choice"' +
' checked="checked">' +
'<label for="single_column">' + PMA_messages.strCreateSingleColumnIndex + '</label>');
var $composite_index_radio = $('<input type="radio" id="composite_index"' +
' name="index_type">' +
' name="index_choice">' +
'<label for="composite_index">' + PMA_messages.strCreateCompositeIndex + '</label>');
var $dialog_content = $('<fieldset id="advance_index_creator"></fieldset>');
$dialog_content.append('<legend>' + index_type.toUpperCase() + '</legend>');
$dialog_content.append('<legend>' + index_choice.toUpperCase() + '</legend>');
// For UNIQUE/INDEX type, show choice for single-column and composite index.
@ -380,8 +391,8 @@ function PMA_indexTypeSelectionDialog(source_array, index_type, col_index)
button_options[PMA_messages.strGo] = function () {
if ($('#single_column').is(':checked')) {
var index = {
'Key_name': (index_type == 'primary' ? 'PRIMARY' : ''),
'Index_type': index_type.toUpperCase()
'Key_name': (index_choice == 'primary' ? 'PRIMARY' : ''),
'Index_choice': index_choice.toUpperCase()
};
PMA_showAddIndexDialog(source_array, (source_array.length), [col_index], col_index, index);
}
@ -458,7 +469,7 @@ function PMA_indexTypeSelectionDialog(source_array, index_type, col_index)
* Unbind all event handlers before tearing down a page
*/
AJAX.registerTeardown('indexes.js', function () {
$(document).off('change', '#select_index_type');
$(document).off('change', '#select_index_choice');
$(document).off('click', 'a.drop_primary_key_index_anchor.ajax');
$(document).off('click', "#table_index tbody tr td.edit_index.ajax, #indexes .add_index.ajax");
$(document).off('click', '#index_frm input[type=submit]');
@ -483,7 +494,7 @@ AJAX.registerOnload('indexes.js', function () {
checkIndexType();
checkIndexName("index_frm");
$(document).on('change', '#select_index_type', function (event) {
$(document).on('change', '#select_index_choice', function (event) {
event.preventDefault();
checkIndexType();
checkIndexName("index_frm");
@ -596,19 +607,19 @@ AJAX.registerOnload('indexes.js', function () {
// Index of column on Table edit and create page.
var col_index = /\d/.exec($(this).attr('name'));
col_index = col_index[0];
// Type of selected index.
var index_type = /[a-z]+/.exec($(this).val());
index_type = index_type[0];
// Choice of selected index.
var index_choice = /[a-z]+/.exec($(this).val());
index_choice = index_choice[0];
// Array containing corresponding indexes.
var source_array = null;
if (index_type == 'none') {
if (index_choice == 'none') {
PMA_removeColumnFromIndex(col_index);
return false;
}
// Select a source array.
switch (index_type) {
switch (index_choice) {
case 'primary':
source_array = primary_indexes;
break;
@ -625,12 +636,12 @@ AJAX.registerOnload('indexes.js', function () {
if (source_array.length === 0) {
var index = {
'Key_name': (index_type == 'primary' ? 'PRIMARY' : ''),
'Index_type': index_type.toUpperCase()
'Key_name': (index_choice == 'primary' ? 'PRIMARY' : ''),
'Index_choice': index_choice.toUpperCase()
};
PMA_showAddIndexDialog(source_array, 0, [col_index], col_index, index);
} else {
if (index_type == 'primary') {
if (index_choice == 'primary') {
var array_index = 0;
var source_length = source_array[array_index].columns.length;
var target_columns = [];
@ -643,7 +654,7 @@ AJAX.registerOnload('indexes.js', function () {
source_array[array_index]);
} else {
// If there are multiple columns selected for an index, show advanced dialog.
PMA_indexTypeSelectionDialog(source_array, index_type, col_index);
PMA_indexTypeSelectionDialog(source_array, index_choice, col_index);
}
}
});

View File

@ -47,7 +47,7 @@ class PMA_Index
private $_columns = array();
/**
* The index method used (BTREE, SPATIAL, FULLTEXT, HASH, RTREE).
* The index method used (BTREE, HASH, RTREE).
*
* @var string
*/
@ -290,16 +290,22 @@ class PMA_Index
if (isset($params['Packed'])) {
$this->_packed = $params['Packed'];
}
if ('PRIMARY' == $this->_name) {
$this->_choice = 'PRIMARY';
} elseif ('FULLTEXT' == $this->_type) {
$this->_choice = 'FULLTEXT';
} elseif ('SPATIAL' == $this->_type) {
$this->_choice = 'SPATIAL';
} elseif ('0' == $this->_non_unique) {
$this->_choice = 'UNIQUE';
if (isset($params['Index_choice'])) {
$this->_choice = $params['Index_choice'];
} else {
$this->_choice = 'INDEX';
if ('PRIMARY' == $this->_name) {
$this->_choice = 'PRIMARY';
} elseif ('FULLTEXT' == $this->_type) {
$this->_choice = 'FULLTEXT';
$this->_type = '';
} elseif ('SPATIAL' == $this->_type) {
$this->_choice = 'SPATIAL';
$this->_type = '';
} elseif ('0' == $this->_non_unique) {
$this->_choice = 'UNIQUE';
} else {
$this->_choice = 'INDEX';
}
}
}
@ -350,7 +356,7 @@ class PMA_Index
}
/**
* Returns index type ((BTREE, SPATIAL, FULLTEXT, HASH, RTREE)
* Returns index type (BTREE, HASH, RTREE)
*
* @return string index type
*/
@ -385,14 +391,31 @@ class PMA_Index
);
}
/**
* Returns a lit of all index types
*
* @return string[] index types
*/
static public function getIndexTypes()
{
return array(
'BTREE',
'HASH'
);
}
/**
* Returns HTML for the index choice selector
*
* @param boolean $edit_table whether this is table editing
*
* @return string HTML for the index choice selector
*/
public function generateIndexSelector()
public function generateIndexChoiceSelector($edit_table)
{
$html_options = '';
$html_options = '<select name="index[Index_choice]"'
. ' id="select_index_choice" '
. ($edit_table ? 'disabled="disabled"' : '') . '>';
foreach (PMA_Index::getIndexChoices() as $each_index_choice) {
if ($each_index_choice === 'PRIMARY'
@ -408,10 +431,29 @@ class PMA_Index
: '')
. '>' . $each_index_choice . '</option>' . "\n";
}
$html_options .= '</select>';
return $html_options;
}
/**
* Returns HTML for the index type selector
*
* @return string HTML for the index type selector
*/
public function generateIndexTypeSelector()
{
$types = array("" => "--");
foreach (PMA_Index::getIndexTypes() as $type) {
$types[$type] = $type;
}
return PMA_Util::getDropdown(
"index[Index_type]", $types,
$this->_type, "select_index_type"
);
}
/**
* Returns how the index is packed
*
@ -637,9 +679,13 @@ class PMA_Index
. htmlspecialchars($index->getName())
. '</td>';
}
$r .= '<td ' . $row_span . '>'
. htmlspecialchars($index->getType())
. '</td>';
$r .= '<td ' . $row_span . '>';
if (! empty($index->getType())) {
$r .= htmlspecialchars($index->getType());
} else {
$r .= htmlspecialchars($index->getChoice());
}
$r .= '</td>';
$r .= '<td ' . $row_span . '>' . $index->isUnique(true) . '</td>';
$r .= '<td ' . $row_span . '>' . $index->isPacked(true) . '</td>';
@ -691,7 +737,7 @@ class PMA_Index
$data = array(
// 'Non_unique' => $this->_non_unique,
'Packed' => $this->_packed,
'Index_type' => $this->_type,
'Index_choice' => $this->_choice,
);
foreach ($this->_columns as $column) {

View File

@ -121,14 +121,14 @@ function PMA_setColumnCreationStatementSuffix($current_field_num,
* Create relevant index statements
*
* @param array $index an array of index columns
* @param string $index_type index type that which represents
* @param string $index_choice index choice that which represents
* the index type of $indexed_fields
* @param boolean $is_create_tbl true if requirement is to get the statement
* for table creation
*
* @return array an array of sql statements for indexes
*/
function PMA_buildIndexStatements($index, $index_type,
function PMA_buildIndexStatements($index, $index_choice,
$is_create_tbl = true
) {
$statement = array();
@ -143,7 +143,7 @@ function PMA_buildIndexStatements($index, $index_type,
. (! empty($field['size']) ? '(' . $field['size'] . ')' : '');
}
$statement[] = PMA_getStatementPrefix($is_create_tbl)
. ' ' . $index_type
. ' ' . $index_choice
. (! empty($index['Key_name']) && $index['Key_name'] != 'PRIMARY' ?
PMA_Util::backquote($index['Key_name'])
: '')

View File

@ -109,7 +109,7 @@ function PMA_getSqlQueryForIndexCreateOrEdit($db, $table, $index, &$error)
} // end if
// Builds the new one
switch ($index->getType()) {
switch ($index->getChoice()) {
case 'PRIMARY':
if ($index->getName() == '') {
$index->setName('PRIMARY');
@ -127,7 +127,7 @@ function PMA_getSqlQueryForIndexCreateOrEdit($db, $table, $index, &$error)
if ($index->getName() == 'PRIMARY') {
$error = PMA_Message::error(__('Can\'t rename index to PRIMARY!'));
}
$sql_query .= ' ADD ' . $index->getType() . ' '
$sql_query .= ' ADD ' . $index->getChoice() . ' '
. ($index->getName() ? PMA_Util::backquote($index->getName()) : '');
break;
} // end switch
@ -146,6 +146,14 @@ function PMA_getSqlQueryForIndexCreateOrEdit($db, $table, $index, &$error)
$sql_query .= ' (' . implode(', ', $index_fields) . ')';
}
// specifying index type is allowed only for primary, unique and index only
if ($index->getChoice() != 'SPATIAL'
&& $index->getChoice() != 'FULLTEXT'
&& in_array($index->getType(), PMA_Index::getIndexTypes())
) {
$sql_query .= ' USING ' . $index->getType();
}
$sql_query .= " COMMENT '"
. PMA_Util::sqlAddSlashes($index->getComment())
. "'";
@ -292,6 +300,18 @@ function PMA_getHtmlForIndexForm($fields, $index, $form_params, $add_fields)
. 'onfocus="this.select()" />'
. '</div>';
$html .= '<div>'
. '<div class="label">'
. '<strong>'
. '<label for="select_index_choice">'
. __('Index choice:')
. PMA_Util::showMySQLDocu('ALTER_TABLE')
. '</label>'
. '</strong>'
. '</div>'
. $index->generateIndexChoiceSelector(isset($_REQUEST['create_edit_table']))
. '</div>';
$html .= '<div>'
. '<div class="label">'
. '<strong>'
@ -301,10 +321,7 @@ function PMA_getHtmlForIndexForm($fields, $index, $form_params, $add_fields)
. '</label>'
. '</strong>'
. '</div>'
. '<select name="index[Index_type]" id="select_index_type" '
. (isset($_REQUEST['create_edit_table']) ? 'disabled="disabled"' : '') . '>'
. $index->generateIndexSelector()
. '</select>'
. $index->generateIndexTypeSelector()
. '</div>';
$html .= '<div class="clearfloat"></div>';
@ -336,9 +353,9 @@ function PMA_getHtmlForIndexForm($fields, $index, $form_params, $add_fields)
$html .= '<select name="index[columns][names][]">';
$html .= '<option value="">-- ' . __('Ignore') . ' --</option>';
foreach ($fields as $field_name => $field_type) {
if (($index->getType() != 'FULLTEXT'
if (($index->getChoice() != 'FULLTEXT'
|| preg_match('/(char|text)/i', $field_type))
&& ($index->getType() != 'SPATIAL'
&& ($index->getChoice() != 'SPATIAL'
|| in_array($field_type, $spatial_types))
) {
$html .= '<option value="' . htmlspecialchars($field_name) . '"'
@ -355,7 +372,7 @@ function PMA_getHtmlForIndexForm($fields, $index, $form_params, $add_fields)
$html .= '<td>';
$html .= '<input type="text" size="5" onfocus="this.select()"'
. 'name="index[columns][sub_parts][]" value="';
if ($index->getType() != 'SPATIAL') {
if ($index->getChoice() != 'SPATIAL') {
$html .= $column->getSubPart();
}
$html .= '"/>';

View File

@ -971,7 +971,7 @@ function PMA_getHtmlForIndex($index, $style)
$html = '<tr class="noclick ' . $style . '">';
$html .= '<td><b>' . htmlspecialchars($index['Key_name']) . '</b></td>';
$html .= '<td>' . htmlspecialchars($index['Index_type']) . '</td>';
$html .= '<td>' . htmlspecialchars($index['Index_choice']) . '</td>';
$html .= '<td>' . $str_unique . '</td>';
$html .= '<td>' . $str_packed . '</td>';
$html .= '<td>' . htmlspecialchars($index['Column_name']) . '</td>';

View File

@ -42,7 +42,7 @@ $form_params = PMA_getFormParameters($db, $table);
if (isset($_REQUEST['create_edit_table'])) {
$fields = json_decode($_REQUEST['columns'], true);
$index_params = array(
'Non_unique' => ($_REQUEST['index']['Index_type'] == 'UNIQUE') ? '0' : '1'
'Non_unique' => ($_REQUEST['index']['Index_choice'] == 'UNIQUE') ? '0' : '1'
);
$index->set($index_params);
$add_fields = count($fields);

View File

@ -31,7 +31,7 @@ class PMA_Index_Test extends PHPUnit_Framework_TestCase
$this->_params['Schema'] = "PMA_Schema";
$this->_params['Table'] = "PMA_Table";
$this->_params['Key_name'] = "PMA_Key_name";
$this->_params['Index_type'] = "PMA_Index_type";
$this->_params['Index_choice'] = "PMA_Index_choice";
$this->_params['Comment'] = "PMA_Comment";
$this->_params['Index_comment'] = "PMA_Index_comment";
$this->_params['Non_unique'] = "PMA_Non_unique";
@ -72,8 +72,8 @@ class PMA_Index_Test extends PHPUnit_Framework_TestCase
$index->getRemarks()
);
$this->assertEquals(
'PMA_Index_type',
$index->getType()
'PMA_Index_choice',
$index->getChoice()
);
$this->assertEquals(
'PMA_Packed',

View File

@ -97,7 +97,7 @@ class PMA_TblIndexTest extends PHPUnit_Framework_TestCase
);
$this->assertEquals(
"ALTER TABLE `pma_db`.`pma_table` DROP PRIMARY KEY, COMMENT '';",
"ALTER TABLE `pma_db`.`pma_table` DROP PRIMARY KEY, ADD UNIQUE COMMENT '';",
$sql
);
}
@ -241,7 +241,7 @@ class PMA_TblIndexTest extends PHPUnit_Framework_TestCase
//generateIndexSelector
$this->assertContains(
$index->generateIndexSelector(),
$index->generateIndexChoiceSelector(),
$html
);

View File

@ -777,7 +777,7 @@ class PMA_TblTrackingTest extends PHPUnit_Framework_TestCase
'Non_unique' => 0,
'Packed' => '',
'Key_name' => 'Key_name1',
'Index_type' => 'Index_type1',
'Index_choice' => 'Index_choice1',
'Column_name' => 'Column_name',
'Cardinality' => 'Cardinality',
'Collation' => 'Collation',
@ -822,7 +822,7 @@ class PMA_TblTrackingTest extends PHPUnit_Framework_TestCase
$html
);
$this->assertContains(
htmlspecialchars($indexs[0]['Index_type']),
htmlspecialchars($indexs[0]['Index_choice']),
$html
);
$this->assertContains(