~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_table.cc

Much closer toward UTF8 being around all the time...

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
static char *make_unique_key_name(const char *field_name,KEY *start,KEY *end);
30
30
static int copy_data_between_tables(Table *from,Table *to,
31
31
                                    List<Create_field> &create, bool ignore,
32
 
                                    uint32_t order_num, order_st *order,
 
32
                                    uint order_num, order_st *order,
33
33
                                    ha_rows *copied,ha_rows *deleted,
34
34
                                    enum enum_enable_or_disable keys_onoff,
35
35
                                    bool error_if_not_empty);
40
40
mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
41
41
                           Alter_info *alter_info,
42
42
                           bool tmp_table,
43
 
                               uint32_t *db_options,
 
43
                               uint *db_options,
44
44
                               handler *file, KEY **key_info_buffer,
45
 
                               uint32_t *key_count, int select_field_count);
 
45
                               uint *key_count, int select_field_count);
46
46
static bool
47
47
mysql_prepare_alter_table(THD *thd, Table *table,
48
48
                          HA_CREATE_INFO *create_info,
60
60
  RETURN
61
61
    Table name length.
62
62
*/
63
 
uint32_t filename_to_tablename(const char *from, char *to, uint32_t to_length)
 
63
uint filename_to_tablename(const char *from, char *to, uint to_length)
64
64
{
65
 
  uint32_t errors;
66
 
  uint32_t res;
 
65
  uint errors;
 
66
  uint res;
67
67
 
68
68
  if (!memcmp(from, tmp_file_prefix, tmp_file_prefix_length))
69
69
  {
70
70
    /* Temporary table name. */
71
 
    res= (my_stpncpy(to, from, to_length) - to);
 
71
    res= (stpncpy(to, from, to_length) - to);
72
72
  }
73
73
  else
74
74
  {
76
76
                    system_charset_info,  to, to_length, &errors);
77
77
    if (errors) // Old 5.0 name
78
78
    {
79
 
      res= (strxnmov(to, to_length, MYSQL50_TABLE_NAME_PREFIX,  from, NULL) -
 
79
      res= (strxnmov(to, to_length, MYSQL50_TABLE_NAME_PREFIX,  from, NullS) -
80
80
            to);
81
81
      sql_print_error(_("Invalid (old?) table or database name '%s'"), from);
82
82
    }
99
99
    File name length.
100
100
*/
101
101
 
102
 
uint32_t tablename_to_filename(const char *from, char *to, uint32_t to_length)
 
102
uint tablename_to_filename(const char *from, char *to, uint to_length)
103
103
{
104
 
  uint32_t errors, length;
 
104
  uint errors, length;
105
105
 
106
106
  if (from[0] == '#' && !strncmp(from, MYSQL50_TABLE_NAME_PREFIX,
107
107
                                 MYSQL50_TABLE_NAME_PREFIX_LENGTH))
153
153
    path length
154
154
*/
155
155
 
156
 
uint32_t build_table_filename(char *buff, size_t bufflen, const char *db,
157
 
                          const char *table_name, const char *ext, uint32_t flags)
 
156
uint build_table_filename(char *buff, size_t bufflen, const char *db,
 
157
                          const char *table_name, const char *ext, uint flags)
158
158
{
159
159
  char dbbuff[FN_REFLEN];
160
160
  char tbbuff[FN_REFLEN];
161
161
 
162
162
  if (flags & FN_IS_TMP) // FN_FROM_IS_TMP | FN_TO_IS_TMP
163
 
    my_stpncpy(tbbuff, table_name, sizeof(tbbuff));
 
163
    stpncpy(tbbuff, table_name, sizeof(tbbuff));
164
164
  else
165
 
    tablename_to_filename(table_name, tbbuff, sizeof(tbbuff));
 
165
    VOID(tablename_to_filename(table_name, tbbuff, sizeof(tbbuff)));
166
166
 
167
 
  tablename_to_filename(db, dbbuff, sizeof(dbbuff));
 
167
  VOID(tablename_to_filename(db, dbbuff, sizeof(dbbuff)));
168
168
 
169
169
  char *end = buff + bufflen;
170
170
  /* Don't add FN_ROOTDIR if mysql_data_home already includes it */
171
 
  char *pos = my_stpncpy(buff, mysql_data_home, bufflen);
 
171
  char *pos = stpncpy(buff, mysql_data_home, bufflen);
172
172
  int rootdir_len= strlen(FN_ROOTDIR);
173
173
  if (pos - rootdir_len >= buff &&
174
174
      memcmp(pos - rootdir_len, FN_ROOTDIR, rootdir_len) != 0)
175
 
    pos= my_stpncpy(pos, FN_ROOTDIR, end - pos);
176
 
  pos= strxnmov(pos, end - pos, dbbuff, FN_ROOTDIR, NULL);
 
175
    pos= stpncpy(pos, FN_ROOTDIR, end - pos);
 
176
  pos= strxnmov(pos, end - pos, dbbuff, FN_ROOTDIR, NullS);
177
177
#ifdef USE_SYMDIR
178
178
  unpack_dirname(buff, buff);
179
179
  pos= strend(buff);
180
180
#endif
181
 
  pos= strxnmov(pos, end - pos, tbbuff, ext, NULL);
 
181
  pos= strxnmov(pos, end - pos, tbbuff, ext, NullS);
182
182
 
183
183
  return(pos - buff);
184
184
}
202
202
    path length
203
203
*/
204
204
 
205
 
uint32_t build_tmptable_filename(THD* thd, char *buff, size_t bufflen)
 
205
uint build_tmptable_filename(THD* thd, char *buff, size_t bufflen)
206
206
{
207
207
 
208
 
  char *p= my_stpncpy(buff, mysql_tmpdir, bufflen);
 
208
  char *p= stpncpy(buff, mysql_tmpdir, bufflen);
209
209
  snprintf(p, bufflen - (p - buff), "/%s%lx_%lx_%x%s",
210
210
              tmp_file_prefix, current_pid,
211
211
              thd->thread_id, thd->tmp_table++, reg_ext);
216
216
    my_casedn_str(files_charset_info, p);
217
217
  }
218
218
 
219
 
  uint32_t length= unpack_filename(buff, buff);
 
219
  uint length= unpack_filename(buff, buff);
220
220
  return(length);
221
221
}
222
222
 
344
344
{
345
345
  TableList *table;
346
346
  char path[FN_REFLEN], *alias;
347
 
  uint32_t path_length;
 
347
  uint path_length;
348
348
  String wrong_tables;
349
349
  int error= 0;
350
350
  int non_temp_tables_count= 0;
402
402
      tmp_table_deleted= 1;
403
403
      continue;
404
404
    case -1:
 
405
      assert(thd->in_sub_stmt);
405
406
      error= 1;
406
407
      goto err_with_placeholders;
407
408
    default:
498
499
      {
499
500
        int new_error;
500
501
        /* Delete the table definition file */
501
 
        my_stpcpy(end,reg_ext);
 
502
        stpcpy(end,reg_ext);
502
503
        if (!(new_error=my_delete(path,MYF(MY_WME))))
503
504
        {
504
505
          some_tables_deleted=1;
604
605
*/
605
606
 
606
607
bool quick_rm_table(handlerton *base,const char *db,
607
 
                    const char *table_name, uint32_t flags)
 
608
                    const char *table_name, uint flags)
608
609
{
609
610
  char path[FN_REFLEN];
610
611
  bool error= 0;
611
612
 
612
 
  uint32_t path_length= build_table_filename(path, sizeof(path),
 
613
  uint path_length= build_table_filename(path, sizeof(path),
613
614
                                         db, table_name, reg_ext, flags);
614
615
  if (my_delete(path,MYF(0)))
615
616
    error= 1; /* purecov: inspected */
730
731
                                uint32_t *max_length, uint32_t *tot_length)
731
732
{
732
733
  const char **pos;
733
 
  uint32_t *len;
 
734
  uint *len;
734
735
  *max_length= *tot_length= 0;
735
736
  for (pos= interval->type_names, len= interval->type_lengths;
736
737
       *pos ; pos++, len++)
737
738
  {
738
 
    uint32_t length= cs->cset->numchars(cs, *pos, *pos + *len);
 
739
    uint length= cs->cset->numchars(cs, *pos, *pos + *len);
739
740
    *tot_length+= length;
740
741
    set_if_bigger(*max_length, (uint32_t)length);
741
742
  }
762
763
*/
763
764
 
764
765
int prepare_create_field(Create_field *sql_field, 
765
 
                         uint32_t *blob_columns,
 
766
                         uint *blob_columns,
766
767
                         int *timestamps, int *timestamps_with_niladic,
767
768
                         int64_t table_flags __attribute__((unused)))
768
769
{
839
840
                          (sql_field->decimals << FIELDFLAG_DEC_SHIFT));
840
841
    break;
841
842
  }
842
 
  if (!(sql_field->flags & NOT_NULL_FLAG) ||
843
 
      (sql_field->vcol_info)) /* Make virtual columns always allow NULL values */
 
843
  if (!(sql_field->flags & NOT_NULL_FLAG))
844
844
    sql_field->pack_flag|= FIELDFLAG_MAYBE_NULL;
845
845
  if (sql_field->flags & NO_DEFAULT_VALUE_FLAG)
846
846
    sql_field->pack_flag|= FIELDFLAG_NO_DEFAULT;
877
877
mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
878
878
                           Alter_info *alter_info,
879
879
                           bool tmp_table,
880
 
                               uint32_t *db_options,
 
880
                               uint *db_options,
881
881
                               handler *file, KEY **key_info_buffer,
882
 
                               uint32_t *key_count, int select_field_count)
 
882
                               uint *key_count, int select_field_count)
883
883
{
884
884
  const char    *key_name;
885
885
  Create_field  *sql_field,*dup_field;
892
892
  int           select_field_pos,auto_increment=0;
893
893
  List_iterator<Create_field> it(alter_info->create_list);
894
894
  List_iterator<Create_field> it2(alter_info->create_list);
895
 
  uint32_t total_uneven_bit_length= 0;
 
895
  uint total_uneven_bit_length= 0;
896
896
 
897
897
  select_field_pos= alter_info->create_list.elements - select_field_count;
898
898
  null_fields=blob_columns=0;
983
983
        List_iterator<String> int_it(sql_field->interval_list);
984
984
        String conv, *tmp;
985
985
        char comma_buf[4];
986
 
        int comma_length= cs->cset->wc_mb(cs, ',', (unsigned char*) comma_buf,
987
 
                                          (unsigned char*) comma_buf + 
 
986
        int comma_length= cs->cset->wc_mb(cs, ',', (uchar*) comma_buf,
 
987
                                          (uchar*) comma_buf + 
988
988
                                          sizeof(comma_buf));
989
989
        assert(comma_length > 0);
990
 
        for (uint32_t i= 0; (tmp= int_it++); i++)
 
990
        for (uint i= 0; (tmp= int_it++); i++)
991
991
        {
992
 
          uint32_t lengthsp;
 
992
          uint lengthsp;
993
993
          if (String::needs_conversion(tmp->length(), tmp->charset(),
994
994
                                       cs, &dummy))
995
995
          {
996
 
            uint32_t cnv_errs;
 
996
            uint cnv_errs;
997
997
            conv.copy(tmp->ptr(), tmp->length(), tmp->charset(), cs, &cnv_errs);
998
998
            interval->type_names[i]= strmake_root(thd->mem_root, conv.ptr(),
999
999
                                                  conv.length());
1004
1004
          lengthsp= cs->cset->lengthsp(cs, interval->type_names[i],
1005
1005
                                       interval->type_lengths[i]);
1006
1006
          interval->type_lengths[i]= lengthsp;
1007
 
          ((unsigned char *)interval->type_names[i])[lengthsp]= '\0';
 
1007
          ((uchar *)interval->type_names[i])[lengthsp]= '\0';
1008
1008
        }
1009
1009
        sql_field->interval_list.empty(); // Don't need interval_list anymore
1010
1010
      }
1094
1094
            null_fields--;
1095
1095
          sql_field->flags=             dup_field->flags;
1096
1096
          sql_field->interval=          dup_field->interval;
1097
 
          sql_field->vcol_info=         dup_field->vcol_info;
1098
 
          sql_field->is_stored=      dup_field->is_stored;
1099
1097
          it2.remove();                 // Remove first (create) definition
1100
1098
          select_field_pos--;
1101
1099
          break;
1127
1125
    sql_field->offset= record_offset;
1128
1126
    if (MTYP_TYPENR(sql_field->unireg_check) == Field::NEXT_NUMBER)
1129
1127
      auto_increment++;
1130
 
    /*
1131
 
          For now skip fields that are not physically stored in the database
1132
 
          (virtual fields) and update their offset later 
1133
 
          (see the next loop).
1134
 
        */
1135
 
    if (sql_field->is_stored)
1136
 
      record_offset+= sql_field->pack_length;
1137
 
  }
1138
 
  /* Update virtual fields' offset */
1139
 
  it.rewind();
1140
 
  while ((sql_field=it++))
1141
 
  {
1142
 
    if (not sql_field->is_stored)
1143
 
    {
1144
 
      sql_field->offset= record_offset;
1145
 
      record_offset+= sql_field->pack_length;
1146
 
    }
 
1128
    record_offset+= sql_field->pack_length;
1147
1129
  }
1148
1130
  if (timestamps_with_niladic > 1)
1149
1131
  {
1175
1157
 
1176
1158
  List_iterator<Key> key_iterator(alter_info->key_list);
1177
1159
  List_iterator<Key> key_iterator2(alter_info->key_list);
1178
 
  uint32_t key_parts=0, fk_key_count=0;
 
1160
  uint key_parts=0, fk_key_count=0;
1179
1161
  bool primary_key=0,unique_key=0;
1180
1162
  Key *key, *key2;
1181
 
  uint32_t tmp, key_number;
 
1163
  uint tmp, key_number;
1182
1164
  /* special marker for keys to be ignored */
1183
1165
  static char ignore_key[1];
1184
1166
 
1190
1172
    if (key->type == Key::FOREIGN_KEY)
1191
1173
    {
1192
1174
      fk_key_count++;
1193
 
      if (((Foreign_key *)key)->validate(alter_info->create_list))
1194
 
        return true;
1195
1175
      Foreign_key *fk_key= (Foreign_key*) key;
1196
1176
      if (fk_key->ref_columns.elements &&
1197
1177
          fk_key->ref_columns.elements != fk_key->columns.elements)
1270
1250
  key_number=0;
1271
1251
  for (; (key=key_iterator++) ; key_number++)
1272
1252
  {
1273
 
    uint32_t key_length=0;
 
1253
    uint key_length=0;
1274
1254
    Key_part_spec *column;
1275
1255
 
1276
1256
    if (key->name.str == ignore_key)
1314
1294
    if (key_info->block_size)
1315
1295
      key_info->flags|= HA_USES_BLOCK_SIZE;
1316
1296
 
1317
 
    uint32_t tmp_len= system_charset_info->cset->charpos(system_charset_info,
 
1297
    uint tmp_len= system_charset_info->cset->charpos(system_charset_info,
1318
1298
                                           key->key_create_info.comment.str,
1319
1299
                                           key->key_create_info.comment.str +
1320
1300
                                           key->key_create_info.comment.length,
1336
1316
    }
1337
1317
 
1338
1318
    List_iterator<Key_part_spec> cols(key->columns), cols2(key->columns);
1339
 
    for (uint32_t column_nr=0 ; (column=cols++) ; column_nr++)
 
1319
    for (uint column_nr=0 ; (column=cols++) ; column_nr++)
1340
1320
    {
1341
 
      uint32_t length;
 
1321
      uint length;
1342
1322
      Key_part_spec *dup_column;
1343
1323
 
1344
1324
      it.rewind();
1381
1361
            return(true);
1382
1362
          }
1383
1363
        }
1384
 
        if (not sql_field->is_stored)
1385
 
        {
1386
 
          /* Key fields must always be physically stored. */
1387
 
          my_error(ER_KEY_BASED_ON_GENERATED_VIRTUAL_COLUMN, MYF(0));
1388
 
          return(true);
1389
 
        }
1390
 
        if (key->type == Key::PRIMARY && sql_field->vcol_info)
1391
 
        {
1392
 
          my_error(ER_PRIMARY_KEY_BASED_ON_VIRTUAL_COLUMN, MYF(0));
1393
 
          return(true);
1394
 
        }
1395
1364
        if (!(sql_field->flags & NOT_NULL_FLAG))
1396
1365
        {
1397
1366
          if (key->type == Key::PRIMARY)
1430
1399
          if ((length=column->length) > max_key_length ||
1431
1400
              length > file->max_key_part_length())
1432
1401
          {
1433
 
            length=cmin(max_key_length, file->max_key_part_length());
 
1402
            length=min(max_key_length, file->max_key_part_length());
1434
1403
            if (key->type == Key::MULTIPLE)
1435
1404
            {
1436
1405
              /* not a critical problem */
1559
1528
    return(true);
1560
1529
  }
1561
1530
  /* Sort keys in optimized order */
1562
 
  my_qsort((unsigned char*) *key_info_buffer, *key_count, sizeof(KEY),
 
1531
  my_qsort((uchar*) *key_info_buffer, *key_count, sizeof(KEY),
1563
1532
           (qsort_cmp) sort_keys);
1564
1533
  create_info->null_bits= null_fields;
1565
1534
 
1744
1713
                                HA_CREATE_INFO *create_info,
1745
1714
                                Alter_info *alter_info,
1746
1715
                                bool internal_tmp_table,
1747
 
                                uint32_t select_field_count,
1748
 
                                bool lock_open_lock)
 
1716
                                uint select_field_count)
1749
1717
{
1750
1718
  char          path[FN_REFLEN];
1751
 
  uint32_t          path_length;
 
1719
  uint          path_length;
1752
1720
  const char    *alias;
1753
1721
  uint          db_options, key_count;
1754
1722
  KEY           *key_info_buffer;
1820
1788
    goto err;
1821
1789
  }
1822
1790
 
1823
 
  if (lock_open_lock)
1824
 
    pthread_mutex_lock(&LOCK_open);
 
1791
  VOID(pthread_mutex_lock(&LOCK_open));
1825
1792
  if (!internal_tmp_table && !(create_info->options & HA_LEX_CREATE_TMP_TABLE))
1826
1793
  {
1827
1794
    if (!access(path,F_OK))
1878
1845
    }
1879
1846
  }
1880
1847
 
1881
 
  thd->set_proc_info("creating table");
 
1848
  thd_proc_info(thd, "creating table");
1882
1849
  create_info->table_existed= 0;                // Mark that table is created
1883
1850
 
1884
1851
#ifdef HAVE_READLINK
1937
1904
    write_bin_log(thd, true, thd->query, thd->query_length);
1938
1905
  error= false;
1939
1906
unlock_and_end:
1940
 
  if (lock_open_lock)
1941
 
    pthread_mutex_unlock(&LOCK_open);
 
1907
  VOID(pthread_mutex_unlock(&LOCK_open));
1942
1908
 
1943
1909
err:
1944
 
  thd->set_proc_info("After create");
 
1910
  thd_proc_info(thd, "After create");
1945
1911
  delete file;
1946
1912
  return(error);
1947
1913
 
1963
1929
                        HA_CREATE_INFO *create_info,
1964
1930
                        Alter_info *alter_info,
1965
1931
                        bool internal_tmp_table,
1966
 
                        uint32_t select_field_count)
 
1932
                        uint select_field_count)
1967
1933
{
1968
1934
  Table *name_lock= 0;
1969
1935
  bool result;
1971
1937
  /* Wait for any database locks */
1972
1938
  pthread_mutex_lock(&LOCK_lock_db);
1973
1939
  while (!thd->killed &&
1974
 
         hash_search(&lock_db_cache,(unsigned char*) db, strlen(db)))
 
1940
         hash_search(&lock_db_cache,(uchar*) db, strlen(db)))
1975
1941
  {
1976
1942
    wait_for_condition(thd, &LOCK_lock_db, &COND_refresh);
1977
1943
    pthread_mutex_lock(&LOCK_lock_db);
2014
1980
  result= mysql_create_table_no_lock(thd, db, table_name, create_info,
2015
1981
                                     alter_info,
2016
1982
                                     internal_tmp_table,
2017
 
                                     select_field_count, true);
 
1983
                                     select_field_count);
2018
1984
 
2019
1985
unlock:
2020
1986
  if (name_lock)
2059
2025
    Only 3 chars + '\0' left, so need to limit to 2 digit
2060
2026
    This is ok as we can't have more than 100 keys anyway
2061
2027
  */
2062
 
  for (uint32_t i=2 ; i< 100; i++)
 
2028
  for (uint i=2 ; i< 100; i++)
2063
2029
  {
2064
2030
    *buff_end= '_';
2065
2031
    int10_to_str(i, buff_end+1, 10);
2099
2065
bool
2100
2066
mysql_rename_table(handlerton *base, const char *old_db,
2101
2067
                   const char *old_name, const char *new_db,
2102
 
                   const char *new_name, uint32_t flags)
 
2068
                   const char *new_name, uint flags)
2103
2069
{
2104
2070
  THD *thd= current_thd;
2105
2071
  char from[FN_REFLEN], to[FN_REFLEN], lc_from[FN_REFLEN], lc_to[FN_REFLEN];
2124
2090
  if (lower_case_table_names == 2 && file &&
2125
2091
      !(file->ha_table_flags() & HA_FILE_BASED))
2126
2092
  {
2127
 
    my_stpcpy(tmp_name, old_name);
 
2093
    stpcpy(tmp_name, old_name);
2128
2094
    my_casedn_str(files_charset_info, tmp_name);
2129
2095
    build_table_filename(lc_from, sizeof(lc_from), old_db, tmp_name, "",
2130
2096
                         flags & FN_FROM_IS_TMP);
2131
2097
    from_base= lc_from;
2132
2098
 
2133
 
    my_stpcpy(tmp_name, new_name);
 
2099
    stpcpy(tmp_name, new_name);
2134
2100
    my_casedn_str(files_charset_info, tmp_name);
2135
2101
    build_table_filename(lc_to, sizeof(lc_to), new_db, tmp_name, "",
2136
2102
                         flags & FN_TO_IS_TMP);
2180
2146
 
2181
2147
  safe_mutex_assert_owner(&LOCK_open);
2182
2148
 
2183
 
  table->file->extra(function);
 
2149
  VOID(table->file->extra(function));
2184
2150
  /* Mark all tables that are in use as 'old' */
2185
2151
  mysql_lock_abort(thd, table, true);   /* end threads waiting on lock */
2186
2152
 
2259
2225
  if (!(table= table_list->table))              /* if open_ltable failed */
2260
2226
  {
2261
2227
    char key[MAX_DBKEY_LENGTH];
2262
 
    uint32_t key_length;
 
2228
    uint key_length;
2263
2229
 
2264
2230
    key_length= create_table_def_key(thd, key, table_list, 0);
2265
2231
    pthread_mutex_lock(&LOCK_open);
2311
2277
    goto end;                                   // No data file
2312
2278
 
2313
2279
  // Name of data file
2314
 
  strxmov(from, table->s->normalized_path.str, ext[1], NULL);
 
2280
  strxmov(from, table->s->normalized_path.str, ext[1], NullS);
2315
2281
  if (stat(from, &stat_info))
2316
2282
    goto end;                           // Can't use USE_FRM flag
2317
2283
 
2397
2363
                              thr_lock_type lock_type,
2398
2364
                              bool open_for_modify,
2399
2365
                              bool no_warnings_for_error,
2400
 
                              uint32_t extra_open_options,
 
2366
                              uint extra_open_options,
2401
2367
                              int (*prepare_func)(THD *, TableList *,
2402
2368
                                                  HA_CHECK_OPT *),
2403
2369
                              int (handler::*operator_func)(THD *,
2436
2402
    char* db = table->db;
2437
2403
    bool fatal_error=0;
2438
2404
 
2439
 
    strxmov(table_name, db, ".", table->table_name, NULL);
 
2405
    strxmov(table_name, db, ".", table->table_name, NullS);
2440
2406
    thd->open_options|= extra_open_options;
2441
2407
    table->lock_type= lock_type;
2442
2408
    /* open only one table from local list of command */
2446
2412
      table->next_global= 0;
2447
2413
      save_next_local= table->next_local;
2448
2414
      table->next_local= 0;
2449
 
      select->table_list.first= (unsigned char*)table;
 
2415
      select->table_list.first= (uchar*)table;
2450
2416
      /*
2451
2417
        Time zone tables and SP tables can be add to lex->query_tables list,
2452
2418
        so it have to be prepared.
2502
2468
    {
2503
2469
      /* purecov: begin inspected */
2504
2470
      char buff[FN_REFLEN + DRIZZLE_ERRMSG_SIZE];
2505
 
      uint32_t length;
 
2471
      uint length;
2506
2472
      protocol->prepare_for_resend();
2507
2473
      protocol->store(table_name, system_charset_info);
2508
2474
      protocol->store(operator_name, system_charset_info);
2609
2575
    case HA_ADMIN_NOT_IMPLEMENTED:
2610
2576
      {
2611
2577
        char buf[ERRMSGSIZE+20];
2612
 
        uint32_t length=snprintf(buf, ERRMSGSIZE,
 
2578
        uint length=snprintf(buf, ERRMSGSIZE,
2613
2579
                             ER(ER_CHECK_NOT_IMPLEMENTED), operator_name);
2614
2580
        protocol->store(STRING_WITH_LEN("note"), system_charset_info);
2615
2581
        protocol->store(buf, length, system_charset_info);
2619
2585
    case HA_ADMIN_NOT_BASE_TABLE:
2620
2586
      {
2621
2587
        char buf[ERRMSGSIZE+20];
2622
 
        uint32_t length= snprintf(buf, ERRMSGSIZE,
 
2588
        uint length= snprintf(buf, ERRMSGSIZE,
2623
2589
                              ER(ER_BAD_TABLE_ERROR), table_name);
2624
2590
        protocol->store(STRING_WITH_LEN("note"), system_charset_info);
2625
2591
        protocol->store(buf, length, system_charset_info);
2734
2700
    case HA_ADMIN_NEEDS_ALTER:
2735
2701
    {
2736
2702
      char buf[ERRMSGSIZE];
2737
 
      uint32_t length;
 
2703
      uint length;
2738
2704
 
2739
2705
      protocol->store(STRING_WITH_LEN("error"), system_charset_info);
2740
2706
      length=snprintf(buf, ERRMSGSIZE, ER(ER_TABLE_NEEDS_UPGRADE), table->table_name);
2746
2712
    default:                            // Probably HA_ADMIN_INTERNAL_ERROR
2747
2713
      {
2748
2714
        char buf[ERRMSGSIZE+20];
2749
 
        uint32_t length=snprintf(buf, ERRMSGSIZE,
 
2715
        uint length=snprintf(buf, ERRMSGSIZE,
2750
2716
                             _("Unknown - internal error %d during operation"),
2751
2717
                             result_code);
2752
2718
        protocol->store(STRING_WITH_LEN("error"), system_charset_info);
2902
2868
  HA_CREATE_INFO local_create_info;
2903
2869
  Alter_info alter_info;
2904
2870
  bool tmp_table= (create_info->options & HA_LEX_CREATE_TMP_TABLE);
2905
 
  uint32_t keys= schema_table->table->s->keys;
2906
 
  uint32_t db_options= 0;
 
2871
  uint keys= schema_table->table->s->keys;
 
2872
  uint db_options= 0;
2907
2873
 
2908
2874
  memset(&local_create_info, 0, sizeof(local_create_info));
2909
2875
  local_create_info.db_type= schema_table->table->s->db_type();
2920
2886
                                 &schema_table->table->s->key_info, &keys, 0))
2921
2887
    return(1);
2922
2888
  local_create_info.max_rows= 0;
2923
 
  if (mysql_create_frm(thd, dst_path, NULL, NULL,
 
2889
  if (mysql_create_frm(thd, dst_path, NullS, NullS,
2924
2890
                       &local_create_info, alter_info.create_list,
2925
2891
                       keys, schema_table->table->s->key_info,
2926
2892
                       schema_table->table->file))
2949
2915
{
2950
2916
  Table *name_lock= 0;
2951
2917
  char src_path[FN_REFLEN], dst_path[FN_REFLEN];
2952
 
  uint32_t dst_path_length;
 
2918
  uint dst_path_length;
2953
2919
  char *db= table->db;
2954
2920
  char *table_name= table->table_name;
2955
2921
  int  err;
2956
2922
  bool res= true;
2957
 
  uint32_t not_used;
 
2923
  uint not_used;
2958
2924
 
2959
2925
  /*
2960
2926
    By opening source table we guarantee that it exists and no concurrent
2968
2934
  if (open_tables(thd, &src_table, &not_used, 0))
2969
2935
    return(true);
2970
2936
 
2971
 
  strxmov(src_path, src_table->table->s->path.str, reg_ext, NULL);
 
2937
  strxmov(src_path, src_table->table->s->path.str, reg_ext, NullS);
2972
2938
 
2973
2939
  /* 
2974
2940
    Check that destination tables does not exist. Note that its name
3006
2972
    Also some engines (e.g. NDB cluster) require that LOCK_open should be held
3007
2973
    during the call to ha_create_table(). See bug #28614 for more info.
3008
2974
  */
3009
 
  pthread_mutex_lock(&LOCK_open);
 
2975
  VOID(pthread_mutex_lock(&LOCK_open));
3010
2976
  if (src_table->schema_table)
3011
2977
  {
3012
2978
    if (mysql_create_like_schema_frm(thd, src_table, dst_path, create_info))
3013
2979
    {
3014
 
      pthread_mutex_unlock(&LOCK_open);
 
2980
      VOID(pthread_mutex_unlock(&LOCK_open));
3015
2981
      goto err;
3016
2982
    }
3017
2983
  }
3021
2987
      my_error(ER_BAD_DB_ERROR,MYF(0),db);
3022
2988
    else
3023
2989
      my_error(ER_CANT_CREATE_FILE,MYF(0),dst_path,my_errno);
3024
 
    pthread_mutex_unlock(&LOCK_open);
 
2990
    VOID(pthread_mutex_unlock(&LOCK_open));
3025
2991
    goto err;
3026
2992
  }
3027
2993
 
3034
3000
  if (thd->variables.keep_files_on_create)
3035
3001
    create_info->options|= HA_CREATE_KEEP_FILES;
3036
3002
  err= ha_create_table(thd, dst_path, db, table_name, create_info, 1);
3037
 
  pthread_mutex_unlock(&LOCK_open);
 
3003
  VOID(pthread_mutex_unlock(&LOCK_open));
3038
3004
 
3039
3005
  if (create_info->options & HA_LEX_CREATE_TMP_TABLE)
3040
3006
  {
3089
3055
          of this function.
3090
3056
        */
3091
3057
        table->table= name_lock;
3092
 
        pthread_mutex_lock(&LOCK_open);
 
3058
        VOID(pthread_mutex_lock(&LOCK_open));
3093
3059
        if (reopen_name_locked_table(thd, table, false))
3094
3060
        {
3095
 
          pthread_mutex_unlock(&LOCK_open);
 
3061
          VOID(pthread_mutex_unlock(&LOCK_open));
3096
3062
          goto err;
3097
3063
        }
3098
 
        pthread_mutex_unlock(&LOCK_open);
 
3064
        VOID(pthread_mutex_unlock(&LOCK_open));
3099
3065
 
3100
3066
        int result= store_create_info(thd, table, &query,
3101
3067
                                               create_info);
3176
3142
    ALTER Table
3177
3143
  */
3178
3144
 
3179
 
  thd->set_proc_info("discard_or_import_tablespace");
 
3145
  thd_proc_info(thd, "discard_or_import_tablespace");
3180
3146
 
3181
3147
  discard= test(tablespace_op == DISCARD_TABLESPACE);
3182
3148
 
3193
3159
 
3194
3160
  error= table->file->ha_discard_or_import_tablespace(discard);
3195
3161
 
3196
 
  thd->set_proc_info("end");
 
3162
  thd_proc_info(thd, "end");
3197
3163
 
3198
3164
  if (error)
3199
3165
    goto err;
3227
3193
 
3228
3194
void setup_ha_alter_flags(Alter_info *alter_info, HA_ALTER_FLAGS *alter_flags)
3229
3195
{
3230
 
  uint32_t flags= alter_info->flags;
 
3196
  uint flags= alter_info->flags;
3231
3197
 
3232
3198
  if (ALTER_ADD_COLUMN & flags)
3233
3199
    *alter_flags|= HA_ADD_COLUMN;
3293
3259
               Table *table,
3294
3260
               Alter_info *alter_info,
3295
3261
                           HA_CREATE_INFO *create_info,
3296
 
               uint32_t order_num,
 
3262
               uint order_num,
3297
3263
               HA_ALTER_FLAGS *alter_flags,
3298
3264
               HA_ALTER_INFO *ha_alter_info,
3299
 
               uint32_t *table_changes)
 
3265
               uint *table_changes)
3300
3266
{
3301
3267
  Field **f_ptr, *field;
3302
 
  uint32_t table_changes_local= 0;
 
3268
  uint table_changes_local= 0;
3303
3269
  List_iterator_fast<Create_field> new_field_it(alter_info->create_list);
3304
3270
  Create_field *new_field;
3305
3271
  KEY_PART_INFO *key_part;
3328
3294
    */
3329
3295
    Alter_info tmp_alter_info(*alter_info, thd->mem_root);
3330
3296
    THD *thd= table->in_use;
3331
 
    uint32_t db_options= 0; /* not used */
 
3297
    uint db_options= 0; /* not used */
3332
3298
    /* Create the prepared information. */
3333
3299
    if (mysql_prepare_create_table(thd, create_info,
3334
3300
                                   &tmp_alter_info,
3441
3407
      if (!(table_changes_local= field->is_equal(new_field)))
3442
3408
        *alter_flags|= HA_ALTER_COLUMN_TYPE;
3443
3409
 
3444
 
      /*
3445
 
        Check if the altered column is a stored virtual field.
3446
 
        TODO: Mark such a column with an alter flag only if
3447
 
        the expression functions are not equal. 
3448
 
      */
3449
 
      if (field->is_stored && field->vcol_info)
3450
 
        *alter_flags|= HA_ALTER_STORED_VCOL;
3451
 
 
3452
3410
      /* Check if field was renamed */
3453
3411
      field->flags&= ~FIELD_IS_RENAMED;
3454
3412
      if (my_strcasecmp(system_charset_info,
3730
3688
    if (create_info->index_file_name)
3731
3689
    {
3732
3690
      /* Fix index_file_name to have 'tmp_name' as basename */
3733
 
      my_stpcpy(index_file, tmp_name);
 
3691
      stpcpy(index_file, tmp_name);
3734
3692
      create_info->index_file_name=fn_same(index_file,
3735
3693
                                           create_info->index_file_name,
3736
3694
                                           1);
3738
3696
    if (create_info->data_file_name)
3739
3697
    {
3740
3698
      /* Fix data_file_name to have 'tmp_name' as basename */
3741
 
      my_stpcpy(data_file, tmp_name);
 
3699
      stpcpy(data_file, tmp_name);
3742
3700
      create_info->data_file_name=fn_same(data_file,
3743
3701
                                          create_info->data_file_name,
3744
3702
                                          1);
3887
3845
    The final .frm file is already created as a temporary file
3888
3846
    and will be renamed to the original table name.
3889
3847
  */
3890
 
  pthread_mutex_lock(&LOCK_open);
 
3848
  VOID(pthread_mutex_lock(&LOCK_open));
3891
3849
  wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN);
3892
3850
  alter_table_manage_keys(table, table->file->indexes_are_disabled(),
3893
3851
                          keys_onoff);
3901
3859
                         table->s->table_name.str, FN_FROM_IS_TMP))
3902
3860
  {
3903
3861
    error= 1;
3904
 
    pthread_mutex_unlock(&LOCK_open);
 
3862
    VOID(pthread_mutex_unlock(&LOCK_open));
3905
3863
    goto err;
3906
3864
  }
3907
3865
  broadcast_refresh();
3908
 
  pthread_mutex_unlock(&LOCK_open);
 
3866
  VOID(pthread_mutex_unlock(&LOCK_open));
3909
3867
 
3910
3868
  /*
3911
3869
    The ALTER Table is always in its own transaction.
3921
3879
    goto err;
3922
3880
  if (online)
3923
3881
  {
3924
 
    pthread_mutex_lock(&LOCK_open);
 
3882
    VOID(pthread_mutex_lock(&LOCK_open));
3925
3883
    if (reopen_table(table))
3926
3884
    {
3927
3885
      error= -1;
3928
3886
      goto err;
3929
3887
    }
3930
 
    pthread_mutex_unlock(&LOCK_open);
 
3888
    VOID(pthread_mutex_unlock(&LOCK_open));
3931
3889
    t_table= table;
3932
3890
 
3933
3891
   /*
3946
3904
    */
3947
3905
    assert(t_table == table);
3948
3906
    table->open_placeholder= 1;
3949
 
    pthread_mutex_lock(&LOCK_open);
 
3907
    VOID(pthread_mutex_lock(&LOCK_open));
3950
3908
    close_handle_and_leave_table_as_lock(table);
3951
 
    pthread_mutex_unlock(&LOCK_open);
 
3909
    VOID(pthread_mutex_unlock(&LOCK_open));
3952
3910
  }
3953
3911
 
3954
3912
 err:
4015
3973
  List_iterator<Create_field> find_it(new_create_list);
4016
3974
  List_iterator<Create_field> field_it(new_create_list);
4017
3975
  List<Key_part_spec> key_parts;
4018
 
  uint32_t db_create_options= (table->s->db_create_options
 
3976
  uint db_create_options= (table->s->db_create_options
4019
3977
                           & ~(HA_OPTION_PACK_RECORD));
4020
 
  uint32_t used_fields= create_info->used_fields;
 
3978
  uint used_fields= create_info->used_fields;
4021
3979
  KEY *key_info=table->key_info;
4022
3980
  bool rc= true;
4023
3981
 
4042
4000
  }
4043
4001
  if (!(used_fields & HA_CREATE_USED_KEY_BLOCK_SIZE))
4044
4002
    create_info->key_block_size= table->s->key_block_size;
 
4003
  if (!(used_fields & HA_CREATE_USED_TRANSACTIONAL))
 
4004
    create_info->transactional= table->s->transactional;
4045
4005
 
4046
4006
  restore_record(table, s->default_values);     // Empty record for DEFAULT
4047
4007
  Create_field *def;
4086
4046
    if (def)
4087
4047
    {                                           // Field is changed
4088
4048
      def->field=field;
4089
 
      if (field->is_stored != def->is_stored)
4090
 
      {
4091
 
        my_error(ER_UNSUPPORTED_ACTION_ON_VIRTUAL_COLUMN,
4092
 
                 MYF(0),
4093
 
                 "Changing the STORED status");
4094
 
        goto err;
4095
 
      }
4096
4049
      if (!def->after)
4097
4050
        {
4098
4051
        new_create_list.push_back(def);
4208
4161
    for which some fields exists.
4209
4162
    */
4210
4163
 
4211
 
  for (uint32_t i=0 ; i < table->s->keys ; i++,key_info++)
 
4164
  for (uint i=0 ; i < table->s->keys ; i++,key_info++)
4212
4165
    {
4213
4166
    char *key_name= key_info->name;
4214
4167
    Alter_drop *drop;
4227
4180
 
4228
4181
    KEY_PART_INFO *key_part= key_info->key_part;
4229
4182
    key_parts.empty();
4230
 
    for (uint32_t j=0 ; j < key_info->key_parts ; j++,key_part++)
 
4183
    for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
4231
4184
    {
4232
4185
      if (!key_part->field)
4233
4186
        continue;                               // Wrong field (from UNIREG)
4248
4201
      }
4249
4202
      if (!cfield)
4250
4203
        continue;                               // Field is removed
4251
 
      uint32_t key_part_length=key_part->length;
 
4204
      uint key_part_length=key_part->length;
4252
4205
      if (cfield->field)                        // Not new field
4253
4206
      {
4254
4207
        /*
4310
4263
    Key *key;
4311
4264
    while ((key=key_it++))                      // Add new keys
4312
4265
    {
4313
 
      if (key->type == Key::FOREIGN_KEY &&
4314
 
          ((Foreign_key *)key)->validate(new_create_list))
4315
 
        goto err;
4316
4266
      if (key->type != Key::FOREIGN_KEY)
4317
4267
        new_key_list.push_back(key);
4318
4268
      if (key->name.str &&
4414
4364
                       HA_CREATE_INFO *create_info,
4415
4365
                       TableList *table_list,
4416
4366
                       Alter_info *alter_info,
4417
 
                       uint32_t order_num, order_st *order, bool ignore)
 
4367
                       uint order_num, order_st *order, bool ignore)
4418
4368
{
4419
4369
  Table *table, *new_table=0, *name_lock= 0;;
4420
4370
  int error= 0;
4436
4386
    to simplify further comparisons: we want to see if it's a RENAME
4437
4387
    later just by comparing the pointers, avoiding the need for strcmp.
4438
4388
  */
4439
 
  thd->set_proc_info("init");
 
4389
  thd_proc_info(thd, "init");
4440
4390
  table_name=table_list->table_name;
4441
4391
  alias= (lower_case_table_names == 2) ? table_list->alias : table_name;
4442
4392
  db=table_list->db;
4452
4402
    return(mysql_discard_or_import_tablespace(thd,table_list,
4453
4403
                                              alter_info->tablespace_op));
4454
4404
  strxnmov(new_name_buff, sizeof (new_name_buff) - 1, mysql_data_home, "/", db, 
4455
 
           "/", table_name, reg_ext, NULL);
 
4405
           "/", table_name, reg_ext, NullS);
4456
4406
  (void) unpack_filename(new_name_buff, new_name_buff);
4457
4407
  /*
4458
4408
    If this is just a rename of a view, short cut to the
4476
4426
  /* Check that we are not trying to rename to an existing table */
4477
4427
  if (new_name)
4478
4428
  {
4479
 
    my_stpcpy(new_name_buff,new_name);
4480
 
    my_stpcpy(new_alias= new_alias_buff, new_name);
 
4429
    stpcpy(new_name_buff,new_name);
 
4430
    stpcpy(new_alias= new_alias_buff, new_name);
4481
4431
    if (lower_case_table_names)
4482
4432
    {
4483
4433
      if (lower_case_table_names != 2)
4561
4511
    goto err;
4562
4512
  }
4563
4513
 
4564
 
  thd->set_proc_info("setup");
 
4514
  thd_proc_info(thd, "setup");
4565
4515
  if (!(alter_info->flags & ~(ALTER_RENAME | ALTER_KEYS_ONOFF)) &&
4566
4516
      !table->s->tmp_table) // no need to touch frm
4567
4517
  {
4578
4528
        while the fact that the table is still open gives us protection
4579
4529
        from concurrent DDL statements.
4580
4530
      */
4581
 
      pthread_mutex_lock(&LOCK_open);
 
4531
      VOID(pthread_mutex_lock(&LOCK_open));
4582
4532
      wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN);
4583
 
      pthread_mutex_unlock(&LOCK_open);
 
4533
      VOID(pthread_mutex_unlock(&LOCK_open));
4584
4534
      error= table->file->ha_enable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
4585
4535
      /* COND_refresh will be signaled in close_thread_tables() */
4586
4536
      break;
4587
4537
    case DISABLE:
4588
 
      pthread_mutex_lock(&LOCK_open);
 
4538
      VOID(pthread_mutex_lock(&LOCK_open));
4589
4539
      wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN);
4590
 
      pthread_mutex_unlock(&LOCK_open);
 
4540
      VOID(pthread_mutex_unlock(&LOCK_open));
4591
4541
      error=table->file->ha_disable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
4592
4542
      /* COND_refresh will be signaled in close_thread_tables() */
4593
4543
      break;
4604
4554
                          table->alias);
4605
4555
    }
4606
4556
 
4607
 
    pthread_mutex_lock(&LOCK_open);
 
4557
    VOID(pthread_mutex_lock(&LOCK_open));
4608
4558
    /*
4609
4559
      Unlike to the above case close_cached_table() below will remove ALL
4610
4560
      instances of Table from table cache (it will also remove table lock
4616
4566
 
4617
4567
    if (!error && (new_name != table_name || new_db != db))
4618
4568
    {
4619
 
      thd->set_proc_info("rename");
 
4569
      thd_proc_info(thd, "rename");
4620
4570
      /*
4621
4571
        Then do a 'simple' rename of the table. First we need to close all
4622
4572
        instances of 'source' table.
4642
4592
          error= -1;
4643
4593
        else if (0)
4644
4594
      {
4645
 
          mysql_rename_table(old_db_type, new_db, new_alias, db,
4646
 
                             table_name, 0);
 
4595
          VOID(mysql_rename_table(old_db_type, new_db, new_alias, db,
 
4596
                                  table_name, 0));
4647
4597
          error= -1;
4648
4598
      }
4649
4599
    }
4669
4619
    }
4670
4620
    if (name_lock)
4671
4621
      unlink_open_table(thd, name_lock, false);
4672
 
    pthread_mutex_unlock(&LOCK_open);
 
4622
    VOID(pthread_mutex_unlock(&LOCK_open));
4673
4623
    table_list->table= NULL;                    // For query cache
4674
4624
    return(error);
4675
4625
  }
4712
4662
    Table *altered_table= 0;
4713
4663
    HA_ALTER_INFO ha_alter_info;
4714
4664
    HA_ALTER_FLAGS ha_alter_flags;
4715
 
    uint32_t table_changes= IS_EQUAL_YES;
 
4665
    uint table_changes= IS_EQUAL_YES;
4716
4666
    bool need_copy_table= true;
4717
4667
    /* Check how much the tables differ. */
4718
4668
    if (compare_tables(thd, table, alter_info,
4865
4815
  /* Copy the data if necessary. */
4866
4816
  thd->count_cuted_fields= CHECK_FIELD_WARN;    // calc cuted fields
4867
4817
  thd->cuted_fields=0L;
4868
 
  thd->set_proc_info("copy to tmp table");
 
4818
  thd_proc_info(thd, "copy to tmp table");
4869
4819
  copied=deleted=0;
4870
4820
  /*
4871
4821
    We do not copy data for MERGE tables. Only the children have data.
4884
4834
  }
4885
4835
  else
4886
4836
  {
4887
 
    pthread_mutex_lock(&LOCK_open);
 
4837
    VOID(pthread_mutex_lock(&LOCK_open));
4888
4838
    wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN);
4889
 
    pthread_mutex_unlock(&LOCK_open);
 
4839
    VOID(pthread_mutex_unlock(&LOCK_open));
4890
4840
    alter_table_manage_keys(table, table->file->indexes_are_disabled(),
4891
4841
                            alter_info->keys_onoff);
4892
4842
    error= ha_autocommit_or_rollback(thd, 0);
4924
4874
      Note that MERGE tables do not have their children attached here.
4925
4875
    */
4926
4876
    intern_close_table(new_table);
4927
 
    free(new_table);
 
4877
    my_free(new_table,MYF(0));
4928
4878
  }
4929
 
  pthread_mutex_lock(&LOCK_open);
 
4879
  VOID(pthread_mutex_lock(&LOCK_open));
4930
4880
  if (error)
4931
4881
  {
4932
 
    quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP);
4933
 
    pthread_mutex_unlock(&LOCK_open);
 
4882
    VOID(quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP));
 
4883
    VOID(pthread_mutex_unlock(&LOCK_open));
4934
4884
    goto err;
4935
4885
  }
4936
4886
 
4950
4900
       call to remove name-locks from table cache and list of open table.
4951
4901
  */
4952
4902
 
4953
 
  thd->set_proc_info("rename result table");
 
4903
  thd_proc_info(thd, "rename result table");
4954
4904
  snprintf(old_name, sizeof(old_name), "%s2-%lx-%lx", tmp_file_prefix,
4955
4905
           current_pid, thd->thread_id);
4956
4906
  if (lower_case_table_names)
4979
4929
                         FN_TO_IS_TMP))
4980
4930
  {
4981
4931
    error=1;
4982
 
    quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP);
 
4932
    VOID(quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP));
4983
4933
  }
4984
4934
  else if (mysql_rename_table(new_db_type, new_db, tmp_name, new_db,
4985
4935
                              new_alias, FN_FROM_IS_TMP) || ((new_name != table_name || new_db != db) && 0))
4986
4936
  {
4987
4937
    /* Try to get everything back. */
4988
4938
    error=1;
4989
 
    quick_rm_table(new_db_type,new_db,new_alias, 0);
4990
 
    quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP);
4991
 
    mysql_rename_table(old_db_type, db, old_name, db, alias,
4992
 
                       FN_FROM_IS_TMP);
 
4939
    VOID(quick_rm_table(new_db_type,new_db,new_alias, 0));
 
4940
    VOID(quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP));
 
4941
    VOID(mysql_rename_table(old_db_type, db, old_name, db, alias,
 
4942
                            FN_FROM_IS_TMP));
4993
4943
  }
4994
4944
 
4995
4945
  if (error)
4998
4948
    goto err_with_placeholders;
4999
4949
  }
5000
4950
 
5001
 
  quick_rm_table(old_db_type, db, old_name, FN_IS_TMP);
 
4951
  VOID(quick_rm_table(old_db_type, db, old_name, FN_IS_TMP));
5002
4952
 
5003
4953
end_online:
5004
4954
  if (thd->locked_tables && new_name == table_name && new_db == db)
5009
4959
    if (error)
5010
4960
      goto err_with_placeholders;
5011
4961
  }
5012
 
  pthread_mutex_unlock(&LOCK_open);
5013
 
 
5014
 
  thd->set_proc_info("end");
 
4962
  VOID(pthread_mutex_unlock(&LOCK_open));
 
4963
 
 
4964
  thd_proc_info(thd, "end");
 
4965
 
 
4966
  ha_binlog_log_query(thd, create_info->db_type, LOGCOM_ALTER_TABLE,
 
4967
                      thd->query, thd->query_length,
 
4968
                      db, table_name);
5015
4969
 
5016
4970
  assert(!(mysql_bin_log.is_open() &&
5017
4971
                thd->current_stmt_binlog_row_based &&
5032
4986
    if (t_table)
5033
4987
    {
5034
4988
      intern_close_table(t_table);
5035
 
      free(t_table);
 
4989
      my_free(t_table, MYF(0));
5036
4990
    }
5037
4991
    else
5038
4992
      sql_print_warning(_("Could not open table %s.%s after rename\n"),
5070
5024
    close_temporary_table(thd, new_table, 1, 1);
5071
5025
  }
5072
5026
  else
5073
 
    quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP);
 
5027
    VOID(quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP));
5074
5028
 
5075
5029
err:
5076
5030
  /*
5121
5075
  unlink_open_table(thd, table, false);
5122
5076
  if (name_lock)
5123
5077
    unlink_open_table(thd, name_lock, false);
5124
 
  pthread_mutex_unlock(&LOCK_open);
 
5078
  VOID(pthread_mutex_unlock(&LOCK_open));
5125
5079
  return(true);
5126
5080
}
5127
5081
/* mysql_alter_table */
5130
5084
copy_data_between_tables(Table *from,Table *to,
5131
5085
                         List<Create_field> &create,
5132
5086
                         bool ignore,
5133
 
                         uint32_t order_num, order_st *order,
 
5087
                         uint order_num, order_st *order,
5134
5088
                         ha_rows *copied,
5135
5089
                         ha_rows *deleted,
5136
5090
                         enum enum_enable_or_disable keys_onoff,
5140
5094
  Copy_field *copy,*copy_end;
5141
5095
  ulong found_count,delete_count;
5142
5096
  THD *thd= current_thd;
5143
 
  uint32_t length= 0;
 
5097
  uint length= 0;
5144
5098
  SORT_FIELD *sortorder;
5145
5099
  READ_RECORD info;
5146
5100
  TableList   tables;
5265
5219
      copy_ptr->do_copy(copy_ptr);
5266
5220
    }
5267
5221
    prev_insert_id= to->file->next_insert_id;
5268
 
    update_virtual_fields_marked_for_write(to, false);
5269
5222
    error=to->file->ha_write_row(to->record[0]);
5270
5223
    to->auto_increment_field_not_null= false;
5271
5224
    if (error)
5275
5228
      {
5276
5229
         if (!to->file->is_fatal_error(error, HA_CHECK_DUP))
5277
5230
         {
5278
 
           uint32_t key_nr= to->file->get_dup_key(error);
 
5231
           uint key_nr= to->file->get_dup_key(error);
5279
5232
           if ((int) key_nr >= 0)
5280
5233
           {
5281
5234
             const char *err_msg= ER(ER_DUP_ENTRY_WITH_KEY_NAME);
5364
5317
  create_info.default_table_charset=default_charset_info;
5365
5318
  /* Force alter table to recreate table */
5366
5319
  alter_info.flags= (ALTER_CHANGE_COLUMN | ALTER_RECREATE);
5367
 
  return(mysql_alter_table(thd, NULL, NULL, &create_info,
 
5320
  return(mysql_alter_table(thd, NullS, NullS, &create_info,
5368
5321
                                table_list, &alter_info, 0,
5369
5322
                                (order_st *) 0, 0));
5370
5323
}
5393
5346
    char table_name[NAME_LEN*2+2];
5394
5347
    Table *t;
5395
5348
 
5396
 
    strxmov(table_name, table->db ,".", table->table_name, NULL);
 
5349
    strxmov(table_name, table->db ,".", table->table_name, NullS);
5397
5350
 
5398
5351
    t= table->table= open_n_lock_single_table(thd, table, TL_READ);
5399
5352
    thd->clear_error();                 // these errors shouldn't get client
5419
5372
      {
5420
5373
        /* calculating table's checksum */
5421
5374
        ha_checksum crc= 0;
5422
 
        unsigned char null_mask=256 -  (1 << t->s->last_null_bit_pos);
 
5375
        uchar null_mask=256 -  (1 << t->s->last_null_bit_pos);
5423
5376
 
5424
5377
        t->use_all_columns();
5425
5378
 
5447
5400
              row_crc= my_checksum(row_crc, t->record[0], t->s->null_bytes);
5448
5401
            }
5449
5402
 
5450
 
            for (uint32_t i= 0; i < t->s->fields; i++ )
 
5403
            for (uint i= 0; i < t->s->fields; i++ )
5451
5404
            {
5452
5405
              Field *f= t->field[i];
5453
5406
              if ((f->type() == DRIZZLE_TYPE_BLOB) ||
5455
5408
              {
5456
5409
                String tmp;
5457
5410
                f->val_str(&tmp);
5458
 
                row_crc= my_checksum(row_crc, (unsigned char*) tmp.ptr(), tmp.length());
 
5411
                row_crc= my_checksum(row_crc, (uchar*) tmp.ptr(), tmp.length());
5459
5412
              }
5460
5413
              else
5461
5414
                row_crc= my_checksum(row_crc, f->ptr,