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 #include <drizzled/show.h>
00023 #include <drizzled/lock.h>
00024 #include <drizzled/session.h>
00025 #include <drizzled/probes.h>
00026 #include <drizzled/statement/insert_select.h>
00027 #include <drizzled/select_insert.h>
00028 #include <drizzled/sql_lex.h>
00029 #include <drizzled/open_tables_state.h>
00030
00031 namespace drizzled {
00032
00033 bool statement::InsertSelect::execute()
00034 {
00035 TableList *first_table= (TableList *) lex().select_lex.table_list.first;
00036 TableList *all_tables= lex().query_tables;
00037 assert(first_table == all_tables && first_table != 0);
00038 Select_Lex *select_lex= &lex().select_lex;
00039
00040 if (insert_precheck(&session(), all_tables))
00041 {
00042 return true;
00043 }
00044
00045
00046 select_lex->options|= SELECT_NO_UNLOCK;
00047
00048 lex().unit.set_limit(select_lex);
00049
00050 if (session().wait_if_global_read_lock(false, true))
00051 {
00052 return true;
00053 }
00054
00055 bool res;
00056 if (! (res= session().openTablesLock(all_tables)))
00057 {
00058 DRIZZLE_INSERT_SELECT_START(session().getQueryString()->c_str());
00059
00060 TableList *second_table= first_table->next_local;
00061 select_lex->table_list.first= (unsigned char*) second_table;
00062 select_lex->context.table_list= select_lex->context.first_name_resolution_table= second_table;
00063 res= insert_select_prepare(&session());
00064 if (not res)
00065 {
00066 select_insert sel_result(first_table, first_table->table, &lex().field_list, &lex().update_list, &lex().value_list, lex().duplicates, lex().ignore);
00067 res= handle_select(&session(), &lex(), &sel_result, OPTION_SETUP_TABLES_DONE);
00068
00069
00070
00071
00072
00073
00074
00075 if (first_table->lock_type == TL_WRITE_CONCURRENT_INSERT && session().open_tables.lock)
00076 {
00077
00078 TableList *save_table= first_table->next_local;
00079 first_table->next_local= 0;
00080 first_table->next_local= save_table;
00081 }
00082 }
00083
00084 select_lex->table_list.first= (unsigned char*) first_table;
00085 }
00086
00087
00088
00089
00090
00091 session().startWaitingGlobalReadLock();
00092
00093 return res;
00094 }
00095
00096 }