25
25
#include <drizzled/probes.h>
26
26
#include <drizzled/statement/insert_select.h>
27
27
#include <drizzled/select_insert.h>
28
#include <drizzled/sql_lex.h>
32
32
bool statement::InsertSelect::execute()
34
TableList *first_table= (TableList *) getSession()->getLex()->select_lex.table_list.first;
35
TableList *all_tables= getSession()->getLex()->query_tables;
34
TableList *first_table= (TableList *) lex().select_lex.table_list.first;
35
TableList *all_tables= lex().query_tables;
36
36
assert(first_table == all_tables && first_table != 0);
37
Select_Lex *select_lex= &getSession()->getLex()->select_lex;
38
Select_Lex_Unit *unit= &getSession()->getLex()->unit;
37
Select_Lex *select_lex= &lex().select_lex;
38
Select_Lex_Unit *unit= &lex().unit;
39
39
select_result *sel_result= NULL;
41
41
bool need_start_waiting= false;
43
if (insert_precheck(getSession(), all_tables))
43
if (insert_precheck(&session(), all_tables))
51
51
unit->set_limit(select_lex);
53
if (! (need_start_waiting= not getSession()->wait_if_global_read_lock(false, true)))
53
if (! (need_start_waiting= not session().wait_if_global_read_lock(false, true)))
58
if (! (res= getSession()->openTablesLock(all_tables)))
58
if (! (res= session().openTablesLock(all_tables)))
60
DRIZZLE_INSERT_SELECT_START(getSession()->getQueryString()->c_str());
60
DRIZZLE_INSERT_SELECT_START(session().getQueryString()->c_str());
61
61
/* Skip first table, which is the table we are inserting in */
62
62
TableList *second_table= first_table->next_local;
63
63
select_lex->table_list.first= (unsigned char*) second_table;
64
64
select_lex->context.table_list=
65
65
select_lex->context.first_name_resolution_table= second_table;
66
res= insert_select_prepare(getSession());
66
res= insert_select_prepare(&session());
67
67
if (! res && (sel_result= new select_insert(first_table,
68
68
first_table->table,
69
&getSession()->getLex()->field_list,
70
&getSession()->getLex()->update_list,
71
&getSession()->getLex()->value_list,
72
getSession()->getLex()->duplicates,
73
getSession()->getLex()->ignore)))
75
res= handle_select(getSession(),
76
getSession()->getLex(),
75
res= handle_select(&session(),
78
78
OPTION_SETUP_TABLES_DONE);
83
83
TODO: this is a workaround. right way will be move invalidating in
84
84
the unlock procedure.
86
if (first_table->lock_type == TL_WRITE_CONCURRENT_INSERT && getSession()->lock)
86
if (first_table->lock_type == TL_WRITE_CONCURRENT_INSERT && session().open_tables.lock)
88
88
/* INSERT ... SELECT should invalidate only the very first table */
89
89
TableList *save_table= first_table->next_local;
100
100
Release the protection against the global read lock and wake
101
101
everyone, who might want to set a global read lock.
103
getSession()->startWaitingGlobalReadLock();
103
session().startWaitingGlobalReadLock();