31
31
#include <drizzled/unireg.h>
32
32
#include <drizzled/item/int.h>
33
33
#include <drizzled/item/empty_string.h>
34
#include <drizzled/replicator.h>
34
#include <drizzled/transaction_services.h>
36
37
using namespace std;
38
extern drizzled::TransactionServices transaction_services;
38
39
extern HASH lock_db_cache;
40
41
int creating_table= 0; // How many mysql_create_table are running
298
299
void write_bin_log(Session *session, bool,
299
300
char const *query, size_t query_length)
301
(void)replicator_statement(session, query, query_length);
302
transaction_services.rawStatement(session, query, query_length);
3171
3172
uint32_t flags= alter_info->flags;
3173
3174
if (ALTER_ADD_COLUMN & flags)
3174
*alter_flags|= HA_ADD_COLUMN;
3175
alter_flags->set(HA_ADD_COLUMN);
3175
3176
if (ALTER_DROP_COLUMN & flags)
3176
*alter_flags|= HA_DROP_COLUMN;
3177
alter_flags->set(HA_DROP_COLUMN);
3177
3178
if (ALTER_RENAME & flags)
3178
*alter_flags|= HA_RENAME_TABLE;
3179
alter_flags->set(HA_RENAME_TABLE);
3179
3180
if (ALTER_CHANGE_COLUMN & flags)
3180
*alter_flags|= HA_CHANGE_COLUMN;
3181
alter_flags->set(HA_CHANGE_COLUMN);
3181
3182
if (ALTER_COLUMN_DEFAULT & flags)
3182
*alter_flags|= HA_COLUMN_DEFAULT_VALUE;
3183
alter_flags->set(HA_COLUMN_DEFAULT_VALUE);
3183
3184
if (ALTER_COLUMN_STORAGE & flags)
3184
*alter_flags|= HA_COLUMN_STORAGE;
3185
alter_flags->set(HA_COLUMN_STORAGE);
3185
3186
if (ALTER_COLUMN_FORMAT & flags)
3186
*alter_flags|= HA_COLUMN_FORMAT;
3187
alter_flags->set(HA_COLUMN_FORMAT);
3187
3188
if (ALTER_COLUMN_ORDER & flags)
3188
*alter_flags|= HA_ALTER_COLUMN_ORDER;
3189
alter_flags->set(HA_ALTER_COLUMN_ORDER);
3189
3190
if (ALTER_STORAGE & flags)
3190
*alter_flags|= HA_ALTER_STORAGE;
3191
alter_flags->set(HA_ALTER_STORAGE);
3191
3192
if (ALTER_ROW_FORMAT & flags)
3192
*alter_flags|= HA_ALTER_ROW_FORMAT;
3193
alter_flags->set(HA_ALTER_ROW_FORMAT);
3193
3194
if (ALTER_RECREATE & flags)
3194
*alter_flags|= HA_RECREATE;
3195
alter_flags->set(HA_RECREATE);
3195
3196
if (ALTER_FOREIGN_KEY & flags)
3196
*alter_flags|= HA_ALTER_FOREIGN_KEY;
3197
alter_flags->set(HA_ALTER_FOREIGN_KEY);
3332
3333
Check what has changed and set alter_flags
3334
3335
if (table->s->fields < alter_info->create_list.elements)
3335
*alter_flags|= HA_ADD_COLUMN;
3336
alter_flags->set(HA_ADD_COLUMN);
3336
3337
else if (table->s->fields > alter_info->create_list.elements)
3337
*alter_flags|= HA_DROP_COLUMN;
3338
alter_flags->set(HA_DROP_COLUMN);
3338
3339
if (create_info->db_type != table->s->db_type() ||
3339
3340
create_info->used_fields & HA_CREATE_USED_ENGINE)
3340
*alter_flags|= HA_ALTER_STORAGE_ENGINE;
3341
alter_flags->set(HA_ALTER_STORAGE_ENGINE);
3341
3342
if (create_info->used_fields & HA_CREATE_USED_CHARSET)
3342
*alter_flags|= HA_CHANGE_CHARACTER_SET;
3343
alter_flags->set(HA_CHANGE_CHARACTER_SET);
3343
3344
if (create_info->used_fields & HA_CREATE_USED_DEFAULT_CHARSET)
3344
*alter_flags|= HA_SET_DEFAULT_CHARACTER_SET;
3345
alter_flags->set(HA_SET_DEFAULT_CHARACTER_SET);
3345
3346
if (alter_info->flags & ALTER_RECREATE)
3346
*alter_flags|= HA_RECREATE;
3347
alter_flags->set(HA_RECREATE);
3347
3348
/* TODO check for ADD/DROP FOREIGN KEY */
3348
3349
if (alter_info->flags & ALTER_FOREIGN_KEY)
3349
*alter_flags|= HA_ALTER_FOREIGN_KEY;
3350
alter_flags->set(HA_ALTER_FOREIGN_KEY);
3352
3353
Go through fields and check if the original ones are compatible
3372
3373
/* Evaluate changes bitmap and send to check_if_incompatible_data() */
3373
3374
if (!(table_changes_local= field->is_equal(new_field)))
3374
*alter_flags|= HA_ALTER_COLUMN_TYPE;
3375
alter_flags->set(HA_ALTER_COLUMN_TYPE);
3377
3378
Check if the altered column is a stored virtual field.
3379
3380
the expression functions are not equal.
3381
3382
if (field->is_stored && field->vcol_info)
3382
*alter_flags|= HA_ALTER_STORED_VCOL;
3383
alter_flags->set(HA_ALTER_STORED_VCOL);
3384
3385
/* Check if field was renamed */
3385
3386
field->flags&= ~FIELD_IS_RENAMED;
3388
3389
new_field->field_name))
3390
3391
field->flags|= FIELD_IS_RENAMED;
3391
*alter_flags|= HA_ALTER_COLUMN_NAME;
3392
alter_flags->set(HA_ALTER_COLUMN_NAME);
3394
3395
*table_changes&= table_changes_local;
3395
3396
if (table_changes_local == IS_EQUAL_PACK_LENGTH)
3396
*alter_flags|= HA_ALTER_COLUMN_TYPE;
3397
alter_flags->set(HA_ALTER_COLUMN_TYPE);
3398
3399
/* Check that NULL behavior is same for old and new fields */
3399
3400
if ((new_field->flags & NOT_NULL_FLAG) !=
3400
3401
(uint32_t) (field->flags & NOT_NULL_FLAG))
3402
3403
*table_changes= IS_EQUAL_NO;
3403
*alter_flags|= HA_ALTER_COLUMN_NULLABLE;
3404
alter_flags->set(HA_ALTER_COLUMN_NULLABLE);
3448
3449
/* Unique key. Check for "PRIMARY". */
3449
3450
if (is_primary_key(table_key))
3450
*alter_flags|= HA_DROP_PK_INDEX;
3451
alter_flags->set(HA_DROP_PK_INDEX);
3452
*alter_flags|= HA_DROP_UNIQUE_INDEX;
3453
alter_flags->set(HA_DROP_UNIQUE_INDEX);
3455
*alter_flags|= HA_DROP_INDEX;
3456
alter_flags->set(HA_DROP_INDEX);
3456
3457
*table_changes= IS_EQUAL_NO;
3468
3469
// Unique key. Check for "PRIMARY".
3469
3470
if (is_primary_key(table_key))
3470
*alter_flags|= HA_ALTER_PK_INDEX;
3471
alter_flags->set(HA_ALTER_PK_INDEX);
3472
*alter_flags|= HA_ALTER_UNIQUE_INDEX;
3473
alter_flags->set(HA_ALTER_UNIQUE_INDEX);
3475
*alter_flags|= HA_ALTER_INDEX;
3476
alter_flags->set(HA_ALTER_INDEX);
3476
3477
goto index_changed;
3497
3498
/* Unique key. Check for "PRIMARY" */
3498
3499
if (is_primary_key(table_key))
3499
*alter_flags|= HA_ALTER_PK_INDEX;
3500
alter_flags->set(HA_ALTER_PK_INDEX);
3501
*alter_flags|= HA_ALTER_UNIQUE_INDEX;
3502
alter_flags->set(HA_ALTER_UNIQUE_INDEX);
3504
*alter_flags|= HA_ALTER_INDEX;
3505
alter_flags->set(HA_ALTER_INDEX);
3505
3506
goto index_changed;
3559
3560
/* Unique key. Check for "PRIMARY" */
3560
3561
if (is_primary_key(new_key))
3561
*alter_flags|= HA_ADD_PK_INDEX;
3562
alter_flags->set(HA_ADD_PK_INDEX);
3563
*alter_flags|= HA_ADD_UNIQUE_INDEX;
3564
alter_flags->set(HA_ADD_UNIQUE_INDEX);
3566
*alter_flags|= HA_ADD_INDEX;
3567
alter_flags->set(HA_ADD_INDEX);
3567
3568
*table_changes= IS_EQUAL_NO;