17
17
*****************************************************************************/
19
/**************************************************//**
20
@file handler/handler0alter.cc
19
/******************************************************
22
21
*******************************************************/
23
#include <drizzled/server_includes.h>
25
24
#include <drizzled/error.h>
26
#include "drizzled/charset_info.h"
25
#include <mystrings/m_ctype.h>
27
26
#include <drizzled/field.h>
28
27
#include <drizzled/table.h>
29
28
#include <drizzled/field/varstring.h>
30
#include "drizzled/internal/my_sys.h"
33
31
#include "log0log.h"
42
40
#include "ha_innodb.h"
43
41
#include "handler0vars.h"
45
/*************************************************************//**
43
/*****************************************************************
46
44
Copies an InnoDB column to a MySQL field. This function is
47
45
adapted from row_sel_field_store_in_mysql_format(). */
50
48
innobase_col_to_mysql(
51
49
/*==================*/
52
const dict_col_t* col, /*!< in: InnoDB column */
53
const unsigned char* data, /*!< in: InnoDB column data */
54
ulint len, /*!< in: length of data, in bytes */
55
Field* field) /*!< in/out: MySQL field */
50
const dict_col_t* col, /* in: InnoDB column */
51
const unsigned char* data, /* in: InnoDB column data */
52
ulint len, /* in: length of data, in bytes */
53
Field* field) /* in/out: MySQL field */
57
55
unsigned char* ptr;
58
56
unsigned char* dest = field->ptr;
131
/*************************************************************//**
129
/*****************************************************************
132
130
Copies an InnoDB record to table->record[0]. */
133
131
extern "C" UNIV_INTERN
135
133
innobase_rec_to_mysql(
136
134
/*==================*/
137
Table* table, /*!< in/out: MySQL table */
138
const rec_t* rec, /*!< in: record */
139
const dict_index_t* index, /*!< in: index */
140
const ulint* offsets) /*!< in: rec_get_offsets(
135
Table* table, /* in/out: MySQL table */
136
const rec_t* rec, /* in: record */
137
const dict_index_t* index, /* in: index */
138
const ulint* offsets) /* in: rec_get_offsets(
141
139
rec, index, ...) */
143
141
uint n_fields = table->s->fields;
181
/*************************************************************//**
179
/*****************************************************************
182
180
Resets table->record[0]. */
183
181
extern "C" UNIV_INTERN
185
183
innobase_rec_reset(
186
184
/*===============*/
187
Table* table) /*!< in/out: MySQL table */
185
Table* table) /* in/out: MySQL table */
189
187
uint n_fields = table->s->fields;
197
/******************************************************************//**
195
/**********************************************************************
198
196
Removes the filename encoding of a database and table name. */
201
199
innobase_convert_tablename(
202
200
/*=======================*/
203
char* s) /*!< in: identifier; out: decoded identifier */
201
char* s) /* in: identifier; out: decoded identifier */
206
204
char* slash = strchr(s, '/');
224
/*******************************************************************//**
225
This function checks that index keys are sensible.
226
@return 0 or error number */
222
/***********************************************************************
223
This function checks that index keys are sensible. */
229
226
innobase_check_index_keys(
230
227
/*======================*/
231
const KEY* key_info, /*!< in: Indexes to be created */
232
ulint num_of_keys) /*!< in: Number of indexes to
228
/* out: 0 or error number */
229
const KEY* key_info, /* in: Indexes to be created */
230
ulint num_of_keys) /* in: Number of indexes to
324
/*******************************************************************//**
322
/***********************************************************************
325
323
Create index field definition for key part */
328
326
innobase_create_index_field_def(
329
327
/*============================*/
330
KEY_PART_INFO* key_part, /*!< in: MySQL key definition */
331
mem_heap_t* heap, /*!< in: memory heap */
332
merge_index_field_t* index_field) /*!< out: index field
328
KEY_PART_INFO* key_part, /* in: MySQL key definition */
329
mem_heap_t* heap, /* in: memory heap */
330
merge_index_field_t* index_field) /* out: index field
333
331
definition for key_part */
364
/*******************************************************************//**
362
/***********************************************************************
365
363
Create index definition for key */
368
366
innobase_create_index_def(
369
367
/*======================*/
370
KEY* key, /*!< in: key definition */
371
bool new_primary, /*!< in: TRUE=generating
368
KEY* key, /* in: key definition */
369
bool new_primary, /* in: TRUE=generating
372
370
a new primary key
374
bool key_primary, /*!< in: TRUE if this key
372
bool key_primary, /* in: TRUE if this key
375
373
is a primary key */
376
merge_index_def_t* index, /*!< out: index definition */
377
mem_heap_t* heap) /*!< in: heap where memory
374
merge_index_def_t* index, /* out: index definition */
375
mem_heap_t* heap) /* in: heap where memory
416
/*******************************************************************//**
414
/***********************************************************************
417
415
Copy index field definition */
420
418
innobase_copy_index_field_def(
421
419
/*==========================*/
422
const dict_field_t* field, /*!< in: definition to copy */
423
merge_index_field_t* index_field) /*!< out: copied definition */
420
const dict_field_t* field, /* in: definition to copy */
421
merge_index_field_t* index_field) /* out: copied definition */
425
423
assert(field != NULL);
426
424
assert(index_field != NULL);
434
/*******************************************************************//**
432
/***********************************************************************
435
433
Copy index definition for the index */
438
436
innobase_copy_index_def(
439
437
/*====================*/
440
const dict_index_t* index, /*!< in: index definition to copy */
441
merge_index_def_t* new_index,/*!< out: Index definition */
442
mem_heap_t* heap) /*!< in: heap where allocated */
438
const dict_index_t* index, /* in: index definition to copy */
439
merge_index_def_t* new_index,/* out: Index definition */
440
mem_heap_t* heap) /* in: heap where allocated */
470
/*******************************************************************//**
468
/***********************************************************************
471
469
Create an index table where indexes are ordered as follows:
473
471
IF a new primary key is defined for the table THEN
486
@return key definitions or NULL */
488
485
merge_index_def_t*
489
486
innobase_create_key_def(
490
487
/*====================*/
491
trx_t* trx, /*!< in: trx */
492
const dict_table_t*table, /*!< in: table definition */
493
mem_heap_t* heap, /*!< in: heap where space for key
488
/* out: key definitions or NULL */
489
trx_t* trx, /* in: trx */
490
const dict_table_t*table, /* in: table definition */
491
mem_heap_t* heap, /* in: heap where space for key
494
492
definitions are allocated */
495
KEY* key_info, /*!< in: Indexes to be created */
496
ulint& n_keys) /*!< in/out: Number of indexes to
493
KEY* key_info, /* in: Indexes to be created */
494
ulint& n_keys) /* in/out: Number of indexes to
571
570
return(indexdefs);
574
/*******************************************************************//**
575
Create a temporary tablename using query id, thread id, and id
576
@return temporary tablename */
573
/***********************************************************************
574
Create a temporary tablename using query id, thread id, and id */
579
577
innobase_create_temporary_tablename(
580
578
/*================================*/
581
mem_heap_t* heap, /*!< in: memory heap */
582
char id, /*!< in: identifier [0-9a-zA-Z] */
583
const char* table_name) /*!< in: table name */
579
/* out: temporary tablename */
580
mem_heap_t* heap, /* in: memory heap */
581
char id, /* in: identifier [0-9a-zA-Z] */
582
const char* table_name) /* in: table name */
599
/*******************************************************************//**
601
@return 0 or error number */
598
/***********************************************************************
604
602
ha_innobase::add_index(
605
603
/*===================*/
606
Table* i_table, /*!< in: Table where indexes are created */
607
KEY* key_info, /*!< in: Indexes to be created */
608
uint num_of_keys) /*!< in: Number of indexes to be created */
604
/* out: 0 or error number */
605
Table* i_table, /* in: Table where indexes are created */
606
KEY* key_info, /* in: Indexes to be created */
607
uint num_of_keys) /* in: Number of indexes to be created */
610
dict_index_t** index; /*!< Index to be created */
611
dict_table_t* innodb_table; /*!< InnoDB table in dictionary */
612
dict_table_t* indexed_table; /*!< Table where indexes are created */
613
merge_index_def_t* index_defs; /*!< Index definitions */
614
mem_heap_t* heap; /*!< Heap for index definitions */
615
trx_t* trx; /*!< Transaction */
609
dict_index_t** index; /* Index to be created */
610
dict_table_t* innodb_table; /* InnoDB table in dictionary */
611
dict_table_t* indexed_table; /* Table where indexes are created */
612
merge_index_def_t* index_defs; /* Index definitions */
613
mem_heap_t* heap; /* Heap for index definitions */
614
trx_t* trx; /* Transaction */
616
615
ulint num_of_idx;
617
616
ulint num_created = 0;
618
617
ibool dict_locked = FALSE;
634
633
/* In case MySQL calls this in the middle of a SELECT query, release
635
634
possible adaptive hash latch to avoid deadlocks of threads. */
636
635
trx_search_latch_release_if_reserved(prebuilt->trx);
637
trx_start_if_not_started(prebuilt->trx);
639
637
/* Create a background transaction for the operations on
640
638
the data dictionary tables. */
903
/*******************************************************************//**
904
Prepare to drop some indexes of a table.
905
@return 0 or error number */
901
/***********************************************************************
902
Prepare to drop some indexes of a table. */
908
905
ha_innobase::prepare_drop_index(
909
906
/*============================*/
910
Table* i_table, /*!< in: Table where indexes are dropped */
911
uint* key_num, /*!< in: Key nums to be dropped */
912
uint num_of_keys) /*!< in: Number of keys to be dropped */
907
/* out: 0 or error number */
908
Table* i_table, /* in: Table where indexes are dropped */
909
uint* key_num, /* in: Key nums to be dropped */
910
uint num_of_keys) /* in: Number of keys to be dropped */
964
962
/* Refuse to drop the clustered index. It would be
965
963
better to automatically generate a clustered index,
966
but drizzled::alter_table() will call this method only
964
but mysql_alter_table() will call this method only
967
965
after ha_innobase::add_index(). */
969
967
if (dict_index_is_clust(index)) {
1103
/*******************************************************************//**
1104
Drop the indexes that were passed to a successful prepare_drop_index().
1105
@return 0 or error number */
1101
/***********************************************************************
1102
Drop the indexes that were passed to a successful prepare_drop_index(). */
1108
1105
ha_innobase::final_drop_index(
1109
1106
/*==========================*/
1110
Table* ) /*!< in: Table where indexes are dropped */
1107
/* out: 0 or error number */
1108
Table* ) /* in: Table where indexes are dropped */
1112
dict_index_t* index; /*!< Index to be dropped */
1113
trx_t* trx; /*!< Transaction */
1110
dict_index_t* index; /* Index to be dropped */
1111
trx_t* trx; /* Transaction */
1116
1114
if (srv_created_new_raw || srv_force_recovery) {