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. */
62
dict_index_t* index, /* in: index to be removed */
63
dict_table_t* table, /* in: table */
64
trx_t* trx); /* in: transaction handle */
65
/*************************************************************************
66
Drop those indexes which were created before an error occurred
67
when building an index. */
70
row_merge_drop_indexes(
71
/*===================*/
72
trx_t* trx, /* in: transaction */
73
dict_table_t* table, /* in: table containing the indexes */
74
dict_index_t** index, /* in: indexes to drop */
75
ulint num_created); /* in: number of elements in index[] */
76
/*************************************************************************
77
Drop all partially created indexes during crash recovery. */
80
row_merge_drop_temp_indexes(void);
81
/*=============================*/
82
/*************************************************************************
83
Rename the tables in the data dictionary. */
86
row_merge_rename_tables(
87
/*====================*/
88
/* out: error code or DB_SUCCESS */
89
dict_table_t* old_table, /* in/out: old table, renamed to
91
dict_table_t* new_table, /* in/out: new table, renamed to
93
const char* tmp_name, /* in: new name for old_table */
94
trx_t* trx); /* in: transaction handle */
96
/*************************************************************************
97
Create a temporary table for creating a primary key, using the definition
98
of an existing table. */
101
row_merge_create_temporary_table(
102
/*=============================*/
105
const char* table_name, /* in: new table name */
106
const merge_index_def_t*index_def, /* in: the index definition
107
of the primary key */
108
const dict_table_t* table, /* in: old table definition */
109
trx_t* trx); /* in/out: transaction
110
(sets error_state) */
111
/*************************************************************************
112
Rename the temporary indexes in the dictionary to permanent ones. */
115
row_merge_rename_indexes(
116
/*=====================*/
117
/* out: DB_SUCCESS if all OK */
118
trx_t* trx, /* in/out: transaction */
119
dict_table_t* table); /* in/out: table with new indexes */
120
/*************************************************************************
121
Create the index and load in to the dictionary. */
124
row_merge_create_index(
125
/*===================*/
126
/* out: index, or NULL on error */
127
trx_t* trx, /* in/out: trx (sets error_state) */
128
dict_table_t* table, /* in: the index is on this table */
129
const merge_index_def_t* /* in: the index definition */
131
#ifdef ROW_MERGE_IS_INDEX_USABLE
132
/*************************************************************************
133
Check if a transaction can use an index. */
136
row_merge_is_index_usable(
137
/*======================*/
138
/* out: TRUE if index can be used by
139
the transaction else FALSE*/
140
const trx_t* trx, /* in: transaction */
141
const dict_index_t* index); /* in: index to check */
142
#endif /* ROW_MERGE_IS_INDEX_USABLE */
143
/*************************************************************************
144
If there are views that refer to the old table name then we "attach" to
145
the new instance of the table else we drop it immediately. */
148
row_merge_drop_table(
149
/*=================*/
150
/* out: DB_SUCCESS or error code */
151
trx_t* trx, /* in: transaction */
152
dict_table_t* table); /* in: table instance to drop */
154
/*************************************************************************
155
Build indexes on a table by reading a clustered index,
156
creating a temporary file containing index entries, merge sorting
157
these index entries and inserting sorted index entries to indexes. */
160
row_merge_build_indexes(
161
/*====================*/
162
/* out: DB_SUCCESS or error code */
163
trx_t* trx, /* in: transaction */
164
dict_table_t* old_table, /* in: table where rows are
166
dict_table_t* new_table, /* in: table where indexes are
167
created; identical to old_table
168
unless creating a PRIMARY KEY */
169
dict_index_t** indexes, /* in: indexes to be created */
170
ulint n_indexes, /* in: size of indexes[] */
171
TABLE* table); /* in/out: MySQL table, for
172
reporting erroneous key value
174
#endif /* row0merge.h */