~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/handler/handler0alter.cc

Reverted my change to interval_list

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
*****************************************************************************/
18
18
 
19
 
/**************************************************//**
20
 
@file handler/handler0alter.cc
 
19
/******************************************************
21
20
Smart ALTER TABLE
22
21
*******************************************************/
23
22
 
24
 
#include "config.h"
 
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"
31
29
 
32
30
extern "C" {
33
31
#include "log0log.h"
42
40
#include "ha_innodb.h"
43
41
#include "handler0vars.h"
44
42
 
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(). */
48
46
static
49
47
void
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 */
56
54
{
57
55
        unsigned char*  ptr;
58
56
        unsigned char*  dest    = field->ptr;
128
126
        }
129
127
}
130
128
 
131
 
/*************************************************************//**
 
129
/*****************************************************************
132
130
Copies an InnoDB record to table->record[0]. */
133
131
extern "C" UNIV_INTERN
134
132
void
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, ...) */
142
140
{
143
141
        uint    n_fields        = table->s->fields;
178
176
        }
179
177
}
180
178
 
181
 
/*************************************************************//**
 
179
/*****************************************************************
182
180
Resets table->record[0]. */
183
181
extern "C" UNIV_INTERN
184
182
void
185
183
innobase_rec_reset(
186
184
/*===============*/
187
 
        Table*                  table)          /*!< in/out: MySQL table */
 
185
        Table*                  table)          /* in/out: MySQL table */
188
186
{
189
187
        uint    n_fields        = table->s->fields;
190
188
        uint    i;
194
192
        }
195
193
}
196
194
 
197
 
/******************************************************************//**
 
195
/**********************************************************************
198
196
Removes the filename encoding of a database and table name. */
199
197
static
200
198
void
201
199
innobase_convert_tablename(
202
200
/*=======================*/
203
 
        char*   s)      /*!< in: identifier; out: decoded identifier */
 
201
        char*   s)      /* in: identifier; out: decoded identifier */
204
202
{
205
203
 
206
204
        char*   slash = strchr(s, '/');
221
219
        }
222
220
}
223
221
 
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. */
227
224
static
228
225
int
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
233
231
                                        be created */
234
232
{
235
233
        ulint           key_num;
321
319
        return(0);
322
320
}
323
321
 
324
 
/*******************************************************************//**
 
322
/***********************************************************************
325
323
Create index field definition for key part */
326
324
static
327
325
void
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 */
334
332
{
335
333
        Field*          field;
361
359
        return;
362
360
}
363
361
 
364
 
/*******************************************************************//**
 
362
/***********************************************************************
365
363
Create index definition for key */
366
364
static
367
365
void
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
373
371
                                                on the table */
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
378
376
                                                is allocated */
379
377
{
380
378
        ulint   i;
413
411
        return;
414
412
}
415
413
 
416
 
/*******************************************************************//**
 
414
/***********************************************************************
417
415
Copy index field definition */
418
416
static
419
417
void
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 */
424
422
{
425
423
        assert(field != NULL);
426
424
        assert(index_field != NULL);
431
429
        return;
432
430
}
433
431
 
434
 
/*******************************************************************//**
 
432
/***********************************************************************
435
433
Copy index definition for the index */
436
434
static
437
435
void
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 */
443
441
{
444
442
        ulint   n_fields;
445
443
        ulint   i;
467
465
        return;
468
466
}
469
467
 
470
 
/*******************************************************************//**
 
468
/***********************************************************************
471
469
Create an index table where indexes are ordered as follows:
472
470
 
473
471
IF a new primary key is defined for the table THEN
482
480
 
483
481
ENDIF
484
482
 
485
 
 
486
 
@return key definitions or NULL */
 
483
*/
487
484
static
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
497
495
                                        be created */
498
496
{
499
497
        ulint                   i = 0;
522
520
                new_primary = TRUE;
523
521
 
524
522
                while (key_part--) {
525
 
                        if (key_info->key_part[key_part].null_bit == 0) {
 
523
                        if (key_info->key_part[key_part].key_type
 
524
                            & FIELDFLAG_MAYBE_NULL) {
526
525
                                new_primary = FALSE;
527
526
                                break;
528
527
                        }
571
570
        return(indexdefs);
572
571
}
573
572
 
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 */
577
575
static
578
576
char*
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 */
584
583
{
585
584
        char*                   name;
586
585
        ulint                   len;
596
595
        return(name);
597
596
}
598
597
 
599
 
/*******************************************************************//**
600
 
Create indexes.
601
 
@return 0 or error number */
 
598
/***********************************************************************
 
599
Create indexes. */
602
600
UNIV_INTERN
603
601
int
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 */
609
608
{
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);
638
636
 
639
637
        /* Create a background transaction for the operations on
640
638
        the data dictionary tables. */
900
898
        return(error);
901
899
}
902
900
 
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. */
906
903
UNIV_INTERN
907
904
int
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 */
913
911
{
914
912
        trx_t*          trx;
915
913
        int             err = 0;
963
961
 
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(). */
968
966
 
969
967
                if (dict_index_is_clust(index)) {
1100
1098
        return(err);
1101
1099
}
1102
1100
 
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(). */
1106
1103
UNIV_INTERN
1107
1104
int
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 */
1111
1109
{
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 */
1114
1112
        int             err;
1115
1113
 
1116
1114
        if (srv_created_new_raw || srv_force_recovery) {
1120
1118
        update_session();
1121
1119
 
1122
1120
        trx_search_latch_release_if_reserved(prebuilt->trx);
1123
 
        trx_start_if_not_started(prebuilt->trx);
1124
1121
 
1125
1122
        /* Create a background transaction for the operations on
1126
1123
        the data dictionary tables. */