18
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27
#include "drizzled/show.h"
28
#include "drizzled/lock.h"
29
#include "drizzled/session.h"
30
#include "drizzled/statement/alter_table.h"
31
#include "drizzled/global_charset_info.h"
34
#include "drizzled/gettext.h"
35
#include "drizzled/data_home.h"
36
#include "drizzled/sql_table.h"
37
#include "drizzled/table_proto.h"
38
#include "drizzled/optimizer/range.h"
39
#include "drizzled/time_functions.h"
40
#include "drizzled/records.h"
41
#include "drizzled/pthread_globals.h"
42
#include "drizzled/internal/my_sys.h"
43
#include "drizzled/internal/iocache.h"
44
#include "drizzled/plugin/storage_engine.h"
27
#include <drizzled/show.h>
28
#include <drizzled/lock.h>
29
#include <drizzled/session.h>
30
#include <drizzled/statement/alter_table.h>
31
#include <drizzled/charset.h>
32
#include <drizzled/gettext.h>
33
#include <drizzled/data_home.h>
34
#include <drizzled/sql_table.h>
35
#include <drizzled/table_proto.h>
36
#include <drizzled/optimizer/range.h>
37
#include <drizzled/time_functions.h>
38
#include <drizzled/records.h>
39
#include <drizzled/pthread_globals.h>
40
#include <drizzled/internal/my_sys.h>
41
#include <drizzled/internal/iocache.h>
42
#include <drizzled/plugin/storage_engine.h>
45
43
#include <drizzled/copy_field.h>
47
#include "drizzled/transaction_services.h"
49
#include "drizzled/filesort.h"
51
#include "drizzled/message.h"
44
#include <drizzled/transaction_services.h>
45
#include <drizzled/filesort.h>
46
#include <drizzled/message.h>
47
#include <drizzled/message/alter_table.pb.h>
48
#include <drizzled/alter_column.h>
49
#include <drizzled/alter_info.h>
50
#include <drizzled/util/test.h>
51
#include <drizzled/open_tables_state.h>
52
#include <drizzled/table/cache.h>
53
#include <drizzled/create_field.h>
53
55
using namespace std;
58
59
extern pid_t current_pid;
68
enum enum_enable_or_disable keys_onoff,
69
message::AlterTable &alter_table_message,
69
70
bool error_if_not_empty);
71
72
static bool prepare_alter_table(Session *session,
73
HA_CREATE_INFO *create_info,
74
const message::Table &original_proto,
75
message::Table &table_message,
76
AlterInfo *alter_info);
74
HA_CREATE_INFO *create_info,
75
const message::Table &original_proto,
76
message::Table &table_message,
77
message::AlterTable &alter_table_message,
78
AlterInfo *alter_info);
78
80
static Table *open_alter_table(Session *session, Table *table, identifier::Table &identifier);
82
static int apply_online_alter_keys_onoff(Session *session,
84
const message::AlterTable::AlterKeysOnOff &op);
86
static int apply_online_rename_table(Session *session,
88
plugin::StorageEngine *original_engine,
89
identifier::Table &original_table_identifier,
90
identifier::Table &new_table_identifier,
91
const message::AlterTable::RenameTable &alter_operation);
80
93
namespace statement {
82
AlterTable::AlterTable(Session *in_session, Table_ident *ident, drizzled::ha_build_method build_arg) :
95
AlterTable::AlterTable(Session *in_session, Table_ident *) :
83
96
CreateTable(in_session)
85
in_session->lex->sql_command= SQLCOM_ALTER_TABLE;
87
alter_info.build_method= build_arg;
98
set_command(SQLCOM_ALTER_TABLE);
90
101
} // namespace statement
92
103
bool statement::AlterTable::execute()
94
TableList *first_table= (TableList *) getSession()->lex->select_lex.table_list.first;
95
TableList *all_tables= getSession()->lex->query_tables;
105
TableList *first_table= (TableList *) lex().select_lex.table_list.first;
106
TableList *all_tables= lex().query_tables;
96
107
assert(first_table == all_tables && first_table != 0);
97
Select_Lex *select_lex= &getSession()->lex->select_lex;
98
bool need_start_waiting= false;
108
Select_Lex *select_lex= &lex().select_lex;
100
110
is_engine_set= not createTableMessage().engine().name().empty();
102
112
if (is_engine_set)
104
create_info().db_type=
105
plugin::StorageEngine::findByName(*getSession(), createTableMessage().engine().name());
114
create_info().db_type=
115
plugin::StorageEngine::findByName(session(), createTableMessage().engine().name());
107
117
if (create_info().db_type == NULL)
165
175
createTableMessage(),
168
select_lex->order_list.elements,
178
select_lex->order_list.size(),
169
179
(Order *) select_lex->order_list.first,
170
getSession()->lex->ignore);
174
184
identifier::Table catch22(first_table->getSchemaName(), first_table->getTableName());
175
Table *table= getSession()->find_temporary_table(catch22);
185
Table *table= session().open_tables.find_temporary_table(catch22);
178
188
identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName(), table->getMutableShare()->getPath());
179
189
identifier::Table new_identifier(select_lex->db ? select_lex->db : first_table->getSchemaName(),
180
getSession()->lex->name.str ? getSession()->lex->name.str : first_table->getTableName(),
190
lex().name.str ? lex().name.str : first_table->getTableName(),
181
191
table->getMutableShare()->getPath());
183
res= alter_table(getSession(),
193
res= alter_table(&session(),
249
259
HA_CREATE_INFO *create_info,
250
260
const message::Table &original_proto,
251
261
message::Table &table_message,
262
message::AlterTable &alter_table_message,
252
263
AlterInfo *alter_info)
254
/* New column definitions are added here */
255
List<CreateField> new_create_list;
256
/* New key definitions are added here */
257
List<Key> new_key_list;
258
List_iterator<AlterDrop> drop_it(alter_info->drop_list);
259
List_iterator<CreateField> def_it(alter_info->create_list);
260
List_iterator<AlterColumn> alter_it(alter_info->alter_list);
261
List_iterator<Key> key_it(alter_info->key_list);
262
List_iterator<CreateField> find_it(new_create_list);
263
List_iterator<CreateField> field_it(new_create_list);
264
List<Key_part_spec> key_parts;
265
265
uint32_t used_fields= create_info->used_fields;
266
KeyInfo *key_info= table->key_info;
266
vector<string> drop_keys;
267
vector<string> drop_columns;
268
vector<string> drop_fkeys;
270
/* we use drop_(keys|columns|fkey) below to check that we can do all
271
operations we've been asked to do */
272
for (int operationnr= 0; operationnr < alter_table_message.operations_size();
275
const message::AlterTable::AlterTableOperation &operation=
276
alter_table_message.operations(operationnr);
278
switch (operation.operation())
280
case message::AlterTable::AlterTableOperation::DROP_KEY:
281
drop_keys.push_back(operation.drop_name());
283
case message::AlterTable::AlterTableOperation::DROP_COLUMN:
284
drop_columns.push_back(operation.drop_name());
286
case message::AlterTable::AlterTableOperation::DROP_FOREIGN_KEY:
287
drop_fkeys.push_back(operation.drop_name());
269
294
/* Let new create options override the old ones */
270
message::Table::TableOptions *table_options;
271
table_options= table_message.mutable_options();
295
message::Table::TableOptions *table_options= table_message.mutable_options();
273
297
if (not (used_fields & HA_CREATE_USED_DEFAULT_CHARSET))
274
298
create_info->default_table_charset= table->getShare()->table_charset;
285
309
table->restoreRecordAsDefault(); /* Empty record for DEFAULT */
311
List<CreateField> new_create_list;
312
List<Key> new_key_list;
288
313
/* First collect all fields from table which isn't in drop_list */
290
315
for (Field **f_ptr= table->getFields(); (field= *f_ptr); f_ptr++)
292
317
/* Check if field should be dropped */
295
while ((drop= drop_it++))
318
vector<string>::iterator it= drop_columns.begin();
319
while ((it != drop_columns.end()))
297
if (drop->type == AlterDrop::COLUMN &&
298
! my_strcasecmp(system_charset_info, field->field_name, drop->name))
321
if (! my_strcasecmp(system_charset_info, field->field_name, (*it).c_str()))
300
323
/* Reset auto_increment value if it was dropped */
301
324
if (MTYP_TYPENR(field->unireg_check) == Field::NEXT_NUMBER &&
302
! (used_fields & HA_CREATE_USED_AUTO))
325
not (used_fields & HA_CREATE_USED_AUTO))
304
327
create_info->auto_increment_value= 0;
305
328
create_info->used_fields|= HA_CREATE_USED_AUTO;
335
if (it != drop_columns.end())
337
drop_columns.erase(it);
317
341
/* Mark that we will read the field */
318
342
field->setReadSet();
320
345
/* Check if field is changed */
346
List<CreateField>::iterator def_it= alter_info->create_list.begin();
322
347
while ((def= def_it++))
324
349
if (def->change &&
345
370
def= new CreateField(field, field);
346
371
new_create_list.push_back(def);
347
alter_it.rewind(); /* Change default if ALTER */
372
AlterInfo::alter_list_t::iterator alter(alter_info->alter_list.begin());
350
while ((alter= alter_it++))
374
for (; alter != alter_info->alter_list.end(); alter++)
352
if (! my_strcasecmp(system_charset_info,field->field_name, alter->name))
376
if (not my_strcasecmp(system_charset_info,field->field_name, alter->name))
380
if (alter != alter_info->alter_list.end())
358
if (def->sql_type == DRIZZLE_TYPE_BLOB)
360
my_error(ER_BLOB_CANT_HAVE_DEFAULT, MYF(0), def->change);
382
def->setDefaultValue(alter->def, NULL);
364
if ((def->def= alter->def))
366
/* Use new default */
367
def->flags&= ~NO_DEFAULT_VALUE_FLAG;
371
def->flags|= NO_DEFAULT_VALUE_FLAG;
384
alter_info->alter_list.erase(alter);
390
List<CreateField>::iterator def_it= alter_info->create_list.begin();
379
391
while ((def= def_it++)) /* Add new columns */
381
393
if (def->change && ! def->field)
427
439
TODO: detect the situation in compare_tables, behave based
428
440
on engine capabilities.
430
if (alter_info->build_method == HA_BUILD_ONLINE)
442
if (alter_table_message.build_method() == message::AlterTable::BUILD_ONLINE)
432
444
my_error(*session->getQueryString(), ER_NOT_SUPPORTED_YET);
436
alter_info->build_method= HA_BUILD_OFFLINE;
440
if (alter_info->alter_list.elements)
450
if (not alter_info->alter_list.empty())
442
my_error(ER_BAD_FIELD_ERROR,
444
alter_info->alter_list.head()->name,
445
table->getMutableShare()->getTableName());
452
my_error(ER_BAD_FIELD_ERROR, MYF(0), alter_info->alter_list.front().name, table->getMutableShare()->getTableName());
449
if (not new_create_list.elements)
456
if (new_create_list.is_empty())
451
my_message(ER_CANT_REMOVE_ALL_FIELDS,
452
ER(ER_CANT_REMOVE_ALL_FIELDS),
458
my_message(ER_CANT_REMOVE_ALL_FIELDS, ER(ER_CANT_REMOVE_ALL_FIELDS), MYF(0));
458
463
Collect all keys which isn't in drop list. Add only those
459
464
for which some fields exists.
466
KeyInfo *key_info= table->key_info;
461
467
for (uint32_t i= 0; i < table->getShare()->sizeKeys(); i++, key_info++)
463
469
char *key_name= key_info->name;
467
while ((drop= drop_it++))
471
vector<string>::iterator it= drop_keys.begin();
472
while ((it != drop_keys.end()))
469
if (drop->type == AlterDrop::KEY &&
470
! my_strcasecmp(system_charset_info, key_name, drop->name))
474
if (! my_strcasecmp(system_charset_info, key_name, (*it).c_str()))
479
if (it != drop_keys.end())
480
485
KeyPartInfo *key_part= key_info->key_part;
486
List<Key_part_spec> key_parts;
482
487
for (uint32_t j= 0; j < key_info->key_parts; j++, key_part++)
484
489
if (! key_part->field)
642
if (alter_info->drop_list.elements)
644
my_error(ER_CANT_DROP_FIELD_OR_KEY,
646
alter_info->drop_list.head()->name);
650
if (alter_info->alter_list.elements)
652
my_error(ER_CANT_DROP_FIELD_OR_KEY,
654
alter_info->alter_list.head()->name);
648
if (drop_keys.size())
650
my_error(ER_CANT_DROP_FIELD_OR_KEY,
652
drop_keys.front().c_str());
656
if (drop_columns.size())
658
my_error(ER_CANT_DROP_FIELD_OR_KEY,
660
drop_columns.front().c_str());
664
if (drop_fkeys.size())
666
my_error(ER_CANT_DROP_FIELD_OR_KEY,
668
drop_fkeys.front().c_str());
672
if (not alter_info->alter_list.empty())
674
my_error(ER_CANT_DROP_FIELD_OR_KEY,
676
alter_info->alter_list.front().name);
705
726
/* table_list should contain just one table */
706
727
static int discard_or_import_tablespace(Session *session,
707
TableList *table_list,
708
enum tablespace_op_type tablespace_op)
728
TableList *table_list,
714
732
Note that DISCARD/IMPORT TABLESPACE always is the only operation in an
717
TransactionServices &transaction_services= TransactionServices::singleton();
718
735
session->set_proc_info("discard_or_import_tablespace");
720
discard= test(tablespace_op == DISCARD_TABLESPACE);
723
738
We set this flag so that ha_innobase::open and ::external_lock() do
724
739
not complain when we lock the table
726
741
session->setDoingTablespaceOperation(true);
727
if (not (table= session->openTableLock(table_list, TL_WRITE)))
742
Table* table= session->openTableLock(table_list, TL_WRITE);
729
745
session->setDoingTablespaceOperation(false);
782
800
static bool alter_table_manage_keys(Session *session,
783
801
Table *table, int indexes_were_disabled,
784
enum enum_enable_or_disable keys_onoff)
802
const message::AlterTable &alter_table_message)
787
switch (keys_onoff) {
805
if (alter_table_message.has_alter_keys_onoff()
806
&& alter_table_message.alter_keys_onoff().enable())
789
808
error= table->cursor->ha_enable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
792
if (not indexes_were_disabled)
794
/* fall-through: disabled indexes */
811
if ((! alter_table_message.has_alter_keys_onoff() && indexes_were_disabled)
812
|| (alter_table_message.has_alter_keys_onoff()
813
&& ! alter_table_message.alter_keys_onoff().enable()))
796
815
error= table->cursor->ha_disable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
979
1003
tmp.reset(ALTER_KEYS_ONOFF);
980
1004
tmp&= alter_info->flags;
982
if (not (tmp.any()) && not table->getShare()->getType()) // no need to touch frm
1006
if((not (tmp.any()) && not table->getShare()->getType())) // no need to touch frm
984
switch (alter_info->keys_onoff)
991
wait_while_table_is_used() ensures that table being altered is
992
opened only by this thread and that Table::TableShare::version
993
of Table object corresponding to this table is 0.
994
The latter guarantees that no DML statement will open this table
995
until ALTER Table finishes (i.e. until close_thread_tables())
996
while the fact that the table is still open gives us protection
997
from concurrent DDL statements.
1000
boost::mutex::scoped_lock scopedLock(table::Cache::singleton().mutex()); /* DDL wait for/blocker */
1001
wait_while_table_is_used(session, table, HA_EXTRA_FORCE_REOPEN);
1003
error= table->cursor->ha_enable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
1005
/* COND_refresh will be signaled in close_thread_tables() */
1010
boost::mutex::scoped_lock scopedLock(table::Cache::singleton().mutex()); /* DDL wait for/blocker */
1011
wait_while_table_is_used(session, table, HA_EXTRA_FORCE_REOPEN);
1013
error= table->cursor->ha_disable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
1015
/* COND_refresh will be signaled in close_thread_tables() */
1019
if (error == HA_ERR_WRONG_COMMAND)
1022
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
1023
ER_ILLEGAL_HA, ER(ER_ILLEGAL_HA),
1027
boost::mutex::scoped_lock scopedLock(table::Cache::singleton().mutex()); /* Lock to remove all instances of table from table cache before ALTER */
1029
Unlike to the above case close_cached_table() below will remove ALL
1030
instances of Table from table cache (it will also remove table lock
1031
held by this thread). So to make actual table renaming and writing
1032
to binlog atomic we have to put them into the same critical section
1033
protected by table::Cache::singleton().mutex() mutex. This also removes gap for races between
1034
access() and rename_table() calls.
1037
if (not error && not (original_table_identifier == new_table_identifier))
1039
session->set_proc_info("rename");
1041
Then do a 'simple' rename of the table. First we need to close all
1042
instances of 'source' table.
1044
session->close_cached_table(table);
1046
Then, we want check once again that target table does not exist.
1047
Actually the order of these two steps does not matter since
1048
earlier we took name-lock on the target table, so we do them
1049
in this particular order only to be consistent with 5.0, in which
1050
we don't take this name-lock and where this order really matters.
1051
@todo Investigate if we need this access() check at all.
1053
if (plugin::StorageEngine::doesTableExist(*session, new_table_identifier))
1055
my_error(ER_TABLE_EXISTS_ERROR, new_table_identifier);
1060
if (rename_table(*session, original_engine, original_table_identifier, new_table_identifier))
1067
if (error == HA_ERR_WRONG_COMMAND)
1070
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
1071
ER_ILLEGAL_HA, ER(ER_ILLEGAL_HA),
1008
if (alter_table_message.has_alter_keys_onoff())
1010
error= apply_online_alter_keys_onoff(session, table,
1011
alter_table_message.alter_keys_onoff());
1013
if (error == HA_ERR_WRONG_COMMAND)
1016
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
1017
ER_ILLEGAL_HA, ER(ER_ILLEGAL_HA),
1022
if (alter_table_message.has_rename())
1024
error= apply_online_rename_table(session,
1027
original_table_identifier,
1028
new_table_identifier,
1029
alter_table_message.rename());
1031
if (error == HA_ERR_WRONG_COMMAND)
1034
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
1035
ER_ILLEGAL_HA, ER(ER_ILLEGAL_HA),
1077
TransactionServices &transaction_services= TransactionServices::singleton();
1078
transaction_services.allocateNewTransactionId();
1079
write_bin_log(session, *session->getQueryString());
1042
TransactionServices::allocateNewTransactionId();
1043
TransactionServices::rawStatement(*session,
1044
*session->getQueryString(),
1045
*session->schema());
1080
1046
session->my_ok();
1082
1048
else if (error > EE_OK) // If we have already set the error, we pass along -1
1059
if (alter_table_message.build_method() == message::AlterTable::BUILD_ONLINE)
1061
my_error(*session->getQueryString(), ER_NOT_SUPPORTED_YET);
1093
1065
/* We have to do full alter table. */
1094
1066
new_engine= create_info->db_type;
1096
if (prepare_alter_table(session, table, create_info, original_proto, create_proto, alter_info))
1068
if (prepare_alter_table(session, table, create_info, original_proto, create_proto, alter_table_message, alter_info))
1101
1073
set_table_default_charset(create_info, new_table_identifier.getSchemaName().c_str());
1103
alter_info->build_method= HA_BUILD_OFFLINE;
1105
1075
snprintf(tmp_name, sizeof(tmp_name), "%s-%lx_%"PRIx64, TMP_FILE_PREFIX, (unsigned long) current_pid, session->thread_id);
1107
1077
/* Create a temporary table with the new format */
1362
1334
(ulong) (copied + deleted), (ulong) deleted,
1363
1335
(ulong) session->cuted_fields);
1364
1336
session->my_ok(copied + deleted, 0, 0L, tmp_name);
1365
session->some_tables_deleted= false;
1340
static int apply_online_alter_keys_onoff(Session *session,
1342
const message::AlterTable::AlterKeysOnOff &op)
1349
wait_while_table_is_used() ensures that table being altered is
1350
opened only by this thread and that Table::TableShare::version
1351
of Table object corresponding to this table is 0.
1352
The latter guarantees that no DML statement will open this table
1353
until ALTER Table finishes (i.e. until close_thread_tables())
1354
while the fact that the table is still open gives us protection
1355
from concurrent DDL statements.
1358
boost::mutex::scoped_lock scopedLock(table::Cache::mutex()); /* DDL wait for/blocker */
1359
wait_while_table_is_used(session, table, HA_EXTRA_FORCE_REOPEN);
1361
error= table->cursor->ha_enable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
1363
/* COND_refresh will be signaled in close_thread_tables() */
1368
boost::mutex::scoped_lock scopedLock(table::Cache::mutex()); /* DDL wait for/blocker */
1369
wait_while_table_is_used(session, table, HA_EXTRA_FORCE_REOPEN);
1371
error= table->cursor->ha_disable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
1373
/* COND_refresh will be signaled in close_thread_tables() */
1379
static int apply_online_rename_table(Session *session,
1381
plugin::StorageEngine *original_engine,
1382
identifier::Table &original_table_identifier,
1383
identifier::Table &new_table_identifier,
1384
const message::AlterTable::RenameTable &alter_operation)
1388
boost::mutex::scoped_lock scopedLock(table::Cache::mutex()); /* Lock to remove all instances of table from table cache before ALTER */
1390
Unlike to the above case close_cached_table() below will remove ALL
1391
instances of Table from table cache (it will also remove table lock
1392
held by this thread). So to make actual table renaming and writing
1393
to binlog atomic we have to put them into the same critical section
1394
protected by table::Cache::mutex() mutex. This also removes gap for races between
1395
access() and rename_table() calls.
1398
if (not (original_table_identifier == new_table_identifier))
1400
assert(alter_operation.to_name() == new_table_identifier.getTableName());
1401
assert(alter_operation.to_schema() == new_table_identifier.getSchemaName());
1403
session->set_proc_info("rename");
1405
Then do a 'simple' rename of the table. First we need to close all
1406
instances of 'source' table.
1408
session->close_cached_table(table);
1410
Then, we want check once again that target table does not exist.
1411
Actually the order of these two steps does not matter since
1412
earlier we took name-lock on the target table, so we do them
1413
in this particular order only to be consistent with 5.0, in which
1414
we don't take this name-lock and where this order really matters.
1415
@todo Investigate if we need this access() check at all.
1417
if (plugin::StorageEngine::doesTableExist(*session, new_table_identifier))
1419
my_error(ER_TABLE_EXISTS_ERROR, new_table_identifier);
1424
if (rename_table(*session, original_engine, original_table_identifier, new_table_identifier))
1370
1433
bool alter_table(Session *session,
1371
1434
identifier::Table &original_table_identifier,
1372
1435
identifier::Table &new_table_identifier,
1385
if (alter_info->tablespace_op != NO_TABLESPACE_OP)
1447
message::AlterTable *alter_table_message= session->lex().alter_table();
1449
alter_table_message->set_catalog(original_table_identifier.getCatalogName());
1450
alter_table_message->set_schema(original_table_identifier.getSchemaName());
1451
alter_table_message->set_name(original_table_identifier.getTableName());
1453
if (alter_table_message->operations_size()
1454
&& (alter_table_message->operations(0).operation()
1455
== message::AlterTable::AlterTableOperation::DISCARD_TABLESPACE
1456
|| alter_table_message->operations(0).operation()
1457
== message::AlterTable::AlterTableOperation::IMPORT_TABLESPACE))
1459
bool discard= (alter_table_message->operations(0).operation() ==
1460
message::AlterTable::AlterTableOperation::DISCARD_TABLESPACE);
1387
1461
/* DISCARD/IMPORT TABLESPACE is always alone in an ALTER Table */
1388
return discard_or_import_tablespace(session, table_list, alter_info->tablespace_op);
1462
return discard_or_import_tablespace(session, table_list, discard);
1391
1465
session->set_proc_info("init");
1524
1597
FileSort filesort(*session);
1525
from->sort.io_cache= new internal::IO_CACHE;
1598
from->sort.io_cache= new internal::io_cache_st;
1527
1600
tables.table= from;
1528
tables.setTableName(const_cast<char *>(from->getMutableShare()->getTableName()));
1529
tables.alias= const_cast<char *>(tables.getTableName());
1530
tables.setSchemaName(const_cast<char *>(from->getMutableShare()->getSchemaName()));
1601
tables.setTableName(from->getMutableShare()->getTableName());
1602
tables.alias= tables.getTableName();
1603
tables.setSchemaName(from->getMutableShare()->getSchemaName());
1533
if (session->lex->select_lex.setup_ref_array(session, order_num) ||
1534
setup_order(session, session->lex->select_lex.ref_pointer_array,
1535
&tables, fields, all_fields, order) ||
1536
!(sortorder= make_unireg_sortorder(order, &length, NULL)) ||
1537
(from->sort.found_records= filesort.run(from, sortorder, length,
1538
(optimizer::SqlSelect *) 0, HA_POS_ERROR,
1539
1, examined_rows)) == HA_POS_ERROR)
1606
session->lex().select_lex.setup_ref_array(session, order_num);
1607
if (setup_order(session, session->lex().select_lex.ref_pointer_array, &tables, fields, all_fields, order))
1609
sortorder= make_unireg_sortorder(order, &length, NULL);
1610
if ((from->sort.found_records= filesort.run(from, sortorder, length, (optimizer::SqlSelect *) 0, HA_POS_ERROR, 1, examined_rows)) == HA_POS_ERROR)
1546
1615
/* Tell handler that we have values for all columns in the to table */
1547
1616
to->use_all_columns();
1549
error= info.init_read_record(session, from, (optimizer::SqlSelect *) 0, 1, true);
1618
error= info.init_read_record(session, from, NULL, 1, true);
1552
1621
to->print_error(errno, MYF(0));
1655
1724
if (to->cursor->ha_external_lock(session, F_UNLCK))
1660
return(error > 0 ? -1 : 0);
1729
return error > 0 ? -1 : 0;
1663
1732
static Table *open_alter_table(Session *session, Table *table, identifier::Table &identifier)
1667
1734
/* Open the table so we need to copy the data to it. */
1668
1735
if (table->getShare()->getType())
1671
tbl.setSchemaName(const_cast<char *>(identifier.getSchemaName().c_str()));
1672
tbl.alias= const_cast<char *>(identifier.getTableName().c_str());
1673
tbl.setTableName(const_cast<char *>(identifier.getTableName().c_str()));
1738
tbl.setSchemaName(identifier.getSchemaName().c_str());
1739
tbl.alias= identifier.getTableName().c_str();
1740
tbl.setTableName(identifier.getTableName().c_str());
1675
1742
/* Table is in session->temporary_tables */
1676
new_table= session->openTable(&tbl, (bool*) 0, DRIZZLE_LOCK_IGNORE_FLUSH);
1743
return session->openTable(&tbl, NULL, DRIZZLE_LOCK_IGNORE_FLUSH);
1680
1747
/* Open our intermediate table */
1681
new_table= session->open_temporary_table(identifier, false);
1748
return session->open_temporary_table(identifier, false);
1687
1752
} /* namespace drizzled */