1
/******************************************************
2
Index build routines using a merge sort
6
Created 13/06/2005 Jan Lindstrom
7
*******************************************************/
13
#include "data0data.h"
14
#include "dict0types.h"
15
#include "trx0types.h"
16
#include "que0types.h"
18
#include "rem0types.h"
20
#include "read0types.h"
21
#include "btr0types.h"
22
#include "row0mysql.h"
23
#include "lock0types.h"
25
/* This structure holds index field definitions */
27
struct merge_index_field_struct {
28
ulint prefix_len; /* Prefix len */
29
const char* field_name; /* Field name */
32
typedef struct merge_index_field_struct merge_index_field_t;
34
/* This structure holds index definitions */
36
struct merge_index_def_struct {
37
const char* name; /* Index name */
38
ulint ind_type; /* 0, DICT_UNIQUE,
40
ulint n_fields; /* Number of fields in index */
41
merge_index_field_t* fields; /* Field definitions */
44
typedef struct merge_index_def_struct merge_index_def_t;
46
/*************************************************************************
47
Sets an exclusive lock on a table, for the duration of creating indexes. */
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
/*************************************************************************
57
Drop an index from the InnoDB system tables. The data dictionary must
58
have been locked exclusively by the caller, because the transaction
59
will not be committed. */
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
/*************************************************************************
68
Drop those indexes which were created before an error occurred when
69
building an index. The data dictionary must have been locked
70
exclusively by the caller, because the transaction will not be
74
row_merge_drop_indexes(
75
/*===================*/
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
/*************************************************************************
81
Drop all partially created indexes during crash recovery. */
84
row_merge_drop_temp_indexes(void);
85
/*=============================*/
86
/*************************************************************************
87
Rename the tables in the data dictionary. The data dictionary must
88
have been locked exclusively by the caller, because the transaction
89
will not be committed. */
92
row_merge_rename_tables(
93
/*====================*/
94
/* out: error code or DB_SUCCESS */
95
dict_table_t* old_table, /* in/out: old table, renamed to
97
dict_table_t* new_table, /* in/out: new table, renamed to
99
const char* tmp_name, /* in: new name for old_table */
100
trx_t* trx); /* in: transaction handle */
102
/*************************************************************************
103
Create a temporary table for creating a primary key, using the definition
104
of an existing table. */
107
row_merge_create_temporary_table(
108
/*=============================*/
111
const char* table_name, /* in: new table name */
112
const merge_index_def_t*index_def, /* in: the index definition
113
of the primary key */
114
const dict_table_t* table, /* in: old table definition */
115
trx_t* trx); /* in/out: transaction
116
(sets error_state) */
117
/*************************************************************************
118
Rename the temporary indexes in the dictionary to permanent ones. The
119
data dictionary must have been locked exclusively by the caller,
120
because the transaction will not be committed. */
123
row_merge_rename_indexes(
124
/*=====================*/
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. */
132
row_merge_create_index(
133
/*===================*/
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 */
139
#ifdef ROW_MERGE_IS_INDEX_USABLE
140
/*************************************************************************
141
Check if a transaction can use an index. */
144
row_merge_is_index_usable(
145
/*======================*/
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
/*************************************************************************
152
If there are views that refer to the old table name then we "attach" to
153
the new instance of the table else we drop it immediately. */
156
row_merge_drop_table(
157
/*=================*/
158
/* out: DB_SUCCESS or error code */
159
trx_t* trx, /* in: transaction */
160
dict_table_t* table); /* in: table instance to drop */
162
/*************************************************************************
163
Build indexes on a table by reading a clustered index,
164
creating a temporary file containing index entries, merge sorting
165
these index entries and inserting sorted index entries to indexes. */
168
row_merge_build_indexes(
169
/*====================*/
170
/* out: DB_SUCCESS or error code */
171
trx_t* trx, /* in: transaction */
172
dict_table_t* old_table, /* in: table where rows are
174
dict_table_t* new_table, /* in: table where indexes are
175
created; identical to old_table
176
unless creating a PRIMARY KEY */
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
180
reporting erroneous key value
182
#endif /* row0merge.h */