~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/alter_table.cc

First pass on cleanup of Stewart's patch, plus re-engineer to make it work a
bit more with the current system. Engines approve key/pair.

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
static bool mysql_prepare_alter_table(Session *session,
65
65
                                      Table *table,
66
66
                                      HA_CREATE_INFO *create_info,
 
67
                                      const message::Table &original_proto,
67
68
                                      message::Table &table_message,
68
69
                                      AlterInfo *alter_info);
69
70
 
97
98
    }
98
99
  }
99
100
 
100
 
 
101
101
  /* Must be set in the parser */
102
102
  assert(select_lex->db);
103
103
 
110
110
      my_error(ER_BAD_TABLE_ERROR, MYF(0), identifier.getSQLPath().c_str());
111
111
      return true;
112
112
    }
 
113
 
 
114
    if (not  create_info.db_type)
 
115
    {
 
116
      create_info.db_type= 
 
117
        plugin::StorageEngine::findByName(*session, original_table_message.engine().name());
 
118
 
 
119
      if (not create_info.db_type)
 
120
      {
 
121
        my_error(ER_BAD_TABLE_ERROR, MYF(0), identifier.getSQLPath().c_str());
 
122
        return true;
 
123
      }
 
124
    }
 
125
  }
 
126
 
 
127
  if (not validateCreateTableOption())
 
128
  {
 
129
    return true;
113
130
  }
114
131
 
115
132
  /* ALTER TABLE ends previous transaction */
134
151
                     identifier,
135
152
                     new_identifier,
136
153
                     &create_info,
 
154
                     original_table_message,
137
155
                     create_table_message,
138
156
                     first_table,
139
157
                     &alter_info,
155
173
                       identifier,
156
174
                       new_identifier,
157
175
                       &create_info,
 
176
                       original_table_message,
158
177
                       create_table_message,
159
178
                       first_table,
160
179
                       &alter_info,
216
235
static bool mysql_prepare_alter_table(Session *session,
217
236
                                      Table *table,
218
237
                                      HA_CREATE_INFO *create_info,
 
238
                                      const message::Table &original_proto,
219
239
                                      message::Table &table_message,
220
240
                                      AlterInfo *alter_info)
221
241
{
560
580
 
561
581
  table_message.set_update_timestamp(time(NULL));
562
582
 
563
 
  if (not table_message.options().has_comment()
564
 
      && table->s->hasComment())
565
 
    table_options->set_comment(table->s->getComment());
566
 
 
567
583
  rc= false;
568
584
  alter_info->create_list.swap(new_create_list);
569
585
  alter_info->key_list.swap(new_key_list);
570
586
err:
 
587
 
 
588
  size_t num_engine_options= table_message.engine().options_size();
 
589
  size_t original_num_engine_options= original_proto.engine().options_size();
 
590
  for (size_t x= 0; x < original_num_engine_options; ++x)
 
591
  {
 
592
    bool found= false;
 
593
 
 
594
    for (size_t y= 0; y < num_engine_options; ++y)
 
595
    {
 
596
      found= not table_message.engine().options(y).name().compare(original_proto.engine().options(x).name());
 
597
      
 
598
      if (found)
 
599
        break;
 
600
    }
 
601
 
 
602
    if (not found)
 
603
    {
 
604
      message::Table::StorageEngine *engine_options;
 
605
      engine_options= table_message.mutable_engine();
 
606
      message::Table::StorageEngine::EngineOption *opt= engine_options->add_options();
 
607
 
 
608
      opt->set_name(original_proto.engine().options(x).name());
 
609
      opt->set_state(original_proto.engine().options(x).state());
 
610
    }
 
611
  }
 
612
 
571
613
  return rc;
572
614
}
573
615
 
646
688
    true   Error
647
689
*/
648
690
static bool alter_table_manage_keys(Table *table, int indexes_were_disabled,
649
 
                             enum enum_enable_or_disable keys_onoff)
 
691
                                    enum enum_enable_or_disable keys_onoff)
650
692
{
651
693
  int error= 0;
652
694
  switch (keys_onoff) {
654
696
    error= table->cursor->ha_enable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
655
697
    break;
656
698
  case LEAVE_AS_IS:
657
 
    if (!indexes_were_disabled)
 
699
    if (not indexes_were_disabled)
658
700
      break;
659
701
    /* fall-through: disabled indexes */
660
702
  case DISABLE:
767
809
                                 TableIdentifier &original_table_identifier,
768
810
                                 TableIdentifier &new_table_identifier,
769
811
                                 HA_CREATE_INFO *create_info,
 
812
                                 const message::Table &original_proto,
770
813
                                 message::Table &create_proto,
771
814
                                 TableList *table_list,
772
815
                                 AlterInfo *alter_info,
957
1000
  /* We have to do full alter table. */
958
1001
  new_engine= create_info->db_type;
959
1002
 
960
 
  if (mysql_prepare_alter_table(session, table, create_info, create_proto, alter_info))
 
1003
  if (mysql_prepare_alter_table(session, table, create_info, original_proto, create_proto, alter_info))
961
1004
  {
962
1005
    return true;
963
1006
  }
1272
1315
                 TableIdentifier &original_table_identifier,
1273
1316
                 TableIdentifier &new_table_identifier,
1274
1317
                 HA_CREATE_INFO *create_info,
 
1318
                 const message::Table &original_proto,
1275
1319
                 message::Table &create_proto,
1276
1320
                 TableList *table_list,
1277
1321
                 AlterInfo *alter_info,
1312
1356
                                original_table_identifier,
1313
1357
                                new_table_identifier,
1314
1358
                                create_info,
 
1359
                                original_proto,
1315
1360
                                create_proto,
1316
1361
                                table_list,
1317
1362
                                alter_info,