00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <config.h>
00022
00023 #include <drizzled/show.h>
00024 #include <drizzled/session.h>
00025 #include <drizzled/statement/create_index.h>
00026 #include <drizzled/statement/alter_table.h>
00027 #include <drizzled/plugin/storage_engine.h>
00028
00029 namespace drizzled
00030 {
00031
00032 namespace statement
00033 {
00034
00035 CreateIndex::CreateIndex(Session *in_session, const drizzled::ha_build_method method_arg) :
00036 CreateTable(in_session)
00037 {
00038 set_command(SQLCOM_CREATE_INDEX);
00039 alter_info.flags.set(ALTER_ADD_INDEX);
00040 alter_info.build_method= method_arg;
00041 lex().col_list.clear();
00042 }
00043
00044 bool statement::CreateIndex::execute()
00045 {
00046 TableList *first_table= (TableList *) lex().select_lex.table_list.first;
00047 TableList *all_tables= lex().query_tables;
00048
00049
00050 message::table::shared_ptr original_table_message;
00051 {
00052 identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName());
00053 if (not (original_table_message= plugin::StorageEngine::getTableMessage(session(), identifier)))
00054 {
00055 my_error(ER_BAD_TABLE_ERROR, identifier);
00056 return true;
00057 }
00058 }
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 assert(first_table == all_tables && first_table != 0);
00070 if (session().inTransaction())
00071 {
00072 my_error(ER_TRANSACTIONAL_DDL_NOT_SUPPORTED, MYF(0));
00073 return true;
00074 }
00075
00076 bool res;
00077 if (original_table_message->type() == message::Table::STANDARD )
00078 {
00079 identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName());
00080 create_info().default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
00081
00082 res= alter_table(&session(),
00083 identifier,
00084 identifier,
00085 &create_info(),
00086 *original_table_message,
00087 createTableMessage(),
00088 first_table,
00089 &alter_info,
00090 0, (Order*) 0, 0);
00091 }
00092 else
00093 {
00094 identifier::Table catch22(first_table->getSchemaName(), first_table->getTableName());
00095 Table *table= session().find_temporary_table(catch22);
00096 assert(table);
00097 {
00098 identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName(), table->getMutableShare()->getPath());
00099 create_info().default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
00100
00101 res= alter_table(&session(),
00102 identifier,
00103 identifier,
00104 &create_info(),
00105 *original_table_message,
00106 createTableMessage(),
00107 first_table,
00108 &alter_info,
00109 0, (Order*) 0, 0);
00110 }
00111 }
00112
00113 return res;
00114 }
00115
00116 }
00117 }