@@ -226,6 +226,24 @@ handlerton innobase_hton = {
226
226
innobase_close_cursor_view,
227
227
HTON_NO_FLAGS
228
228
};
229
+ /* **********************************************************************
230
+ This function checks each index name for a table against reserved
231
+ system default primary index name 'GEN_CLUST_INDEX'. If a name matches,
232
+ this function pushes an error message to the client, and returns true. */
233
+ static
234
+ bool
235
+ innobase_index_name_is_reserved (
236
+ /* ============================*/
237
+ /* out: true if index name matches a
238
+ reserved name */
239
+ const trx_t * trx, /* in: InnoDB transaction handle */
240
+ const TABLE* form, /* in: information on table
241
+ columns and indexes */
242
+ const char * norm_name); /* in: table name */
243
+
244
+ /* "GEN_CLUST_INDEX" is the name reserved for Innodb default
245
+ system primary index. */
246
+ static const char innobase_index_reserve_name[]= " GEN_CLUST_INDEX" ;
229
247
230
248
/* ********************************************************************
231
249
Commits a transaction in an InnoDB database. */
@@ -4496,7 +4514,10 @@ create_index(
4496
4514
4497
4515
n_fields = key->key_parts ;
4498
4516
4499
- ind_type = 0 ;
4517
+ /* Assert that "GEN_CLUST_INDEX" cannot be used as non-primary index */
4518
+ ut_a (innobase_strcasecmp (key->name , innobase_index_reserve_name) != 0 );
4519
+
4520
+ ind_type = 0 ;
4500
4521
4501
4522
if (key_num == form->s ->primary_key ) {
4502
4523
ind_type = ind_type | DICT_CLUSTERED;
@@ -4606,9 +4627,8 @@ create_clustered_index_when_no_primary(
4606
4627
4607
4628
/* We pass 0 as the space id, and determine at a lower level the space
4608
4629
id where to store the table */
4609
-
4610
- index = dict_mem_index_create ((char *) table_name,
4611
- (char *) " GEN_CLUST_INDEX" ,
4630
+ index = dict_mem_index_create (table_name,
4631
+ innobase_index_reserve_name,
4612
4632
0 , DICT_CLUSTERED, 0 );
4613
4633
error = row_create_index_for_mysql (index, trx, NULL );
4614
4634
@@ -4706,16 +4726,6 @@ ha_innobase::create(
4706
4726
4707
4727
row_mysql_lock_data_dictionary (trx);
4708
4728
4709
- /* Create the table definition in InnoDB */
4710
-
4711
- error = create_table_def (trx, form, norm_name,
4712
- create_info->options & HA_LEX_CREATE_TMP_TABLE ? name2 : NULL ,
4713
- form->s ->row_type != ROW_TYPE_REDUNDANT);
4714
-
4715
- if (error) {
4716
- goto cleanup;
4717
- }
4718
-
4719
4729
/* Look for a primary key */
4720
4730
4721
4731
primary_key_no= (table->s ->primary_key != MAX_KEY ?
@@ -4727,6 +4737,23 @@ ha_innobase::create(
4727
4737
4728
4738
DBUG_ASSERT (primary_key_no == -1 || primary_key_no == 0 );
4729
4739
4740
+ /* Check for name conflicts (with reserved name) for
4741
+ any user indices to be created. */
4742
+ if (innobase_index_name_is_reserved (trx, form, norm_name)) {
4743
+ error = -1 ;
4744
+ goto cleanup;
4745
+ }
4746
+
4747
+ /* Create the table definition in InnoDB */
4748
+ error = create_table_def (trx, form, norm_name,
4749
+ create_info->options & HA_LEX_CREATE_TMP_TABLE ? name2 : NULL ,
4750
+ form->s ->row_type != ROW_TYPE_REDUNDANT);
4751
+
4752
+ if (error) {
4753
+ goto cleanup;
4754
+ }
4755
+
4756
+
4730
4757
/* Create the keys */
4731
4758
4732
4759
if (form->s ->keys == 0 || primary_key_no == -1 ) {
@@ -7431,4 +7458,43 @@ innobase_set_cursor_view(
7431
7458
(cursor_view_t *) curview);
7432
7459
}
7433
7460
7461
+ /* **********************************************************************
7462
+ This function checks each index name for a table against reserved
7463
+ system default primary index name 'GEN_CLUST_INDEX'. If a name matches,
7464
+ this function pushes an error message to the client, and returns true. */
7465
+ static
7466
+ bool
7467
+ innobase_index_name_is_reserved (
7468
+ /* ============================*/
7469
+ /* out: true if an index name
7470
+ matches the reserved name */
7471
+ const trx_t * trx, /* in: InnoDB transaction handle */
7472
+ const TABLE* form, /* in: information on table
7473
+ columns and indexes */
7474
+ const char * norm_name) /* in: table name */
7475
+ {
7476
+ KEY* key;
7477
+ uint key_num; /* index number */
7478
+
7479
+ for (key_num = 0 ; key_num < form->s ->keys ; key_num++) {
7480
+ key = form->key_info + key_num;
7481
+
7482
+ if (innobase_strcasecmp (key->name ,
7483
+ innobase_index_reserve_name) == 0 ) {
7484
+ /* Push warning to mysql */
7485
+ push_warning_printf ((THD*) trx->mysql_thd ,
7486
+ MYSQL_ERROR::WARN_LEVEL_WARN,
7487
+ ER_CANT_CREATE_TABLE,
7488
+ " Cannot Create Index with name "
7489
+ " '%s'. The name is reserved "
7490
+ " for the system default primary "
7491
+ " index." ,
7492
+ innobase_index_reserve_name);
7493
+
7494
+ return (true );
7495
+ }
7496
+ }
7497
+
7498
+ return (false );
7499
+ }
7434
7500
#endif /* HAVE_INNOBASE_DB */
0 commit comments