~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_table.cc

  • Committer: Stewart Smith
  • Date: 2008-09-15 07:13:59 UTC
  • mfrom: (383.1.21 drizzle)
  • mto: This revision was merged to the branch mainline in revision 408.
  • Revision ID: stewart@flamingspork.com-20080915071359-f8bznznyaiqrtqxa
merged

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
/* drop and alter of tables */
17
17
 
18
 
#include "mysql_priv.h"
19
 
#include <mysys/hash.h>
 
18
#include <drizzled/server_includes.h>
20
19
#include <storage/myisam/myisam.h>
21
 
#include "sql_show.h"
 
20
#include <drizzled/sql_show.h>
 
21
#include <drizzled/drizzled_error_messages.h>
 
22
#include <libdrizzle/gettext.h>
22
23
 
23
24
int creating_table= 0;        // How many mysql_create_table are running
24
25
 
26
27
 
27
28
static bool check_if_keyname_exists(const char *name,KEY *start, KEY *end);
28
29
static char *make_unique_key_name(const char *field_name,KEY *start,KEY *end);
29
 
static int copy_data_between_tables(TABLE *from,TABLE *to,
 
30
static int copy_data_between_tables(Table *from,Table *to,
30
31
                                    List<Create_field> &create, bool ignore,
31
 
                                    uint order_num, ORDER *order,
 
32
                                    uint order_num, order_st *order,
32
33
                                    ha_rows *copied,ha_rows *deleted,
33
34
                                    enum enum_enable_or_disable keys_onoff,
34
35
                                    bool error_if_not_empty);
43
44
                               handler *file, KEY **key_info_buffer,
44
45
                               uint *key_count, int select_field_count);
45
46
static bool
46
 
mysql_prepare_alter_table(THD *thd, TABLE *table,
 
47
mysql_prepare_alter_table(THD *thd, Table *table,
47
48
                          HA_CREATE_INFO *create_info,
48
49
                          Alter_info *alter_info);
49
50
 
67
68
  if (!memcmp(from, tmp_file_prefix, tmp_file_prefix_length))
68
69
  {
69
70
    /* Temporary table name. */
70
 
    res= (strnmov(to, from, to_length) - to);
 
71
    res= (stpncpy(to, from, to_length) - to);
71
72
  }
72
73
  else
73
74
  {
77
78
    {
78
79
      res= (strxnmov(to, to_length, MYSQL50_TABLE_NAME_PREFIX,  from, NullS) -
79
80
            to);
80
 
      sql_print_error("Invalid (old?) table or database name '%s'", from);
81
 
      /*
82
 
        TODO: add a stored procedure for fix table and database names,
83
 
        and mention its name in error log.
84
 
      */
 
81
      sql_print_error(_("Invalid (old?) table or database name '%s'"), from);
85
82
    }
86
83
  }
87
84
 
146
143
    'db' is always converted.
147
144
    'ext' is not converted.
148
145
 
149
 
    The conversion suppression is required for ALTER TABLE. This
 
146
    The conversion suppression is required for ALTER Table. This
150
147
    statement creates intermediate tables. These are regular
151
148
    (non-temporary) tables with a temporary name. Their path names must
152
149
    be derivable from the table name. So we cannot use
163
160
  char tbbuff[FN_REFLEN];
164
161
 
165
162
  if (flags & FN_IS_TMP) // FN_FROM_IS_TMP | FN_TO_IS_TMP
166
 
    strnmov(tbbuff, table_name, sizeof(tbbuff));
 
163
    stpncpy(tbbuff, table_name, sizeof(tbbuff));
167
164
  else
168
165
    VOID(tablename_to_filename(table_name, tbbuff, sizeof(tbbuff)));
169
166
 
171
168
 
172
169
  char *end = buff + bufflen;
173
170
  /* Don't add FN_ROOTDIR if mysql_data_home already includes it */
174
 
  char *pos = strnmov(buff, mysql_data_home, bufflen);
 
171
  char *pos = stpncpy(buff, mysql_data_home, bufflen);
175
172
  int rootdir_len= strlen(FN_ROOTDIR);
176
173
  if (pos - rootdir_len >= buff &&
177
174
      memcmp(pos - rootdir_len, FN_ROOTDIR, rootdir_len) != 0)
178
 
    pos= strnmov(pos, FN_ROOTDIR, end - pos);
 
175
    pos= stpncpy(pos, FN_ROOTDIR, end - pos);
179
176
  pos= strxnmov(pos, end - pos, dbbuff, FN_ROOTDIR, NullS);
180
177
#ifdef USE_SYMDIR
181
178
  unpack_dirname(buff, buff);
208
205
uint build_tmptable_filename(THD* thd, char *buff, size_t bufflen)
209
206
{
210
207
 
211
 
  char *p= strnmov(buff, mysql_tmpdir, bufflen);
 
208
  char *p= stpncpy(buff, mysql_tmpdir, bufflen);
212
209
  snprintf(p, bufflen - (p - buff), "/%s%lx_%lx_%x%s",
213
210
              tmp_file_prefix, current_pid,
214
211
              thd->thread_id, thd->tmp_table++, reg_ext);
276
273
 
277
274
*/
278
275
 
279
 
bool mysql_rm_table(THD *thd,TABLE_LIST *tables, bool if_exists, bool drop_temporary)
 
276
bool mysql_rm_table(THD *thd,TableList *tables, bool if_exists, bool drop_temporary)
280
277
{
281
278
  bool error, need_start_waiting= false;
282
279
 
341
338
   -1   Thread was killed
342
339
*/
343
340
 
344
 
int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
 
341
int mysql_rm_table_part2(THD *thd, TableList *tables, bool if_exists,
345
342
                         bool drop_temporary, bool drop_view,
346
343
                         bool dont_log_query)
347
344
{
348
 
  TABLE_LIST *table;
 
345
  TableList *table;
349
346
  char path[FN_REFLEN], *alias;
350
347
  uint path_length;
351
348
  String wrong_tables;
358
355
  {
359
356
    built_query.set_charset(system_charset_info);
360
357
    if (if_exists)
361
 
      built_query.append("DROP TABLE IF EXISTS ");
 
358
      built_query.append("DROP Table IF EXISTS ");
362
359
    else
363
 
      built_query.append("DROP TABLE ");
 
360
      built_query.append("DROP Table ");
364
361
  }
365
362
 
366
363
  mysql_ha_rm_tables(thd, tables, false);
440
437
    table_type= table->db_type;
441
438
    if (!drop_temporary)
442
439
    {
443
 
      TABLE *locked_table;
 
440
      Table *locked_table;
444
441
      abort_locked_tables(thd, db, table->table_name);
445
442
      remove_table_from_cache(thd, db, table->table_name,
446
443
                              RTFC_WAIT_OTHER_THREAD_FLAG |
465
462
    }
466
463
    if (drop_temporary ||
467
464
        ((table_type == NULL && (access(path, F_OK) && ha_create_table_from_engine(thd, db, alias))) ||
468
 
         (!drop_view && mysql_frm_type(thd, path, &frm_db_type) != FRMTYPE_TABLE)))
 
465
         (!drop_view && mysql_frm_type(thd, path, &frm_db_type) != true)))
469
466
    {
470
467
      // Table was not found on disk and table can't be created from engine
471
468
      if (if_exists)
472
 
        push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
 
469
        push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
473
470
                            ER_BAD_TABLE_ERROR, ER(ER_BAD_TABLE_ERROR),
474
471
                            table->table_name);
475
472
      else
502
499
      {
503
500
        int new_error;
504
501
        /* Delete the table definition file */
505
 
        strmov(end,reg_ext);
 
502
        stpcpy(end,reg_ext);
506
503
        if (!(new_error=my_delete(path,MYF(MY_WME))))
507
504
        {
508
505
          some_tables_deleted=1;
585
582
  }
586
583
  pthread_mutex_lock(&LOCK_open);
587
584
err_with_placeholders:
588
 
  unlock_table_names(thd, tables, (TABLE_LIST*) 0);
 
585
  unlock_table_names(thd, tables, (TableList*) 0);
589
586
  pthread_mutex_unlock(&LOCK_open);
590
587
  thd->no_warnings_for_error= 0;
591
588
  return(error);
689
686
 
690
687
bool check_duplicates_in_interval(const char *set_or_name,
691
688
                                  const char *name, TYPELIB *typelib,
692
 
                                  CHARSET_INFO *cs, unsigned int *dup_val_count)
 
689
                                  const CHARSET_INFO * const cs, unsigned int *dup_val_count)
693
690
{
694
691
  TYPELIB tmp= *typelib;
695
692
  const char **cur_value= typelib->type_names;
730
727
  RETURN VALUES
731
728
    void
732
729
*/
733
 
void calculate_interval_lengths(CHARSET_INFO *cs, TYPELIB *interval,
 
730
void calculate_interval_lengths(const CHARSET_INFO * const cs, TYPELIB *interval,
734
731
                                uint32_t *max_length, uint32_t *tot_length)
735
732
{
736
733
  const char **pos;
805
802
                                     sql_field->charset, &dup_val_count))
806
803
      return(1);
807
804
    break;
808
 
  case DRIZZLE_TYPE_SET:
809
 
    sql_field->pack_flag=pack_length_to_packflag(sql_field->pack_length) |
810
 
      FIELDFLAG_BITFIELD;
811
 
    if (sql_field->charset->state & MY_CS_BINSORT)
812
 
      sql_field->pack_flag|=FIELDFLAG_BINARY;
813
 
    sql_field->unireg_check=Field::BIT_FIELD;
814
 
    if (check_duplicates_in_interval("SET",sql_field->field_name,
815
 
                                 sql_field->interval,
816
 
                                     sql_field->charset, &dup_val_count))
817
 
      return(1);
818
 
    /* Check that count of unique members is not more then 64 */
819
 
    if (sql_field->interval->count -  dup_val_count > sizeof(int64_t)*8)
820
 
    {
821
 
       my_error(ER_TOO_BIG_SET, MYF(0), sql_field->field_name);
822
 
       return(1);
823
 
    }
824
 
    break;
825
805
  case DRIZZLE_TYPE_NEWDATE:  // Rest of string types
826
806
  case DRIZZLE_TYPE_TIME:
827
807
  case DRIZZLE_TYPE_DATETIME:
921
901
 
922
902
  for (field_no=0; (sql_field=it++) ; field_no++)
923
903
  {
924
 
    CHARSET_INFO *save_cs;
 
904
    const CHARSET_INFO *save_cs;
925
905
 
926
906
    /*
927
907
      Initialize length from its original value (number of characters),
932
912
    if (!sql_field->charset)
933
913
      sql_field->charset= create_info->default_table_charset;
934
914
    /*
935
 
      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
936
916
      for all varchar/char columns.
937
917
      But the table charset must not affect the BLOB fields, so don't
938
918
      allow to change my_charset_bin to somethig else.
958
938
    */
959
939
    if (sql_field->def && 
960
940
        save_cs != sql_field->def->collation.collation &&
961
 
        (sql_field->sql_type == DRIZZLE_TYPE_SET ||
962
 
         sql_field->sql_type == DRIZZLE_TYPE_ENUM))
 
941
        (sql_field->sql_type == DRIZZLE_TYPE_ENUM))
963
942
    {
964
943
      /*
965
944
        Starting from 5.1 we work here with a copy of Create_field
981
960
      }
982
961
    }
983
962
 
984
 
    if (sql_field->sql_type == DRIZZLE_TYPE_SET ||
985
 
        sql_field->sql_type == DRIZZLE_TYPE_ENUM)
 
963
    if (sql_field->sql_type == DRIZZLE_TYPE_ENUM)
986
964
    {
987
965
      uint32_t dummy;
988
 
      CHARSET_INFO *cs= sql_field->charset;
 
966
      const CHARSET_INFO * const cs= sql_field->charset;
989
967
      TYPELIB *interval= sql_field->interval;
990
968
 
991
969
      /*
1027
1005
                                       interval->type_lengths[i]);
1028
1006
          interval->type_lengths[i]= lengthsp;
1029
1007
          ((uchar *)interval->type_names[i])[lengthsp]= '\0';
1030
 
          if (sql_field->sql_type == DRIZZLE_TYPE_SET)
1031
 
          {
1032
 
            if (cs->coll->instr(cs, interval->type_names[i], 
1033
 
                                interval->type_lengths[i], 
1034
 
                                comma_buf, comma_length, NULL, 0))
1035
 
            {
1036
 
              my_error(ER_ILLEGAL_VALUE_FOR_TYPE, MYF(0), "set", tmp->ptr());
1037
 
              return(true);
1038
 
            }
1039
 
          }
1040
1008
        }
1041
1009
        sql_field->interval_list.empty(); // Don't need interval_list anymore
1042
1010
      }
1043
1011
 
1044
 
      if (sql_field->sql_type == DRIZZLE_TYPE_SET)
1045
 
      {
1046
 
        uint32_t field_length;
1047
 
        if (sql_field->def != NULL)
1048
 
        {
1049
 
          char *not_used;
1050
 
          uint not_used2;
1051
 
          bool not_found= 0;
1052
 
          String str, *def= sql_field->def->val_str(&str);
1053
 
          if (def == NULL) /* SQL "NULL" maps to NULL */
1054
 
          {
1055
 
            if ((sql_field->flags & NOT_NULL_FLAG) != 0)
1056
 
            {
1057
 
              my_error(ER_INVALID_DEFAULT, MYF(0), sql_field->field_name);
1058
 
              return(true);
1059
 
            }
1060
 
 
1061
 
            /* else, NULL is an allowed value */
1062
 
            (void) find_set(interval, NULL, 0,
1063
 
                            cs, &not_used, &not_used2, &not_found);
1064
 
          }
1065
 
          else /* not NULL */
1066
 
          {
1067
 
            (void) find_set(interval, def->ptr(), def->length(),
1068
 
                            cs, &not_used, &not_used2, &not_found);
1069
 
          }
1070
 
 
1071
 
          if (not_found)
1072
 
          {
1073
 
            my_error(ER_INVALID_DEFAULT, MYF(0), sql_field->field_name);
1074
 
            return(true);
1075
 
          }
1076
 
        }
1077
 
        calculate_interval_lengths(cs, interval, &dummy, &field_length);
1078
 
        sql_field->length= field_length + (interval->count - 1);
1079
 
      }
1080
 
      else  /* DRIZZLE_TYPE_ENUM */
 
1012
      /* DRIZZLE_TYPE_ENUM */
1081
1013
      {
1082
1014
        uint32_t field_length;
1083
1015
        assert(sql_field->sql_type == DRIZZLE_TYPE_ENUM);
1471
1403
            if (key->type == Key::MULTIPLE)
1472
1404
            {
1473
1405
              /* not a critical problem */
1474
 
              char warn_buff[MYSQL_ERRMSG_SIZE];
 
1406
              char warn_buff[DRIZZLE_ERRMSG_SIZE];
1475
1407
              snprintf(warn_buff, sizeof(warn_buff), ER(ER_TOO_LONG_KEY),
1476
1408
                       length);
1477
 
              push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
 
1409
              push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1478
1410
                           ER_TOO_LONG_KEY, warn_buff);
1479
1411
              /* Align key length to multibyte char boundary */
1480
1412
              length-= length % sql_field->charset->mbmaxlen;
1510
1442
        if (key->type == Key::MULTIPLE)
1511
1443
        {
1512
1444
          /* not a critical problem */
1513
 
          char warn_buff[MYSQL_ERRMSG_SIZE];
 
1445
          char warn_buff[DRIZZLE_ERRMSG_SIZE];
1514
1446
          snprintf(warn_buff, sizeof(warn_buff), ER(ER_TOO_LONG_KEY),
1515
1447
                   length);
1516
 
          push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
 
1448
          push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1517
1449
                       ER_TOO_LONG_KEY, warn_buff);
1518
1450
          /* Align key length to multibyte char boundary */
1519
1451
          length-= length % sql_field->charset->mbmaxlen;
1723
1655
 
1724
1656
void sp_prepare_create_field(THD *thd, Create_field *sql_field)
1725
1657
{
1726
 
  if (sql_field->sql_type == DRIZZLE_TYPE_SET ||
1727
 
      sql_field->sql_type == DRIZZLE_TYPE_ENUM)
 
1658
  if (sql_field->sql_type == DRIZZLE_TYPE_ENUM)
1728
1659
  {
1729
1660
    uint32_t field_length, dummy;
1730
 
    if (sql_field->sql_type == DRIZZLE_TYPE_SET)
1731
 
    {
1732
 
      calculate_interval_lengths(sql_field->charset,
1733
 
                                 sql_field->interval, &dummy, 
1734
 
                                 &field_length);
1735
 
      sql_field->length= field_length + 
1736
 
                         (sql_field->interval->count - 1);
1737
 
    }
1738
 
    else /* DRIZZLE_TYPE_ENUM */
 
1661
    /* DRIZZLE_TYPE_ENUM */
1739
1662
    {
1740
1663
      calculate_interval_lengths(sql_field->charset,
1741
1664
                                 sql_field->interval,
1764
1687
    fields              List of fields to create
1765
1688
    keys                List of keys to create
1766
1689
    internal_tmp_table  Set to 1 if this is an internal temporary table
1767
 
                        (From ALTER TABLE)
 
1690
                        (From ALTER Table)
1768
1691
    select_field_count  
1769
1692
 
1770
1693
  DESCRIPTION
1855
1778
    if (create_info->options & HA_LEX_CREATE_IF_NOT_EXISTS)
1856
1779
    {
1857
1780
      create_info->table_existed= 1;            // Mark that table existed
1858
 
      push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
 
1781
      push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
1859
1782
                          ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR),
1860
1783
                          alias);
1861
1784
      error= 0;
1941
1864
#endif /* HAVE_READLINK */
1942
1865
  {
1943
1866
    if (create_info->data_file_name)
1944
 
      push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0,
 
1867
      push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN, 0,
1945
1868
                   "DATA DIRECTORY option ignored");
1946
1869
    if (create_info->index_file_name)
1947
 
      push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0,
 
1870
      push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN, 0,
1948
1871
                   "INDEX DIRECTORY option ignored");
1949
1872
    create_info->data_file_name= create_info->index_file_name= 0;
1950
1873
  }
1990
1913
 
1991
1914
warn:
1992
1915
  error= false;
1993
 
  push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
 
1916
  push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
1994
1917
                      ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR),
1995
1918
                      alias);
1996
1919
  create_info->table_existed= 1;                // Mark that table existed
2008
1931
                        bool internal_tmp_table,
2009
1932
                        uint select_field_count)
2010
1933
{
2011
 
  TABLE *name_lock= 0;
 
1934
  Table *name_lock= 0;
2012
1935
  bool result;
2013
1936
 
2014
1937
  /* Wait for any database locks */
2039
1962
    {
2040
1963
      if (create_info->options & HA_LEX_CREATE_IF_NOT_EXISTS)
2041
1964
      {
2042
 
        push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
 
1965
        push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
2043
1966
                            ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR),
2044
1967
                            table_name);
2045
1968
        create_info->table_existed= 1;
2167
2090
  if (lower_case_table_names == 2 && file &&
2168
2091
      !(file->ha_table_flags() & HA_FILE_BASED))
2169
2092
  {
2170
 
    strmov(tmp_name, old_name);
 
2093
    stpcpy(tmp_name, old_name);
2171
2094
    my_casedn_str(files_charset_info, tmp_name);
2172
2095
    build_table_filename(lc_from, sizeof(lc_from), old_db, tmp_name, "",
2173
2096
                         flags & FN_FROM_IS_TMP);
2174
2097
    from_base= lc_from;
2175
2098
 
2176
 
    strmov(tmp_name, new_name);
 
2099
    stpcpy(tmp_name, new_name);
2177
2100
    my_casedn_str(files_charset_info, tmp_name);
2178
2101
    build_table_filename(lc_to, sizeof(lc_to), new_db, tmp_name, "",
2179
2102
                         flags & FN_TO_IS_TMP);
2191
2114
  }
2192
2115
  delete file;
2193
2116
  if (error == HA_ERR_WRONG_COMMAND)
2194
 
    my_error(ER_NOT_SUPPORTED_YET, MYF(0), "ALTER TABLE");
 
2117
    my_error(ER_NOT_SUPPORTED_YET, MYF(0), "ALTER Table");
2195
2118
  else if (error)
2196
2119
    my_error(ER_ERROR_ON_RENAME, MYF(0), from, to, error);
2197
2120
  return(error != 0);
2217
2140
    Win32 clients must also have a WRITE LOCK on the table !
2218
2141
*/
2219
2142
 
2220
 
void wait_while_table_is_used(THD *thd, TABLE *table,
 
2143
void wait_while_table_is_used(THD *thd, Table *table,
2221
2144
                              enum ha_extra_function function)
2222
2145
{
2223
2146
 
2251
2174
    Win32 clients must also have a WRITE LOCK on the table !
2252
2175
*/
2253
2176
 
2254
 
void close_cached_table(THD *thd, TABLE *table)
 
2177
void close_cached_table(THD *thd, Table *table)
2255
2178
{
2256
2179
 
2257
2180
  wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN);
2269
2192
  return;
2270
2193
}
2271
2194
 
2272
 
static int send_check_errmsg(THD *thd, TABLE_LIST* table,
 
2195
static int send_check_errmsg(THD *thd, TableList* table,
2273
2196
                             const char* operator_name, const char* errmsg)
2274
2197
 
2275
2198
{
2286
2209
}
2287
2210
 
2288
2211
 
2289
 
static int prepare_for_repair(THD *thd, TABLE_LIST *table_list,
 
2212
static int prepare_for_repair(THD *thd, TableList *table_list,
2290
2213
                              HA_CHECK_OPT *check_opt)
2291
2214
{
2292
2215
  int error= 0;
2293
 
  TABLE tmp_table, *table;
 
2216
  Table tmp_table, *table;
2294
2217
  TABLE_SHARE *share;
2295
2218
  char from[FN_REFLEN],tmp[FN_REFLEN+32];
2296
2219
  const char **ext;
2324
2247
  }
2325
2248
 
2326
2249
  /*
2327
 
    REPAIR TABLE ... USE_FRM for temporary tables makes little sense.
 
2250
    REPAIR Table ... USE_FRM for temporary tables makes little sense.
2328
2251
  */
2329
2252
  if (table->s->tmp_table)
2330
2253
  {
2434
2357
    true  Message should be sent by caller 
2435
2358
          (admin operation or network communication failed)
2436
2359
*/
2437
 
static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
 
2360
static bool mysql_admin_table(THD* thd, TableList* tables,
2438
2361
                              HA_CHECK_OPT* check_opt,
2439
2362
                              const char *operator_name,
2440
2363
                              thr_lock_type lock_type,
2441
2364
                              bool open_for_modify,
2442
2365
                              bool no_warnings_for_error,
2443
2366
                              uint extra_open_options,
2444
 
                              int (*prepare_func)(THD *, TABLE_LIST *,
 
2367
                              int (*prepare_func)(THD *, TableList *,
2445
2368
                                                  HA_CHECK_OPT *),
2446
2369
                              int (handler::*operator_func)(THD *,
2447
2370
                                                            HA_CHECK_OPT *))
2448
2371
{
2449
 
  TABLE_LIST *table;
 
2372
  TableList *table;
2450
2373
  SELECT_LEX *select= &thd->lex->select_lex;
2451
2374
  List<Item> field_list;
2452
2375
  Item *item;
2453
2376
  Protocol *protocol= thd->protocol;
2454
2377
  LEX *lex= thd->lex;
2455
2378
  int result_code= 0;
2456
 
  CHARSET_INFO *cs= system_charset_info;
 
2379
  const CHARSET_INFO * const cs= system_charset_info;
2457
2380
 
2458
2381
  if (end_active_trans(thd))
2459
2382
    return(1);
2484
2407
    table->lock_type= lock_type;
2485
2408
    /* open only one table from local list of command */
2486
2409
    {
2487
 
      TABLE_LIST *save_next_global, *save_next_local;
 
2410
      TableList *save_next_global, *save_next_local;
2488
2411
      save_next_global= table->next_global;
2489
2412
      table->next_global= 0;
2490
2413
      save_next_local= table->next_local;
2500
2423
      lex->query_tables_last= &table->next_global;
2501
2424
      lex->query_tables_own_last= 0;
2502
2425
      thd->no_warnings_for_error= no_warnings_for_error;
2503
 
      table->required_type=FRMTYPE_TABLE;
2504
2426
 
2505
2427
      open_and_lock_tables(thd, table);
2506
2428
      thd->no_warnings_for_error= 0;
2527
2449
    }
2528
2450
 
2529
2451
    /*
2530
 
      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
2531
2453
      command use only temporary teble method for VIEWs resolving => there
2532
2454
      can't be VIEW tree substitition of join view => if opening table
2533
 
      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
2534
2456
      case of join view substitution table->table can be 0, but here it is
2535
2457
      impossible)
2536
2458
    */
2537
2459
    if (!table->table)
2538
2460
    {
2539
2461
      if (!thd->warn_list.elements)
2540
 
        push_warning(thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
 
2462
        push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
2541
2463
                     ER_CHECK_NO_SUCH_TABLE, ER(ER_CHECK_NO_SUCH_TABLE));
2542
2464
      goto send_result;
2543
2465
    }
2545
2467
    if ((table->table->db_stat & HA_READ_ONLY) && open_for_modify)
2546
2468
    {
2547
2469
      /* purecov: begin inspected */
2548
 
      char buff[FN_REFLEN + MYSQL_ERRMSG_SIZE];
 
2470
      char buff[FN_REFLEN + DRIZZLE_ERRMSG_SIZE];
2549
2471
      uint length;
2550
2472
      protocol->prepare_for_resend();
2551
2473
      protocol->store(table_name, system_charset_info);
2627
2549
    lex->cleanup_after_one_table_open();
2628
2550
    thd->clear_error();  // these errors shouldn't get client
2629
2551
    {
2630
 
      List_iterator_fast<MYSQL_ERROR> it(thd->warn_list);
2631
 
      MYSQL_ERROR *err;
 
2552
      List_iterator_fast<DRIZZLE_ERROR> it(thd->warn_list);
 
2553
      DRIZZLE_ERROR *err;
2632
2554
      while ((err= it++))
2633
2555
      {
2634
2556
        protocol->prepare_for_resend();
2641
2563
        if (protocol->write())
2642
2564
          goto err;
2643
2565
      }
2644
 
      mysql_reset_errors(thd, true);
 
2566
      drizzle_reset_errors(thd, true);
2645
2567
    }
2646
2568
    protocol->prepare_for_resend();
2647
2569
    protocol->store(table_name, system_charset_info);
2710
2632
    {
2711
2633
      /*
2712
2634
        This is currently used only by InnoDB. ha_innobase::optimize() answers
2713
 
        "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,
2714
2636
        reopen the table and do ha_innobase::analyze() on it.
2715
2637
      */
2716
2638
      ha_autocommit_or_rollback(thd, 0);
2717
2639
      close_thread_tables(thd);
2718
 
      TABLE_LIST *save_next_local= table->next_local,
 
2640
      TableList *save_next_local= table->next_local,
2719
2641
                 *save_next_global= table->next_global;
2720
2642
      table->next_local= table->next_global= 0;
2721
2643
      tmp_disable_binlog(thd); // binlogging is done by caller if wanted
2791
2713
      {
2792
2714
        char buf[ERRMSGSIZE+20];
2793
2715
        uint length=snprintf(buf, ERRMSGSIZE,
2794
 
                             "Unknown - internal error %d during operation",
 
2716
                             _("Unknown - internal error %d during operation"),
2795
2717
                             result_code);
2796
2718
        protocol->store(STRING_WITH_LEN("error"), system_charset_info);
2797
2719
        protocol->store(buf, length, system_charset_info);
2837
2759
}
2838
2760
 
2839
2761
 
2840
 
bool mysql_repair_table(THD* thd, TABLE_LIST* tables, HA_CHECK_OPT* check_opt)
 
2762
bool mysql_repair_table(THD* thd, TableList* tables, HA_CHECK_OPT* check_opt)
2841
2763
{
2842
2764
  return(mysql_admin_table(thd, tables, check_opt,
2843
2765
                                "repair", TL_WRITE, 1,
2848
2770
}
2849
2771
 
2850
2772
 
2851
 
bool mysql_optimize_table(THD* thd, TABLE_LIST* tables, HA_CHECK_OPT* check_opt)
 
2773
bool mysql_optimize_table(THD* thd, TableList* tables, HA_CHECK_OPT* check_opt)
2852
2774
{
2853
2775
  return(mysql_admin_table(thd, tables, check_opt,
2854
2776
                                "optimize", TL_WRITE, 1,0,0,0,
2869
2791
   true  error
2870
2792
*/
2871
2793
 
2872
 
bool mysql_assign_to_keycache(THD* thd, TABLE_LIST* tables,
 
2794
bool mysql_assign_to_keycache(THD* thd, TableList* tables,
2873
2795
                             LEX_STRING *key_cache_name)
2874
2796
{
2875
2797
  HA_CHECK_OPT check_opt;
2940
2862
    @retval       0                        success
2941
2863
    @retval       1                        error
2942
2864
*/
2943
 
bool mysql_create_like_schema_frm(THD* thd, TABLE_LIST* schema_table,
 
2865
bool mysql_create_like_schema_frm(THD* thd, TableList* schema_table,
2944
2866
                                  char *dst_path, HA_CREATE_INFO *create_info)
2945
2867
{
2946
2868
  HA_CREATE_INFO local_create_info;
2949
2871
  uint keys= schema_table->table->s->keys;
2950
2872
  uint db_options= 0;
2951
2873
 
2952
 
  memset((char*) &local_create_info, 0, sizeof(local_create_info));
 
2874
  memset(&local_create_info, 0, sizeof(local_create_info));
2953
2875
  local_create_info.db_type= schema_table->table->s->db_type();
2954
2876
  local_create_info.row_type= schema_table->table->s->row_type;
2955
2877
  local_create_info.default_table_charset=default_charset_info;
2988
2910
    true  error
2989
2911
*/
2990
2912
 
2991
 
bool mysql_create_like_table(THD* thd, TABLE_LIST* table, TABLE_LIST* src_table,
 
2913
bool mysql_create_like_table(THD* thd, TableList* table, TableList* src_table,
2992
2914
                             HA_CREATE_INFO *create_info)
2993
2915
{
2994
 
  TABLE *name_lock= 0;
 
2916
  Table *name_lock= 0;
2995
2917
  char src_path[FN_REFLEN], dst_path[FN_REFLEN];
2996
2918
  uint dst_path_length;
2997
2919
  char *db= table->db;
3000
2922
  bool res= true;
3001
2923
  uint not_used;
3002
2924
 
3003
 
 
3004
 
  /* CREATE TABLE ... LIKE is not allowed for views. */
3005
 
  src_table->required_type= FRMTYPE_TABLE;
3006
 
 
3007
2925
  /*
3008
2926
    By opening source table we guarantee that it exists and no concurrent
3009
2927
    DDL operation will mess with it. Later we also take an exclusive
3167
3085
table_exists:
3168
3086
  if (create_info->options & HA_LEX_CREATE_IF_NOT_EXISTS)
3169
3087
  {
3170
 
    char warn_buff[MYSQL_ERRMSG_SIZE];
 
3088
    char warn_buff[DRIZZLE_ERRMSG_SIZE];
3171
3089
    snprintf(warn_buff, sizeof(warn_buff),
3172
3090
             ER(ER_TABLE_EXISTS_ERROR), table_name);
3173
 
    push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
 
3091
    push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
3174
3092
                 ER_TABLE_EXISTS_ERROR,warn_buff);
3175
3093
    res= false;
3176
3094
  }
3188
3106
}
3189
3107
 
3190
3108
 
3191
 
bool mysql_analyze_table(THD* thd, TABLE_LIST* tables, HA_CHECK_OPT* check_opt)
 
3109
bool mysql_analyze_table(THD* thd, TableList* tables, HA_CHECK_OPT* check_opt)
3192
3110
{
3193
3111
  thr_lock_type lock_type = TL_READ_NO_INSERT;
3194
3112
 
3198
3116
}
3199
3117
 
3200
3118
 
3201
 
bool mysql_check_table(THD* thd, TABLE_LIST* tables,HA_CHECK_OPT* check_opt)
 
3119
bool mysql_check_table(THD* thd, TableList* tables,HA_CHECK_OPT* check_opt)
3202
3120
{
3203
3121
  thr_lock_type lock_type = TL_READ_NO_INSERT;
3204
3122
 
3212
3130
/* table_list should contain just one table */
3213
3131
static int
3214
3132
mysql_discard_or_import_tablespace(THD *thd,
3215
 
                                   TABLE_LIST *table_list,
 
3133
                                   TableList *table_list,
3216
3134
                                   enum tablespace_op_type tablespace_op)
3217
3135
{
3218
 
  TABLE *table;
 
3136
  Table *table;
3219
3137
  bool discard;
3220
3138
  int error;
3221
3139
 
3222
3140
  /*
3223
3141
    Note that DISCARD/IMPORT TABLESPACE always is the only operation in an
3224
 
    ALTER TABLE
 
3142
    ALTER Table
3225
3143
  */
3226
3144
 
3227
3145
  thd_proc_info(thd, "discard_or_import_tablespace");
3246
3164
  if (error)
3247
3165
    goto err;
3248
3166
 
3249
 
  /* The ALTER TABLE is always in its own transaction */
 
3167
  /* The ALTER Table is always in its own transaction */
3250
3168
  error = ha_autocommit_or_rollback(thd, 0);
3251
3169
  if (end_active_trans(thd))
3252
3170
    error=1;
3320
3238
   table has in arguments create_list, key_list and create_info.
3321
3239
 
3322
3240
   By comparing the changes between the original and new table
3323
 
   we can determine how much it has changed after ALTER TABLE
 
3241
   we can determine how much it has changed after ALTER Table
3324
3242
   and whether we need to make a copy of the table, or just change
3325
3243
   the .frm file.
3326
3244
 
3338
3256
static
3339
3257
bool
3340
3258
compare_tables(THD *thd,
3341
 
               TABLE *table,
 
3259
               Table *table,
3342
3260
               Alter_info *alter_info,
3343
3261
                           HA_CREATE_INFO *create_info,
3344
3262
               uint order_num,
3371
3289
      like to keep compare_tables() idempotent (not altering any
3372
3290
      of the arguments) we create a copy of alter_info here and
3373
3291
      pass it to mysql_prepare_create_table, then use the result
3374
 
      to evaluate possibility of fast ALTER TABLE, and then
 
3292
      to evaluate possibility of fast ALTER Table, and then
3375
3293
      destroy the copy.
3376
3294
    */
3377
3295
    Alter_info tmp_alter_info(*alter_info, thd->mem_root);
3404
3322
 
3405
3323
  /*
3406
3324
    Some very basic checks. If number of fields changes, or the
3407
 
    handler, we need to run full ALTER TABLE. In the future
 
3325
    handler, we need to run full ALTER Table. In the future
3408
3326
    new fields can be added and old dropped without copy, but
3409
3327
    not yet.
3410
3328
 
3411
 
    Test also that engine was not given during ALTER TABLE, or
 
3329
    Test also that engine was not given during ALTER Table, or
3412
3330
    we are force to run regular alter table (copy).
3413
 
    E.g. ALTER TABLE tbl_name ENGINE=MyISAM.
 
3331
    E.g. ALTER Table tbl_name ENGINE=MyISAM.
3414
3332
 
3415
3333
    For the following ones we also want to run regular alter table:
3416
 
    ALTER TABLE tbl_name ORDER BY ..
3417
 
    ALTER TABLE tbl_name CONVERT TO CHARACTER SET ..
 
3334
    ALTER Table tbl_name order_st BY ..
 
3335
    ALTER Table tbl_name CONVERT TO CHARACTER SET ..
3418
3336
 
3419
3337
    At the moment we can't handle altering temporary tables without a copy.
3420
 
    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.
3421
3339
    In that case we always do full copy.
3422
3340
 
3423
3341
    There was a bug prior to mysql-4.0.25. Number of null fields was
3685
3603
 
3686
3604
 
3687
3605
/*
3688
 
  Manages enabling/disabling of indexes for ALTER TABLE
 
3606
  Manages enabling/disabling of indexes for ALTER Table
3689
3607
 
3690
3608
  SYNOPSIS
3691
3609
    alter_table_manage_keys()
3700
3618
*/
3701
3619
 
3702
3620
static
3703
 
bool alter_table_manage_keys(TABLE *table, int indexes_were_disabled,
 
3621
bool alter_table_manage_keys(Table *table, int indexes_were_disabled,
3704
3622
                             enum enum_enable_or_disable keys_onoff)
3705
3623
{
3706
3624
  int error= 0;
3718
3636
 
3719
3637
  if (error == HA_ERR_WRONG_COMMAND)
3720
3638
  {
3721
 
    push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
 
3639
    push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
3722
3640
                        ER_ILLEGAL_HA, ER(ER_ILLEGAL_HA),
3723
3641
                        table->s->table_name.str);
3724
3642
    error= 0;
3729
3647
}
3730
3648
 
3731
3649
int create_temporary_table(THD *thd,
3732
 
                           TABLE *table,
 
3650
                           Table *table,
3733
3651
                           char *new_db,
3734
3652
                           char *tmp_name,
3735
3653
                           HA_CREATE_INFO *create_info,
3770
3688
    if (create_info->index_file_name)
3771
3689
    {
3772
3690
      /* Fix index_file_name to have 'tmp_name' as basename */
3773
 
      strmov(index_file, tmp_name);
 
3691
      stpcpy(index_file, tmp_name);
3774
3692
      create_info->index_file_name=fn_same(index_file,
3775
3693
                                           create_info->index_file_name,
3776
3694
                                           1);
3778
3696
    if (create_info->data_file_name)
3779
3697
    {
3780
3698
      /* Fix data_file_name to have 'tmp_name' as basename */
3781
 
      strmov(data_file, tmp_name);
 
3699
      stpcpy(data_file, tmp_name);
3782
3700
      create_info->data_file_name=fn_same(data_file,
3783
3701
                                          create_info->data_file_name,
3784
3702
                                          1);
3820
3738
    The temporary table is created without storing it in any storage engine
3821
3739
    and is opened only to get the table struct and frm file reference.
3822
3740
*/
3823
 
TABLE *create_altered_table(THD *thd,
3824
 
                            TABLE *table,
 
3741
Table *create_altered_table(THD *thd,
 
3742
                            Table *table,
3825
3743
                            char *new_db,
3826
3744
                            HA_CREATE_INFO *create_info,
3827
3745
                            Alter_info *alter_info,
3829
3747
{
3830
3748
  int error;
3831
3749
  HA_CREATE_INFO altered_create_info(*create_info);
3832
 
  TABLE *altered_table;
 
3750
  Table *altered_table;
3833
3751
  char tmp_name[80];
3834
3752
  char path[FN_REFLEN];
3835
3753
 
3883
3801
    the table.
3884
3802
*/
3885
3803
int mysql_fast_or_online_alter_table(THD *thd,
3886
 
                                     TABLE *table,
3887
 
                                     TABLE *altered_table,
 
3804
                                     Table *table,
 
3805
                                     Table *altered_table,
3888
3806
                                     HA_CREATE_INFO *create_info,
3889
3807
                                     HA_ALTER_INFO *alter_info,
3890
3808
                                     HA_ALTER_FLAGS *ha_alter_flags,
3892
3810
{
3893
3811
  int error= 0;
3894
3812
  bool online= (table->file->ha_table_flags() & HA_ONLINE_ALTER)?true:false;
3895
 
  TABLE *t_table;
 
3813
  Table *t_table;
3896
3814
 
3897
3815
  if (online)
3898
3816
  {
3948
3866
  VOID(pthread_mutex_unlock(&LOCK_open));
3949
3867
 
3950
3868
  /*
3951
 
    The ALTER TABLE is always in its own transaction.
 
3869
    The ALTER Table is always in its own transaction.
3952
3870
    Commit must not be called while LOCK_open is locked. It could call
3953
3871
    wait_if_global_read_lock(), which could create a deadlock if called
3954
3872
    with LOCK_open.
3981
3899
 
3982
3900
    /*
3983
3901
      We are going to reopen table down on the road, so we have to restore
3984
 
      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
3985
3903
      object to make it suitable for reopening.
3986
3904
    */
3987
3905
    assert(t_table == table);
3999
3917
 
4000
3918
 
4001
3919
/**
4002
 
  Prepare column and key definitions for CREATE TABLE in ALTER TABLE.
 
3920
  Prepare column and key definitions for CREATE TABLE in ALTER Table.
4003
3921
 
4004
 
  This function transforms parse output of ALTER TABLE - lists of
 
3922
  This function transforms parse output of ALTER Table - lists of
4005
3923
  columns and keys to add, drop or modify into, essentially,
4006
3924
  CREATE TABLE definition - a list of columns and keys of the new
4007
3925
  table. While doing so, it also performs some (bug not all)
4008
3926
  semantic checks.
4009
3927
 
4010
3928
  This function is invoked when we know that we're going to
4011
 
  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
4012
3930
  is not possible, perhaps because the ALTER statement contains
4013
3931
  instructions that require change in table data, not only in
4014
3932
  table definition or indexes.
4019
3937
                              Used as an interface to the storage engine
4020
3938
                              to acquire additional information about
4021
3939
                              the original table.
4022
 
  @param[in,out]  create_info A blob with CREATE/ALTER TABLE
 
3940
  @param[in,out]  create_info A blob with CREATE/ALTER Table
4023
3941
                              parameters
4024
3942
  @param[in,out]  alter_info  Another blob with ALTER/CREATE parameters.
4025
3943
                              Originally create_info was used only in
4026
 
                              CREATE TABLE and alter_info only in ALTER TABLE.
 
3944
                              CREATE TABLE and alter_info only in ALTER Table.
4027
3945
                              But since ALTER might end-up doing CREATE,
4028
3946
                              this distinction is gone and we just carry
4029
3947
                              around two structures.
4035
3953
    Prepares alter_info->create_list and alter_info->key_list with
4036
3954
    columns and keys of the new table.
4037
3955
  @retval true   error, out of memory or a semantical error in ALTER
4038
 
                 TABLE instructions
 
3956
                 Table instructions
4039
3957
  @retval false  success
4040
3958
*/
4041
3959
 
4042
3960
static bool
4043
 
mysql_prepare_alter_table(THD *thd, TABLE *table,
 
3961
mysql_prepare_alter_table(THD *thd, Table *table,
4044
3962
                          HA_CREATE_INFO *create_info,
4045
3963
                          Alter_info *alter_info)
4046
3964
{
4070
3988
    create_info->max_rows= table->s->max_rows;
4071
3989
  if (!(used_fields & HA_CREATE_USED_AVG_ROW_LENGTH))
4072
3990
    create_info->avg_row_length= table->s->avg_row_length;
 
3991
  if (!(used_fields & HA_CREATE_USED_BLOCK_SIZE))
 
3992
    create_info->block_size= table->s->block_size;
4073
3993
  if (!(used_fields & HA_CREATE_USED_DEFAULT_CHARSET))
4074
3994
    create_info->default_table_charset= table->s->table_charset;
4075
3995
  if (!(used_fields & HA_CREATE_USED_AUTO) && table->found_next_number_field)
4175
4095
      either has a default value or the '0000-00-00' is allowed by the
4176
4096
      set sql mode.
4177
4097
      If the '0000-00-00' value isn't allowed then raise the error_if_not_empty
4178
 
      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.
4179
4099
      */
4180
4100
    if ((def->sql_type == DRIZZLE_TYPE_NEWDATE ||
4181
4101
         def->sql_type == DRIZZLE_TYPE_DATETIME) &&
4207
4127
      find_it.after(def);                       // Put element after this
4208
4128
      /*
4209
4129
        XXX: hack for Bug#28427.
4210
 
        If column order has changed, force OFFLINE ALTER TABLE
 
4130
        If column order has changed, force OFFLINE ALTER Table
4211
4131
        without querying engine capabilities.  If we ever have an
4212
 
        engine that supports online ALTER TABLE CHANGE COLUMN
 
4132
        engine that supports online ALTER Table CHANGE COLUMN
4213
4133
        <name> AFTER <name1> (Falcon?), this fix will effectively
4214
4134
        disable the capability.
4215
4135
        TODO: detect the situation in compare_tables, behave based
4314
4234
      KEY_CREATE_INFO key_create_info;
4315
4235
      Key *key;
4316
4236
      enum Key::Keytype key_type;
4317
 
      memset((char*) &key_create_info, 0, sizeof(key_create_info));
 
4237
      memset(&key_create_info, 0, sizeof(key_create_info));
4318
4238
 
4319
4239
      key_create_info.algorithm= key_info->algorithm;
4320
4240
      if (key_info->flags & HA_USES_BLOCK_SIZE)
4411
4331
      table_list       The table to change.
4412
4332
      alter_info       Lists of fields, keys to be changed, added
4413
4333
                       or dropped.
4414
 
      order_num        How many ORDER BY fields has been specified.
4415
 
      order            List of fields to ORDER BY.
4416
 
      ignore           Whether we have ALTER IGNORE TABLE
 
4334
      order_num        How many order_st BY fields has been specified.
 
4335
      order            List of fields to order_st BY.
 
4336
      ignore           Whether we have ALTER IGNORE Table
4417
4337
 
4418
4338
  DESCRIPTION
4419
4339
    This is a veery long function and is everything but the kitchen sink :)
4420
 
    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
4421
4341
    CREATE|DROP INDEX are mapped on this function.
4422
4342
 
4423
 
    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,
4424
4344
    or both, then this function short cuts its operation by renaming
4425
4345
    the table and/or enabling/disabling the keys. In this case, the FRM is
4426
4346
    not changed, directly by mysql_alter_table. However, if there is a
4442
4362
 
4443
4363
bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
4444
4364
                       HA_CREATE_INFO *create_info,
4445
 
                       TABLE_LIST *table_list,
 
4365
                       TableList *table_list,
4446
4366
                       Alter_info *alter_info,
4447
 
                       uint order_num, ORDER *order, bool ignore)
 
4367
                       uint order_num, order_st *order, bool ignore)
4448
4368
{
4449
 
  TABLE *table, *new_table=0, *name_lock= 0;;
 
4369
  Table *table, *new_table=0, *name_lock= 0;;
4450
4370
  int error= 0;
4451
4371
  char tmp_name[80],old_name[32],new_name_buff[FN_REFLEN];
4452
4372
  char new_alias_buff[FN_REFLEN], *table_name, *db, *new_alias, *alias;
4454
4374
  ha_rows copied= 0,deleted= 0;
4455
4375
  handlerton *old_db_type, *new_db_type, *save_old_db_type;
4456
4376
  legacy_db_type table_type;
4457
 
  frm_type_enum frm_type;
4458
4377
 
4459
4378
  if (table_list && table_list->schema_table)
4460
4379
  {
4477
4396
 
4478
4397
  mysql_ha_rm_tables(thd, table_list, false);
4479
4398
 
4480
 
  /* DISCARD/IMPORT TABLESPACE is always alone in an ALTER TABLE */
 
4399
  /* DISCARD/IMPORT TABLESPACE is always alone in an ALTER Table */
4481
4400
  if (alter_info->tablespace_op != NO_TABLESPACE_OP)
4482
4401
    /* Conditionally writes to binlog. */
4483
4402
    return(mysql_discard_or_import_tablespace(thd,table_list,
4490
4409
    following scenario: 1) lock LOCK_open 2) do a RENAME
4491
4410
    2) unlock LOCK_open.
4492
4411
    This is a copy-paste added to make sure
4493
 
    ALTER (sic:) TABLE .. RENAME works for views. ALTER VIEW is handled
 
4412
    ALTER (sic:) Table .. RENAME works for views. ALTER VIEW is handled
4494
4413
    as an independent branch in mysql_execute_command. The need
4495
 
    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
4496
4415
    ... RENAME tries to use open_ltable, which does not work for views
4497
4416
    (open_ltable was never modified to merge table lists of child tables
4498
4417
    into the main table list, like open_tables does).
4499
4418
    This code is wrong and will be removed, please do not copy.
4500
4419
  */
4501
 
  frm_type= mysql_frm_type(thd, new_name_buff, &table_type);
 
4420
  (void)mysql_frm_type(thd, new_name_buff, &table_type);
4502
4421
 
4503
4422
  if (!(table= open_n_lock_single_table(thd, table_list, TL_WRITE_ALLOW_READ)))
4504
4423
    return(true);
4505
4424
  table->use_all_columns();
4506
4425
 
4507
 
  /*
4508
 
    Prohibit changing of the UNION list of a non-temporary MERGE table
4509
 
    under LOCK tables. It would be quite difficult to reuse a shrinked
4510
 
    set of tables from the old table or to open a new TABLE object for
4511
 
    an extended list and verify that they belong to locked tables.
4512
 
  */
4513
 
  if (thd->locked_tables &&
4514
 
      (create_info->used_fields & HA_CREATE_USED_UNION) &&
4515
 
      (table->s->tmp_table == NO_TMP_TABLE))
4516
 
  {
4517
 
    my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0));
4518
 
    return(true);
4519
 
  }
4520
 
 
4521
4426
  /* Check that we are not trying to rename to an existing table */
4522
4427
  if (new_name)
4523
4428
  {
4524
 
    strmov(new_name_buff,new_name);
4525
 
    strmov(new_alias= new_alias_buff, new_name);
 
4429
    stpcpy(new_name_buff,new_name);
 
4430
    stpcpy(new_alias= new_alias_buff, new_name);
4526
4431
    if (lower_case_table_names)
4527
4432
    {
4528
4433
      if (lower_case_table_names != 2)
4616
4521
    case ENABLE:
4617
4522
      /*
4618
4523
        wait_while_table_is_used() ensures that table being altered is
4619
 
        opened only by this thread and that TABLE::TABLE_SHARE::version
4620
 
        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.
4621
4526
        The latter guarantees that no DML statement will open this table
4622
 
        until ALTER TABLE finishes (i.e. until close_thread_tables())
 
4527
        until ALTER Table finishes (i.e. until close_thread_tables())
4623
4528
        while the fact that the table is still open gives us protection
4624
4529
        from concurrent DDL statements.
4625
4530
      */
4644
4549
    if (error == HA_ERR_WRONG_COMMAND)
4645
4550
    {
4646
4551
      error= 0;
4647
 
      push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
 
4552
      push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
4648
4553
                          ER_ILLEGAL_HA, ER(ER_ILLEGAL_HA),
4649
4554
                          table->alias);
4650
4555
    }
4652
4557
    VOID(pthread_mutex_lock(&LOCK_open));
4653
4558
    /*
4654
4559
      Unlike to the above case close_cached_table() below will remove ALL
4655
 
      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
4656
4561
      held by this thread). So to make actual table renaming and writing
4657
4562
      to binlog atomic we have to put them into the same critical section
4658
4563
      protected by LOCK_open mutex. This also removes gap for races between
4697
4602
    if (error == HA_ERR_WRONG_COMMAND)
4698
4603
  {
4699
4604
      error= 0;
4700
 
      push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
 
4605
      push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
4701
4606
                          ER_ILLEGAL_HA, ER(ER_ILLEGAL_HA),
4702
4607
                          table->alias);
4703
4608
  }
4722
4627
  /* We have to do full alter table. */
4723
4628
 
4724
4629
    /*
4725
 
    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 ...
4726
4631
    engine= <new_engine>, the new table must preserve the original
4727
4632
    partitioning. That means that the new engine is still the
4728
4633
    partitioning engine, not the engine specified in the parser.
4754
4659
 
4755
4660
  if (alter_info->build_method != HA_BUILD_OFFLINE)
4756
4661
  {
4757
 
    TABLE *altered_table= 0;
 
4662
    Table *altered_table= 0;
4758
4663
    HA_ALTER_INFO ha_alter_info;
4759
4664
    HA_ALTER_FLAGS ha_alter_flags;
4760
4665
    uint table_changes= IS_EQUAL_YES;
4806
4711
        /*
4807
4712
          @todo: Currently we always acquire an exclusive name
4808
4713
          lock on the table metadata when performing fast or online
4809
 
          ALTER TABLE. In future we may consider this unnecessary,
 
4714
          ALTER Table. In future we may consider this unnecessary,
4810
4715
          and narrow the scope of the exclusive name lock to only
4811
4716
          cover manipulation with .frms. Storage engine API
4812
4717
          call check_if_supported_alter has provision for this
4830
4735
      }
4831
4736
 
4832
4737
    }
4833
 
    /* 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 */
4834
4739
    if (!altered_table)
4835
4740
      need_copy_table= true;
4836
4741
 
4888
4793
  /* Open the table so we need to copy the data to it. */
4889
4794
  if (table->s->tmp_table)
4890
4795
  {
4891
 
    TABLE_LIST tbl;
4892
 
    memset((void*) &tbl, 0, sizeof(tbl));
 
4796
    TableList tbl;
 
4797
    memset(&tbl, 0, sizeof(tbl));
4893
4798
    tbl.db= new_db;
4894
4799
    tbl.table_name= tbl.alias= tmp_name;
4895
4800
    /* Table is in thd->temporary_tables */
4896
 
    new_table= open_table(thd, &tbl, thd->mem_root, (bool*) 0,
4897
 
                          MYSQL_LOCK_IGNORE_FLUSH);
 
4801
    new_table= open_table(thd, &tbl, (bool*) 0, DRIZZLE_LOCK_IGNORE_FLUSH);
4898
4802
  }
4899
4803
  else
4900
4804
  {
4919
4823
  */
4920
4824
  if (new_table && !(new_table->file->ha_table_flags() & HA_NO_COPY_ON_ALTER))
4921
4825
  {
4922
 
    /* We don't want update TIMESTAMP fields during ALTER TABLE. */
 
4826
    /* We don't want update TIMESTAMP fields during ALTER Table. */
4923
4827
    new_table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
4924
4828
    new_table->next_number_field=new_table->found_next_number_field;
4925
4829
    error= copy_data_between_tables(table, new_table,
4987
4891
       with exclusive name-locks.
4988
4892
    3) Rename the old table to a temp name, rename the new one to the
4989
4893
       old name.
4990
 
    4) If we are under LOCK TABLES and don't do ALTER TABLE ... RENAME
 
4894
    4) If we are under LOCK TABLES and don't do ALTER Table ... RENAME
4991
4895
       we reopen new version of table.
4992
4896
    5) Write statement to the binary log.
4993
 
    6) If we are under LOCK TABLES and do ALTER TABLE ... RENAME we
 
4897
    6) If we are under LOCK TABLES and do ALTER Table ... RENAME we
4994
4898
       remove name-locks from list of open tables and table cache.
4995
4899
    7) If we are not not under LOCK TABLES we rely on close_thread_tables()
4996
4900
       call to remove name-locks from table cache and list of open table.
5013
4917
    mysql_rename_table(), because we just juggle with the FRM and nothing
5014
4918
    more. If we have an intermediate table, then we notify the SE that
5015
4919
    it should become the actual table. Later, we will recycle the old table.
5016
 
    However, in case of ALTER TABLE RENAME there might be no intermediate
 
4920
    However, in case of ALTER Table RENAME there might be no intermediate
5017
4921
    table. This is when the old and new tables are compatible, according to
5018
4922
    compare_table(). Then, we need one additional call to
5019
4923
    mysql_rename_table() with flag NO_FRM_RENAME, which does nothing else but
5076
4980
      shutdown. But we do not need to attach MERGE children.
5077
4981
    */
5078
4982
    char path[FN_REFLEN];
5079
 
    TABLE *t_table;
 
4983
    Table *t_table;
5080
4984
    build_table_filename(path, sizeof(path), new_db, table_name, "", 0);
5081
4985
    t_table= open_temporary_table(thd, path, new_db, tmp_name, false, OTM_OPEN);
5082
4986
    if (t_table)
5085
4989
      my_free(t_table, MYF(0));
5086
4990
    }
5087
4991
    else
5088
 
      sql_print_warning("Could not open table %s.%s after rename\n",
 
4992
      sql_print_warning(_("Could not open table %s.%s after rename\n"),
5089
4993
                        new_db,table_name);
5090
4994
    ha_flush_logs(old_db_type);
5091
4995
  }
5094
4998
  if (thd->locked_tables && (new_name != table_name || new_db != db))
5095
4999
  {
5096
5000
    /*
5097
 
      If are we under LOCK TABLES and did ALTER TABLE with RENAME we need
 
5001
      If are we under LOCK TABLES and did ALTER Table with RENAME we need
5098
5002
      to remove placeholders for the old table and for the target table
5099
5003
      from the list of open tables and table cache. If we are not under
5100
5004
      LOCK TABLES we can rely on close_thread_tables() doing this job.
5149
5053
    }
5150
5054
    bool save_abort_on_warning= thd->abort_on_warning;
5151
5055
    thd->abort_on_warning= true;
5152
 
    make_truncated_value_warning(thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
 
5056
    make_truncated_value_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
5153
5057
                                 f_val, strlength(f_val), t_type,
5154
5058
                                 alter_info->datetime_field->field_name);
5155
5059
    thd->abort_on_warning= save_abort_on_warning;
5177
5081
/* mysql_alter_table */
5178
5082
 
5179
5083
static int
5180
 
copy_data_between_tables(TABLE *from,TABLE *to,
 
5084
copy_data_between_tables(Table *from,Table *to,
5181
5085
                         List<Create_field> &create,
5182
5086
                         bool ignore,
5183
 
                         uint order_num, ORDER *order,
 
5087
                         uint order_num, order_st *order,
5184
5088
                         ha_rows *copied,
5185
5089
                         ha_rows *deleted,
5186
5090
                         enum enum_enable_or_disable keys_onoff,
5193
5097
  uint length= 0;
5194
5098
  SORT_FIELD *sortorder;
5195
5099
  READ_RECORD info;
5196
 
  TABLE_LIST   tables;
 
5100
  TableList   tables;
5197
5101
  List<Item>   fields;
5198
5102
  List<Item>   all_fields;
5199
5103
  ha_rows examined_rows;
5237
5141
    if (def->field)
5238
5142
    {
5239
5143
      if (*ptr == to->next_number_field)
5240
 
      {
5241
5144
        auto_increment_field_copied= true;
5242
 
        /*
5243
 
          If we are going to copy contents of one auto_increment column to
5244
 
          another auto_increment column it is sensible to preserve zeroes.
5245
 
          This condition also covers case when we are don't actually alter
5246
 
          auto_increment column.
5247
 
        */
5248
 
        if (def->field == from->found_next_number_field)
5249
 
          thd->variables.sql_mode|= MODE_NO_AUTO_VALUE_ON_ZERO;
5250
 
      }
 
5145
 
5251
5146
      (copy_end++)->set(*ptr,def->field,0);
5252
5147
    }
5253
5148
 
5259
5154
  {
5260
5155
    if (to->s->primary_key != MAX_KEY && to->file->primary_key_is_clustered())
5261
5156
    {
5262
 
      char warn_buff[MYSQL_ERRMSG_SIZE];
 
5157
      char warn_buff[DRIZZLE_ERRMSG_SIZE];
5263
5158
      snprintf(warn_buff, sizeof(warn_buff), 
5264
 
               "ORDER BY ignored as there is a user-defined clustered index"
5265
 
               " in the table '%-.192s'", from->s->table_name.str);
5266
 
      push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_UNKNOWN_ERROR,
 
5159
               _("order_st BY ignored because there is a user-defined clustered "
 
5160
                 "index in the table '%-.192s'"),
 
5161
               from->s->table_name.str);
 
5162
      push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_UNKNOWN_ERROR,
5267
5163
                   warn_buff);
5268
5164
    }
5269
5165
    else
5270
5166
    {
5271
5167
      from->sort.io_cache=(IO_CACHE*) my_malloc(sizeof(IO_CACHE),
5272
5168
                                                MYF(MY_FAE | MY_ZEROFILL));
5273
 
      memset((char *) &tables, 0, sizeof(tables));
 
5169
      memset(&tables, 0, sizeof(tables));
5274
5170
      tables.table= from;
5275
5171
      tables.alias= tables.table_name= from->s->table_name.str;
5276
5172
      tables.db= from->s->db.str;
5404
5300
 RETURN
5405
5301
    Like mysql_alter_table().
5406
5302
*/
5407
 
bool mysql_recreate_table(THD *thd, TABLE_LIST *table_list)
 
5303
bool mysql_recreate_table(THD *thd, TableList *table_list)
5408
5304
{
5409
5305
  HA_CREATE_INFO create_info;
5410
5306
  Alter_info alter_info;
5416
5312
  */
5417
5313
  table_list->table= NULL;
5418
5314
 
5419
 
  memset((char*) &create_info, 0, sizeof(create_info));
 
5315
  memset(&create_info, 0, sizeof(create_info));
5420
5316
  create_info.row_type=ROW_TYPE_NOT_USED;
5421
5317
  create_info.default_table_charset=default_charset_info;
5422
5318
  /* Force alter table to recreate table */
5423
5319
  alter_info.flags= (ALTER_CHANGE_COLUMN | ALTER_RECREATE);
5424
5320
  return(mysql_alter_table(thd, NullS, NullS, &create_info,
5425
5321
                                table_list, &alter_info, 0,
5426
 
                                (ORDER *) 0, 0));
 
5322
                                (order_st *) 0, 0));
5427
5323
}
5428
5324
 
5429
5325
 
5430
 
bool mysql_checksum_table(THD *thd, TABLE_LIST *tables,
 
5326
bool mysql_checksum_table(THD *thd, TableList *tables,
5431
5327
                          HA_CHECK_OPT *check_opt)
5432
5328
{
5433
 
  TABLE_LIST *table;
 
5329
  TableList *table;
5434
5330
  List<Item> field_list;
5435
5331
  Item *item;
5436
5332
  Protocol *protocol= thd->protocol;
5448
5344
  for (table= tables; table; table= table->next_local)
5449
5345
  {
5450
5346
    char table_name[NAME_LEN*2+2];
5451
 
    TABLE *t;
 
5347
    Table *t;
5452
5348
 
5453
5349
    strxmov(table_name, table->db ,".", table->table_name, NullS);
5454
5350
 
5555
5451
 
5556
5452
  if (req_engine && req_engine != *new_engine)
5557
5453
  {
5558
 
    push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
 
5454
    push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
5559
5455
                       ER_WARN_USING_OTHER_HANDLER,
5560
5456
                       ER(ER_WARN_USING_OTHER_HANDLER),
5561
5457
                       ha_resolve_storage_engine_name(*new_engine),