row0merge.h 7.21 KB
Newer Older
Vadim Tkachenko's avatar
Vadim Tkachenko committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*****************************************************************************

Copyright (c) 2005, 2009, Innobase Oy. All Rights Reserved.

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; version 2 of the License.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA

*****************************************************************************/

Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
19 20
/**************************************************//**
@file include/row0merge.h
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
Index build routines using a merge sort

Created 13/06/2005 Jan Lindstrom
*******************************************************/

#ifndef row0merge_h
#define row0merge_h

#include "univ.i"
#include "data0data.h"
#include "dict0types.h"
#include "trx0types.h"
#include "que0types.h"
#include "mtr0mtr.h"
#include "rem0types.h"
#include "rem0rec.h"
#include "read0types.h"
#include "btr0types.h"
#include "row0mysql.h"
#include "lock0types.h"

Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
42
/** Index field definition */
43
struct merge_index_field_struct {
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
44 45 46
	ulint		prefix_len;	/*!< column prefix length, or 0
					if indexing the whole column */
	const char*	field_name;	/*!< field name */
47 48
};

Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
49
/** Index field definition */
50 51
typedef struct merge_index_field_struct merge_index_field_t;

Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
52
/** Definition of an index being created */
53
struct merge_index_def_struct {
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
54 55
	const char*		name;		/*!< index name */
	ulint			ind_type;	/*!< 0, DICT_UNIQUE,
56
						or DICT_CLUSTERED */
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
57 58 59
	ulint			n_fields;	/*!< number of fields
						in index */
	merge_index_field_t*	fields;		/*!< field definitions */
60 61
};

Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
62
/** Definition of an index being created */
63 64
typedef struct merge_index_def_struct merge_index_def_t;

Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
65 66 67
/*********************************************************************//**
Sets an exclusive lock on a table, for the duration of creating indexes.
@return	error code or DB_SUCCESS */
68 69 70 71
UNIV_INTERN
ulint
row_merge_lock_table(
/*=================*/
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
72 73 74 75
	trx_t*		trx,		/*!< in/out: transaction */
	dict_table_t*	table,		/*!< in: table to lock */
	enum lock_mode	mode);		/*!< in: LOCK_X or LOCK_S */
/*********************************************************************//**
Vadim Tkachenko's avatar
Vadim Tkachenko committed
76 77 78
Drop an index from the InnoDB system tables.  The data dictionary must
have been locked exclusively by the caller, because the transaction
will not be committed. */
79 80 81 82
UNIV_INTERN
void
row_merge_drop_index(
/*=================*/
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
83 84 85 86
	dict_index_t*	index,	/*!< in: index to be removed */
	dict_table_t*	table,	/*!< in: table */
	trx_t*		trx);	/*!< in: transaction handle */
/*********************************************************************//**
Vadim Tkachenko's avatar
Vadim Tkachenko committed
87 88 89 90
Drop those indexes which were created before an error occurred when
building an index.  The data dictionary must have been locked
exclusively by the caller, because the transaction will not be
committed. */
91 92 93 94
UNIV_INTERN
void
row_merge_drop_indexes(
/*===================*/
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
95 96 97 98 99
	trx_t*		trx,		/*!< in: transaction */
	dict_table_t*	table,		/*!< in: table containing the indexes */
	dict_index_t**	index,		/*!< in: indexes to drop */
	ulint		num_created);	/*!< in: number of elements in index[] */
/*********************************************************************//**
100 101 102 103 104
Drop all partially created indexes during crash recovery. */
UNIV_INTERN
void
row_merge_drop_temp_indexes(void);
/*=============================*/
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
105
/*********************************************************************//**
Vadim Tkachenko's avatar
Vadim Tkachenko committed
106 107
Rename the tables in the data dictionary.  The data dictionary must
have been locked exclusively by the caller, because the transaction
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
108 109
will not be committed.
@return	error code or DB_SUCCESS */
110 111 112 113
UNIV_INTERN
ulint
row_merge_rename_tables(
/*====================*/
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
114
	dict_table_t*	old_table,	/*!< in/out: old table, renamed to
115
					tmp_name */
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
116
	dict_table_t*	new_table,	/*!< in/out: new table, renamed to
117
					old_table->name */
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
118 119
	const char*	tmp_name,	/*!< in: new name for old_table */
	trx_t*		trx);		/*!< in: transaction handle */
120

Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
121
/*********************************************************************//**
122
Create a temporary table for creating a primary key, using the definition
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
123 124
of an existing table.
@return	table, or NULL on error */
125 126 127 128
UNIV_INTERN
dict_table_t*
row_merge_create_temporary_table(
/*=============================*/
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
129 130
	const char*		table_name,	/*!< in: new table name */
	const merge_index_def_t*index_def,	/*!< in: the index definition
131
						of the primary key */
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
132 133
	const dict_table_t*	table,		/*!< in: old table definition */
	trx_t*			trx);		/*!< in/out: transaction
134
						(sets error_state) */
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
135
/*********************************************************************//**
Vadim Tkachenko's avatar
Vadim Tkachenko committed
136 137
Rename the temporary indexes in the dictionary to permanent ones.  The
data dictionary must have been locked exclusively by the caller,
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
138 139
because the transaction will not be committed.
@return	DB_SUCCESS if all OK */
140 141 142 143
UNIV_INTERN
ulint
row_merge_rename_indexes(
/*=====================*/
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
144 145 146 147 148
	trx_t*		trx,		/*!< in/out: transaction */
	dict_table_t*	table);		/*!< in/out: table with new indexes */
/*********************************************************************//**
Create the index and load in to the dictionary.
@return	index, or NULL on error */
149 150 151 152
UNIV_INTERN
dict_index_t*
row_merge_create_index(
/*===================*/
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
153 154 155 156 157 158 159
	trx_t*			trx,	/*!< in/out: trx (sets error_state) */
	dict_table_t*		table,	/*!< in: the index is on this table */
	const merge_index_def_t*index_def);
					/*!< in: the index definition */
/*********************************************************************//**
Check if a transaction can use an index.
@return	TRUE if index can be used by the transaction else FALSE */
160 161 162 163
UNIV_INTERN
ibool
row_merge_is_index_usable(
/*======================*/
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
164 165 166
	const trx_t*		trx,	/*!< in: transaction */
	const dict_index_t*	index);	/*!< in: index to check */
/*********************************************************************//**
167
If there are views that refer to the old table name then we "attach" to
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
168 169
the new instance of the table else we drop it immediately.
@return	DB_SUCCESS or error code */
170 171 172 173
UNIV_INTERN
ulint
row_merge_drop_table(
/*=================*/
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
174 175
	trx_t*		trx,		/*!< in: transaction */
	dict_table_t*	table);		/*!< in: table instance to drop */
176

Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
177
/*********************************************************************//**
178 179
Build indexes on a table by reading a clustered index,
creating a temporary file containing index entries, merge sorting
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
180 181
these index entries and inserting sorted index entries to indexes.
@return	DB_SUCCESS or error code */
182 183 184 185
UNIV_INTERN
ulint
row_merge_build_indexes(
/*====================*/
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
186 187
	trx_t*		trx,		/*!< in: transaction */
	dict_table_t*	old_table,	/*!< in: table where rows are
188
					read from */
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
189
	dict_table_t*	new_table,	/*!< in: table where indexes are
190 191
					created; identical to old_table
					unless creating a PRIMARY KEY */
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
192 193 194
	dict_index_t**	indexes,	/*!< in: indexes to be created */
	ulint		n_indexes,	/*!< in: size of indexes[] */
	TABLE*		table);		/*!< in/out: MySQL table, for
195 196 197
					reporting erroneous key value
					if applicable */
#endif /* row0merge.h */