31
31
bool statement::InsertSelect::execute()
33
TableList *first_table= (TableList *) session->lex->select_lex.table_list.first;
34
TableList *all_tables= session->lex->query_tables;
33
TableList *first_table= (TableList *) getSession()->lex->select_lex.table_list.first;
34
TableList *all_tables= getSession()->lex->query_tables;
35
35
assert(first_table == all_tables && first_table != 0);
36
Select_Lex *select_lex= &session->lex->select_lex;
37
Select_Lex_Unit *unit= &session->lex->unit;
36
Select_Lex *select_lex= &getSession()->lex->select_lex;
37
Select_Lex_Unit *unit= &getSession()->lex->unit;
38
38
select_result *sel_result= NULL;
40
40
bool need_start_waiting= false;
42
if (insert_precheck(session, all_tables))
42
if (insert_precheck(getSession(), all_tables))
50
50
unit->set_limit(select_lex);
52
if (! (need_start_waiting= not session->wait_if_global_read_lock(false, true)))
52
if (! (need_start_waiting= not getSession()->wait_if_global_read_lock(false, true)))
57
if (! (res= session->openTablesLock(all_tables)))
57
if (! (res= getSession()->openTablesLock(all_tables)))
59
DRIZZLE_INSERT_SELECT_START(session->getQueryString()->c_str());
59
DRIZZLE_INSERT_SELECT_START(getSession()->getQueryString()->c_str());
60
60
/* Skip first table, which is the table we are inserting in */
61
61
TableList *second_table= first_table->next_local;
62
62
select_lex->table_list.first= (unsigned char*) second_table;
63
63
select_lex->context.table_list=
64
64
select_lex->context.first_name_resolution_table= second_table;
65
res= insert_select_prepare(session);
65
res= insert_select_prepare(getSession());
66
66
if (! res && (sel_result= new select_insert(first_table,
67
67
first_table->table,
68
&session->lex->field_list,
69
&session->lex->update_list,
70
&session->lex->value_list,
71
session->lex->duplicates,
72
session->lex->ignore)))
68
&getSession()->lex->field_list,
69
&getSession()->lex->update_list,
70
&getSession()->lex->value_list,
71
getSession()->lex->duplicates,
72
getSession()->lex->ignore)))
74
res= handle_select(session,
74
res= handle_select(getSession(),
77
77
OPTION_SETUP_TABLES_DONE);
82
82
TODO: this is a workaround. right way will be move invalidating in
83
83
the unlock procedure.
85
if (first_table->lock_type == TL_WRITE_CONCURRENT_INSERT &&
85
if (first_table->lock_type == TL_WRITE_CONCURRENT_INSERT && getSession()->lock)
88
87
/* INSERT ... SELECT should invalidate only the very first table */
89
88
TableList *save_table= first_table->next_local;
100
99
Release the protection against the global read lock and wake
101
100
everyone, who might want to set a global read lock.
103
session->startWaitingGlobalReadLock();
102
getSession()->startWaitingGlobalReadLock();