36
36
TableList *first_table= (TableList *) session->lex->select_lex.table_list.first;
37
37
TableList *all_tables= session->lex->query_tables;
38
38
assert(first_table == all_tables && first_table != 0);
39
Select_Lex *select_lex= &session->lex->select_lex;
40
Select_Lex_Unit *unit= &session->lex->unit;
41
39
bool need_start_waiting= false;
43
bool link_to_local= false;
44
bool lex_identified_temp_table=
45
create_table_message.type() == message::Table::TEMPORARY;
40
lex_identified_temp_table= createTableMessage().type() == message::Table::TEMPORARY;
42
is_engine_set= not createTableMessage().engine().name().empty();
50
plugin::StorageEngine::findByName(*session, create_table_message.engine().name());
46
create_info().db_type=
47
plugin::StorageEngine::findByName(*session, createTableMessage().engine().name());
52
if (create_info.db_type == NULL)
49
if (create_info().db_type == NULL)
54
51
my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0),
55
create_table_message.engine().name().c_str());
52
createTableMessage().engine().name().c_str());
60
57
else /* We now get the default, place it in create_info, and put the engine name in table proto */
62
create_info.db_type= session->getDefaultStorageEngine();
59
create_info().db_type= session->getDefaultStorageEngine();
65
62
if (not validateCreateTableOption())
79
76
/* Skip first table, which is the table we are creating */
80
TableList *create_table_list= session->lex->unlink_first_table(&link_to_local);
81
TableList *select_tables= session->lex->query_tables;
77
create_table_list= session->lex->unlink_first_table(&link_to_local);
83
drizzled::message::init(create_table_message, create_table_message.name(), create_table_list->getSchemaName(), create_info.db_type->getName());
79
drizzled::message::init(createTableMessage(), createTableMessage().name(), create_table_list->getSchemaName(), create_info().db_type->getName());
85
81
TableIdentifier new_table_identifier(create_table_list->getSchemaName(),
86
82
create_table_list->getTableName(),
87
create_table_message.type());
83
createTableMessage().type());
89
85
if (not check(new_table_identifier))
119
if (select_lex->item_list.elements) // With select
121
select_result *result;
123
select_lex->options|= SELECT_NO_UNLOCK;
124
unit->set_limit(select_lex);
126
if (not lex_identified_temp_table)
128
session->lex->link_first_table_back(create_table_list, link_to_local);
129
create_table_list->setCreate(true);
132
if (not (res= session->openTablesLock(session->lex->query_tables)))
135
Is table which we are changing used somewhere in other parts
115
bool res= executeInner(new_table_identifier);
118
Release the protection against the global read lock and wake
119
everyone, who might want to set a global read lock.
121
session->startWaitingGlobalReadLock();
126
bool statement::CreateTable::executeInner(TableIdentifier::const_reference new_table_identifier)
129
Select_Lex *select_lex= &session->lex->select_lex;
130
TableList *select_tables= session->lex->query_tables;
133
if (select_lex->item_list.elements) // With select
135
Select_Lex_Unit *unit= &session->lex->unit;
136
select_result *result;
138
select_lex->options|= SELECT_NO_UNLOCK;
139
unit->set_limit(select_lex);
138
141
if (not lex_identified_temp_table)
140
TableList *duplicate= NULL;
143
session->lex->link_first_table_back(create_table_list, link_to_local);
144
create_table_list->setCreate(true);
147
if (not (res= session->openTablesLock(session->lex->query_tables)))
150
Is table which we are changing used somewhere in other parts
153
if (not lex_identified_temp_table)
155
TableList *duplicate= NULL;
156
create_table_list= session->lex->unlink_first_table(&link_to_local);
158
if ((duplicate= unique_table(create_table_list, select_tables)))
160
my_error(ER_UPDATE_TABLE_USED, MYF(0), create_table_list->alias);
161
/* put tables back for PS rexecuting */
162
session->lex->link_first_table_back(create_table_list, link_to_local);
170
select_create is currently not re-execution friendly and
171
needs to be created for every execution of a PS/SP.
173
if ((result= new select_create(create_table_list,
174
session->getLex()->exists(),
176
createTableMessage(),
178
select_lex->item_list,
179
session->lex->duplicates,
180
session->lex->ignore,
182
new_table_identifier)))
185
CREATE from SELECT give its Select_Lex for SELECT,
186
and item_list belong to SELECT
188
res= handle_select(session, session->lex, result, 0);
192
else if (not lex_identified_temp_table)
141
194
create_table_list= session->lex->unlink_first_table(&link_to_local);
142
if ((duplicate= unique_table(create_table_list, select_tables)))
144
my_error(ER_UPDATE_TABLE_USED, MYF(0), create_table_list->alias);
146
Release the protection against the global read lock and wake
147
everyone, who might want to set a global read lock.
149
session->startWaitingGlobalReadLock();
150
/* put tables back for PS rexecuting */
151
session->lex->link_first_table_back(create_table_list, link_to_local);
158
select_create is currently not re-execution friendly and
159
needs to be created for every execution of a PS/SP.
161
if ((result= new select_create(create_table_list,
164
create_table_message,
166
select_lex->item_list,
167
session->lex->duplicates,
168
session->lex->ignore,
170
new_table_identifier)))
173
CREATE from SELECT give its Select_Lex for SELECT,
174
and item_list belong to SELECT
176
res= handle_select(session, session->lex, result, 0);
180
else if (not lex_identified_temp_table)
182
create_table_list= session->lex->unlink_first_table(&link_to_local);
188
if (is_create_table_like)
190
res= create_like_table(session,
191
new_table_identifier,
194
create_table_message,
201
for (int32_t x= 0; x < alter_info.alter_proto.added_field_size(); x++)
203
message::Table::Field *field= create_table_message.add_field();
205
*field= alter_info.alter_proto.added_field(x);
208
res= create_table(session,
209
new_table_identifier,
211
create_table_message,
225
Release the protection against the global read lock and wake
226
everyone, who might want to set a global read lock.
228
session->startWaitingGlobalReadLock();
200
if (is_create_table_like)
202
res= create_like_table(session,
203
new_table_identifier,
206
createTableMessage(),
207
session->getLex()->exists(),
213
for (int32_t x= 0; x < alter_info.alter_proto.added_field_size(); x++)
215
message::Table::Field *field= createTableMessage().add_field();
217
*field= alter_info.alter_proto.added_field(x);
220
res= create_table(session,
221
new_table_identifier,
223
createTableMessage(),
227
session->getLex()->exists());
259
266
bool statement::CreateTable::validateCreateTableOption()
262
size_t num_engine_options= create_table_message.engine().options_size();
269
size_t num_engine_options= createTableMessage().engine().options_size();
264
assert(create_info.db_type);
271
assert(create_info().db_type);
266
273
for (size_t y= 0; y < num_engine_options; ++y)
268
bool valid= create_info.db_type->validateCreateTableOption(create_table_message.engine().options(y).name(),
269
create_table_message.engine().options(y).state());
275
bool valid= create_info().db_type->validateCreateTableOption(createTableMessage().engine().options(y).name(),
276
createTableMessage().engine().options(y).state());
273
280
my_error(ER_UNKNOWN_ENGINE_OPTION, MYF(0),
274
create_table_message.engine().options(y).name().c_str(),
275
create_table_message.engine().options(y).state().c_str());
281
createTableMessage().engine().options(y).name().c_str(),
282
createTableMessage().engine().options(y).state().c_str());