Drizzled Public API Documentation

drop_index.cc
1 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3  *
4  * Copyright (C) 2009 Sun Microsystems, Inc.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include <config.h>
22 
23 #include <drizzled/show.h>
24 #include <drizzled/session.h>
25 #include <drizzled/statement/drop_index.h>
26 #include <drizzled/statement/alter_table.h>
27 #include <drizzled/plugin/storage_engine.h>
28 #include <drizzled/open_tables_state.h>
29 #include <drizzled/catalog/instance.h>
30 
31 namespace drizzled {
32 
34 {
35  TableList *first_table= (TableList *) lex().select_lex.table_list.first;
36  TableList *all_tables= lex().query_tables;
37 
38  /* Chicken/Egg... we need to search for the table, to know if the table exists, so we can build a full identifier from it */
39  message::table::shared_ptr original_table_message;
40  {
41  identifier::Table identifier(session().catalog().identifier(),
42  first_table->getSchemaName(),
43  first_table->getTableName());
44  if (not (original_table_message= plugin::StorageEngine::getTableMessage(session(), identifier)))
45  {
46  my_error(ER_BAD_TABLE_ERROR, identifier);
47  return true;
48  }
49  }
50 
51  /*
52  CREATE INDEX and DROP INDEX are implemented by calling ALTER
53  TABLE with proper arguments.
54 
55  In the future ALTER TABLE will notice that the request is to
56  only add indexes and create these one by one for the existing
57  table without having to do a full rebuild.
58  */
59  /* Prepare stack copies to be re-execution safe */
60  HA_CREATE_INFO create_info;
61 
62  assert(first_table == all_tables && first_table != 0);
63  if (session().inTransaction())
64  {
65  my_error(ER_TRANSACTIONAL_DDL_NOT_SUPPORTED, MYF(0));
66  return true;
67  }
68 
69  create_info.db_type= 0;
70 
71  bool res;
72  if (original_table_message->type() == message::Table::STANDARD )
73  {
74  identifier::Table identifier(session().catalog().identifier(),
75  first_table->getSchemaName(),
76  first_table->getTableName());
77 
78  create_info.default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
79 
80  res= alter_table(&session(),
81  identifier,
82  identifier,
83  &create_info,
84  *original_table_message,
85  create_table_proto,
86  first_table,
87  &alter_info,
88  0, (Order*) 0, 0);
89  }
90  else
91  {
92  identifier::Table catch22(session().catalog().identifier(),
93  first_table->getSchemaName(),
94  first_table->getTableName());
95  Table *table= session().open_tables.find_temporary_table(catch22);
96  assert(table);
97  {
98  identifier::Table identifier(session().catalog().identifier(),
99  first_table->getSchemaName(),
100  first_table->getTableName(),
101  table->getShare()->getPath());
102  create_info.default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
103 
104  res= alter_table(&session(),
105  identifier,
106  identifier,
107  &create_info,
108  *original_table_message,
109  create_table_proto,
110  first_table,
111  &alter_info,
112  0, (Order*) 0, 0);
113  }
114  }
115  return res;
116 }
117 
118 } /* namespace drizzled */