@@ -77,8 +77,7 @@ static int copy_data_between_tables(THD *, TABLE *,TABLE *,
77
77
ha_rows *, ha_rows *,
78
78
Alter_info::enum_enable_or_disable,
79
79
Alter_table_ctx *);
80
- static int append_system_key_parts (THD *thd, HA_CREATE_INFO *create_info,
81
- Key *key);
80
+ static int append_system_key_parts (THD *, HA_CREATE_INFO *, Key *);
82
81
static int mysql_prepare_create_table (THD *, HA_CREATE_INFO *, Alter_info *,
83
82
uint *, handler *, KEY **, uint *, int ,
84
83
const LEX_CSTRING db,
@@ -396,8 +395,7 @@ uint filename_to_tablename(const char *from, char *to, size_t to_length,
396
395
system_charset_info, to, to_length, &errors);
397
396
if (unlikely (errors)) // Old 5.0 name
398
397
{
399
- res= (strxnmov (to, to_length, MYSQL50_TABLE_NAME_PREFIX, from, NullS) -
400
- to);
398
+ res= strxnmov (to, to_length, MYSQL50_TABLE_NAME_PREFIX, from, NullS) - to;
401
399
if (!stay_quiet)
402
400
sql_print_error (" Invalid (old?) table or database name '%s'" , from);
403
401
}
@@ -3578,6 +3576,7 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
3578
3576
const Column_derived_attributes dattr (create_info->default_table_charset );
3579
3577
const Column_bulk_alter_attributes
3580
3578
battr (create_info->alter_table_convert_to_charset );
3579
+ const CHARSET_INFO *scs= system_charset_info;
3581
3580
DBUG_ENTER (" mysql_prepare_create_table" );
3582
3581
3583
3582
DBUG_EXECUTE_IF (" test_pseudo_invisible" ,{
@@ -3591,23 +3590,17 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
3591
3590
new (thd->mem_root )Item_int (thd, 9 ));
3592
3591
});
3593
3592
DBUG_EXECUTE_IF (" test_invisible_index" ,{
3594
- LEX_CSTRING temp;
3595
- temp.str = " invisible" ;
3596
- temp.length = strlen (" invisible" );
3597
- mysql_add_invisible_index (thd, &alter_info->key_list
3598
- , &temp, Key::MULTIPLE);
3593
+ LEX_CSTRING temp= { STRING_WITH_LEN (" invisible" ) };
3594
+ mysql_add_invisible_index (thd, &alter_info->key_list , &temp,
3595
+ Key::MULTIPLE);
3599
3596
});
3600
- LEX_CSTRING* connect_string = &create_info->connect_string ;
3601
- if (connect_string->length != 0 &&
3602
- connect_string->length > CONNECT_STRING_MAXLEN &&
3603
- (system_charset_info->charpos (connect_string->str ,
3604
- (connect_string->str +
3605
- connect_string->length ),
3606
- CONNECT_STRING_MAXLEN)
3607
- < connect_string->length ))
3608
- {
3609
- my_error (ER_WRONG_STRING_LENGTH, MYF (0 ),
3610
- connect_string->str , " CONNECTION" , CONNECT_STRING_MAXLEN);
3597
+ LEX_CSTRING* connstr = &create_info->connect_string ;
3598
+ if (connstr->length > CONNECT_STRING_MAXLEN &&
3599
+ scs->charpos (connstr->str , connstr->str + connstr->length ,
3600
+ CONNECT_STRING_MAXLEN) < connstr->length )
3601
+ {
3602
+ my_error (ER_WRONG_STRING_LENGTH, MYF (0 ), connstr->str , " CONNECTION" ,
3603
+ CONNECT_STRING_MAXLEN);
3611
3604
DBUG_RETURN (TRUE );
3612
3605
}
3613
3606
@@ -3670,9 +3663,7 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
3670
3663
/* Check if we have used the same field name before */
3671
3664
for (dup_no=0 ; (dup_field=it2++) != sql_field; dup_no++)
3672
3665
{
3673
- if (lex_string_cmp (system_charset_info,
3674
- &sql_field->field_name ,
3675
- &dup_field->field_name ) == 0 )
3666
+ if (lex_string_cmp (scs, &sql_field->field_name , &dup_field->field_name ) == 0 )
3676
3667
{
3677
3668
/*
3678
3669
If this was a CREATE ... SELECT statement, accept a field
@@ -3852,7 +3843,6 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
3852
3843
key2->name .str != ignore_key &&
3853
3844
!foreign_key_prefix (key, key2)))
3854
3845
{
3855
- /* TODO: issue warning message */
3856
3846
/* mark that the generated key should be ignored */
3857
3847
if (!key2->generated ||
3858
3848
(key->generated && key->columns .elements <
@@ -3873,13 +3863,13 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
3873
3863
else
3874
3864
(*key_count)--;
3875
3865
if (key->name .str && !tmp_table && (key->type != Key::PRIMARY) &&
3876
- !my_strcasecmp (system_charset_info , key->name .str , primary_key_name))
3866
+ !my_strcasecmp (scs , key->name .str , primary_key_name))
3877
3867
{
3878
3868
my_error (ER_WRONG_NAME_FOR_INDEX, MYF (0 ), key->name .str );
3879
3869
DBUG_RETURN (TRUE );
3880
3870
}
3881
3871
if (key->type == Key::PRIMARY && key->name .str &&
3882
- my_strcasecmp (system_charset_info , key->name .str , primary_key_name) != 0 )
3872
+ my_strcasecmp (scs , key->name .str , primary_key_name) != 0 )
3883
3873
{
3884
3874
bool sav_abort_on_warning= thd->abort_on_warning ;
3885
3875
thd->abort_on_warning = FALSE ; /* Don't make an error out of this. */
@@ -3917,9 +3907,7 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
3917
3907
auto field_name= key->columns .elem (0 )->field_name ;
3918
3908
it.rewind ();
3919
3909
while ((sql_field=it++) &&
3920
- lex_string_cmp (system_charset_info,
3921
- &field_name,
3922
- &sql_field->field_name ));
3910
+ lex_string_cmp (scs, &field_name, &sql_field->field_name ));
3923
3911
if (sql_field)
3924
3912
field_name= sql_field->field_name ;
3925
3913
key_name=make_unique_key_name (thd, field_name.str ,
@@ -4092,9 +4080,7 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
4092
4080
it.rewind ();
4093
4081
field=0 ;
4094
4082
while ((sql_field=it++) &&
4095
- lex_string_cmp (system_charset_info,
4096
- &column->field_name ,
4097
- &sql_field->field_name ))
4083
+ lex_string_cmp (scs, &column->field_name , &sql_field->field_name ))
4098
4084
field++;
4099
4085
/*
4100
4086
Either field is not present or field visibility is > INVISIBLE_USER
@@ -4114,8 +4100,7 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
4114
4100
}
4115
4101
while ((dup_column= cols2++) != column)
4116
4102
{
4117
- if (!lex_string_cmp (system_charset_info,
4118
- &column->field_name , &dup_column->field_name ))
4103
+ if (!lex_string_cmp (scs, &column->field_name , &dup_column->field_name ))
4119
4104
{
4120
4105
my_error (ER_DUP_FIELDNAME, MYF (0 ), column->field_name .str );
4121
4106
DBUG_RETURN (TRUE );
@@ -4418,8 +4403,7 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
4418
4403
{
4419
4404
for (Key_part_spec& kp2: fk->columns )
4420
4405
{
4421
- if (!lex_string_cmp (system_charset_info, &kp.field_name ,
4422
- &kp2.field_name ))
4406
+ if (!lex_string_cmp (scs, &kp.field_name , &kp2.field_name ))
4423
4407
{
4424
4408
goto without_overlaps_err;
4425
4409
}
@@ -4530,28 +4514,28 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
4530
4514
if (create_simple)
4531
4515
{
4532
4516
/*
4533
- NOTE: we cannot do this in check_vcol_func_processor() as there is already
4534
- no table name qualifier in expression.
4517
+ NOTE: we cannot do this in check_vcol_func_processor() as there is
4518
+ already no table name qualifier in expression.
4535
4519
*/
4536
4520
if (sql_field->vcol_info && sql_field->vcol_info ->expr &&
4537
4521
sql_field->vcol_info ->expr ->walk (&Item::check_table_name_processor,
4538
- false , ( void *) &walk_prm))
4522
+ false , &walk_prm))
4539
4523
{
4540
4524
my_error (ER_BAD_FIELD_ERROR, MYF (0 ), walk_prm.field .c_ptr (), " GENERATED ALWAYS" );
4541
4525
DBUG_RETURN (TRUE );
4542
4526
}
4543
4527
4544
4528
if (sql_field->default_value &&
4545
4529
sql_field->default_value ->expr ->walk (&Item::check_table_name_processor,
4546
- false , ( void *) &walk_prm))
4530
+ false , &walk_prm))
4547
4531
{
4548
4532
my_error (ER_BAD_FIELD_ERROR, MYF (0 ), walk_prm.field .c_ptr (), " DEFAULT" );
4549
4533
DBUG_RETURN (TRUE );
4550
4534
}
4551
4535
4552
4536
if (sql_field->check_constraint &&
4553
4537
sql_field->check_constraint ->expr ->walk (&Item::check_table_name_processor,
4554
- false , ( void *) &walk_prm))
4538
+ false , &walk_prm))
4555
4539
{
4556
4540
my_error (ER_BAD_FIELD_ERROR, MYF (0 ), walk_prm.field .c_ptr (), " CHECK" );
4557
4541
DBUG_RETURN (TRUE );
@@ -4563,65 +4547,51 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
4563
4547
create_info->check_constraint_list = &alter_info->check_constraint_list ;
4564
4548
{
4565
4549
List_iterator_fast<Virtual_column_info> c_it (alter_info->check_constraint_list );
4566
- Virtual_column_info *check;
4567
- while ((check= c_it++))
4550
+ while (Virtual_column_info *check= c_it++)
4568
4551
{
4569
- if (create_simple && check->expr ->walk (&Item::check_table_name_processor, false ,
4570
- ( void *) &walk_prm))
4552
+ if (create_simple && check->expr ->walk (&Item::check_table_name_processor,
4553
+ false , &walk_prm))
4571
4554
{
4572
4555
my_error (ER_BAD_FIELD_ERROR, MYF (0 ), walk_prm.field .c_ptr (), " CHECK" );
4573
4556
DBUG_RETURN (TRUE );
4574
4557
}
4575
- if (!check->name .length || check->automatic_name )
4576
- {
4577
- if (check_expression (check, &check->name , VCOL_CHECK_TABLE, alter_info))
4578
- DBUG_RETURN (TRUE );
4579
- continue ;
4580
- }
4581
-
4558
+ if (check->name .length && !check->automatic_name )
4582
4559
{
4583
4560
/* Check that there's no repeating table CHECK constraint names. */
4584
4561
List_iterator_fast<Virtual_column_info>
4585
4562
dup_it (alter_info->check_constraint_list );
4586
4563
const Virtual_column_info *dup_check;
4587
4564
while ((dup_check= dup_it++) && dup_check != check)
4588
4565
{
4589
- if (!lex_string_cmp (system_charset_info,
4590
- &check->name , &dup_check->name ))
4566
+ if (check->name .streq (dup_check->name ))
4591
4567
{
4592
4568
my_error (ER_DUP_CONSTRAINT_NAME, MYF (0 ), " CHECK" , check->name .str );
4593
4569
DBUG_RETURN (TRUE );
4594
4570
}
4595
4571
}
4596
- }
4597
4572
4598
- /* Check that there's no repeating key constraint names. */
4599
- List_iterator_fast<Key> key_it (alter_info->key_list );
4600
- while (const Key *key= key_it++)
4601
- {
4602
- /*
4603
- Not all keys considered to be the CONSTRAINT
4604
- Noly Primary Key UNIQUE and Foreign keys.
4605
- */
4606
- if (key->type != Key::PRIMARY && key->type != Key::UNIQUE &&
4607
- key->type != Key::FOREIGN_KEY)
4608
- continue ;
4573
+ /* Check that there's no repeating key constraint names. */
4574
+ List_iterator_fast<Key> key_it (alter_info->key_list );
4575
+ while (const Key *key= key_it++)
4576
+ {
4577
+ if (key->type != Key::PRIMARY && key->type != Key::UNIQUE &&
4578
+ key->type != Key::FOREIGN_KEY)
4579
+ continue ;
4609
4580
4610
- if (check->name .length == key->name .length &&
4611
- my_strcasecmp (system_charset_info,
4612
- check->name .str , key->name .str ) == 0 )
4581
+ if (check->name .length == key->name .length &&
4582
+ my_strcasecmp (scs, check->name .str , key->name .str ) == 0 )
4583
+ {
4584
+ my_error (ER_DUP_CONSTRAINT_NAME, MYF (0 ), " CHECK" , check->name .str );
4585
+ DBUG_RETURN (TRUE );
4586
+ }
4587
+ }
4588
+
4589
+ if (check_string_char_length (&check->name , 0 , NAME_CHAR_LEN, scs, 1 ))
4613
4590
{
4614
- my_error (ER_DUP_CONSTRAINT_NAME , MYF (0 ), " CHECK " , check->name .str );
4591
+ my_error (ER_TOO_LONG_IDENT , MYF (0 ), check->name .str );
4615
4592
DBUG_RETURN (TRUE );
4616
4593
}
4617
4594
}
4618
-
4619
- if (check_string_char_length (&check->name , 0 , NAME_CHAR_LEN,
4620
- system_charset_info, 1 ))
4621
- {
4622
- my_error (ER_TOO_LONG_IDENT, MYF (0 ), check->name .str );
4623
- DBUG_RETURN (TRUE );
4624
- }
4625
4595
if (check_expression (check, &check->name , VCOL_CHECK_TABLE, alter_info))
4626
4596
DBUG_RETURN (TRUE );
4627
4597
}
@@ -4644,12 +4614,10 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
4644
4614
thd->mem_root ))
4645
4615
DBUG_RETURN (TRUE );
4646
4616
4647
- #ifndef DBUG_OFF
4648
4617
DBUG_EXECUTE_IF (" key" ,
4649
4618
Debug_key::print_keys (thd, " prep_create_table: " ,
4650
4619
*key_info_buffer, *key_count);
4651
4620
);
4652
- #endif
4653
4621
4654
4622
DBUG_RETURN (FALSE );
4655
4623
}
@@ -7736,10 +7704,8 @@ static void update_altered_table(const Alter_inplace_info &ha_alter_info,
7736
7704
@retval false success
7737
7705
*/
7738
7706
7739
- bool mysql_compare_tables (TABLE *table,
7740
- Alter_info *alter_info,
7741
- HA_CREATE_INFO *create_info,
7742
- bool *metadata_equal)
7707
+ bool mysql_compare_tables (TABLE *table, Alter_info *alter_info,
7708
+ HA_CREATE_INFO *create_info, bool *metadata_equal)
7743
7709
{
7744
7710
DBUG_ENTER (" mysql_compare_tables" );
7745
7711
@@ -7764,15 +7730,14 @@ bool mysql_compare_tables(TABLE *table,
7764
7730
Alter_info tmp_alter_info (*alter_info, thd->mem_root );
7765
7731
uint db_options= 0 ; /* not used */
7766
7732
KEY *key_info_buffer= NULL ;
7767
- LEX_CSTRING db= { table->s ->db .str , table->s ->db .length };
7768
- LEX_CSTRING table_name= { table->s ->db .str , table->s ->table_name .length };
7769
7733
7770
7734
/* Create the prepared information. */
7771
7735
int create_table_mode= table->s ->tmp_table == NO_TMP_TABLE ?
7772
7736
C_ORDINARY_CREATE : C_ALTER_TABLE;
7773
7737
if (mysql_prepare_create_table (thd, create_info, &tmp_alter_info,
7774
7738
&db_options, table->file , &key_info_buffer,
7775
- &key_count, create_table_mode, db, table_name))
7739
+ &key_count, create_table_mode,
7740
+ table->s ->db , table->s ->table_name ))
7776
7741
DBUG_RETURN (1 );
7777
7742
7778
7743
/* Some very basic checks. */
@@ -9205,7 +9170,7 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
9205
9170
tmp_name.length = strlen (key_name);
9206
9171
/* We dont need LONG_UNIQUE_HASH_FIELD flag because it will be autogenerated */
9207
9172
key= new (thd->mem_root ) Key (key_type, &tmp_name, &key_create_info,
9208
- MY_TEST ( key_info->flags & HA_GENERATED_KEY) ,
9173
+ key_info->flags & HA_GENERATED_KEY,
9209
9174
&key_parts, key_info->option_list , DDL_options ());
9210
9175
key->without_overlaps = key_info->without_overlaps ;
9211
9176
key->period = table->s ->period .name ;
@@ -10798,10 +10763,9 @@ do_continue:;
10798
10763
*/
10799
10764
error= create_table_impl (thd, alter_ctx.db , alter_ctx.table_name ,
10800
10765
alter_ctx.new_db , alter_ctx.tmp_name ,
10801
- alter_ctx.get_tmp_path (),
10802
- thd->lex ->create_info , create_info, alter_info,
10803
- C_ALTER_TABLE_FRM_ONLY, NULL ,
10804
- &key_info, &key_count, &frm);
10766
+ alter_ctx.get_tmp_path (), thd->lex ->create_info ,
10767
+ create_info, alter_info, C_ALTER_TABLE_FRM_ONLY,
10768
+ NULL , &key_info, &key_count, &frm);
10805
10769
thd->abort_on_warning = false ;
10806
10770
reenable_binlog (thd);
10807
10771
if (unlikely (error))
0 commit comments