~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_table.cc

  • Committer: Monty Taylor
  • Date: 2008-08-18 23:04:17 UTC
  • mfrom: (327.1.12 drizzle)
  • Revision ID: monty@inaugust.com-20080818230417-442rhihpahnout34
MergedĀ fromĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 
28
28
static bool check_if_keyname_exists(const char *name,KEY *start, KEY *end);
29
29
static char *make_unique_key_name(const char *field_name,KEY *start,KEY *end);
30
 
static int copy_data_between_tables(TABLE *from,TABLE *to,
 
30
static int copy_data_between_tables(Table *from,Table *to,
31
31
                                    List<Create_field> &create, bool ignore,
32
32
                                    uint order_num, ORDER *order,
33
33
                                    ha_rows *copied,ha_rows *deleted,
44
44
                               handler *file, KEY **key_info_buffer,
45
45
                               uint *key_count, int select_field_count);
46
46
static bool
47
 
mysql_prepare_alter_table(THD *thd, TABLE *table,
 
47
mysql_prepare_alter_table(THD *thd, Table *table,
48
48
                          HA_CREATE_INFO *create_info,
49
49
                          Alter_info *alter_info);
50
50
 
143
143
    'db' is always converted.
144
144
    'ext' is not converted.
145
145
 
146
 
    The conversion suppression is required for ALTER TABLE. This
 
146
    The conversion suppression is required for ALTER Table. This
147
147
    statement creates intermediate tables. These are regular
148
148
    (non-temporary) tables with a temporary name. Their path names must
149
149
    be derivable from the table name. So we cannot use
355
355
  {
356
356
    built_query.set_charset(system_charset_info);
357
357
    if (if_exists)
358
 
      built_query.append("DROP TABLE IF EXISTS ");
 
358
      built_query.append("DROP Table IF EXISTS ");
359
359
    else
360
 
      built_query.append("DROP TABLE ");
 
360
      built_query.append("DROP Table ");
361
361
  }
362
362
 
363
363
  mysql_ha_rm_tables(thd, tables, false);
437
437
    table_type= table->db_type;
438
438
    if (!drop_temporary)
439
439
    {
440
 
      TABLE *locked_table;
 
440
      Table *locked_table;
441
441
      abort_locked_tables(thd, db, table->table_name);
442
442
      remove_table_from_cache(thd, db, table->table_name,
443
443
                              RTFC_WAIT_OTHER_THREAD_FLAG |
462
462
    }
463
463
    if (drop_temporary ||
464
464
        ((table_type == NULL && (access(path, F_OK) && ha_create_table_from_engine(thd, db, alias))) ||
465
 
         (!drop_view && mysql_frm_type(thd, path, &frm_db_type) != FRMTYPE_TABLE)))
 
465
         (!drop_view && mysql_frm_type(thd, path, &frm_db_type) != true)))
466
466
    {
467
467
      // Table was not found on disk and table can't be created from engine
468
468
      if (if_exists)
912
912
    if (!sql_field->charset)
913
913
      sql_field->charset= create_info->default_table_charset;
914
914
    /*
915
 
      table_charset is set in ALTER TABLE if we want change character set
 
915
      table_charset is set in ALTER Table if we want change character set
916
916
      for all varchar/char columns.
917
917
      But the table charset must not affect the BLOB fields, so don't
918
918
      allow to change my_charset_bin to somethig else.
1687
1687
    fields              List of fields to create
1688
1688
    keys                List of keys to create
1689
1689
    internal_tmp_table  Set to 1 if this is an internal temporary table
1690
 
                        (From ALTER TABLE)
 
1690
                        (From ALTER Table)
1691
1691
    select_field_count  
1692
1692
 
1693
1693
  DESCRIPTION
1931
1931
                        bool internal_tmp_table,
1932
1932
                        uint select_field_count)
1933
1933
{
1934
 
  TABLE *name_lock= 0;
 
1934
  Table *name_lock= 0;
1935
1935
  bool result;
1936
1936
 
1937
1937
  /* Wait for any database locks */
2114
2114
  }
2115
2115
  delete file;
2116
2116
  if (error == HA_ERR_WRONG_COMMAND)
2117
 
    my_error(ER_NOT_SUPPORTED_YET, MYF(0), "ALTER TABLE");
 
2117
    my_error(ER_NOT_SUPPORTED_YET, MYF(0), "ALTER Table");
2118
2118
  else if (error)
2119
2119
    my_error(ER_ERROR_ON_RENAME, MYF(0), from, to, error);
2120
2120
  return(error != 0);
2140
2140
    Win32 clients must also have a WRITE LOCK on the table !
2141
2141
*/
2142
2142
 
2143
 
void wait_while_table_is_used(THD *thd, TABLE *table,
 
2143
void wait_while_table_is_used(THD *thd, Table *table,
2144
2144
                              enum ha_extra_function function)
2145
2145
{
2146
2146
 
2174
2174
    Win32 clients must also have a WRITE LOCK on the table !
2175
2175
*/
2176
2176
 
2177
 
void close_cached_table(THD *thd, TABLE *table)
 
2177
void close_cached_table(THD *thd, Table *table)
2178
2178
{
2179
2179
 
2180
2180
  wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN);
2213
2213
                              HA_CHECK_OPT *check_opt)
2214
2214
{
2215
2215
  int error= 0;
2216
 
  TABLE tmp_table, *table;
 
2216
  Table tmp_table, *table;
2217
2217
  TABLE_SHARE *share;
2218
2218
  char from[FN_REFLEN],tmp[FN_REFLEN+32];
2219
2219
  const char **ext;
2247
2247
  }
2248
2248
 
2249
2249
  /*
2250
 
    REPAIR TABLE ... USE_FRM for temporary tables makes little sense.
 
2250
    REPAIR Table ... USE_FRM for temporary tables makes little sense.
2251
2251
  */
2252
2252
  if (table->s->tmp_table)
2253
2253
  {
2423
2423
      lex->query_tables_last= &table->next_global;
2424
2424
      lex->query_tables_own_last= 0;
2425
2425
      thd->no_warnings_for_error= no_warnings_for_error;
2426
 
      table->required_type=FRMTYPE_TABLE;
2427
2426
 
2428
2427
      open_and_lock_tables(thd, table);
2429
2428
      thd->no_warnings_for_error= 0;
2450
2449
    }
2451
2450
 
2452
2451
    /*
2453
 
      CHECK TABLE command is only command where VIEW allowed here and this
 
2452
      CHECK Table command is only command where VIEW allowed here and this
2454
2453
      command use only temporary teble method for VIEWs resolving => there
2455
2454
      can't be VIEW tree substitition of join view => if opening table
2456
 
      succeed then table->table will have real TABLE pointer as value (in
 
2455
      succeed then table->table will have real Table pointer as value (in
2457
2456
      case of join view substitution table->table can be 0, but here it is
2458
2457
      impossible)
2459
2458
    */
2633
2632
    {
2634
2633
      /*
2635
2634
        This is currently used only by InnoDB. ha_innobase::optimize() answers
2636
 
        "try with alter", so here we close the table, do an ALTER TABLE,
 
2635
        "try with alter", so here we close the table, do an ALTER Table,
2637
2636
        reopen the table and do ha_innobase::analyze() on it.
2638
2637
      */
2639
2638
      ha_autocommit_or_rollback(thd, 0);
2914
2913
bool mysql_create_like_table(THD* thd, TABLE_LIST* table, TABLE_LIST* src_table,
2915
2914
                             HA_CREATE_INFO *create_info)
2916
2915
{
2917
 
  TABLE *name_lock= 0;
 
2916
  Table *name_lock= 0;
2918
2917
  char src_path[FN_REFLEN], dst_path[FN_REFLEN];
2919
2918
  uint dst_path_length;
2920
2919
  char *db= table->db;
2923
2922
  bool res= true;
2924
2923
  uint not_used;
2925
2924
 
2926
 
 
2927
 
  /* CREATE TABLE ... LIKE is not allowed for views. */
2928
 
  src_table->required_type= FRMTYPE_TABLE;
2929
 
 
2930
2925
  /*
2931
2926
    By opening source table we guarantee that it exists and no concurrent
2932
2927
    DDL operation will mess with it. Later we also take an exclusive
3138
3133
                                   TABLE_LIST *table_list,
3139
3134
                                   enum tablespace_op_type tablespace_op)
3140
3135
{
3141
 
  TABLE *table;
 
3136
  Table *table;
3142
3137
  bool discard;
3143
3138
  int error;
3144
3139
 
3145
3140
  /*
3146
3141
    Note that DISCARD/IMPORT TABLESPACE always is the only operation in an
3147
 
    ALTER TABLE
 
3142
    ALTER Table
3148
3143
  */
3149
3144
 
3150
3145
  thd_proc_info(thd, "discard_or_import_tablespace");
3169
3164
  if (error)
3170
3165
    goto err;
3171
3166
 
3172
 
  /* The ALTER TABLE is always in its own transaction */
 
3167
  /* The ALTER Table is always in its own transaction */
3173
3168
  error = ha_autocommit_or_rollback(thd, 0);
3174
3169
  if (end_active_trans(thd))
3175
3170
    error=1;
3243
3238
   table has in arguments create_list, key_list and create_info.
3244
3239
 
3245
3240
   By comparing the changes between the original and new table
3246
 
   we can determine how much it has changed after ALTER TABLE
 
3241
   we can determine how much it has changed after ALTER Table
3247
3242
   and whether we need to make a copy of the table, or just change
3248
3243
   the .frm file.
3249
3244
 
3261
3256
static
3262
3257
bool
3263
3258
compare_tables(THD *thd,
3264
 
               TABLE *table,
 
3259
               Table *table,
3265
3260
               Alter_info *alter_info,
3266
3261
                           HA_CREATE_INFO *create_info,
3267
3262
               uint order_num,
3294
3289
      like to keep compare_tables() idempotent (not altering any
3295
3290
      of the arguments) we create a copy of alter_info here and
3296
3291
      pass it to mysql_prepare_create_table, then use the result
3297
 
      to evaluate possibility of fast ALTER TABLE, and then
 
3292
      to evaluate possibility of fast ALTER Table, and then
3298
3293
      destroy the copy.
3299
3294
    */
3300
3295
    Alter_info tmp_alter_info(*alter_info, thd->mem_root);
3327
3322
 
3328
3323
  /*
3329
3324
    Some very basic checks. If number of fields changes, or the
3330
 
    handler, we need to run full ALTER TABLE. In the future
 
3325
    handler, we need to run full ALTER Table. In the future
3331
3326
    new fields can be added and old dropped without copy, but
3332
3327
    not yet.
3333
3328
 
3334
 
    Test also that engine was not given during ALTER TABLE, or
 
3329
    Test also that engine was not given during ALTER Table, or
3335
3330
    we are force to run regular alter table (copy).
3336
 
    E.g. ALTER TABLE tbl_name ENGINE=MyISAM.
 
3331
    E.g. ALTER Table tbl_name ENGINE=MyISAM.
3337
3332
 
3338
3333
    For the following ones we also want to run regular alter table:
3339
 
    ALTER TABLE tbl_name ORDER BY ..
3340
 
    ALTER TABLE tbl_name CONVERT TO CHARACTER SET ..
 
3334
    ALTER Table tbl_name ORDER BY ..
 
3335
    ALTER Table tbl_name CONVERT TO CHARACTER SET ..
3341
3336
 
3342
3337
    At the moment we can't handle altering temporary tables without a copy.
3343
 
    We also test if OPTIMIZE TABLE was given and was mapped to alter table.
 
3338
    We also test if OPTIMIZE Table was given and was mapped to alter table.
3344
3339
    In that case we always do full copy.
3345
3340
 
3346
3341
    There was a bug prior to mysql-4.0.25. Number of null fields was
3608
3603
 
3609
3604
 
3610
3605
/*
3611
 
  Manages enabling/disabling of indexes for ALTER TABLE
 
3606
  Manages enabling/disabling of indexes for ALTER Table
3612
3607
 
3613
3608
  SYNOPSIS
3614
3609
    alter_table_manage_keys()
3623
3618
*/
3624
3619
 
3625
3620
static
3626
 
bool alter_table_manage_keys(TABLE *table, int indexes_were_disabled,
 
3621
bool alter_table_manage_keys(Table *table, int indexes_were_disabled,
3627
3622
                             enum enum_enable_or_disable keys_onoff)
3628
3623
{
3629
3624
  int error= 0;
3652
3647
}
3653
3648
 
3654
3649
int create_temporary_table(THD *thd,
3655
 
                           TABLE *table,
 
3650
                           Table *table,
3656
3651
                           char *new_db,
3657
3652
                           char *tmp_name,
3658
3653
                           HA_CREATE_INFO *create_info,
3743
3738
    The temporary table is created without storing it in any storage engine
3744
3739
    and is opened only to get the table struct and frm file reference.
3745
3740
*/
3746
 
TABLE *create_altered_table(THD *thd,
3747
 
                            TABLE *table,
 
3741
Table *create_altered_table(THD *thd,
 
3742
                            Table *table,
3748
3743
                            char *new_db,
3749
3744
                            HA_CREATE_INFO *create_info,
3750
3745
                            Alter_info *alter_info,
3752
3747
{
3753
3748
  int error;
3754
3749
  HA_CREATE_INFO altered_create_info(*create_info);
3755
 
  TABLE *altered_table;
 
3750
  Table *altered_table;
3756
3751
  char tmp_name[80];
3757
3752
  char path[FN_REFLEN];
3758
3753
 
3806
3801
    the table.
3807
3802
*/
3808
3803
int mysql_fast_or_online_alter_table(THD *thd,
3809
 
                                     TABLE *table,
3810
 
                                     TABLE *altered_table,
 
3804
                                     Table *table,
 
3805
                                     Table *altered_table,
3811
3806
                                     HA_CREATE_INFO *create_info,
3812
3807
                                     HA_ALTER_INFO *alter_info,
3813
3808
                                     HA_ALTER_FLAGS *ha_alter_flags,
3815
3810
{
3816
3811
  int error= 0;
3817
3812
  bool online= (table->file->ha_table_flags() & HA_ONLINE_ALTER)?true:false;
3818
 
  TABLE *t_table;
 
3813
  Table *t_table;
3819
3814
 
3820
3815
  if (online)
3821
3816
  {
3871
3866
  VOID(pthread_mutex_unlock(&LOCK_open));
3872
3867
 
3873
3868
  /*
3874
 
    The ALTER TABLE is always in its own transaction.
 
3869
    The ALTER Table is always in its own transaction.
3875
3870
    Commit must not be called while LOCK_open is locked. It could call
3876
3871
    wait_if_global_read_lock(), which could create a deadlock if called
3877
3872
    with LOCK_open.
3904
3899
 
3905
3900
    /*
3906
3901
      We are going to reopen table down on the road, so we have to restore
3907
 
      state of the TABLE object which we used for obtaining of handler
 
3902
      state of the Table object which we used for obtaining of handler
3908
3903
      object to make it suitable for reopening.
3909
3904
    */
3910
3905
    assert(t_table == table);
3922
3917
 
3923
3918
 
3924
3919
/**
3925
 
  Prepare column and key definitions for CREATE TABLE in ALTER TABLE.
 
3920
  Prepare column and key definitions for CREATE TABLE in ALTER Table.
3926
3921
 
3927
 
  This function transforms parse output of ALTER TABLE - lists of
 
3922
  This function transforms parse output of ALTER Table - lists of
3928
3923
  columns and keys to add, drop or modify into, essentially,
3929
3924
  CREATE TABLE definition - a list of columns and keys of the new
3930
3925
  table. While doing so, it also performs some (bug not all)
3931
3926
  semantic checks.
3932
3927
 
3933
3928
  This function is invoked when we know that we're going to
3934
 
  perform ALTER TABLE via a temporary table -- i.e. fast ALTER TABLE
 
3929
  perform ALTER Table via a temporary table -- i.e. fast ALTER Table
3935
3930
  is not possible, perhaps because the ALTER statement contains
3936
3931
  instructions that require change in table data, not only in
3937
3932
  table definition or indexes.
3942
3937
                              Used as an interface to the storage engine
3943
3938
                              to acquire additional information about
3944
3939
                              the original table.
3945
 
  @param[in,out]  create_info A blob with CREATE/ALTER TABLE
 
3940
  @param[in,out]  create_info A blob with CREATE/ALTER Table
3946
3941
                              parameters
3947
3942
  @param[in,out]  alter_info  Another blob with ALTER/CREATE parameters.
3948
3943
                              Originally create_info was used only in
3949
 
                              CREATE TABLE and alter_info only in ALTER TABLE.
 
3944
                              CREATE TABLE and alter_info only in ALTER Table.
3950
3945
                              But since ALTER might end-up doing CREATE,
3951
3946
                              this distinction is gone and we just carry
3952
3947
                              around two structures.
3958
3953
    Prepares alter_info->create_list and alter_info->key_list with
3959
3954
    columns and keys of the new table.
3960
3955
  @retval true   error, out of memory or a semantical error in ALTER
3961
 
                 TABLE instructions
 
3956
                 Table instructions
3962
3957
  @retval false  success
3963
3958
*/
3964
3959
 
3965
3960
static bool
3966
 
mysql_prepare_alter_table(THD *thd, TABLE *table,
 
3961
mysql_prepare_alter_table(THD *thd, Table *table,
3967
3962
                          HA_CREATE_INFO *create_info,
3968
3963
                          Alter_info *alter_info)
3969
3964
{
4100
4095
      either has a default value or the '0000-00-00' is allowed by the
4101
4096
      set sql mode.
4102
4097
      If the '0000-00-00' value isn't allowed then raise the error_if_not_empty
4103
 
      flag to allow ALTER TABLE only if the table to be altered is empty.
 
4098
      flag to allow ALTER Table only if the table to be altered is empty.
4104
4099
      */
4105
4100
    if ((def->sql_type == DRIZZLE_TYPE_NEWDATE ||
4106
4101
         def->sql_type == DRIZZLE_TYPE_DATETIME) &&
4132
4127
      find_it.after(def);                       // Put element after this
4133
4128
      /*
4134
4129
        XXX: hack for Bug#28427.
4135
 
        If column order has changed, force OFFLINE ALTER TABLE
 
4130
        If column order has changed, force OFFLINE ALTER Table
4136
4131
        without querying engine capabilities.  If we ever have an
4137
 
        engine that supports online ALTER TABLE CHANGE COLUMN
 
4132
        engine that supports online ALTER Table CHANGE COLUMN
4138
4133
        <name> AFTER <name1> (Falcon?), this fix will effectively
4139
4134
        disable the capability.
4140
4135
        TODO: detect the situation in compare_tables, behave based
4338
4333
                       or dropped.
4339
4334
      order_num        How many ORDER BY fields has been specified.
4340
4335
      order            List of fields to ORDER BY.
4341
 
      ignore           Whether we have ALTER IGNORE TABLE
 
4336
      ignore           Whether we have ALTER IGNORE Table
4342
4337
 
4343
4338
  DESCRIPTION
4344
4339
    This is a veery long function and is everything but the kitchen sink :)
4345
 
    It is used to alter a table and not only by ALTER TABLE but also
 
4340
    It is used to alter a table and not only by ALTER Table but also
4346
4341
    CREATE|DROP INDEX are mapped on this function.
4347
4342
 
4348
 
    When the ALTER TABLE statement just does a RENAME or ENABLE|DISABLE KEYS,
 
4343
    When the ALTER Table statement just does a RENAME or ENABLE|DISABLE KEYS,
4349
4344
    or both, then this function short cuts its operation by renaming
4350
4345
    the table and/or enabling/disabling the keys. In this case, the FRM is
4351
4346
    not changed, directly by mysql_alter_table. However, if there is a
4371
4366
                       Alter_info *alter_info,
4372
4367
                       uint order_num, ORDER *order, bool ignore)
4373
4368
{
4374
 
  TABLE *table, *new_table=0, *name_lock= 0;;
 
4369
  Table *table, *new_table=0, *name_lock= 0;;
4375
4370
  int error= 0;
4376
4371
  char tmp_name[80],old_name[32],new_name_buff[FN_REFLEN];
4377
4372
  char new_alias_buff[FN_REFLEN], *table_name, *db, *new_alias, *alias;
4379
4374
  ha_rows copied= 0,deleted= 0;
4380
4375
  handlerton *old_db_type, *new_db_type, *save_old_db_type;
4381
4376
  legacy_db_type table_type;
4382
 
  frm_type_enum frm_type;
4383
4377
 
4384
4378
  if (table_list && table_list->schema_table)
4385
4379
  {
4402
4396
 
4403
4397
  mysql_ha_rm_tables(thd, table_list, false);
4404
4398
 
4405
 
  /* DISCARD/IMPORT TABLESPACE is always alone in an ALTER TABLE */
 
4399
  /* DISCARD/IMPORT TABLESPACE is always alone in an ALTER Table */
4406
4400
  if (alter_info->tablespace_op != NO_TABLESPACE_OP)
4407
4401
    /* Conditionally writes to binlog. */
4408
4402
    return(mysql_discard_or_import_tablespace(thd,table_list,
4415
4409
    following scenario: 1) lock LOCK_open 2) do a RENAME
4416
4410
    2) unlock LOCK_open.
4417
4411
    This is a copy-paste added to make sure
4418
 
    ALTER (sic:) TABLE .. RENAME works for views. ALTER VIEW is handled
 
4412
    ALTER (sic:) Table .. RENAME works for views. ALTER VIEW is handled
4419
4413
    as an independent branch in mysql_execute_command. The need
4420
 
    for a copy-paste arose because the main code flow of ALTER TABLE
 
4414
    for a copy-paste arose because the main code flow of ALTER Table
4421
4415
    ... RENAME tries to use open_ltable, which does not work for views
4422
4416
    (open_ltable was never modified to merge table lists of child tables
4423
4417
    into the main table list, like open_tables does).
4424
4418
    This code is wrong and will be removed, please do not copy.
4425
4419
  */
4426
 
  frm_type= mysql_frm_type(thd, new_name_buff, &table_type);
 
4420
  (void)mysql_frm_type(thd, new_name_buff, &table_type);
4427
4421
 
4428
4422
  if (!(table= open_n_lock_single_table(thd, table_list, TL_WRITE_ALLOW_READ)))
4429
4423
    return(true);
4527
4521
    case ENABLE:
4528
4522
      /*
4529
4523
        wait_while_table_is_used() ensures that table being altered is
4530
 
        opened only by this thread and that TABLE::TABLE_SHARE::version
4531
 
        of TABLE object corresponding to this table is 0.
 
4524
        opened only by this thread and that Table::TABLE_SHARE::version
 
4525
        of Table object corresponding to this table is 0.
4532
4526
        The latter guarantees that no DML statement will open this table
4533
 
        until ALTER TABLE finishes (i.e. until close_thread_tables())
 
4527
        until ALTER Table finishes (i.e. until close_thread_tables())
4534
4528
        while the fact that the table is still open gives us protection
4535
4529
        from concurrent DDL statements.
4536
4530
      */
4563
4557
    VOID(pthread_mutex_lock(&LOCK_open));
4564
4558
    /*
4565
4559
      Unlike to the above case close_cached_table() below will remove ALL
4566
 
      instances of TABLE from table cache (it will also remove table lock
 
4560
      instances of Table from table cache (it will also remove table lock
4567
4561
      held by this thread). So to make actual table renaming and writing
4568
4562
      to binlog atomic we have to put them into the same critical section
4569
4563
      protected by LOCK_open mutex. This also removes gap for races between
4633
4627
  /* We have to do full alter table. */
4634
4628
 
4635
4629
    /*
4636
 
    If the old table had partitions and we are doing ALTER TABLE ...
 
4630
    If the old table had partitions and we are doing ALTER Table ...
4637
4631
    engine= <new_engine>, the new table must preserve the original
4638
4632
    partitioning. That means that the new engine is still the
4639
4633
    partitioning engine, not the engine specified in the parser.
4665
4659
 
4666
4660
  if (alter_info->build_method != HA_BUILD_OFFLINE)
4667
4661
  {
4668
 
    TABLE *altered_table= 0;
 
4662
    Table *altered_table= 0;
4669
4663
    HA_ALTER_INFO ha_alter_info;
4670
4664
    HA_ALTER_FLAGS ha_alter_flags;
4671
4665
    uint table_changes= IS_EQUAL_YES;
4717
4711
        /*
4718
4712
          @todo: Currently we always acquire an exclusive name
4719
4713
          lock on the table metadata when performing fast or online
4720
 
          ALTER TABLE. In future we may consider this unnecessary,
 
4714
          ALTER Table. In future we may consider this unnecessary,
4721
4715
          and narrow the scope of the exclusive name lock to only
4722
4716
          cover manipulation with .frms. Storage engine API
4723
4717
          call check_if_supported_alter has provision for this
4741
4735
      }
4742
4736
 
4743
4737
    }
4744
 
    /* TODO need to check if changes can be handled as fast ALTER TABLE */
 
4738
    /* TODO need to check if changes can be handled as fast ALTER Table */
4745
4739
    if (!altered_table)
4746
4740
      need_copy_table= true;
4747
4741
 
4830
4824
  */
4831
4825
  if (new_table && !(new_table->file->ha_table_flags() & HA_NO_COPY_ON_ALTER))
4832
4826
  {
4833
 
    /* We don't want update TIMESTAMP fields during ALTER TABLE. */
 
4827
    /* We don't want update TIMESTAMP fields during ALTER Table. */
4834
4828
    new_table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
4835
4829
    new_table->next_number_field=new_table->found_next_number_field;
4836
4830
    error= copy_data_between_tables(table, new_table,
4898
4892
       with exclusive name-locks.
4899
4893
    3) Rename the old table to a temp name, rename the new one to the
4900
4894
       old name.
4901
 
    4) If we are under LOCK TABLES and don't do ALTER TABLE ... RENAME
 
4895
    4) If we are under LOCK TABLES and don't do ALTER Table ... RENAME
4902
4896
       we reopen new version of table.
4903
4897
    5) Write statement to the binary log.
4904
 
    6) If we are under LOCK TABLES and do ALTER TABLE ... RENAME we
 
4898
    6) If we are under LOCK TABLES and do ALTER Table ... RENAME we
4905
4899
       remove name-locks from list of open tables and table cache.
4906
4900
    7) If we are not not under LOCK TABLES we rely on close_thread_tables()
4907
4901
       call to remove name-locks from table cache and list of open table.
4924
4918
    mysql_rename_table(), because we just juggle with the FRM and nothing
4925
4919
    more. If we have an intermediate table, then we notify the SE that
4926
4920
    it should become the actual table. Later, we will recycle the old table.
4927
 
    However, in case of ALTER TABLE RENAME there might be no intermediate
 
4921
    However, in case of ALTER Table RENAME there might be no intermediate
4928
4922
    table. This is when the old and new tables are compatible, according to
4929
4923
    compare_table(). Then, we need one additional call to
4930
4924
    mysql_rename_table() with flag NO_FRM_RENAME, which does nothing else but
4987
4981
      shutdown. But we do not need to attach MERGE children.
4988
4982
    */
4989
4983
    char path[FN_REFLEN];
4990
 
    TABLE *t_table;
 
4984
    Table *t_table;
4991
4985
    build_table_filename(path, sizeof(path), new_db, table_name, "", 0);
4992
4986
    t_table= open_temporary_table(thd, path, new_db, tmp_name, false, OTM_OPEN);
4993
4987
    if (t_table)
5005
4999
  if (thd->locked_tables && (new_name != table_name || new_db != db))
5006
5000
  {
5007
5001
    /*
5008
 
      If are we under LOCK TABLES and did ALTER TABLE with RENAME we need
 
5002
      If are we under LOCK TABLES and did ALTER Table with RENAME we need
5009
5003
      to remove placeholders for the old table and for the target table
5010
5004
      from the list of open tables and table cache. If we are not under
5011
5005
      LOCK TABLES we can rely on close_thread_tables() doing this job.
5088
5082
/* mysql_alter_table */
5089
5083
 
5090
5084
static int
5091
 
copy_data_between_tables(TABLE *from,TABLE *to,
 
5085
copy_data_between_tables(Table *from,Table *to,
5092
5086
                         List<Create_field> &create,
5093
5087
                         bool ignore,
5094
5088
                         uint order_num, ORDER *order,
5360
5354
  for (table= tables; table; table= table->next_local)
5361
5355
  {
5362
5356
    char table_name[NAME_LEN*2+2];
5363
 
    TABLE *t;
 
5357
    Table *t;
5364
5358
 
5365
5359
    strxmov(table_name, table->db ,".", table->table_name, NullS);
5366
5360