Skip to content

Commit

Permalink
[ticket/10327] Change CREATE INDEX to ALTER TABLE table ADD INDEX for…
Browse files Browse the repository at this point in the history
… MySQL.

* CREATE INDEX is internally mapped to an ALTER INDEX statement.
* CREATE INDEX requires the INDEX permission.
* ALTER TABLE requires the (more powerful) ALTER permission.
* We require the ALTER permission anyway for operation.
* Changing CREATE INDEX to ALTER TABLE thus removes dependency on the INDEX
  permission which is good because some management software does not give
  out the INDEX permission by default.

http://dev.mysql.com/doc/refman/5.0/en/create-index.html

PHPBB3-10327
  • Loading branch information
bantu committed Oct 14, 2011
1 parent 4e69fe6 commit d86fccf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion phpBB/includes/db/db_tools.php
Expand Up @@ -2145,7 +2145,7 @@ function sql_create_index($table_name, $index_name, $column)
}
// no break
case 'mysql_41':
$statements[] = 'CREATE INDEX ' . $index_name . ' ON ' . $table_name . '(' . implode(', ', $column) . ')';
$statements[] = 'ALTER TABLE ' . $table_name . ' ADD INDEX ' . $index_name . '(' . implode(', ', $column) . ')';
break;

case 'mssql':
Expand Down
18 changes: 18 additions & 0 deletions tests/dbal/db_tools_test.php
Expand Up @@ -333,4 +333,22 @@ public function test_peform_schema_changes_drop_columns()
),
));
}

public function test_index_exists()
{
$db_tools = new phpbb_db_tools($this->db);

$this->assertTrue($db_tools->sql_index_exists('prefix_table_name', 'i_simple'));
}

public function test_create_index_against_index_exists()
{
$db_tools = new phpbb_db_tools($this->db);

$table_name = 'prefix_table_name';
$index_name = 'fookey';

$db_tools->sql_create_index($table_name, $index_name, array('c_timestamp', 'c_decimal'));
$this->assertTrue($db_tools->sql_index_exists($table_name, $index_name));
}
}

0 comments on commit d86fccf

Please sign in to comment.