~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to plugin/innobase/handler/handler0alter.cc

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-11-12 12:26:01 UTC
  • mfrom: (1.1.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20101112122601-myppfj3tfmlkccuq
Tags: upstream-2010.11.03
ImportĀ upstreamĀ versionĀ 2010.11.03

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
12
 
13
13
You should have received a copy of the GNU General Public License along with
14
 
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15
 
Place, Suite 330, Boston, MA 02111-1307 USA
 
14
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
 
15
St, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
*****************************************************************************/
18
18
 
129
129
}
130
130
 
131
131
/*************************************************************//**
132
 
Copies an InnoDB record to table->record[0]. */
 
132
Copies an InnoDB record to table->getInsertRecord(). */
133
133
extern "C" UNIV_INTERN
134
134
void
135
135
innobase_rec_to_mysql(
140
140
        const ulint*            offsets)        /*!< in: rec_get_offsets(
141
141
                                                rec, index, ...) */
142
142
{
143
 
        uint    n_fields        = table->s->fields;
 
143
        uint    n_fields        = table->getShare()->sizeFields();
144
144
        uint    i;
145
145
 
146
146
        ut_ad(n_fields == dict_table_get_n_user_cols(index->table));
147
147
 
148
148
        for (i = 0; i < n_fields; i++) {
149
 
                Field*          field   = table->field[i];
 
149
                Field*          field   = table->getField(i);
150
150
                ulint           ipos;
151
151
                ulint           ilen;
152
152
                const unsigned char*    ifield;
179
179
}
180
180
 
181
181
/*************************************************************//**
182
 
Resets table->record[0]. */
 
182
Resets table->getInsertRecord(). */
183
183
extern "C" UNIV_INTERN
184
184
void
185
185
innobase_rec_reset(
186
186
/*===============*/
187
187
        Table*                  table)          /*!< in/out: MySQL table */
188
188
{
189
 
        uint    n_fields        = table->s->fields;
 
189
        uint    n_fields        = table->getShare()->sizeFields();
190
190
        uint    i;
191
191
 
192
192
        for (i = 0; i < n_fields; i++) {
193
 
                table->field[i]->set_default();
 
193
                table->getField(i)->set_default();
194
194
        }
195
195
}
196
196
 
 
197
#if 0 // This is a part of the fast index code.
197
198
/******************************************************************//**
198
199
Removes the filename encoding of a database and table name. */
199
200
static
221
222
        }
222
223
}
223
224
 
 
225
 
224
226
/*******************************************************************//**
225
227
This function checks that index keys are sensible.
226
228
@return 0 or error number */
228
230
int
229
231
innobase_check_index_keys(
230
232
/*======================*/
231
 
        const KEY*      key_info,       /*!< in: Indexes to be created */
 
233
        const KeyInfo*  key_info,       /*!< in: Indexes to be created */
232
234
        ulint           num_of_keys)    /*!< in: Number of indexes to
233
235
                                        be created */
234
236
{
238
240
        ut_ad(num_of_keys);
239
241
 
240
242
        for (key_num = 0; key_num < num_of_keys; key_num++) {
241
 
                const KEY&      key = key_info[key_num];
 
243
                const KeyInfo&  key = key_info[key_num];
242
244
 
243
245
                /* Check that the same index name does not appear
244
246
                twice in indexes to be created. */
245
247
 
246
248
                for (ulint i = 0; i < key_num; i++) {
247
 
                        const KEY&      key2 = key_info[i];
 
249
                        const KeyInfo&  key2 = key_info[i];
248
250
 
249
251
                        if (0 == strcmp(key.name, key2.name)) {
250
252
                                errmsg_printf(ERRMSG_LVL_ERROR, "InnoDB: key name `%s` appears"
260
262
                that the same colum does not appear twice in the index. */
261
263
 
262
264
                for (ulint i = 0; i < key.key_parts; i++) {
263
 
                        const KEY_PART_INFO&    key_part1
 
265
                        const KeyPartInfo&      key_part1
264
266
                                = key.key_part[i];
265
267
                        const Field*            field
266
268
                                = key_part1.field;
300
302
                        }
301
303
 
302
304
                        for (ulint j = 0; j < i; j++) {
303
 
                                const KEY_PART_INFO&    key_part2
 
305
                                const KeyPartInfo&      key_part2
304
306
                                        = key.key_part[j];
305
307
 
306
308
                                if (strcmp(key_part1.field->field_name,
327
329
void
328
330
innobase_create_index_field_def(
329
331
/*============================*/
330
 
        KEY_PART_INFO*          key_part,       /*!< in: MySQL key definition */
 
332
        KeyPartInfo*            key_part,       /*!< in: MySQL key definition */
331
333
        mem_heap_t*             heap,           /*!< in: memory heap */
332
334
        merge_index_field_t*    index_field)    /*!< out: index field
333
335
                                                definition for key_part */
367
369
void
368
370
innobase_create_index_def(
369
371
/*======================*/
370
 
        KEY*                    key,            /*!< in: key definition */
 
372
        KeyInfo*                        key,            /*!< in: key definition */
371
373
        bool                    new_primary,    /*!< in: TRUE=generating
372
374
                                                a new primary key
373
375
                                                on the table */
484
486
 
485
487
 
486
488
@return key definitions or NULL */
 
489
 
487
490
static
488
491
merge_index_def_t*
489
492
innobase_create_key_def(
492
495
        const dict_table_t*table,               /*!< in: table definition */
493
496
        mem_heap_t*     heap,           /*!< in: heap where space for key
494
497
                                        definitions are allocated */
495
 
        KEY*            key_info,       /*!< in: Indexes to be created */
 
498
        KeyInfo*                key_info,       /*!< in: Indexes to be created */
496
499
        ulint&          n_keys)         /*!< in/out: Number of indexes to
497
500
                                        be created */
498
501
{
596
599
        return(name);
597
600
}
598
601
 
 
602
 
599
603
/*******************************************************************//**
600
604
Create indexes.
601
605
@return 0 or error number */
603
607
int
604
608
ha_innobase::add_index(
605
609
/*===================*/
 
610
                       Session *session,
606
611
        Table*  i_table,        /*!< in: Table where indexes are created */
607
 
        KEY*    key_info,       /*!< in: Indexes to be created */
 
612
        KeyInfo*        key_info,       /*!< in: Indexes to be created */
608
613
        uint    num_of_keys)    /*!< in: Number of indexes to be created */
609
614
{
610
615
        dict_index_t**  index;          /*!< Index to be created */
617
622
        ulint           num_created     = 0;
618
623
        ibool           dict_locked     = FALSE;
619
624
        ulint           new_primary;
620
 
        ulint           error;
 
625
        int             error;
621
626
 
622
627
        ut_a(i_table);
623
628
        ut_a(key_info);
627
632
                return(HA_ERR_WRONG_COMMAND);
628
633
        }
629
634
 
630
 
        update_session();
 
635
        update_session(session);
631
636
 
632
637
        heap = mem_heap_create(1024);
633
638
 
644
649
        innodb_table = indexed_table
645
650
                = dict_table_get(prebuilt->table->name, FALSE);
646
651
 
647
 
        /* Check that index keys are sensible */
648
 
 
649
 
        error = innobase_check_index_keys(key_info, num_of_keys);
 
652
        /* Check if the index name is reserved. */
 
653
        if (innobase_index_name_is_reserved(trx, key_info, num_of_keys)) {
 
654
                error = -1;
 
655
        } else {
 
656
                /* Check that index keys are sensible */
 
657
                error = innobase_check_index_keys(key_info, num_of_keys);
 
658
        }
650
659
 
651
660
        if (UNIV_UNLIKELY(error)) {
652
661
err_exit:
653
662
                mem_heap_free(heap);
654
 
                trx_general_rollback_for_mysql(trx, FALSE, NULL);
 
663
                trx_general_rollback_for_mysql(trx, NULL);
655
664
                trx_free_for_mysql(trx);
656
665
                trx_commit_for_mysql(prebuilt->trx);
657
666
                return(error);
749
758
        ut_ad(error == DB_SUCCESS);
750
759
 
751
760
        /* Commit the data dictionary transaction in order to release
752
 
        the table locks on the system tables.  Unfortunately, this
753
 
        means that if MySQL crashes while creating a new primary key
754
 
        inside row_merge_build_indexes(), indexed_table will not be
755
 
        dropped on crash recovery.  Thus, it will become orphaned. */
 
761
        the table locks on the system tables.  This means that if
 
762
        MySQL crashes while creating a new primary key inside
 
763
        row_merge_build_indexes(), indexed_table will not be dropped
 
764
        by trx_rollback_active().  It will have to be recovered or
 
765
        dropped by the database administrator. */
756
766
        trx_commit_for_mysql(trx);
757
767
 
758
768
        row_mysql_unlock_data_dictionary(trx);
851
861
                indexed_table->n_mysql_handles_opened++;
852
862
 
853
863
                error = row_merge_drop_table(trx, innodb_table);
 
864
                innodb_table = indexed_table;
854
865
                goto convert_error;
855
866
 
856
867
        case DB_TOO_BIG_RECORD:
865
876
                /* fall through */
866
877
        default:
867
878
                if (new_primary) {
868
 
                        row_merge_drop_table(trx, indexed_table);
 
879
                        if (indexed_table != innodb_table) {
 
880
                                row_merge_drop_table(trx, indexed_table);
 
881
                        }
869
882
                } else {
870
883
                        if (!dict_locked) {
871
884
                                row_mysql_lock_data_dictionary(trx);
907
920
int
908
921
ha_innobase::prepare_drop_index(
909
922
/*============================*/
 
923
                                Session *session,
910
924
        Table*  i_table,        /*!< in: Table where indexes are dropped */
911
925
        uint*   key_num,        /*!< in: Key nums to be dropped */
912
926
        uint    num_of_keys)    /*!< in: Number of keys to be dropped */
922
936
                return(HA_ERR_WRONG_COMMAND);
923
937
        }
924
938
 
925
 
        update_session();
 
939
        update_session(session);
926
940
 
927
941
        trx_search_latch_release_if_reserved(prebuilt->trx);
928
942
        trx = prebuilt->trx;
943
957
        }
944
958
 
945
959
        for (n_key = 0; n_key < num_of_keys; n_key++) {
946
 
                const KEY*      key;
 
960
                const KeyInfo*  key;
947
961
                dict_index_t*   index;
948
962
 
949
963
                key = i_table->key_info + key_num[n_key];
1107
1121
int
1108
1122
ha_innobase::final_drop_index(
1109
1123
/*==========================*/
 
1124
                              Session *session,
1110
1125
        Table*  )               /*!< in: Table where indexes are dropped */
1111
1126
{
1112
1127
        dict_index_t*   index;          /*!< Index to be dropped */
1117
1132
                return(HA_ERR_WRONG_COMMAND);
1118
1133
        }
1119
1134
 
1120
 
        update_session();
 
1135
        update_session(session);
1121
1136
 
1122
1137
        trx_search_latch_release_if_reserved(prebuilt->trx);
1123
1138
        trx_start_if_not_started(prebuilt->trx);
1198
1213
 
1199
1214
        return(err);
1200
1215
}
 
1216
#endif