~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/include/row0merge.h

  • Committer: Brian Aker
  • Date: 2009-01-07 21:26:58 UTC
  • Revision ID: brian@tangent.org-20090107212658-2fh0s2uwh10w68y2
Committing fix lock_multi

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
2
 
 
3
 
Copyright (c) 2005, 2010, Innobase Oy. All Rights Reserved.
4
 
 
5
 
This program is free software; you can redistribute it and/or modify it under
6
 
the terms of the GNU General Public License as published by the Free Software
7
 
Foundation; version 2 of the License.
8
 
 
9
 
This program is distributed in the hope that it will be useful, but WITHOUT
10
 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
 
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
 
 
13
 
You should have received a copy of the GNU General Public License along with
14
 
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15
 
St, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
*****************************************************************************/
18
 
 
19
 
/**************************************************//**
20
 
@file include/row0merge.h
 
1
/******************************************************
21
2
Index build routines using a merge sort
22
3
 
 
4
(c) 2005 Innobase Oy
 
5
 
23
6
Created 13/06/2005 Jan Lindstrom
24
7
*******************************************************/
25
8
 
39
22
#include "row0mysql.h"
40
23
#include "lock0types.h"
41
24
 
42
 
/** Index field definition */
 
25
/* This structure holds index field definitions */
 
26
 
43
27
struct merge_index_field_struct {
44
 
        ulint           prefix_len;     /*!< column prefix length, or 0
45
 
                                        if indexing the whole column */
46
 
        const char*     field_name;     /*!< field name */
 
28
        ulint           prefix_len;     /* Prefix len */
 
29
        const char*     field_name;     /* Field name */
47
30
};
48
31
 
49
 
/** Index field definition */
50
32
typedef struct merge_index_field_struct merge_index_field_t;
51
33
 
52
 
/** Definition of an index being created */
 
34
/* This structure holds index definitions */
 
35
 
53
36
struct merge_index_def_struct {
54
 
        const char*             name;           /*!< index name */
55
 
        ulint                   ind_type;       /*!< 0, DICT_UNIQUE,
 
37
        const char*             name;           /* Index name */
 
38
        ulint                   ind_type;       /* 0, DICT_UNIQUE,
56
39
                                                or DICT_CLUSTERED */
57
 
        ulint                   n_fields;       /*!< number of fields
58
 
                                                in index */
59
 
        merge_index_field_t*    fields;         /*!< field definitions */
 
40
        ulint                   n_fields;       /* Number of fields in index */
 
41
        merge_index_field_t*    fields;         /* Field definitions */
60
42
};
61
43
 
62
 
/** Definition of an index being created */
63
44
typedef struct merge_index_def_struct merge_index_def_t;
64
45
 
65
 
/*********************************************************************//**
66
 
Sets an exclusive lock on a table, for the duration of creating indexes.
67
 
@return error code or DB_SUCCESS */
 
46
/*************************************************************************
 
47
Sets an exclusive lock on a table, for the duration of creating indexes. */
68
48
UNIV_INTERN
69
49
ulint
70
50
row_merge_lock_table(
71
51
/*=================*/
72
 
        trx_t*          trx,            /*!< in/out: transaction */
73
 
        dict_table_t*   table,          /*!< in: table to lock */
74
 
        enum lock_mode  mode);          /*!< in: LOCK_X or LOCK_S */
75
 
/*********************************************************************//**
 
52
                                        /* out: error code or DB_SUCCESS */
 
53
        trx_t*          trx,            /* in/out: transaction */
 
54
        dict_table_t*   table,          /* in: table to lock */
 
55
        enum lock_mode  mode);          /* in: LOCK_X or LOCK_S */
 
56
/*************************************************************************
76
57
Drop an index from the InnoDB system tables.  The data dictionary must
77
58
have been locked exclusively by the caller, because the transaction
78
59
will not be committed. */
80
61
void
81
62
row_merge_drop_index(
82
63
/*=================*/
83
 
        dict_index_t*   index,  /*!< in: index to be removed */
84
 
        dict_table_t*   table,  /*!< in: table */
85
 
        trx_t*          trx);   /*!< in: transaction handle */
86
 
/*********************************************************************//**
 
64
        dict_index_t*   index,  /* in: index to be removed */
 
65
        dict_table_t*   table,  /* in: table */
 
66
        trx_t*          trx);   /* in: transaction handle */
 
67
/*************************************************************************
87
68
Drop those indexes which were created before an error occurred when
88
69
building an index.  The data dictionary must have been locked
89
70
exclusively by the caller, because the transaction will not be
92
73
void
93
74
row_merge_drop_indexes(
94
75
/*===================*/
95
 
        trx_t*          trx,            /*!< in: transaction */
96
 
        dict_table_t*   table,          /*!< in: table containing the indexes */
97
 
        dict_index_t**  index,          /*!< in: indexes to drop */
98
 
        ulint           num_created);   /*!< in: number of elements in index[] */
99
 
/*********************************************************************//**
 
76
        trx_t*          trx,            /* in: transaction */
 
77
        dict_table_t*   table,          /* in: table containing the indexes */
 
78
        dict_index_t**  index,          /* in: indexes to drop */
 
79
        ulint           num_created);   /* in: number of elements in index[] */
 
80
/*************************************************************************
100
81
Drop all partially created indexes during crash recovery. */
101
82
UNIV_INTERN
102
83
void
103
84
row_merge_drop_temp_indexes(void);
104
85
/*=============================*/
105
 
/*********************************************************************//**
 
86
/*************************************************************************
106
87
Rename the tables in the data dictionary.  The data dictionary must
107
88
have been locked exclusively by the caller, because the transaction
108
 
will not be committed.
109
 
@return error code or DB_SUCCESS */
 
89
will not be committed. */
110
90
UNIV_INTERN
111
91
ulint
112
92
row_merge_rename_tables(
113
93
/*====================*/
114
 
        dict_table_t*   old_table,      /*!< in/out: old table, renamed to
 
94
                                        /* out: error code or DB_SUCCESS */
 
95
        dict_table_t*   old_table,      /* in/out: old table, renamed to
115
96
                                        tmp_name */
116
 
        dict_table_t*   new_table,      /*!< in/out: new table, renamed to
 
97
        dict_table_t*   new_table,      /* in/out: new table, renamed to
117
98
                                        old_table->name */
118
 
        const char*     tmp_name,       /*!< in: new name for old_table */
119
 
        trx_t*          trx);           /*!< in: transaction handle */
 
99
        const char*     tmp_name,       /* in: new name for old_table */
 
100
        trx_t*          trx);           /* in: transaction handle */
120
101
 
121
 
/*********************************************************************//**
 
102
/*************************************************************************
122
103
Create a temporary table for creating a primary key, using the definition
123
 
of an existing table.
124
 
@return table, or NULL on error */
 
104
of an existing table. */
125
105
UNIV_INTERN
126
106
dict_table_t*
127
107
row_merge_create_temporary_table(
128
108
/*=============================*/
129
 
        const char*             table_name,     /*!< in: new table name */
130
 
        const merge_index_def_t*index_def,      /*!< in: the index definition
 
109
                                                /* out: table,
 
110
                                                or NULL on error */
 
111
        const char*             table_name,     /* in: new table name */
 
112
        const merge_index_def_t*index_def,      /* in: the index definition
131
113
                                                of the primary key */
132
 
        const dict_table_t*     table,          /*!< in: old table definition */
133
 
        trx_t*                  trx);           /*!< in/out: transaction
 
114
        const dict_table_t*     table,          /* in: old table definition */
 
115
        trx_t*                  trx);           /* in/out: transaction
134
116
                                                (sets error_state) */
135
 
/*********************************************************************//**
 
117
/*************************************************************************
136
118
Rename the temporary indexes in the dictionary to permanent ones.  The
137
119
data dictionary must have been locked exclusively by the caller,
138
 
because the transaction will not be committed.
139
 
@return DB_SUCCESS if all OK */
 
120
because the transaction will not be committed. */
140
121
UNIV_INTERN
141
122
ulint
142
123
row_merge_rename_indexes(
143
124
/*=====================*/
144
 
        trx_t*          trx,            /*!< in/out: transaction */
145
 
        dict_table_t*   table);         /*!< in/out: table with new indexes */
146
 
/*********************************************************************//**
147
 
Create the index and load in to the dictionary.
148
 
@return index, or NULL on error */
 
125
                                        /* out: DB_SUCCESS if all OK */
 
126
        trx_t*          trx,            /* in/out: transaction */
 
127
        dict_table_t*   table);         /* in/out: table with new indexes */
 
128
/*************************************************************************
 
129
Create the index and load in to the dictionary. */
149
130
UNIV_INTERN
150
131
dict_index_t*
151
132
row_merge_create_index(
152
133
/*===================*/
153
 
        trx_t*                  trx,    /*!< in/out: trx (sets error_state) */
154
 
        dict_table_t*           table,  /*!< in: the index is on this table */
155
 
        const merge_index_def_t*index_def);
156
 
                                        /*!< in: the index definition */
157
 
/*********************************************************************//**
158
 
Check if a transaction can use an index.
159
 
@return TRUE if index can be used by the transaction else FALSE */
 
134
                                        /* out: index, or NULL on error */
 
135
        trx_t*          trx,            /* in/out: trx (sets error_state) */
 
136
        dict_table_t*   table,          /* in: the index is on this table */
 
137
        const merge_index_def_t*        /* in: the index definition */
 
138
                        index_def);
 
139
#ifdef ROW_MERGE_IS_INDEX_USABLE
 
140
/*************************************************************************
 
141
Check if a transaction can use an index. */
160
142
UNIV_INTERN
161
143
ibool
162
144
row_merge_is_index_usable(
163
145
/*======================*/
164
 
        const trx_t*            trx,    /*!< in: transaction */
165
 
        const dict_index_t*     index); /*!< in: index to check */
166
 
/*********************************************************************//**
 
146
                                        /* out: TRUE if index can be used by
 
147
                                        the transaction else FALSE*/
 
148
        const trx_t*            trx,    /* in: transaction */
 
149
        const dict_index_t*     index); /* in: index to check */
 
150
#endif /* ROW_MERGE_IS_INDEX_USABLE */
 
151
/*************************************************************************
167
152
If there are views that refer to the old table name then we "attach" to
168
 
the new instance of the table else we drop it immediately.
169
 
@return DB_SUCCESS or error code */
 
153
the new instance of the table else we drop it immediately. */
170
154
UNIV_INTERN
171
155
ulint
172
156
row_merge_drop_table(
173
157
/*=================*/
174
 
        trx_t*          trx,            /*!< in: transaction */
175
 
        dict_table_t*   table);         /*!< in: table instance to drop */
 
158
                                        /* out: DB_SUCCESS or error code */
 
159
        trx_t*          trx,            /* in: transaction */
 
160
        dict_table_t*   table);         /* in: table instance to drop */
176
161
 
177
 
/*********************************************************************//**
 
162
/*************************************************************************
178
163
Build indexes on a table by reading a clustered index,
179
164
creating a temporary file containing index entries, merge sorting
180
 
these index entries and inserting sorted index entries to indexes.
181
 
@return DB_SUCCESS or error code */
 
165
these index entries and inserting sorted index entries to indexes. */
182
166
UNIV_INTERN
183
167
ulint
184
168
row_merge_build_indexes(
185
169
/*====================*/
186
 
        trx_t*          trx,            /*!< in: transaction */
187
 
        dict_table_t*   old_table,      /*!< in: table where rows are
 
170
                                        /* out: DB_SUCCESS or error code */
 
171
        trx_t*          trx,            /* in: transaction */
 
172
        dict_table_t*   old_table,      /* in: table where rows are
188
173
                                        read from */
189
 
        dict_table_t*   new_table,      /*!< in: table where indexes are
 
174
        dict_table_t*   new_table,      /* in: table where indexes are
190
175
                                        created; identical to old_table
191
176
                                        unless creating a PRIMARY KEY */
192
 
        dict_index_t**  indexes,        /*!< in: indexes to be created */
193
 
        ulint           n_indexes,      /*!< in: size of indexes[] */
194
 
        TABLE*  table);         /*!< in/out: MySQL table, for
 
177
        dict_index_t**  indexes,        /* in: indexes to be created */
 
178
        ulint           n_indexes,      /* in: size of indexes[] */
 
179
        TABLE*          table);         /* in/out: MySQL table, for
195
180
                                        reporting erroneous key value
196
181
                                        if applicable */
197
182
#endif /* row0merge.h */