Skip to content

Commit

Permalink
Merge branch 'index'
Browse files Browse the repository at this point in the history
  • Loading branch information
madhuracj committed Jan 28, 2015
2 parents 0733b08 + acee15b commit 94dd60d
Show file tree
Hide file tree
Showing 11 changed files with 145 additions and 70 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions js/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
71 changes: 41 additions & 30 deletions js/indexes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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 () {
Expand Down Expand Up @@ -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));
}
}

Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand All @@ -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);
}
Expand Down Expand Up @@ -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]');
Expand All @@ -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");
Expand Down Expand Up @@ -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;
Expand All @@ -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 = [];
Expand All @@ -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);
}
}
});
Expand Down
80 changes: 63 additions & 17 deletions libraries/Index.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -290,16 +290,22 @@ public function set($params)
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';
}
}
}

Expand Down Expand Up @@ -350,7 +356,7 @@ public function getComments()
}

/**
* Returns index type ((BTREE, SPATIAL, FULLTEXT, HASH, RTREE)
* Returns index type (BTREE, HASH, RTREE)
*
* @return string index type
*/
Expand Down Expand Up @@ -385,14 +391,31 @@ static public function getIndexChoices()
);
}

/**
* 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'
Expand All @@ -408,10 +431,29 @@ public function generateIndexSelector()
: '')
. '>' . $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
*
Expand Down Expand Up @@ -637,9 +679,13 @@ static public function getView($table, $schema, $print_mode = false)
. 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>';

Expand Down Expand Up @@ -691,7 +737,7 @@ public function getCompareData()
$data = array(
// 'Non_unique' => $this->_non_unique,
'Packed' => $this->_packed,
'Index_type' => $this->_type,
'Index_choice' => $this->_choice,
);

foreach ($this->_columns as $column) {
Expand Down
6 changes: 3 additions & 3 deletions libraries/create_addfield.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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'])
: '')
Expand Down
Loading

0 comments on commit 94dd60d

Please sign in to comment.