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 
00029 namespace drizzled {
00030 
00031 bool statement::DropIndex::execute()
00032 {
00033   TableList *first_table= (TableList *) lex().select_lex.table_list.first;
00034   TableList *all_tables= lex().query_tables;
00035 
00036   /* Chicken/Egg... we need to search for the table, to know if the table exists, so we can build a full identifier from it */
00037   message::table::shared_ptr original_table_message;
00038   {
00039     identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName());
00040     if (not (original_table_message= plugin::StorageEngine::getTableMessage(session(), identifier)))
00041     {
00042       my_error(ER_BAD_TABLE_ERROR, identifier);
00043       return true;
00044     }
00045   }
00046 
00047   /*
00048      CREATE INDEX and DROP INDEX are implemented by calling ALTER
00049      TABLE with proper arguments.
00050 
00051      In the future ALTER TABLE will notice that the request is to
00052      only add indexes and create these one by one for the existing
00053      table without having to do a full rebuild.
00054    */
00055   /* Prepare stack copies to be re-execution safe */
00056   HA_CREATE_INFO create_info;
00057 
00058   assert(first_table == all_tables && first_table != 0);
00059   if (session().inTransaction())
00060   {
00061     my_error(ER_TRANSACTIONAL_DDL_NOT_SUPPORTED, MYF(0));
00062     return true;
00063   }
00064 
00065   create_info.db_type= 0;
00066 
00067   bool res;
00068   if (original_table_message->type() == message::Table::STANDARD )
00069   {
00070     identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName());
00071 
00072     create_info.default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
00073 
00074     res= alter_table(&session(), 
00075                      identifier,
00076                      identifier,
00077                      &create_info, 
00078                      *original_table_message,
00079                      create_table_proto, 
00080                      first_table,
00081                      &alter_info,
00082                      0, (Order*) 0, 0);
00083   }
00084   else
00085   {
00086     identifier::Table catch22(first_table->getSchemaName(), first_table->getTableName());
00087     Table *table= session().find_temporary_table(catch22);
00088     assert(table);
00089     {
00090       identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName(), table->getShare()->getPath());
00091       create_info.default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
00092 
00093       res= alter_table(&session(), 
00094                        identifier,
00095                        identifier,
00096                        &create_info, 
00097                        *original_table_message,
00098                        create_table_proto, 
00099                        first_table,
00100                        &alter_info,
00101                        0, (Order*) 0, 0);
00102     }
00103   }
00104   return res;
00105 }
00106 
00107 } /* namespace drizzled */