~drizzle-trunk/drizzle/development

641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
1
/*****************************************************************************
2
1819.7.68 by Stewart Smith
Merge initial InnoDB+ import.
3
Copyright (c) 1996, 2010, Innobase Oy. All Rights Reserved.
641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
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
1802.10.2 by Monty Taylor
Update all of the copyright headers to include the correct address.
14
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15
St, Fifth Floor, Boston, MA 02110-1301 USA
641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
16
17
*****************************************************************************/
18
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
19
/**************************************************//**
20
@file include/dict0mem.h
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
21
Data dictionary memory object creation
22
23
Created 1/8/1996 Heikki Tuuri
24
*******************************************************/
25
26
#ifndef dict0mem_h
27
#define dict0mem_h
28
29
#include "univ.i"
30
#include "dict0types.h"
31
#include "data0type.h"
32
#include "mem0mem.h"
33
#include "rem0types.h"
34
#include "btr0types.h"
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
35
#ifndef UNIV_HOTBACKUP
36
# include "lock0types.h"
37
# include "que0types.h"
38
# include "sync0rw.h"
39
#endif /* !UNIV_HOTBACKUP */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
40
#include "ut0mem.h"
41
#include "ut0lst.h"
42
#include "ut0rnd.h"
43
#include "ut0byte.h"
44
#include "hash0hash.h"
641.2.1 by Monty Taylor
InnoDB Plugin 1.0.2
45
#include "trx0types.h"
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
46
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
47
/** Type flags of an index: OR'ing of the flags is allowed to define a
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
48
combination of types */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
49
/* @{ */
50
#define DICT_CLUSTERED	1	/*!< clustered index */
51
#define DICT_UNIQUE	2	/*!< unique index */
52
#define	DICT_UNIVERSAL	4	/*!< index which can contain records from any
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
53
				other index */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
54
#define	DICT_IBUF 	8	/*!< insert buffer tree */
55
/* @} */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
56
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
57
/** Types for a table object */
58
#define DICT_TABLE_ORDINARY		1 /*!< ordinary table */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
59
#if 0 /* not implemented */
60
#define	DICT_TABLE_CLUSTER_MEMBER	2
61
#define	DICT_TABLE_CLUSTER		3 /* this means that the table is
62
					  really a cluster definition */
63
#endif
64
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
65
/** Table flags.  All unused bits must be 0. */
66
/* @{ */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
67
#define DICT_TF_COMPACT			1	/* Compact page format.
68
						This must be set for
69
						new file formats
70
						(later than
71
						DICT_TF_FORMAT_51). */
72
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
73
/** Compressed page size (0=uncompressed, up to 15 compressed sizes) */
74
/* @{ */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
75
#define DICT_TF_ZSSIZE_SHIFT		1
76
#define DICT_TF_ZSSIZE_MASK		(15 << DICT_TF_ZSSIZE_SHIFT)
77
#define DICT_TF_ZSSIZE_MAX (UNIV_PAGE_SIZE_SHIFT - PAGE_ZIP_MIN_SIZE_SHIFT + 1)
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
78
/* @} */
79
80
/** File format */
81
/* @{ */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
82
#define DICT_TF_FORMAT_SHIFT		5	/* file format */
1819.5.129 by stewart at flamingspork
[patch 129/129] Merge patch for revision 1947 from InnoDB SVN:
83
#define DICT_TF_FORMAT_MASK		\
84
((~(~0 << (DICT_TF_BITS - DICT_TF_FORMAT_SHIFT))) << DICT_TF_FORMAT_SHIFT)
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
85
#define DICT_TF_FORMAT_51		0	/*!< InnoDB/MySQL up to 5.1 */
86
#define DICT_TF_FORMAT_ZIP		1	/*!< InnoDB plugin for 5.1:
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
87
						compressed tables,
88
						new BLOB treatment */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
89
/** Maximum supported file format */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
90
#define DICT_TF_FORMAT_MAX		DICT_TF_FORMAT_ZIP
1819.7.175 by Jimmy Yang, Stewart Smith
Merge Revision revid:jimmy.yang@oracle.com-20100617091353-5zga8o5hxpi0l15q from MySQL InnoDB
91
92
/** Minimum supported file format */
93
#define DICT_TF_FORMAT_MIN		DICT_TF_FORMAT_51
94
1819.5.129 by stewart at flamingspork
[patch 129/129] Merge patch for revision 1947 from InnoDB SVN:
95
/* @} */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
96
#define DICT_TF_BITS			6	/*!< number of flag bits */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
97
#if (1 << (DICT_TF_BITS - DICT_TF_FORMAT_SHIFT)) <= DICT_TF_FORMAT_MAX
98
# error "DICT_TF_BITS is insufficient for DICT_TF_FORMAT_MAX"
99
#endif
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
100
/* @} */
1819.5.129 by stewart at flamingspork
[patch 129/129] Merge patch for revision 1947 from InnoDB SVN:
101
102
/** @brief Additional table flags.
103
104
These flags will be stored in SYS_TABLES.MIX_LEN.  All unused flags
105
will be written as 0.  The column may contain garbage for tables
106
created with old versions of InnoDB that only implemented
107
ROW_FORMAT=REDUNDANT. */
108
/* @{ */
109
#define DICT_TF2_SHIFT			DICT_TF_BITS
110
						/*!< Shift value for
111
						table->flags. */
112
#define DICT_TF2_TEMPORARY		1	/*!< TRUE for tables from
113
						CREATE TEMPORARY TABLE. */
114
#define DICT_TF2_BITS			(DICT_TF2_SHIFT + 1)
115
						/*!< Total number of bits
116
						in table->flags. */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
117
/* @} */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
118
1819.5.129 by stewart at flamingspork
[patch 129/129] Merge patch for revision 1947 from InnoDB SVN:
119
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
120
/**********************************************************************//**
121
Creates a table memory object.
122
@return	own: table object */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
123
UNIV_INTERN
124
dict_table_t*
125
dict_mem_table_create(
126
/*==================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
127
	const char*	name,		/*!< in: table name */
128
	ulint		space,		/*!< in: space where the clustered index
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
129
					of the table is placed; this parameter
130
					is ignored if the table is made
131
					a member of a cluster */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
132
	ulint		n_cols,		/*!< in: number of columns */
133
	ulint		flags);		/*!< in: table flags */
134
/****************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
135
Free a table memory object. */
136
UNIV_INTERN
137
void
138
dict_mem_table_free(
139
/*================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
140
	dict_table_t*	table);		/*!< in: table */
141
/**********************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
142
Adds a column definition to a table. */
143
UNIV_INTERN
144
void
145
dict_mem_table_add_col(
146
/*===================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
147
	dict_table_t*	table,	/*!< in: table */
148
	mem_heap_t*	heap,	/*!< in: temporary memory heap, or NULL */
149
	const char*	name,	/*!< in: column name, or NULL */
150
	ulint		mtype,	/*!< in: main datatype */
151
	ulint		prtype,	/*!< in: precise type */
152
	ulint		len);	/*!< in: precision */
153
/**********************************************************************//**
1819.9.36 by Marko Mäkelä, Stewart Smith
Merge Revision revid:marko.makela@oracle.com-20100629113248-fvl48lnzr44z94gg from MySQL InnoDB
154
This function populates a dict_col_t memory structure with
1819.7.143 by Jimmy Yang, Stewart Smith
Merge Revision revid:jimmy.yang@oracle.com-20100526014433-bx0t9794mnvkiaft from MySQL InnoDB
155
supplied information. */
1819.9.36 by Marko Mäkelä, Stewart Smith
Merge Revision revid:marko.makela@oracle.com-20100629113248-fvl48lnzr44z94gg from MySQL InnoDB
156
UNIV_INTERN
1819.7.143 by Jimmy Yang, Stewart Smith
Merge Revision revid:jimmy.yang@oracle.com-20100526014433-bx0t9794mnvkiaft from MySQL InnoDB
157
void
158
dict_mem_fill_column_struct(
159
/*========================*/
160
	dict_col_t*	column,		/*!< out: column struct to be
161
					filled */
162
	ulint		col_pos,	/*!< in: column position */
163
	ulint		mtype,		/*!< in: main data type */
164
	ulint		prtype,		/*!< in: precise type */
1819.9.36 by Marko Mäkelä, Stewart Smith
Merge Revision revid:marko.makela@oracle.com-20100629113248-fvl48lnzr44z94gg from MySQL InnoDB
165
	ulint		col_len);	/*!< in: column length */
1819.7.143 by Jimmy Yang, Stewart Smith
Merge Revision revid:jimmy.yang@oracle.com-20100526014433-bx0t9794mnvkiaft from MySQL InnoDB
166
/**********************************************************************//**
167
This function poplulates a dict_index_t index memory structure with
168
supplied information. */
169
UNIV_INLINE
170
void
171
dict_mem_fill_index_struct(
172
/*=======================*/
173
	dict_index_t*	index,		/*!< out: index to be filled */
174
	mem_heap_t*	heap,		/*!< in: memory heap */
175
	const char*	table_name,	/*!< in: table name */
176
	const char*	index_name,	/*!< in: index name */
177
	ulint		space,		/*!< in: space where the index tree is
178
					placed, ignored if the index is of
179
					the clustered type */
180
	ulint		type,		/*!< in: DICT_UNIQUE,
181
					DICT_CLUSTERED, ... ORed */
182
	ulint		n_fields);	/*!< in: number of fields */
183
/**********************************************************************//**
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
184
Creates an index memory object.
185
@return	own: index object */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
186
UNIV_INTERN
187
dict_index_t*
188
dict_mem_index_create(
189
/*==================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
190
	const char*	table_name,	/*!< in: table name */
191
	const char*	index_name,	/*!< in: index name */
192
	ulint		space,		/*!< in: space where the index tree is
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
193
					placed, ignored if the index is of
194
					the clustered type */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
195
	ulint		type,		/*!< in: DICT_UNIQUE,
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
196
					DICT_CLUSTERED, ... ORed */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
197
	ulint		n_fields);	/*!< in: number of fields */
198
/**********************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
199
Adds a field definition to an index. NOTE: does not take a copy
200
of the column name if the field is a column. The memory occupied
201
by the column name may be released only after publishing the index. */
202
UNIV_INTERN
203
void
204
dict_mem_index_add_field(
205
/*=====================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
206
	dict_index_t*	index,		/*!< in: index */
207
	const char*	name,		/*!< in: column name */
208
	ulint		prefix_len);	/*!< in: 0 or the column prefix length
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
209
					in a MySQL index like
210
					INDEX (textcol(25)) */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
211
/**********************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
212
Frees an index memory object. */
213
UNIV_INTERN
214
void
215
dict_mem_index_free(
216
/*================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
217
	dict_index_t*	index);	/*!< in: index */
218
/**********************************************************************//**
219
Creates and initializes a foreign constraint memory object.
220
@return	own: foreign constraint struct */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
221
UNIV_INTERN
222
dict_foreign_t*
223
dict_mem_foreign_create(void);
224
/*=========================*/
225
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
226
/** Data structure for a column in a table */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
227
struct dict_col_struct{
228
	/*----------------------*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
229
	/** The following are copied from dtype_t,
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
230
	so that all bit-fields can be packed tightly. */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
231
	/* @{ */
232
	unsigned	mtype:8;	/*!< main data type */
233
	unsigned	prtype:24;	/*!< precise type; MySQL data
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
234
					type, charset code, flags to
235
					indicate nullability,
236
					signedness, whether this is a
237
					binary string, whether this is
238
					a true VARCHAR where MySQL
239
					uses 2 bytes to store the length */
240
241
	/* the remaining fields do not affect alphabetical ordering: */
242
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
243
	unsigned	len:16;		/*!< length; for MySQL data this
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
244
					is field->pack_length(),
245
					except that for a >= 5.0.3
246
					type true VARCHAR this is the
247
					maximum byte length of the
248
					string data (in addition to
249
					the string, MySQL uses 1 or 2
250
					bytes to store the string length) */
251
1819.9.36 by Marko Mäkelä, Stewart Smith
Merge Revision revid:marko.makela@oracle.com-20100629113248-fvl48lnzr44z94gg from MySQL InnoDB
252
	unsigned	mbminmaxlen:5;	/*!< minimum and maximum length of a
253
					character, in bytes;
254
					DATA_MBMINMAXLEN(mbminlen,mbmaxlen);
255
					mbminlen=DATA_MBMINLEN(mbminmaxlen);
256
					mbmaxlen=DATA_MBMINLEN(mbminmaxlen) */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
257
	/*----------------------*/
258
	/* End of definitions copied from dtype_t */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
259
	/* @} */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
260
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
261
	unsigned	ind:10;		/*!< table column position
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
262
					(starting from 0) */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
263
	unsigned	ord_part:1;	/*!< nonzero if this column
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
264
					appears in the ordering fields
265
					of an index */
266
};
267
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
268
/** @brief DICT_MAX_INDEX_COL_LEN is measured in bytes and is the maximum
269
indexed column length (or indexed prefix length).
270
271
It is set to 3*256, so that one can create a column prefix index on
272
256 characters of a TEXT or VARCHAR column also in the UTF-8
273
charset. In that charset, a character may take at most 3 bytes.  This
274
constant MUST NOT BE CHANGED, or the compatibility of InnoDB data
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
275
files would be at risk! */
276
#define DICT_MAX_INDEX_COL_LEN		REC_MAX_INDEX_COL_LEN
277
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
278
/** Data structure for a field in an index */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
279
struct dict_field_struct{
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
280
	dict_col_t*	col;		/*!< pointer to the table column */
281
	const char*	name;		/*!< name of the column */
282
	unsigned	prefix_len:10;	/*!< 0 or the length of the column
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
283
					prefix in bytes in a MySQL index of
284
					type, e.g., INDEX (textcol(25));
285
					must be smaller than
286
					DICT_MAX_INDEX_COL_LEN; NOTE that
287
					in the UTF-8 charset, MySQL sets this
288
					to 3 * the prefix len in UTF-8 chars */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
289
	unsigned	fixed_len:10;	/*!< 0 or the fixed length of the
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
290
					column if smaller than
291
					DICT_MAX_INDEX_COL_LEN */
292
};
293
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
294
/** Data structure for an index.  Most fields will be
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
295
initialized to 0, NULL or FALSE in dict_mem_index_create(). */
296
struct dict_index_struct{
1819.9.31 by Marko Mäkelä, Stewart Smith
Merge Revision revid:marko.makela@oracle.com-20100623110659-pk5bqnmo0j7hj6md from MySQL InnoDB
297
	index_id_t	id;	/*!< id of the index */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
298
	mem_heap_t*	heap;	/*!< memory heap */
299
	const char*	name;	/*!< index name */
300
	const char*	table_name;/*!< table name */
301
	dict_table_t*	table;	/*!< back pointer to table */
302
#ifndef UNIV_HOTBACKUP
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
303
	unsigned	space:32;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
304
				/*!< space where the index tree is placed */
305
	unsigned	page:32;/*!< index tree root page number */
306
#endif /* !UNIV_HOTBACKUP */
307
	unsigned	type:4;	/*!< index type (DICT_CLUSTERED, DICT_UNIQUE,
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
308
				DICT_UNIVERSAL, DICT_IBUF) */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
309
	unsigned	trx_id_offset:10;/*!< position of the trx id column
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
310
				in a clustered index record, if the fields
311
				before it are known to be of a fixed size,
312
				0 otherwise */
313
	unsigned	n_user_defined_cols:10;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
314
				/*!< number of columns the user defined to
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
315
				be in the index: in the internal
316
				representation we add more columns */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
317
	unsigned	n_uniq:10;/*!< number of fields from the beginning
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
318
				which are enough to determine an index
319
				entry uniquely */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
320
	unsigned	n_def:10;/*!< number of fields defined so far */
321
	unsigned	n_fields:10;/*!< number of fields in the index */
322
	unsigned	n_nullable:10;/*!< number of nullable fields */
323
	unsigned	cached:1;/*!< TRUE if the index object is in the
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
324
				dictionary cache */
325
	unsigned	to_be_dropped:1;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
326
				/*!< TRUE if this index is marked to be
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
327
				dropped in ha_innobase::prepare_drop_index(),
328
				otherwise FALSE */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
329
	dict_field_t*	fields;	/*!< array of field descriptions */
330
#ifndef UNIV_HOTBACKUP
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
331
	UT_LIST_NODE_T(dict_index_t)
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
332
			indexes;/*!< list of indexes of the table */
333
	btr_search_t*	search_info; /*!< info used in optimistic searches */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
334
	/*----------------------*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
335
	/** Statistics for query optimization */
336
	/* @{ */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
337
	ib_int64_t*	stat_n_diff_key_vals;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
338
				/*!< approximate number of different
339
				key values for this index, for each
340
				n-column prefix where n <=
341
				dict_get_n_unique(index); we
342
				periodically calculate new
343
				estimates */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
344
	ulint		stat_index_size;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
345
				/*!< approximate index size in
346
				database pages */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
347
	ulint		stat_n_leaf_pages;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
348
				/*!< approximate number of leaf pages in the
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
349
				index tree */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
350
	/* @} */
351
	rw_lock_t	lock;	/*!< read-write lock protecting the
352
				upper levels of the index tree */
1819.9.31 by Marko Mäkelä, Stewart Smith
Merge Revision revid:marko.makela@oracle.com-20100623110659-pk5bqnmo0j7hj6md from MySQL InnoDB
353
	trx_id_t	trx_id; /*!< id of the transaction that created this
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
354
				index, or 0 if the index existed
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
355
				when InnoDB was started up */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
356
#endif /* !UNIV_HOTBACKUP */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
357
#ifdef UNIV_DEBUG
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
358
	ulint		magic_n;/*!< magic number */
359
/** Value of dict_index_struct::magic_n */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
360
# define DICT_INDEX_MAGIC_N	76789786
361
#endif
362
};
363
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
364
/** Data structure for a foreign key constraint; an example:
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
365
FOREIGN KEY (A, B) REFERENCES TABLE2 (C, D).  Most fields will be
366
initialized to 0, NULL or FALSE in dict_mem_foreign_create(). */
367
struct dict_foreign_struct{
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
368
	mem_heap_t*	heap;		/*!< this object is allocated from
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
369
					this memory heap */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
370
	char*		id;		/*!< id of the constraint as a
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
371
					null-terminated string */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
372
	unsigned	n_fields:10;	/*!< number of indexes' first fields
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
373
					for which the the foreign key
374
					constraint is defined: we allow the
375
					indexes to contain more fields than
376
					mentioned in the constraint, as long
377
					as the first fields are as mentioned */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
378
	unsigned	type:6;		/*!< 0 or DICT_FOREIGN_ON_DELETE_CASCADE
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
379
					or DICT_FOREIGN_ON_DELETE_SET_NULL */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
380
	char*		foreign_table_name;/*!< foreign table name */
381
	dict_table_t*	foreign_table;	/*!< table where the foreign key is */
382
	const char**	foreign_col_names;/*!< names of the columns in the
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
383
					foreign key */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
384
	char*		referenced_table_name;/*!< referenced table name */
385
	dict_table_t*	referenced_table;/*!< table where the referenced key
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
386
					is */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
387
	const char**	referenced_col_names;/*!< names of the referenced
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
388
					columns in the referenced table */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
389
	dict_index_t*	foreign_index;	/*!< foreign index; we require that
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
390
					both tables contain explicitly defined
391
					indexes for the constraint: InnoDB
392
					does not generate new indexes
393
					implicitly */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
394
	dict_index_t*	referenced_index;/*!< referenced index */
395
	UT_LIST_NODE_T(dict_foreign_t)
396
			foreign_list;	/*!< list node for foreign keys of the
397
					table */
398
	UT_LIST_NODE_T(dict_foreign_t)
399
			referenced_list;/*!< list node for referenced
400
					keys of the table */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
401
};
402
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
403
/** The flags for ON_UPDATE and ON_DELETE can be ORed; the default is that
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
404
a foreign key constraint is enforced, therefore RESTRICT just means no flag */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
405
/* @{ */
406
#define DICT_FOREIGN_ON_DELETE_CASCADE	1	/*!< ON DELETE CASCADE */
407
#define DICT_FOREIGN_ON_DELETE_SET_NULL	2	/*!< ON UPDATE SET NULL */
408
#define DICT_FOREIGN_ON_UPDATE_CASCADE	4	/*!< ON DELETE CASCADE */
409
#define DICT_FOREIGN_ON_UPDATE_SET_NULL	8	/*!< ON UPDATE SET NULL */
410
#define DICT_FOREIGN_ON_DELETE_NO_ACTION 16	/*!< ON DELETE NO ACTION */
411
#define DICT_FOREIGN_ON_UPDATE_NO_ACTION 32	/*!< ON UPDATE NO ACTION */
412
/* @} */
413
414
415
/** Data structure for a database table.  Most fields will be
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
416
initialized to 0, NULL or FALSE in dict_mem_table_create(). */
417
struct dict_table_struct{
1819.9.31 by Marko Mäkelä, Stewart Smith
Merge Revision revid:marko.makela@oracle.com-20100623110659-pk5bqnmo0j7hj6md from MySQL InnoDB
418
	table_id_t	id;	/*!< id of the table */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
419
	mem_heap_t*	heap;	/*!< memory heap */
1819.9.19 by Vasil Dimov
Merge Revision revid:vasil.dimov@oracle.com-20100622163043-dc0lxy0byg74viet from MySQL InnoDB
420
	char*		name;	/*!< table name */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
421
	const char*	dir_path_of_temp_table;/*!< NULL or the directory path
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
422
				where a TEMPORARY table that was explicitly
423
				created by a user should be placed if
424
				innodb_file_per_table is defined in my.cnf;
425
				in Unix this is usually /tmp/..., in Windows
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
426
				temp\... */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
427
	unsigned	space:32;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
428
				/*!< space where the clustered index of the
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
429
				table is placed */
1819.5.129 by stewart at flamingspork
[patch 129/129] Merge patch for revision 1947 from InnoDB SVN:
430
	unsigned	flags:DICT_TF2_BITS;/*!< DICT_TF_COMPACT, ... */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
431
	unsigned	ibd_file_missing:1;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
432
				/*!< TRUE if this is in a single-table
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
433
				tablespace and the .ibd file is missing; then
434
				we must return in ha_innodb.cc an error if the
435
				user tries to query such an orphaned table */
436
	unsigned	tablespace_discarded:1;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
437
				/*!< this flag is set TRUE when the user
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
438
				calls DISCARD TABLESPACE on this
439
				table, and reset to FALSE in IMPORT
440
				TABLESPACE */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
441
	unsigned	cached:1;/*!< TRUE if the table object has been added
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
442
				to the dictionary cache */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
443
	unsigned	n_def:10;/*!< number of columns defined so far */
444
	unsigned	n_cols:10;/*!< number of columns */
445
	dict_col_t*	cols;	/*!< array of column descriptions */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
446
	const char*	col_names;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
447
				/*!< Column names packed in a character string
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
448
				"name1\0name2\0...nameN\0".  Until
449
				the string contains n_cols, it will be
450
				allocated from a temporary heap.  The final
451
				string will be allocated from table->heap. */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
452
#ifndef UNIV_HOTBACKUP
453
	hash_node_t	name_hash; /*!< hash chain node */
454
	hash_node_t	id_hash; /*!< hash chain node */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
455
	UT_LIST_BASE_NODE_T(dict_index_t)
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
456
			indexes; /*!< list of indexes of the table */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
457
	UT_LIST_BASE_NODE_T(dict_foreign_t)
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
458
			foreign_list;/*!< list of foreign key constraints
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
459
				in the table; these refer to columns
460
				in other tables */
461
	UT_LIST_BASE_NODE_T(dict_foreign_t)
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
462
			referenced_list;/*!< list of foreign key constraints
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
463
				which refer to this table */
464
	UT_LIST_NODE_T(dict_table_t)
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
465
			table_LRU; /*!< node of the LRU list of tables */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
466
	ulint		n_mysql_handles_opened;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
467
				/*!< count of how many handles MySQL has opened
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
468
				to this table; dropping of the table is
469
				NOT allowed until this count gets to zero;
470
				MySQL does NOT itself check the number of
471
				open handles at drop */
472
	ulint		n_foreign_key_checks_running;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
473
				/*!< count of how many foreign key check
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
474
				operations are currently being performed
475
				on the table: we cannot drop the table while
476
				there are foreign key checks running on
477
				it! */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
478
	trx_id_t	query_cache_inv_trx_id;
479
				/*!< transactions whose trx id is
480
				smaller than this number are not
481
				allowed to store to the MySQL query
482
				cache or retrieve from it; when a trx
483
				with undo logs commits, it sets this
484
				to the value of the trx id counter for
485
				the tables it had an IX lock on */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
486
	UT_LIST_BASE_NODE_T(lock_t)
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
487
			locks; /*!< list of locks on the table */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
488
#ifdef UNIV_DEBUG
489
	/*----------------------*/
490
	ibool		does_not_fit_in_memory;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
491
				/*!< this field is used to specify in
492
				simulations tables which are so big
493
				that disk should be accessed: disk
494
				access is simulated by putting the
495
				thread to sleep for a while; NOTE that
496
				this flag is not stored to the data
497
				dictionary on disk, and the database
498
				will forget about value TRUE if it has
499
				to reload the table definition from
500
				disk */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
501
#endif /* UNIV_DEBUG */
502
	/*----------------------*/
503
	unsigned	big_rows:1;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
504
				/*!< flag: TRUE if the maximum length of
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
505
				a single row exceeds BIG_ROW_SIZE;
506
				initialized in dict_table_add_to_cache() */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
507
				/** Statistics for query optimization */
508
				/* @{ */
509
	unsigned	stat_initialized:1; /*!< TRUE if statistics have
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
510
				been calculated the first time
511
				after database startup or table creation */
512
	ib_int64_t	stat_n_rows;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
513
				/*!< approximate number of rows in the table;
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
514
				we periodically calculate new estimates */
515
	ulint		stat_clustered_index_size;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
516
				/*!< approximate clustered index size in
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
517
				database pages */
518
	ulint		stat_sum_of_other_index_sizes;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
519
				/*!< other indexes in database pages */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
520
	ulint		stat_modified_counter;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
521
				/*!< when a row is inserted, updated,
522
				or deleted,
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
523
				we add 1 to this number; we calculate new
524
				estimates for the stat_... values for the
525
				table and the indexes at an interval of 2 GB
526
				or when about 1 / 16 of table has been
527
				modified; also when the estimate operation is
528
				called for MySQL SHOW TABLE STATUS; the
529
				counter is reset to zero at statistics
530
				calculation; this counter is not protected by
531
				any latch, because this is only used for
532
				heuristics */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
533
				/* @} */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
534
	/*----------------------*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
535
				/**!< The following fields are used by the
641.2.1 by Monty Taylor
InnoDB Plugin 1.0.2
536
				AUTOINC code.  The actual collection of
537
				tables locked during AUTOINC read/write is
538
				kept in trx_t. In order to quickly determine
539
				whether a transaction has locked the AUTOINC
540
				lock we keep a pointer to the transaction
541
				here in the autoinc_trx variable. This is to
542
				avoid acquiring the kernel mutex and scanning
543
				the vector in trx_t.
544
545
				When an AUTOINC lock has to wait, the
546
				corresponding lock instance is created on
547
				the trx lock heap rather than use the
548
				pre-allocated instance in autoinc_lock below.*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
549
				/* @{ */
641.2.1 by Monty Taylor
InnoDB Plugin 1.0.2
550
	lock_t*		autoinc_lock;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
551
				/*!< a buffer for an AUTOINC lock
641.2.1 by Monty Taylor
InnoDB Plugin 1.0.2
552
				for this table: we allocate the memory here
553
				so that individual transactions can get it
554
				and release it without a need to allocate
555
				space from the lock heap of the trx:
556
				otherwise the lock heap would grow rapidly
557
				if we do a large insert from a select */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
558
	mutex_t		autoinc_mutex;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
559
				/*!< mutex protecting the autoincrement
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
560
				counter */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
561
	ib_uint64_t	autoinc;/*!< autoinc counter value to give to the
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
562
				next inserted row */
563
	ulong		n_waiting_or_granted_auto_inc_locks;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
564
				/*!< This counter is used to track the number
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
565
				of granted and pending autoinc locks on this
566
				table. This value is set after acquiring the
567
				kernel mutex but we peek the contents to
568
				determine whether other transactions have
569
				acquired the AUTOINC lock or not. Of course
570
				only one transaction can be granted the
571
				lock but there can be multiple waiters. */
641.2.1 by Monty Taylor
InnoDB Plugin 1.0.2
572
	const trx_t*		autoinc_trx;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
573
				/*!< The transaction that currently holds the
641.2.1 by Monty Taylor
InnoDB Plugin 1.0.2
574
				the AUTOINC lock on this table. */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
575
				/* @} */
641.2.1 by Monty Taylor
InnoDB Plugin 1.0.2
576
	/*----------------------*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
577
#endif /* !UNIV_HOTBACKUP */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
578
579
#ifdef UNIV_DEBUG
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
580
	ulint		magic_n;/*!< magic number */
581
/** Value of dict_table_struct::magic_n */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
582
# define DICT_TABLE_MAGIC_N	76333786
583
#endif /* UNIV_DEBUG */
584
};
585
586
#ifndef UNIV_NONINL
587
#include "dict0mem.ic"
588
#endif
589
590
#endif