1100.3.66
by Padraig O'Sullivan
Extracted the last commands....Finally removed that gigantic switch |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
4 |
* Copyright (C) 2009 Sun Microsystems
|
|
5 |
*
|
|
6 |
* This program is free software; you can redistribute it and/or modify
|
|
7 |
* it under the terms of the GNU General Public License as published by
|
|
8 |
* the Free Software Foundation; either version 2 of the License, or
|
|
9 |
* (at your option) any later version.
|
|
10 |
*
|
|
11 |
* This program is distributed in the hope that it will be useful,
|
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 |
* GNU General Public License for more details.
|
|
15 |
*
|
|
16 |
* You should have received a copy of the GNU General Public License
|
|
17 |
* along with this program; if not, write to the Free Software
|
|
18 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
19 |
*/
|
|
20 |
||
1241.9.36
by Monty Taylor
ZOMG. I deleted drizzled/server_includes.h. |
21 |
#include "config.h" |
1100.3.66
by Padraig O'Sullivan
Extracted the last commands....Finally removed that gigantic switch |
22 |
#include <drizzled/show.h> |
23 |
#include <drizzled/lock.h> |
|
24 |
#include <drizzled/session.h> |
|
1126.10.18
by Padraig O'Sullivan
Various small build fixes for when dtrace is enabled. |
25 |
#include <drizzled/probes.h> |
1100.3.66
by Padraig O'Sullivan
Extracted the last commands....Finally removed that gigantic switch |
26 |
#include <drizzled/statement/insert_select.h> |
27 |
||
1130.3.12
by Monty Taylor
using namespace drizzled; to namespace drizzled { in statement/ |
28 |
namespace drizzled |
29 |
{
|
|
1100.3.66
by Padraig O'Sullivan
Extracted the last commands....Finally removed that gigantic switch |
30 |
|
31 |
bool statement::InsertSelect::execute() |
|
32 |
{
|
|
33 |
TableList *first_table= (TableList *) session->lex->select_lex.table_list.first; |
|
34 |
TableList *all_tables= session->lex->query_tables; |
|
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; |
|
38 |
select_result *sel_result= NULL; |
|
39 |
bool res= false; |
|
40 |
bool need_start_waiting= false; |
|
41 |
||
42 |
if (insert_precheck(session, all_tables)) |
|
43 |
{
|
|
44 |
return true; |
|
45 |
}
|
|
46 |
||
47 |
/* Don't unlock tables until command is written to binary log */
|
|
48 |
select_lex->options|= SELECT_NO_UNLOCK; |
|
49 |
||
50 |
unit->set_limit(select_lex); |
|
51 |
||
52 |
if (! (need_start_waiting= ! wait_if_global_read_lock(session, 0, 1))) |
|
53 |
{
|
|
54 |
return true; |
|
55 |
}
|
|
56 |
||
57 |
if (! (res= session->openTablesLock(all_tables))) |
|
58 |
{
|
|
1280.3.16
by Padraig O'Sullivan
Updated the calls to dtrace probes to use the c_str() pointer from query in Session |
59 |
DRIZZLE_INSERT_SELECT_START(session->query.c_str()); |
1100.3.66
by Padraig O'Sullivan
Extracted the last commands....Finally removed that gigantic switch |
60 |
/* Skip first table, which is the table we are inserting in */
|
61 |
TableList *second_table= first_table->next_local; |
|
62 |
select_lex->table_list.first= (unsigned char*) second_table; |
|
63 |
select_lex->context.table_list= |
|
64 |
select_lex->context.first_name_resolution_table= second_table; |
|
65 |
res= mysql_insert_select_prepare(session); |
|
66 |
if (! res && (sel_result= new select_insert(first_table, |
|
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))) |
|
73 |
{
|
|
74 |
res= handle_select(session, |
|
75 |
session->lex, |
|
76 |
sel_result, |
|
77 |
OPTION_SETUP_TABLES_DONE); |
|
1487.1.1
by Brian Aker
There is room for improvement around this. We should be using rows as well |
78 |
|
1100.3.66
by Padraig O'Sullivan
Extracted the last commands....Finally removed that gigantic switch |
79 |
/*
|
80 |
Invalidate the table in the query cache if something changed
|
|
81 |
after unlocking when changes become visible.
|
|
82 |
TODO: this is a workaround. right way will be move invalidating in
|
|
83 |
the unlock procedure.
|
|
84 |
*/
|
|
85 |
if (first_table->lock_type == TL_WRITE_CONCURRENT_INSERT && |
|
86 |
session->lock) |
|
87 |
{
|
|
88 |
/* INSERT ... SELECT should invalidate only the very first table */
|
|
89 |
TableList *save_table= first_table->next_local; |
|
90 |
first_table->next_local= 0; |
|
91 |
first_table->next_local= save_table; |
|
92 |
}
|
|
93 |
delete sel_result; |
|
94 |
}
|
|
95 |
/* revert changes for SP */
|
|
96 |
select_lex->table_list.first= (unsigned char*) first_table; |
|
97 |
}
|
|
98 |
||
99 |
/*
|
|
100 |
Release the protection against the global read lock and wake
|
|
101 |
everyone, who might want to set a global read lock.
|
|
102 |
*/
|
|
103 |
start_waiting_global_read_lock(session); |
|
104 |
||
105 |
return res; |
|
106 |
}
|
|
1130.3.12
by Monty Taylor
using namespace drizzled; to namespace drizzled { in statement/ |
107 |
|
108 |
} /* namespace drizzled */ |