652
heap = mem_heap_create(1024);
654
652
/* In case MySQL calls this in the middle of a SELECT query, release
655
653
possible adaptive hash latch to avoid deadlocks of threads. */
656
654
trx_search_latch_release_if_reserved(prebuilt->trx);
657
trx_start_if_not_started(prebuilt->trx);
659
/* Create a background transaction for the operations on
660
the data dictionary tables. */
661
trx = innobase_trx_allocate(user_thd);
662
trx_start_if_not_started(trx);
656
/* Check if the index name is reserved. */
657
if (innobase_index_name_is_reserved(user_thd, key_info, num_of_keys)) {
664
661
innodb_table = indexed_table
665
662
= dict_table_get(prebuilt->table->name, FALSE);
667
664
if (UNIV_UNLIKELY(!innodb_table)) {
668
error = HA_ERR_NO_SUCH_TABLE;
665
DBUG_RETURN(HA_ERR_NO_SUCH_TABLE);
672
/* Check if the index name is reserved. */
673
if (innobase_index_name_is_reserved(trx, key_info, num_of_keys)) {
676
/* Check that index keys are sensible */
677
error = innobase_check_index_keys(key_info, num_of_keys,
668
/* Check that index keys are sensible */
669
error = innobase_check_index_keys(key_info, num_of_keys, innodb_table);
681
671
if (UNIV_UNLIKELY(error)) {
684
trx_general_rollback_for_mysql(trx, NULL);
685
trx_free_for_mysql(trx);
686
trx_commit_for_mysql(prebuilt->trx);
687
672
DBUG_RETURN(error);
675
heap = mem_heap_create(1024);
676
trx_start_if_not_started(prebuilt->trx);
678
/* Create a background transaction for the operations on
679
the data dictionary tables. */
680
trx = innobase_trx_allocate(user_thd);
681
trx_start_if_not_started(trx);
690
683
/* Create table containing all indexes to be built in this
691
684
alter table add index so that they are in the correct order
759
752
ut_d(dict_table_check_for_dup_indexes(innodb_table,
755
trx_general_rollback_for_mysql(trx, NULL);
761
756
row_mysql_unlock_data_dictionary(trx);
757
trx_free_for_mysql(trx);
758
trx_commit_for_mysql(prebuilt->trx);
765
762
trx->table_id = indexed_table->id;
783
780
ut_ad(error == DB_SUCCESS);
785
/* We will need to rebuild index translation table. Set
786
valid index entry count in the translation table to zero */
787
share->idx_trans_tbl.index_count = 0;
789
782
/* Commit the data dictionary transaction in order to release
790
783
the table locks on the system tables. This means that if
791
784
MySQL crashes while creating a new primary key inside
907
if (error == DB_SUCCESS) {
908
/* Build index is successful. We will need to
909
rebuild index translation table. Reset the
910
index entry count in the translation table
911
to zero, so that translation table will be rebuilt */
912
share->idx_trans_tbl.index_count = 0;
914
915
error = convert_error_code_to_mysql(error,
915
916
innodb_table->flags,
1012
1013
index->to_be_dropped = TRUE;
1015
/* If FOREIGN_KEY_CHECK = 1 you may not drop an index defined
1016
/* If FOREIGN_KEY_CHECKS = 1 you may not drop an index defined
1016
1017
for a foreign key constraint because InnoDB requires that both
1017
tables contain indexes for the constraint. Note that CREATE
1018
INDEX id ON table does a CREATE INDEX and DROP INDEX, and we
1019
can ignore here foreign keys because a new index for the
1020
foreign key has already been created.
1018
tables contain indexes for the constraint. Such index can
1019
be dropped only if FOREIGN_KEY_CHECKS is set to 0.
1020
Note that CREATE INDEX id ON table does a CREATE INDEX and
1021
DROP INDEX, and we can ignore here foreign keys because a
1022
new index for the foreign key has already been created.
1022
1024
We check for the foreign key constraints after marking the
1023
1025
candidate indexes for deletion, because when we check for an