~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/alter_table.cc

  • Committer: Lee Bieber
  • Date: 2011-03-18 04:10:25 UTC
  • mfrom: (2241.1.2 build)
  • Revision ID: kalebral@gmail.com-20110318041025-1xoj1azy6zobhnbm
Merge Stewart - refactoring of default values
Merge Olaf - more refactoring

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
#include <drizzled/transaction_services.h>
45
45
#include <drizzled/filesort.h>
46
46
#include <drizzled/message.h>
 
47
#include <drizzled/message/alter_table.pb.h>
47
48
#include <drizzled/alter_column.h>
48
 
#include <drizzled/alter_drop.h>
49
49
#include <drizzled/alter_info.h>
50
50
#include <drizzled/util/test.h>
51
51
 
64
64
                                    Order *order,
65
65
                                    ha_rows *copied,
66
66
                                    ha_rows *deleted,
67
 
                                    enum enum_enable_or_disable keys_onoff,
 
67
                                    message::AlterTable &alter_table_message,
68
68
                                    bool error_if_not_empty);
69
69
 
70
70
static bool prepare_alter_table(Session *session,
71
 
                                      Table *table,
72
 
                                      HA_CREATE_INFO *create_info,
73
 
                                      const message::Table &original_proto,
74
 
                                      message::Table &table_message,
75
 
                                      AlterInfo *alter_info);
 
71
                                Table *table,
 
72
                                HA_CREATE_INFO *create_info,
 
73
                                const message::Table &original_proto,
 
74
                                message::Table &table_message,
 
75
                                message::AlterTable &alter_table_message,
 
76
                                AlterInfo *alter_info);
76
77
 
77
78
static Table *open_alter_table(Session *session, Table *table, identifier::Table &identifier);
78
79
 
 
80
static int apply_online_alter_keys_onoff(Session *session,
 
81
                                         Table* table,
 
82
                                         const message::AlterTable::AlterKeysOnOff &op);
 
83
 
 
84
static int apply_online_rename_table(Session *session,
 
85
                                     Table *table,
 
86
                                     plugin::StorageEngine *original_engine,
 
87
                                     identifier::Table &original_table_identifier,
 
88
                                     identifier::Table &new_table_identifier,
 
89
                                     const message::AlterTable::RenameTable &alter_operation);
 
90
 
79
91
namespace statement {
80
92
 
81
 
AlterTable::AlterTable(Session *in_session, Table_ident *, drizzled::ha_build_method build_arg) :
 
93
AlterTable::AlterTable(Session *in_session, Table_ident *) :
82
94
  CreateTable(in_session)
83
95
{
84
96
  set_command(SQLCOM_ALTER_TABLE);
85
 
  alter_info.build_method= build_arg;
86
97
}
87
98
 
88
99
} // namespace statement
247
258
                                HA_CREATE_INFO *create_info,
248
259
                                const message::Table &original_proto,
249
260
                                message::Table &table_message,
 
261
                                message::AlterTable &alter_table_message,
250
262
                                AlterInfo *alter_info)
251
263
{
252
264
  uint32_t used_fields= create_info->used_fields;
 
265
  vector<string> drop_keys;
 
266
  vector<string> drop_columns;
 
267
  vector<string> drop_fkeys;
 
268
 
 
269
  /* we use drop_(keys|columns|fkey) below to check that we can do all
 
270
     operations we've been asked to do */
 
271
  for (int operationnr= 0; operationnr < alter_table_message.operations_size();
 
272
       operationnr++)
 
273
  {
 
274
    const message::AlterTable::AlterTableOperation &operation=
 
275
      alter_table_message.operations(operationnr);
 
276
 
 
277
    switch (operation.operation())
 
278
    {
 
279
    case message::AlterTable::AlterTableOperation::DROP_KEY:
 
280
      drop_keys.push_back(operation.drop_name());
 
281
      break;
 
282
    case message::AlterTable::AlterTableOperation::DROP_COLUMN:
 
283
      drop_columns.push_back(operation.drop_name());
 
284
      break;
 
285
    case message::AlterTable::AlterTableOperation::DROP_FOREIGN_KEY:
 
286
      drop_fkeys.push_back(operation.drop_name());
 
287
      break;
 
288
    default:
 
289
      break;
 
290
    }
 
291
  }
253
292
 
254
293
  /* Let new create options override the old ones */
255
294
  message::Table::TableOptions *table_options= table_message.mutable_options();
275
314
  for (Field **f_ptr= table->getFields(); (field= *f_ptr); f_ptr++)
276
315
  {
277
316
    /* Check if field should be dropped */
278
 
    AlterInfo::drop_list_t::iterator drop(alter_info->drop_list.begin());
279
 
    for (; drop != alter_info->drop_list.end(); drop++)
 
317
    vector<string>::iterator it= drop_columns.begin();
 
318
    while ((it != drop_columns.end()))
280
319
    {
281
 
      if (drop->type == AlterDrop::COLUMN &&
282
 
          ! my_strcasecmp(system_charset_info, field->field_name, drop->name))
 
320
      if (! my_strcasecmp(system_charset_info, field->field_name, (*it).c_str()))
283
321
      {
284
322
        /* Reset auto_increment value if it was dropped */
285
323
        if (MTYP_TYPENR(field->unireg_check) == Field::NEXT_NUMBER &&
290
328
        }
291
329
        break;
292
330
      }
 
331
      it++;
293
332
    }
294
333
 
295
 
    if (drop != alter_info->drop_list.end())
 
334
    if (it != drop_columns.end())
296
335
    {
297
 
      alter_info->drop_list.erase(drop);
 
336
      drop_columns.erase(it);
298
337
      continue;
299
338
    }
300
339
 
399
438
        TODO: detect the situation in compare_tables, behave based
400
439
        on engine capabilities.
401
440
      */
402
 
      if (alter_info->build_method == HA_BUILD_ONLINE)
 
441
      if (alter_table_message.build_method() == message::AlterTable::BUILD_ONLINE)
403
442
      {
404
443
        my_error(*session->getQueryString(), ER_NOT_SUPPORTED_YET);
405
444
        return true;
406
445
      }
407
 
      alter_info->build_method= HA_BUILD_OFFLINE;
408
446
    }
409
447
  }
410
448
 
428
466
  for (uint32_t i= 0; i < table->getShare()->sizeKeys(); i++, key_info++)
429
467
  {
430
468
    char *key_name= key_info->name;
431
 
    AlterInfo::drop_list_t::iterator drop(alter_info->drop_list.begin());
432
 
    for (; drop != alter_info->drop_list.end(); drop++)
 
469
 
 
470
    vector<string>::iterator it= drop_keys.begin();
 
471
    while ((it != drop_keys.end()))
433
472
    {
434
 
      if (drop->type == AlterDrop::KEY &&
435
 
          not my_strcasecmp(system_charset_info, key_name, drop->name))
 
473
      if (! my_strcasecmp(system_charset_info, key_name, (*it).c_str()))
436
474
        break;
 
475
      it++;
437
476
    }
438
477
 
439
 
    if (drop != alter_info->drop_list.end())
 
478
    if (it != drop_keys.end())
440
479
    {
441
 
      alter_info->drop_list.erase(drop);
 
480
      drop_keys.erase(it);
442
481
      continue;
443
482
    }
444
483
 
532
571
  /* Copy over existing foreign keys */
533
572
  for (int32_t j= 0; j < original_proto.fk_constraint_size(); j++)
534
573
  {
535
 
    AlterInfo::drop_list_t::iterator drop(alter_info->drop_list.begin());
536
 
    for (; drop != alter_info->drop_list.end(); drop++)
 
574
    vector<string>::iterator it= drop_fkeys.begin();
 
575
    while ((it != drop_fkeys.end()))
537
576
    {
538
 
      if (drop->type == AlterDrop::FOREIGN_KEY &&
539
 
          not my_strcasecmp(system_charset_info, original_proto.fk_constraint(j).name().c_str(), drop->name))
 
577
      if (! my_strcasecmp(system_charset_info, original_proto.fk_constraint(j).name().c_str(), (*it).c_str()))
540
578
      {
541
579
        break;
542
580
      }
 
581
      it++;
543
582
    }
544
 
    if (drop != alter_info->drop_list.end())
 
583
 
 
584
    if (it != drop_fkeys.end())
545
585
    {
546
 
      alter_info->drop_list.erase(drop);
 
586
      drop_fkeys.erase(it);
547
587
      continue;
548
588
    }
549
589
 
604
644
    }
605
645
  }
606
646
 
607
 
  if (not alter_info->drop_list.empty())
608
 
  {
609
 
    my_error(ER_CANT_DROP_FIELD_OR_KEY,
610
 
             MYF(0),
611
 
             alter_info->drop_list.front().name);
 
647
  if (drop_keys.size())
 
648
  {
 
649
    my_error(ER_CANT_DROP_FIELD_OR_KEY,
 
650
             MYF(0),
 
651
             drop_keys.front().c_str());
 
652
    return true;
 
653
  }
 
654
 
 
655
  if (drop_columns.size())
 
656
  {
 
657
    my_error(ER_CANT_DROP_FIELD_OR_KEY,
 
658
             MYF(0),
 
659
             drop_columns.front().c_str());
 
660
    return true;
 
661
  }
 
662
 
 
663
  if (drop_fkeys.size())
 
664
  {
 
665
    my_error(ER_CANT_DROP_FIELD_OR_KEY,
 
666
             MYF(0),
 
667
             drop_fkeys.front().c_str());
612
668
    return true;
613
669
  }
614
670
 
667
723
}
668
724
 
669
725
/* table_list should contain just one table */
670
 
static int discard_or_import_tablespace(Session *session, TableList *table_list, tablespace_op_type tablespace_op)
 
726
static int discard_or_import_tablespace(Session *session,
 
727
                                        TableList *table_list,
 
728
                                        bool discard)
671
729
{
672
730
  /*
673
731
    Note that DISCARD/IMPORT TABLESPACE always is the only operation in an
690
748
 
691
749
  int error;
692
750
  do {
693
 
    error= table->cursor->ha_discard_or_import_tablespace(tablespace_op == DISCARD_TABLESPACE);
 
751
    error= table->cursor->ha_discard_or_import_tablespace(discard);
694
752
 
695
753
    session->set_proc_info("end");
696
754
 
741
799
*/
742
800
static bool alter_table_manage_keys(Session *session,
743
801
                                    Table *table, int indexes_were_disabled,
744
 
                                    enum enum_enable_or_disable keys_onoff)
 
802
                                    const message::AlterTable &alter_table_message)
745
803
{
746
804
  int error= 0;
747
 
  switch (keys_onoff) {
748
 
  case ENABLE:
 
805
  if (alter_table_message.has_alter_keys_onoff()
 
806
      && alter_table_message.alter_keys_onoff().enable())
 
807
  {
749
808
    error= table->cursor->ha_enable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
750
 
    break;
751
 
  case LEAVE_AS_IS:
752
 
    if (not indexes_were_disabled)
753
 
      break;
754
 
    /* fall-through: disabled indexes */
755
 
  case DISABLE:
 
809
  }
 
810
 
 
811
  if ((! alter_table_message.has_alter_keys_onoff() && indexes_were_disabled)
 
812
      || (alter_table_message.has_alter_keys_onoff()
 
813
          && ! alter_table_message.alter_keys_onoff().enable()))
 
814
  {
756
815
    error= table->cursor->ha_disable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
757
816
  }
758
817
 
868
927
                                 HA_CREATE_INFO *create_info,
869
928
                                 const message::Table &original_proto,
870
929
                                 message::Table &create_proto,
 
930
                                 message::AlterTable &alter_table_message,
871
931
                                 TableList *table_list,
872
932
                                 AlterInfo *alter_info,
873
933
                                 uint32_t order_num,
928
988
 
929
989
  session->set_proc_info("setup");
930
990
 
931
 
  /*
932
 
   * test if no other bits except ALTER_RENAME and ALTER_KEYS_ONOFF are set
933
 
 */
 
991
  /* First we try for operations that do not require a copying
 
992
     ALTER TABLE.
 
993
 
 
994
     In future there should be more operations, currently it's just a couple.
 
995
  */
 
996
 
 
997
  if ((alter_table_message.has_rename()
 
998
       || alter_table_message.has_alter_keys_onoff())
 
999
      && alter_table_message.operations_size() == 0)
934
1000
  {
 
1001
    /*
 
1002
     * test if no other bits except ALTER_RENAME and ALTER_KEYS_ONOFF are set
 
1003
     */
935
1004
    bitset<32> tmp;
936
1005
 
937
1006
    tmp.set();
939
1008
    tmp.reset(ALTER_KEYS_ONOFF);
940
1009
    tmp&= alter_info->flags;
941
1010
 
942
 
    if (not (tmp.any()) && not table->getShare()->getType()) // no need to touch frm
 
1011
    if((not (tmp.any()) && not table->getShare()->getType())) // no need to touch frm
943
1012
    {
944
 
      switch (alter_info->keys_onoff)
945
 
      {
946
 
      case LEAVE_AS_IS:
947
 
        break;
948
 
 
949
 
      case ENABLE:
950
 
        /*
951
 
          wait_while_table_is_used() ensures that table being altered is
952
 
          opened only by this thread and that Table::TableShare::version
953
 
          of Table object corresponding to this table is 0.
954
 
          The latter guarantees that no DML statement will open this table
955
 
          until ALTER Table finishes (i.e. until close_thread_tables())
956
 
          while the fact that the table is still open gives us protection
957
 
          from concurrent DDL statements.
958
 
        */
959
 
        {
960
 
          boost::mutex::scoped_lock scopedLock(table::Cache::singleton().mutex()); /* DDL wait for/blocker */
961
 
          wait_while_table_is_used(session, table, HA_EXTRA_FORCE_REOPEN);
962
 
        }
963
 
        error= table->cursor->ha_enable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
964
 
 
965
 
        /* COND_refresh will be signaled in close_thread_tables() */
966
 
        break;
967
 
 
968
 
      case DISABLE:
969
 
        {
970
 
          boost::mutex::scoped_lock scopedLock(table::Cache::singleton().mutex()); /* DDL wait for/blocker */
971
 
          wait_while_table_is_used(session, table, HA_EXTRA_FORCE_REOPEN);
972
 
        }
973
 
        error= table->cursor->ha_disable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
974
 
 
975
 
        /* COND_refresh will be signaled in close_thread_tables() */
976
 
        break;
977
 
      }
978
 
 
979
 
      if (error == HA_ERR_WRONG_COMMAND)
980
 
      {
981
 
        error= EE_OK;
982
 
        push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
983
 
                            ER_ILLEGAL_HA, ER(ER_ILLEGAL_HA),
984
 
                            table->getAlias());
985
 
      }
986
 
 
987
 
      boost::mutex::scoped_lock scopedLock(table::Cache::singleton().mutex()); /* Lock to remove all instances of table from table cache before ALTER */
988
 
      /*
989
 
        Unlike to the above case close_cached_table() below will remove ALL
990
 
        instances of Table from table cache (it will also remove table lock
991
 
        held by this thread). So to make actual table renaming and writing
992
 
        to binlog atomic we have to put them into the same critical section
993
 
        protected by table::Cache::singleton().mutex() mutex. This also removes gap for races between
994
 
        access() and rename_table() calls.
995
 
      */
996
 
 
997
 
      if (not error &&  not (original_table_identifier == new_table_identifier))
998
 
      {
999
 
        session->set_proc_info("rename");
1000
 
        /*
1001
 
          Then do a 'simple' rename of the table. First we need to close all
1002
 
          instances of 'source' table.
1003
 
        */
1004
 
        session->close_cached_table(table);
1005
 
        /*
1006
 
          Then, we want check once again that target table does not exist.
1007
 
          Actually the order of these two steps does not matter since
1008
 
          earlier we took name-lock on the target table, so we do them
1009
 
          in this particular order only to be consistent with 5.0, in which
1010
 
          we don't take this name-lock and where this order really matters.
1011
 
          @todo Investigate if we need this access() check at all.
1012
 
        */
1013
 
        if (plugin::StorageEngine::doesTableExist(*session, new_table_identifier))
1014
 
        {
1015
 
          my_error(ER_TABLE_EXISTS_ERROR, new_table_identifier);
1016
 
          error= -1;
1017
 
        }
1018
 
        else
1019
 
        {
1020
 
          if (rename_table(*session, original_engine, original_table_identifier, new_table_identifier))
1021
 
          {
1022
 
            error= -1;
1023
 
          }
1024
 
        }
1025
 
      }
1026
 
 
1027
 
      if (error == HA_ERR_WRONG_COMMAND)
1028
 
      {
1029
 
        error= EE_OK;
1030
 
        push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
1031
 
                            ER_ILLEGAL_HA, ER(ER_ILLEGAL_HA),
1032
 
                            table->getAlias());
 
1013
      if (alter_table_message.has_alter_keys_onoff())
 
1014
      {
 
1015
        error= apply_online_alter_keys_onoff(session, table,
 
1016
                                       alter_table_message.alter_keys_onoff());
 
1017
 
 
1018
        if (error == HA_ERR_WRONG_COMMAND)
 
1019
        {
 
1020
          error= EE_OK;
 
1021
          push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
 
1022
                              ER_ILLEGAL_HA, ER(ER_ILLEGAL_HA),
 
1023
                              table->getAlias());
 
1024
        }
 
1025
      }
 
1026
 
 
1027
      if (alter_table_message.has_rename())
 
1028
      {
 
1029
        error= apply_online_rename_table(session,
 
1030
                                         table,
 
1031
                                         original_engine,
 
1032
                                         original_table_identifier,
 
1033
                                         new_table_identifier,
 
1034
                                         alter_table_message.rename());
 
1035
 
 
1036
        if (error == HA_ERR_WRONG_COMMAND)
 
1037
        {
 
1038
          error= EE_OK;
 
1039
          push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
 
1040
                              ER_ILLEGAL_HA, ER(ER_ILLEGAL_HA),
 
1041
                              table->getAlias());
 
1042
        }
1033
1043
      }
1034
1044
 
1035
1045
      if (not error)
1052
1062
    }
1053
1063
  }
1054
1064
 
 
1065
  if (alter_table_message.build_method() == message::AlterTable::BUILD_ONLINE)
 
1066
  {
 
1067
    my_error(*session->getQueryString(), ER_NOT_SUPPORTED_YET);
 
1068
    return true;
 
1069
  }
 
1070
 
1055
1071
  /* We have to do full alter table. */
1056
1072
  new_engine= create_info->db_type;
1057
1073
 
1058
 
  if (prepare_alter_table(session, table, create_info, original_proto, create_proto, alter_info))
 
1074
  if (prepare_alter_table(session, table, create_info, original_proto, create_proto, alter_table_message, alter_info))
1059
1075
  {
1060
1076
    return true;
1061
1077
  }
1062
1078
 
1063
1079
  set_table_default_charset(create_info, new_table_identifier.getSchemaName().c_str());
1064
1080
 
1065
 
  alter_info->build_method= HA_BUILD_OFFLINE;
1066
 
 
1067
1081
  snprintf(tmp_name, sizeof(tmp_name), "%s-%lx_%"PRIx64, TMP_FILE_PREFIX, (unsigned long) current_pid, session->thread_id);
1068
1082
 
1069
1083
  /* Create a temporary table with the new format */
1123
1137
                                    order,
1124
1138
                                    &copied,
1125
1139
                                    &deleted,
1126
 
                                    alter_info->keys_onoff,
 
1140
                                    alter_table_message,
1127
1141
                                    alter_info->error_if_not_empty);
1128
1142
 
1129
1143
    /* We must not ignore bad input! */
1332
1346
  return false;
1333
1347
}
1334
1348
 
 
1349
static int apply_online_alter_keys_onoff(Session *session,
 
1350
                                         Table* table,
 
1351
                                         const message::AlterTable::AlterKeysOnOff &op)
 
1352
{
 
1353
  int error= 0;
 
1354
 
 
1355
  if (op.enable())
 
1356
  {
 
1357
    /*
 
1358
      wait_while_table_is_used() ensures that table being altered is
 
1359
      opened only by this thread and that Table::TableShare::version
 
1360
      of Table object corresponding to this table is 0.
 
1361
      The latter guarantees that no DML statement will open this table
 
1362
      until ALTER Table finishes (i.e. until close_thread_tables())
 
1363
      while the fact that the table is still open gives us protection
 
1364
      from concurrent DDL statements.
 
1365
    */
 
1366
    {
 
1367
      boost::mutex::scoped_lock scopedLock(table::Cache::singleton().mutex()); /* DDL wait for/blocker */
 
1368
      wait_while_table_is_used(session, table, HA_EXTRA_FORCE_REOPEN);
 
1369
    }
 
1370
    error= table->cursor->ha_enable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
 
1371
 
 
1372
    /* COND_refresh will be signaled in close_thread_tables() */
 
1373
  }
 
1374
  else
 
1375
  {
 
1376
    {
 
1377
      boost::mutex::scoped_lock scopedLock(table::Cache::singleton().mutex()); /* DDL wait for/blocker */
 
1378
      wait_while_table_is_used(session, table, HA_EXTRA_FORCE_REOPEN);
 
1379
    }
 
1380
    error= table->cursor->ha_disable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
 
1381
 
 
1382
    /* COND_refresh will be signaled in close_thread_tables() */
 
1383
  }
 
1384
 
 
1385
  return error;
 
1386
}
 
1387
 
 
1388
static int apply_online_rename_table(Session *session,
 
1389
                                     Table *table,
 
1390
                                     plugin::StorageEngine *original_engine,
 
1391
                                     identifier::Table &original_table_identifier,
 
1392
                                     identifier::Table &new_table_identifier,
 
1393
                                     const message::AlterTable::RenameTable &alter_operation)
 
1394
{
 
1395
  int error= 0;
 
1396
 
 
1397
  boost::mutex::scoped_lock scopedLock(table::Cache::singleton().mutex()); /* Lock to remove all instances of table from table cache before ALTER */
 
1398
  /*
 
1399
    Unlike to the above case close_cached_table() below will remove ALL
 
1400
    instances of Table from table cache (it will also remove table lock
 
1401
    held by this thread). So to make actual table renaming and writing
 
1402
    to binlog atomic we have to put them into the same critical section
 
1403
    protected by table::Cache::singleton().mutex() mutex. This also removes gap for races between
 
1404
    access() and rename_table() calls.
 
1405
  */
 
1406
 
 
1407
  if (not (original_table_identifier == new_table_identifier))
 
1408
  {
 
1409
    assert(alter_operation.to_name() == new_table_identifier.getTableName());
 
1410
    assert(alter_operation.to_schema() == new_table_identifier.getSchemaName());
 
1411
 
 
1412
    session->set_proc_info("rename");
 
1413
    /*
 
1414
      Then do a 'simple' rename of the table. First we need to close all
 
1415
      instances of 'source' table.
 
1416
    */
 
1417
    session->close_cached_table(table);
 
1418
    /*
 
1419
      Then, we want check once again that target table does not exist.
 
1420
      Actually the order of these two steps does not matter since
 
1421
      earlier we took name-lock on the target table, so we do them
 
1422
      in this particular order only to be consistent with 5.0, in which
 
1423
      we don't take this name-lock and where this order really matters.
 
1424
      @todo Investigate if we need this access() check at all.
 
1425
    */
 
1426
    if (plugin::StorageEngine::doesTableExist(*session, new_table_identifier))
 
1427
    {
 
1428
      my_error(ER_TABLE_EXISTS_ERROR, new_table_identifier);
 
1429
      error= -1;
 
1430
    }
 
1431
    else
 
1432
    {
 
1433
      if (rename_table(*session, original_engine, original_table_identifier, new_table_identifier))
 
1434
      {
 
1435
        error= -1;
 
1436
      }
 
1437
    }
 
1438
  }
 
1439
  return error;
 
1440
}
 
1441
 
1335
1442
bool alter_table(Session *session,
1336
1443
                 identifier::Table &original_table_identifier,
1337
1444
                 identifier::Table &new_table_identifier,
1346
1453
{
1347
1454
  bool error;
1348
1455
  Table *table;
1349
 
 
1350
 
  if (alter_info->tablespace_op != NO_TABLESPACE_OP)
 
1456
  message::AlterTable *alter_table_message= session->lex().alter_table();
 
1457
 
 
1458
  alter_table_message->set_catalog(original_table_identifier.getCatalogName());
 
1459
  alter_table_message->set_schema(original_table_identifier.getSchemaName());
 
1460
  alter_table_message->set_name(original_table_identifier.getTableName());
 
1461
 
 
1462
  if (alter_table_message->operations_size()
 
1463
      && (alter_table_message->operations(0).operation()
 
1464
          == message::AlterTable::AlterTableOperation::DISCARD_TABLESPACE
 
1465
          || alter_table_message->operations(0).operation()
 
1466
          == message::AlterTable::AlterTableOperation::IMPORT_TABLESPACE))
1351
1467
  {
 
1468
    bool discard= (alter_table_message->operations(0).operation() ==
 
1469
                   message::AlterTable::AlterTableOperation::DISCARD_TABLESPACE);
1352
1470
    /* DISCARD/IMPORT TABLESPACE is always alone in an ALTER Table */
1353
 
    return discard_or_import_tablespace(session, table_list, alter_info->tablespace_op);
 
1471
    return discard_or_import_tablespace(session, table_list, discard);
1354
1472
  }
1355
1473
 
1356
1474
  session->set_proc_info("init");
1379
1497
                                create_info,
1380
1498
                                original_proto,
1381
1499
                                create_proto,
 
1500
                                *alter_table_message,
1382
1501
                                table_list,
1383
1502
                                alter_info,
1384
1503
                                order_num,
1404
1523
                         uint32_t order_num, Order *order,
1405
1524
                         ha_rows *copied,
1406
1525
                         ha_rows *deleted,
1407
 
                         enum enum_enable_or_disable keys_onoff,
 
1526
                         message::AlterTable &alter_table_message,
1408
1527
                         bool error_if_not_empty)
1409
1528
{
1410
1529
  int error= 0;
1444
1563
    return -1;
1445
1564
 
1446
1565
  /* We need external lock before we can disable/enable keys */
1447
 
  alter_table_manage_keys(session, to, from->cursor->indexes_are_disabled(), keys_onoff);
 
1566
  alter_table_manage_keys(session, to, from->cursor->indexes_are_disabled(),
 
1567
                          alter_table_message);
1448
1568
 
1449
1569
  /* We can abort alter table for any table type */
1450
1570
  session->setAbortOnWarning(not ignore);