~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/alter_table.cc

  • Committer: Brian Aker
  • Date: 2009-11-25 06:46:36 UTC
  • mto: (1226.1.4 push)
  • mto: This revision was merged to the branch mainline in revision 1228.
  • Revision ID: brian@gaz-20091125064636-44jfoziuhtmkjbca
Small shift in alter table (break the baby down...).

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
                                    ha_rows *deleted,
44
44
                                    enum enum_enable_or_disable keys_onoff,
45
45
                                    bool error_if_not_empty);
 
46
 
46
47
static bool mysql_prepare_alter_table(Session *session,
47
48
                                      Table *table,
48
49
                                      HA_CREATE_INFO *create_info,
49
50
                                      message::Table *table_proto,
50
51
                                      AlterInfo *alter_info);
 
52
 
51
53
static int create_temporary_table(Session *session,
52
54
                                  Table *table,
53
55
                                  char *new_db,
56
58
                                  message::Table *create_proto,
57
59
                                  AlterInfo *alter_info);
58
60
 
 
61
static Table *open_alter_table(Session *session, Table *table, char *db, char *table_name);
 
62
 
59
63
bool statement::AlterTable::execute()
60
64
{
61
65
  TableList *first_table= (TableList *) session->lex->select_lex.table_list.first;
974
978
    goto err;
975
979
 
976
980
  /* Open the table so we need to copy the data to it. */
977
 
  if (table->s->tmp_table)
978
 
  {
979
 
    TableList tbl;
980
 
    tbl.db= new_db;
981
 
    tbl.alias= tmp_name;
982
 
    tbl.table_name= tmp_name;
983
 
 
984
 
    /* Table is in session->temporary_tables */
985
 
    new_table= session->openTable(&tbl, (bool*) 0, DRIZZLE_LOCK_IGNORE_FLUSH);
986
 
  }
987
 
  else
988
 
  {
989
 
    TableIdentifier new_identifier(new_db, tmp_name, INTERNAL_TMP_TABLE);
990
 
 
991
 
    /* Open our intermediate table */
992
 
    new_table= session->open_temporary_table(new_identifier, false);
993
 
  }
 
981
  new_table= open_alter_table(session, table, new_db, tmp_name);
994
982
 
995
983
  if (new_table == NULL)
996
984
    goto err1;
1098
1086
    However, in case of ALTER Table RENAME there might be no intermediate
1099
1087
    table. This is when the old and new tables are compatible, according to
1100
1088
    compare_table(). Then, we need one additional call to
1101
 
    mysql_rename_table() with flag NO_FRM_RENAME, which does nothing else but
1102
 
    actual rename in the SE and the FRM is not touched. Note that, if the
1103
 
    table is renamed and the SE is also changed, then an intermediate table
1104
 
    is created and the additional call will not take place.
1105
1089
  */
1106
1090
  if (mysql_rename_table(old_db_type, db, table_name, db, old_name, FN_TO_IS_TMP))
1107
1091
  {
1500
1484
  return false;
1501
1485
}
1502
1486
 
 
1487
 
 
1488
static Table *open_alter_table(Session *session, Table *table, char *db, char *table_name)
 
1489
{
 
1490
  Table *new_table;
 
1491
 
 
1492
  /* Open the table so we need to copy the data to it. */
 
1493
  if (table->s->tmp_table)
 
1494
  {
 
1495
    TableList tbl;
 
1496
    tbl.db= db;
 
1497
    tbl.alias= table_name;
 
1498
    tbl.table_name= table_name;
 
1499
 
 
1500
    /* Table is in session->temporary_tables */
 
1501
    new_table= session->openTable(&tbl, (bool*) 0, DRIZZLE_LOCK_IGNORE_FLUSH);
 
1502
  }
 
1503
  else
 
1504
  {
 
1505
    TableIdentifier new_identifier(db, table_name, INTERNAL_TMP_TABLE);
 
1506
 
 
1507
    /* Open our intermediate table */
 
1508
    new_table= session->open_temporary_table(new_identifier, false);
 
1509
  }
 
1510
 
 
1511
  return new_table;
 
1512
}
 
1513
 
1503
1514
} /* namespace drizzled */