~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/alter_table.cc

  • Committer: Brian Aker
  • Date: 2009-12-01 21:53:49 UTC
  • mto: (1235.1.4 push)
  • mto: This revision was merged to the branch mainline in revision 1236.
  • Revision ID: brian@gaz-20091201215349-veugbv3su39q6ard
More identifier work.

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
 
54
54
static int create_temporary_table(Session *session,
55
55
                                  Table *table,
56
 
                                  char *new_db,
57
 
                                  char *tmp_name,
 
56
                                  TableIdentifier &identifier,
58
57
                                  HA_CREATE_INFO *create_info,
59
58
                                  message::Table *create_proto,
60
59
                                  AlterInfo *alter_info);
974
973
  alter_info->build_method= HA_BUILD_OFFLINE;
975
974
 
976
975
  snprintf(tmp_name, sizeof(tmp_name), "%s-%lx_%"PRIx64, TMP_FILE_PREFIX, (unsigned long) current_pid, session->thread_id);
977
 
 
 
976
 
978
977
  /* Safety fix for innodb */
979
978
  my_casedn_str(files_charset_info, tmp_name);
980
979
 
981
980
  /* Create a temporary table with the new format */
982
 
  error= create_temporary_table(session, table, new_db, tmp_name, create_info, create_proto, alter_info);
983
 
  if (error != 0)
984
 
    goto err;
 
981
  {
 
982
    /**
 
983
      @note we make an internal temporary table unless the table is a temporary table. In last
 
984
      case we just use it as is. Neither of these tables require locks in order to  be
 
985
      filled.
 
986
    */
 
987
    TableIdentifier new_table_temp(new_db,
 
988
                                   tmp_name,
 
989
                                   create_proto->type() != message::Table::TEMPORARY ? INTERNAL_TMP_TABLE :
 
990
                                   create_info->db_type->check_flag(HTON_BIT_DOES_TRANSACTIONS) ? TRANSACTIONAL_TMP_TABLE :
 
991
                                   NON_TRANSACTIONAL_TMP_TABLE );
 
992
 
 
993
    error= create_temporary_table(session, table, new_table_temp, create_info, create_proto, alter_info);
 
994
 
 
995
    if (error != 0)
 
996
      goto err;
 
997
  }
985
998
 
986
999
  /* Open the table so we need to copy the data to it. */
987
1000
  new_table= open_alter_table(session, table, new_db, tmp_name);
1000
1013
  /* We don't want update TIMESTAMP fields during ALTER Table. */
1001
1014
  new_table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
1002
1015
  new_table->next_number_field= new_table->found_next_number_field;
1003
 
  error= copy_data_between_tables(table, 
 
1016
  error= copy_data_between_tables(table,
1004
1017
                                  new_table,
1005
 
                                  alter_info->create_list, 
 
1018
                                  alter_info->create_list,
1006
1019
                                  ignore,
1007
 
                                  order_num, 
1008
 
                                  order, 
1009
 
                                  &copied, 
 
1020
                                  order_num,
 
1021
                                  order,
 
1022
                                  &copied,
1010
1023
                                  &deleted,
1011
1024
                                  alter_info->keys_onoff,
1012
1025
                                  alter_info->error_if_not_empty);
1033
1046
    /* Should pass the 'new_name' as we store table name in the cache */
1034
1047
    if (new_table->rename_temporary_table(new_db, new_name))
1035
1048
      goto err1;
1036
 
    
 
1049
 
1037
1050
    goto end_temporary;
1038
1051
  }
1039
1052
 
1048
1061
  }
1049
1062
 
1050
1063
  pthread_mutex_lock(&LOCK_open); /* ALTER TABLE */
1051
 
  
 
1064
 
1052
1065
  if (error)
1053
1066
  {
1054
 
    quick_rm_table(*session, new_db, tmp_name, true);
 
1067
    TableIdentifier identifier(new_db, tmp_name, INTERNAL_TMP_TABLE);
 
1068
    quick_rm_table(*session, identifier);
1055
1069
    pthread_mutex_unlock(&LOCK_open);
1056
1070
    goto err;
1057
1071
  }
1096
1110
  if (mysql_rename_table(old_db_type, db, table_name, db, old_name, FN_TO_IS_TMP))
1097
1111
  {
1098
1112
    error= 1;
1099
 
    quick_rm_table(*session, new_db, tmp_name, true);
 
1113
    TableIdentifier identifier(new_db, tmp_name, INTERNAL_TMP_TABLE);
 
1114
    quick_rm_table(*session, identifier);
1100
1115
  }
1101
1116
  else
1102
1117
  {
1104
1119
    {
1105
1120
      /* Try to get everything back. */
1106
1121
      error= 1;
1107
 
      quick_rm_table(*session, new_db, new_alias, false);
1108
 
      quick_rm_table(*session, new_db, tmp_name, true);
 
1122
 
 
1123
      TableIdentifier alias_identifier(new_db, new_alias, NO_TMP_TABLE);
 
1124
      quick_rm_table(*session, alias_identifier);
 
1125
 
 
1126
      TableIdentifier tmp_identifier(new_db, tmp_name, INTERNAL_TMP_TABLE);
 
1127
      quick_rm_table(*session, tmp_identifier);
 
1128
 
1109
1129
      mysql_rename_table(old_db_type, db, old_name, db, table_name, FN_FROM_IS_TMP);
1110
1130
    }
1111
1131
  }
1116
1136
    goto err_with_placeholders;
1117
1137
  }
1118
1138
 
1119
 
  quick_rm_table(*session, db, old_name, true);
 
1139
  {
 
1140
    TableIdentifier old_identifier(db, old_name, INTERNAL_TMP_TABLE);
 
1141
    quick_rm_table(*session, old_identifier);
 
1142
  }
 
1143
  
1120
1144
 
1121
1145
  pthread_mutex_unlock(&LOCK_open);
1122
1146
 
1153
1177
    session->close_temporary_table(new_table);
1154
1178
  }
1155
1179
  else
1156
 
    quick_rm_table(*session, new_db, tmp_name, true);
 
1180
  {
 
1181
    TableIdentifier tmp_identifier(new_db, tmp_name, INTERNAL_TMP_TABLE);
 
1182
    quick_rm_table(*session, tmp_identifier);
 
1183
  }
1157
1184
 
1158
1185
err:
1159
1186
  /*
1402
1429
static int
1403
1430
create_temporary_table(Session *session,
1404
1431
                       Table *table,
1405
 
                       char *new_db,
1406
 
                       char *tmp_name,
 
1432
                       TableIdentifier &identifier,
1407
1433
                       HA_CREATE_INFO *create_info,
1408
1434
                       message::Table *create_proto,
1409
1435
                       AlterInfo *alter_info)
1410
1436
{
1411
1437
  int error;
1412
1438
  plugin::StorageEngine *old_db_type, *new_db_type;
1413
 
  TableIdentifier identifier(new_db,
1414
 
                             tmp_name,
1415
 
                             create_proto->type() != message::Table::TEMPORARY ? INTERNAL_TMP_TABLE :
1416
 
                             create_info->db_type->check_flag(HTON_BIT_DOES_TRANSACTIONS) ? TRANSACTIONAL_TMP_TABLE :
1417
 
                             NON_TRANSACTIONAL_TMP_TABLE );
1418
1439
 
1419
1440
  old_db_type= table->s->db_type();
1420
1441
  new_db_type= create_info->db_type;
1423
1444
    Create a table with a temporary name.
1424
1445
    We don't log the statement, it will be logged later.
1425
1446
  */
1426
 
  create_proto->set_name(tmp_name);
 
1447
  create_proto->set_name(identifier.getTableName());
1427
1448
 
1428
1449
  message::Table::StorageEngine *protoengine;
1429
1450
  protoengine= create_proto->mutable_engine();