~ubuntu-branches/ubuntu/maverick/mysql-5.1/maverick-proposed

« back to all changes in this revision

Viewing changes to storage/innodb_plugin/handler/handler0alter.cc

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2012-02-22 14:16:05 UTC
  • mto: This revision was merged to the branch mainline in revision 20.
  • Revision ID: package-import@ubuntu.com-20120222141605-nxlu9yzc6attylc2
Tags: upstream-5.1.61
ImportĀ upstreamĀ versionĀ 5.1.61

Show diffs side-by-side

added added

removed removed

Lines of Context:
649
649
 
650
650
        update_thd();
651
651
 
652
 
        heap = mem_heap_create(1024);
653
 
 
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);
658
655
 
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)) {
 
658
                DBUG_RETURN(-1);
 
659
        }
663
660
 
664
661
        innodb_table = indexed_table
665
662
                = dict_table_get(prebuilt->table->name, FALSE);
666
663
 
667
664
        if (UNIV_UNLIKELY(!innodb_table)) {
668
 
                error = HA_ERR_NO_SUCH_TABLE;
669
 
                goto err_exit;
 
665
                DBUG_RETURN(HA_ERR_NO_SUCH_TABLE);
670
666
        }
671
667
 
672
 
        /* Check if the index name is reserved. */
673
 
        if (innobase_index_name_is_reserved(trx, key_info, num_of_keys)) {
674
 
                error = -1;
675
 
        } else {
676
 
                /* Check that index keys are sensible */
677
 
                error = innobase_check_index_keys(key_info, num_of_keys,
678
 
                                                  innodb_table);
679
 
        }
 
668
        /* Check that index keys are sensible */
 
669
        error = innobase_check_index_keys(key_info, num_of_keys, innodb_table);
680
670
 
681
671
        if (UNIV_UNLIKELY(error)) {
682
 
err_exit:
683
 
                mem_heap_free(heap);
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);
688
673
        }
689
674
 
 
675
        heap = mem_heap_create(1024);
 
676
        trx_start_if_not_started(prebuilt->trx);
 
677
 
 
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);
 
682
 
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
692
685
        in the table. */
758
751
 
759
752
                        ut_d(dict_table_check_for_dup_indexes(innodb_table,
760
753
                                                              FALSE));
 
754
                        mem_heap_free(heap);
 
755
                        trx_general_rollback_for_mysql(trx, NULL);
761
756
                        row_mysql_unlock_data_dictionary(trx);
762
 
                        goto err_exit;
 
757
                        trx_free_for_mysql(trx);
 
758
                        trx_commit_for_mysql(prebuilt->trx);
 
759
                        DBUG_RETURN(error);
763
760
                }
764
761
 
765
762
                trx->table_id = indexed_table->id;
782
779
 
783
780
        ut_ad(error == DB_SUCCESS);
784
781
 
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;
788
 
 
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
911
904
                }
912
905
 
913
906
convert_error:
 
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;
 
913
                }
 
914
 
914
915
                error = convert_error_code_to_mysql(error,
915
916
                                                    innodb_table->flags,
916
917
                                                    user_thd);
1012
1013
                index->to_be_dropped = TRUE;
1013
1014
        }
1014
1015
 
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.
1021
1023
 
1022
1024
        We check for the foreign key constraints after marking the
1023
1025
        candidate indexes for deletion, because when we check for an