Drizzled Public API Documentation

drop_index.cc
00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2009 Sun Microsystems, Inc.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019  */
00020 
00021 #include <config.h>
00022 
00023 #include <drizzled/show.h>
00024 #include <drizzled/session.h>
00025 #include <drizzled/statement/drop_index.h>
00026 #include <drizzled/statement/alter_table.h>
00027 #include <drizzled/plugin/storage_engine.h>
00028 #include <drizzled/open_tables_state.h>
00029 
00030 namespace drizzled {
00031 
00032 bool statement::DropIndex::execute()
00033 {
00034   TableList *first_table= (TableList *) lex().select_lex.table_list.first;
00035   TableList *all_tables= lex().query_tables;
00036 
00037   /* Chicken/Egg... we need to search for the table, to know if the table exists, so we can build a full identifier from it */
00038   message::table::shared_ptr original_table_message;
00039   {
00040     identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName());
00041     if (not (original_table_message= plugin::StorageEngine::getTableMessage(session(), identifier)))
00042     {
00043       my_error(ER_BAD_TABLE_ERROR, identifier);
00044       return true;
00045     }
00046   }
00047 
00048   /*
00049      CREATE INDEX and DROP INDEX are implemented by calling ALTER
00050      TABLE with proper arguments.
00051 
00052      In the future ALTER TABLE will notice that the request is to
00053      only add indexes and create these one by one for the existing
00054      table without having to do a full rebuild.
00055    */
00056   /* Prepare stack copies to be re-execution safe */
00057   HA_CREATE_INFO create_info;
00058 
00059   assert(first_table == all_tables && first_table != 0);
00060   if (session().inTransaction())
00061   {
00062     my_error(ER_TRANSACTIONAL_DDL_NOT_SUPPORTED, MYF(0));
00063     return true;
00064   }
00065 
00066   create_info.db_type= 0;
00067 
00068   bool res;
00069   if (original_table_message->type() == message::Table::STANDARD )
00070   {
00071     identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName());
00072 
00073     create_info.default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
00074 
00075     res= alter_table(&session(), 
00076                      identifier,
00077                      identifier,
00078                      &create_info, 
00079                      *original_table_message,
00080                      create_table_proto, 
00081                      first_table,
00082                      &alter_info,
00083                      0, (Order*) 0, 0);
00084   }
00085   else
00086   {
00087     identifier::Table catch22(first_table->getSchemaName(), first_table->getTableName());
00088     Table *table= session().open_tables.find_temporary_table(catch22);
00089     assert(table);
00090     {
00091       identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName(), table->getShare()->getPath());
00092       create_info.default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
00093 
00094       res= alter_table(&session(), 
00095                        identifier,
00096                        identifier,
00097                        &create_info, 
00098                        *original_table_message,
00099                        create_table_proto, 
00100                        first_table,
00101                        &alter_info,
00102                        0, (Order*) 0, 0);
00103     }
00104   }
00105   return res;
00106 }
00107 
00108 } /* namespace drizzled */