dict0dict.h 47.4 KB
Newer Older
1 2
/*****************************************************************************

3
Copyright (c) 1996, 2012, Oracle and/or its affiliates. All Rights Reserved.
4 5 6 7 8 9 10 11 12 13

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
14 15
this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
16 17 18

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

19 20
/**************************************************//**
@file include/dict0dict.h
osku's avatar
osku committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
Data dictionary system

Created 1/8/1996 Heikki Tuuri
*******************************************************/

#ifndef dict0dict_h
#define dict0dict_h

#include "univ.i"
#include "dict0types.h"
#include "dict0mem.h"
#include "data0type.h"
#include "data0data.h"
#include "mem0mem.h"
#include "rem0types.h"
#include "ut0mem.h"
#include "ut0lst.h"
#include "hash0hash.h"
#include "ut0rnd.h"
#include "ut0byte.h"
#include "trx0types.h"

43
#ifndef UNIV_HOTBACKUP
44 45
# include "sync0sync.h"
# include "sync0rw.h"
46
/******************************************************************//**
osku's avatar
osku committed
47
Makes all characters in a NUL-terminated UTF-8 string lower case. */
48
UNIV_INTERN
osku's avatar
osku committed
49 50 51
void
dict_casedn_str(
/*============*/
52
	char*	a);	/*!< in/out: string to put in lower case */
53
/********************************************************************//**
54 55
Get the database name length in a table name.
@return	database name length */
56
UNIV_INTERN
osku's avatar
osku committed
57 58 59
ulint
dict_get_db_name_len(
/*=================*/
60
	const char*	name);	/*!< in: table name in the form
osku's avatar
osku committed
61
				dbname '/' tablename */
62
/********************************************************************//**
63 64
Return the end of table name where we have removed dbname and '/'.
@return	table name */
osku's avatar
osku committed
65 66

const char*
67 68
dict_remove_db_name(
/*================*/
69
	const char*	name);	/*!< in: table name in the form
70
				dbname '/' tablename */
71
/**********************************************************************//**
72 73
Returns a table object based on table id.
@return	table, NULL if does not exist */
74
UNIV_INTERN
75 76 77
dict_table_t*
dict_table_get_on_id(
/*=================*/
78 79
        table_id_t	table_id,	/*!< in: table id */
        trx_t*		trx);		/*!< in: transaction handle */
80
/********************************************************************//**
osku's avatar
osku committed
81
Decrements the count of open MySQL handles to a table. */
82
UNIV_INTERN
osku's avatar
osku committed
83 84 85
void
dict_table_decrement_handle_count(
/*==============================*/
86 87
	dict_table_t*	table,		/*!< in/out: table */
	ibool		dict_locked);	/*!< in: TRUE=data dictionary locked */
88
/**********************************************************************//**
osku's avatar
osku committed
89
Inits the data dictionary module. */
90
UNIV_INTERN
osku's avatar
osku committed
91 92 93
void
dict_init(void);
/*===========*/
94
/********************************************************************//**
osku's avatar
osku committed
95 96 97 98 99
Gets the space id of every table of the data dictionary and makes a linear
list and a hash table of them to the data dictionary cache. This function
can be called at database startup if we did not need to do a crash recovery.
In crash recovery we must scan the space id's from the .ibd files in MySQL
database directories. */
100
UNIV_INTERN
osku's avatar
osku committed
101 102 103
void
dict_load_space_id_list(void);
/*=========================*/
104
/*********************************************************************//**
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
Gets the minimum number of bytes per character.
@return minimum multi-byte char size, in bytes */
UNIV_INLINE
ulint
dict_col_get_mbminlen(
/*==================*/
	const dict_col_t*	col);	/*!< in: column */
/*********************************************************************//**
Gets the maximum number of bytes per character.
@return maximum multi-byte char size, in bytes */
UNIV_INLINE
ulint
dict_col_get_mbmaxlen(
/*==================*/
	const dict_col_t*	col);	/*!< in: column */
/*********************************************************************//**
Sets the minimum and maximum number of bytes per character. */
UNIV_INLINE
void
dict_col_set_mbminmaxlen(
/*=====================*/
	dict_col_t*	col,		/*!< in/out: column */
	ulint		mbminlen,	/*!< in: minimum multi-byte
					character size, in bytes */
	ulint		mbmaxlen);	/*!< in: minimum multi-byte
					character size, in bytes */
/*********************************************************************//**
osku's avatar
osku committed
132 133
Gets the column data type. */
UNIV_INLINE
134 135 136
void
dict_col_copy_type(
/*===============*/
137 138
	const dict_col_t*	col,	/*!< in: column */
	dtype_t*		type);	/*!< out: data type */
139 140 141 142 143 144 145 146 147 148 149 150 151
/**********************************************************************//**
Determine bytes of column prefix to be stored in the undo log. Please
note if the table format is UNIV_FORMAT_A (< DICT_TF_FORMAT_ZIP), no prefix
needs to be stored in the undo log.
@return bytes of column prefix to be stored in the undo log */
UNIV_INLINE
ulint
dict_max_field_len_store_undo(
/*==========================*/
	dict_table_t*		table,	/*!< in: table */
	const dict_col_t*	col);	/*!< in: column which index prefix
					is based on */

152
#endif /* !UNIV_HOTBACKUP */
153
#ifdef UNIV_DEBUG
154
/*********************************************************************//**
155 156
Assert that a column and a data type match.
@return	TRUE */
157 158 159 160
UNIV_INLINE
ibool
dict_col_type_assert_equal(
/*=======================*/
161 162
	const dict_col_t*	col,	/*!< in: column */
	const dtype_t*		type);	/*!< in: data type */
163
#endif /* UNIV_DEBUG */
164
#ifndef UNIV_HOTBACKUP
165
/***********************************************************************//**
166 167
Returns the minimum size of the column.
@return	minimum size */
168 169 170 171
UNIV_INLINE
ulint
dict_col_get_min_size(
/*==================*/
172
	const dict_col_t*	col);	/*!< in: column */
173
/***********************************************************************//**
174 175
Returns the maximum size of the column.
@return	maximum size */
176 177 178 179
UNIV_INLINE
ulint
dict_col_get_max_size(
/*==================*/
180
	const dict_col_t*	col);	/*!< in: column */
181
/***********************************************************************//**
182 183
Returns the size of a fixed size column, 0 if not a fixed size column.
@return	fixed size, or 0 */
184 185 186 187
UNIV_INLINE
ulint
dict_col_get_fixed_size(
/*====================*/
188 189
	const dict_col_t*	col,	/*!< in: column */
	ulint			comp);	/*!< in: nonzero=ROW_FORMAT=COMPACT  */
190
/***********************************************************************//**
191
Returns the ROW_FORMAT=REDUNDANT stored SQL NULL size of a column.
192 193
For fixed length types it is the fixed length of the type, otherwise 0.
@return	SQL null storage size in ROW_FORMAT=REDUNDANT */
194 195 196 197
UNIV_INLINE
ulint
dict_col_get_sql_null_size(
/*=======================*/
198 199
	const dict_col_t*	col,	/*!< in: column */
	ulint			comp);	/*!< in: nonzero=ROW_FORMAT=COMPACT  */
200

201
/*********************************************************************//**
202 203
Gets the column number.
@return	col->ind, table column position (starting from 0) */
osku's avatar
osku committed
204 205 206 207
UNIV_INLINE
ulint
dict_col_get_no(
/*============*/
208
	const dict_col_t*	col);	/*!< in: column */
209
/*********************************************************************//**
osku's avatar
osku committed
210 211 212 213 214
Gets the column position in the clustered index. */
UNIV_INLINE
ulint
dict_col_get_clust_pos(
/*===================*/
215 216
	const dict_col_t*	col,		/*!< in: table column */
	const dict_index_t*	clust_index);	/*!< in: clustered index */
217
/****************************************************************//**
218
If the given column name is reserved for InnoDB system columns, return
219 220
TRUE.
@return	TRUE if name is reserved */
221
UNIV_INTERN
222 223 224
ibool
dict_col_name_is_reserved(
/*======================*/
225
	const char*	name);	/*!< in: column name */
226
/********************************************************************//**
227
Acquire the autoinc lock. */
228
UNIV_INTERN
229 230 231
void
dict_table_autoinc_lock(
/*====================*/
232
	dict_table_t*	table);	/*!< in/out: table */
233
/********************************************************************//**
234
Unconditionally set the autoinc counter. */
235
UNIV_INTERN
osku's avatar
osku committed
236 237 238
void
dict_table_autoinc_initialize(
/*==========================*/
239 240
	dict_table_t*	table,	/*!< in/out: table */
	ib_uint64_t	value);	/*!< in: next value to assign to a row */
241
/********************************************************************//**
osku's avatar
osku committed
242
Reads the next autoinc value (== autoinc counter value), 0 if not yet
243 244
initialized.
@return	value for a new row, or 0 */
245
UNIV_INTERN
246
ib_uint64_t
osku's avatar
osku committed
247 248
dict_table_autoinc_read(
/*====================*/
249
	const dict_table_t*	table);	/*!< in: table */
250
/********************************************************************//**
251 252
Updates the autoinc counter if the value supplied is greater than the
current value. */
253
UNIV_INTERN
osku's avatar
osku committed
254
void
255 256
dict_table_autoinc_update_if_greater(
/*=================================*/
osku's avatar
osku committed
257

258 259
	dict_table_t*	table,	/*!< in/out: table */
	ib_uint64_t	value);	/*!< in: value which was assigned to a row */
260
/********************************************************************//**
261
Release the autoinc lock. */
262
UNIV_INTERN
263 264 265
void
dict_table_autoinc_unlock(
/*======================*/
266
	dict_table_t*	table);	/*!< in/out: table */
267
#endif /* !UNIV_HOTBACKUP */
268
/**********************************************************************//**
269
Adds system columns to a table object. */
270
UNIV_INTERN
271 272 273
void
dict_table_add_system_columns(
/*==========================*/
274 275
	dict_table_t*	table,	/*!< in/out: table */
	mem_heap_t*	heap);	/*!< in: temporary heap */
276
#ifndef UNIV_HOTBACKUP
277
/**********************************************************************//**
osku's avatar
osku committed
278
Adds a table object to the dictionary cache. */
279
UNIV_INTERN
osku's avatar
osku committed
280 281 282
void
dict_table_add_to_cache(
/*====================*/
283 284
	dict_table_t*	table,	/*!< in: table */
	mem_heap_t*	heap);	/*!< in: temporary heap */
285
/**********************************************************************//**
osku's avatar
osku committed
286
Removes a table object from the dictionary cache. */
287
UNIV_INTERN
osku's avatar
osku committed
288 289 290
void
dict_table_remove_from_cache(
/*=========================*/
291
	dict_table_t*	table);	/*!< in, own: table */
292
/**********************************************************************//**
293 294
Renames a table object.
@return	TRUE if success */
295
UNIV_INTERN
osku's avatar
osku committed
296 297 298
ibool
dict_table_rename_in_cache(
/*=======================*/
299 300 301
	dict_table_t*	table,		/*!< in/out: table */
	const char*	new_name,	/*!< in: new name */
	ibool		rename_also_foreigns);/*!< in: in ALTER TABLE we want
osku's avatar
osku committed
302 303
					to preserve the original table name
					in constraints which reference it */
304
/**********************************************************************//**
305
Removes an index from the dictionary cache. */
306
UNIV_INTERN
307 308 309
void
dict_index_remove_from_cache(
/*=========================*/
310 311
	dict_table_t*	table,	/*!< in/out: table */
	dict_index_t*	index);	/*!< in, own: index */
312
/**********************************************************************//**
osku's avatar
osku committed
313 314
Change the id of a table object in the dictionary cache. This is used in
DISCARD TABLESPACE. */
315
UNIV_INTERN
osku's avatar
osku committed
316 317 318
void
dict_table_change_id_in_cache(
/*==========================*/
319
	dict_table_t*	table,	/*!< in/out: table object already in cache */
320
	table_id_t	new_id);/*!< in: new id to set */
321
/**********************************************************************//**
osku's avatar
osku committed
322 323 324
Adds a foreign key constraint object to the dictionary cache. May free
the object if there already is an object with the same identifier in.
At least one of foreign table or referenced table must already be in
325 326
the dictionary cache!
@return	DB_SUCCESS or error code */
327
UNIV_INTERN
osku's avatar
osku committed
328 329 330
ulint
dict_foreign_add_to_cache(
/*======================*/
331 332
	dict_foreign_t*	foreign,	/*!< in, own: foreign key constraint */
	ibool		check_charsets);/*!< in: TRUE=check charset
333
					compatibility */
334
/*********************************************************************//**
335
Check if the index is referenced by a foreign key, if TRUE return the
336
matching instance NULL otherwise.
337 338
@return pointer to foreign key struct if index is defined for foreign
key, otherwise NULL */
339
UNIV_INTERN
340 341 342
dict_foreign_t*
dict_table_get_referenced_constraint(
/*=================================*/
343 344
	dict_table_t*	table,	/*!< in: InnoDB table */
	dict_index_t*	index);	/*!< in: InnoDB index */
345
/*********************************************************************//**
346 347
Checks if a table is referenced by foreign keys.
@return	TRUE if table is referenced by a foreign key */
348
UNIV_INTERN
osku's avatar
osku committed
349
ibool
350 351
dict_table_is_referenced_by_foreign_key(
/*====================================*/
352
	const dict_table_t*	table);	/*!< in: InnoDB table */
353
/**********************************************************************//**
354 355
Replace the index in the foreign key list that matches this index's
definition with an equivalent index. */
356
UNIV_INTERN
357 358 359
void
dict_table_replace_index_in_foreign_list(
/*=====================================*/
360
	dict_table_t*	table,  /*!< in/out: table */
361 362
	dict_index_t*	index,	/*!< in: index to be replaced */
	const trx_t*	trx);	/*!< in: transaction handle */
363
/*********************************************************************//**
364 365
Checks if a index is defined for a foreign key constraint. Index is a part
of a foreign key constraint if the index is referenced by foreign key
366
or index is a foreign key index
367 368
@return pointer to foreign key struct if index is defined for foreign
key, otherwise NULL */
369
UNIV_INTERN
370 371 372
dict_foreign_t*
dict_table_get_foreign_constraint(
/*==============================*/
373 374
	dict_table_t*	table,	/*!< in: InnoDB table */
	dict_index_t*	index);	/*!< in: InnoDB index */
375
/*********************************************************************//**
osku's avatar
osku committed
376 377 378 379 380
Scans a table create SQL string and adds to the data dictionary
the foreign key constraints declared in the string. This function
should be called after the indexes for a table have been created.
Each foreign key constraint must be accompanied with indexes in
bot participating tables. The indexes are allowed to contain more
381 382
fields than mentioned in the constraint.
@return	error code or DB_SUCCESS */
383
UNIV_INTERN
osku's avatar
osku committed
384 385 386
ulint
dict_create_foreign_constraints(
/*============================*/
387 388
	trx_t*		trx,		/*!< in: transaction */
	const char*	sql_string,	/*!< in: table create statement where
osku's avatar
osku committed
389 390 391 392 393 394 395
					foreign keys are declared like:
					FOREIGN KEY (a, b) REFERENCES
					table2(c, d), table2 can be written
					also with the database
					name before it: test.table2; the
					default database id the database of
					parameter name */
396
	size_t		sql_length,	/*!< in: length of sql_string */
397
	const char*	name,		/*!< in: table full name in the
osku's avatar
osku committed
398 399
					normalized form
					database_name/table_name */
400
	ibool		reject_fks);	/*!< in: if TRUE, fail with error
osku's avatar
osku committed
401 402
					code DB_CANNOT_ADD_CONSTRAINT if
					any foreign keys are found. */
403
/**********************************************************************//**
404
Parses the CONSTRAINT id's to be dropped in an ALTER TABLE statement.
405 406
@return DB_SUCCESS or DB_CANNOT_DROP_CONSTRAINT if syntax error or the
constraint id does not match */
407
UNIV_INTERN
osku's avatar
osku committed
408 409 410
ulint
dict_foreign_parse_drop_constraints(
/*================================*/
411
	mem_heap_t*	heap,			/*!< in: heap from which we can
osku's avatar
osku committed
412
						allocate memory */
413 414 415
	trx_t*		trx,			/*!< in: transaction */
	dict_table_t*	table,			/*!< in: table */
	ulint*		n,			/*!< out: number of constraints
osku's avatar
osku committed
416
						to drop */
417
	const char***	constraints_to_drop);	/*!< out: id's of the
osku's avatar
osku committed
418
						constraints to drop */
419
/**********************************************************************//**
420 421 422
Returns a table object and optionally increment its MySQL open handle count.
NOTE! This is a high-level function to be used mainly from outside the
'dict' directory. Inside this directory dict_table_get_low is usually the
423 424
appropriate function.
@return	table, NULL if does not exist */
425
UNIV_INTERN
osku's avatar
osku committed
426 427 428
dict_table_t*
dict_table_get(
/*===========*/
429
	const char*	table_name,	/*!< in: table name */
430
	ibool		inc_mysql_count);
431
					/*!< in: whether to increment the open
432
					handle count on the table */
433
/**********************************************************************//**
434 435
Returns a index object, based on table and index id, and memoryfixes it.
@return	index, NULL if does not exist */
436
UNIV_INTERN
437 438
dict_index_t*
dict_index_get_on_id_low(
osku's avatar
osku committed
439
/*=====================*/
440
	dict_table_t*	table,		/*!< in: table */
441
	index_id_t	index_id);	/*!< in: index id */
442
/**********************************************************************//**
443 444
Checks if a table is in the dictionary cache.
@return	table, NULL if not found */
445

osku's avatar
osku committed
446 447 448
UNIV_INLINE
dict_table_t*
dict_table_check_if_in_cache_low(
449
/*=============================*/
450
	const char*	table_name);	/*!< in: table name */
451
/**********************************************************************//**
osku's avatar
osku committed
452
Gets a table; loads it to the dictionary cache if necessary. A low-level
453 454
function.
@return	table, NULL if not found */
osku's avatar
osku committed
455 456
UNIV_INLINE
dict_table_t*
457 458 459 460 461 462 463 464 465 466 467 468
dict_table_get_low_ignore_err(
/*===========================*/
	const char*	table_name,	/*!< in: table name */
	dict_err_ignore_t
			ignore_err);	/*!< in: error to be ignored when
					loading a table definition */
/**********************************************************************//**
Gets a table; loads it to the dictionary cache if necessary. A low-level
function.
@return	table, NULL if not found */
UNIV_INLINE
dict_table_t*
osku's avatar
osku committed
469 470
dict_table_get_low(
/*===============*/
471
	const char*	table_name);	/*!< in: table name */
472
/**********************************************************************//**
473 474
Returns a table object based on table id.
@return	table, NULL if does not exist */
475 476 477 478
UNIV_INLINE
dict_table_t*
dict_table_get_on_id_low(
/*=====================*/
479
	table_id_t	table_id);	/*!< in: table id */
480
/**********************************************************************//**
481
Find an index that is equivalent to the one passed in and is not marked
482 483
for deletion.
@return	index equivalent to foreign->foreign_index, or NULL */
484 485 486 487
UNIV_INTERN
dict_index_t*
dict_foreign_find_equiv_index(
/*==========================*/
488
	dict_foreign_t*	foreign);/*!< in: foreign key */
489
/**********************************************************************//**
490
Returns an index object by matching on the name and column names and
491 492
if more than one index matches return the index with the max id
@return	matching index, NULL if not found */
493
UNIV_INTERN
osku's avatar
osku committed
494
dict_index_t*
495
dict_table_get_index_by_max_id(
osku's avatar
osku committed
496
/*===========================*/
497 498 499 500
	dict_table_t*	table,	/*!< in: table */
	const char*	name,	/*!< in: the index name to find */
	const char**	columns,/*!< in: array of column names */
	ulint		n_cols);/*!< in: number of columns */
501
/**********************************************************************//**
502
Returns a column's name.
503 504 505
@return column name. NOTE: not guaranteed to stay valid if table is
modified in any way (columns added, etc.). */
UNIV_INTERN
506 507 508
const char*
dict_table_get_col_name(
/*====================*/
509 510
	const dict_table_t*	table,	/*!< in: table */
	ulint			col_nr);/*!< in: column number */
511

512
/**********************************************************************//**
osku's avatar
osku committed
513
Prints a table definition. */
514
UNIV_INTERN
osku's avatar
osku committed
515 516 517
void
dict_table_print(
/*=============*/
518
	dict_table_t*	table);	/*!< in: table */
519
/**********************************************************************//**
osku's avatar
osku committed
520
Prints a table data. */
521
UNIV_INTERN
osku's avatar
osku committed
522 523 524
void
dict_table_print_low(
/*=================*/
525
	dict_table_t*	table);	/*!< in: table */
526
/**********************************************************************//**
osku's avatar
osku committed
527
Prints a table data when we know the table name. */
528
UNIV_INTERN
osku's avatar
osku committed
529 530 531
void
dict_table_print_by_name(
/*=====================*/
532
	const char*	name);	/*!< in: table name */
533
/**********************************************************************//**
osku's avatar
osku committed
534
Outputs info on foreign keys of a table. */
535
UNIV_INTERN
osku's avatar
osku committed
536 537 538
void
dict_print_info_on_foreign_keys(
/*============================*/
539
	ibool		create_table_format, /*!< in: if TRUE then print in
osku's avatar
osku committed
540 541 542
				a format suitable to be inserted into
				a CREATE TABLE, otherwise in the format
				of SHOW TABLE STATUS */
543 544 545
	FILE*		file,	/*!< in: file where to print */
	trx_t*		trx,	/*!< in: transaction */
	dict_table_t*	table);	/*!< in: table */
546
/**********************************************************************//**
osku's avatar
osku committed
547 548
Outputs info on a foreign key of a table in a format suitable for
CREATE TABLE. */
549
UNIV_INTERN
osku's avatar
osku committed
550 551 552
void
dict_print_info_on_foreign_key_in_create_format(
/*============================================*/
553 554 555 556
	FILE*		file,		/*!< in: file where to print */
	trx_t*		trx,		/*!< in: transaction */
	dict_foreign_t*	foreign,	/*!< in: foreign key constraint */
	ibool		add_newline);	/*!< in: whether to add a newline */
557
/********************************************************************//**
osku's avatar
osku committed
558
Displays the names of the index and the table. */
559
UNIV_INTERN
osku's avatar
osku committed
560 561 562
void
dict_index_name_print(
/*==================*/
563 564 565
	FILE*			file,	/*!< in: output stream */
	trx_t*			trx,	/*!< in: transaction */
	const dict_index_t*	index);	/*!< in: index to print */
566
#ifdef UNIV_DEBUG
567
/********************************************************************//**
568 569
Gets the first index on the table (the clustered index).
@return	index, NULL if none exists */
osku's avatar
osku committed
570 571 572 573
UNIV_INLINE
dict_index_t*
dict_table_get_first_index(
/*=======================*/
574
	const dict_table_t*	table);	/*!< in: table */
575
/********************************************************************//**
576 577
Gets the next index on the table.
@return	index, NULL if none left */
osku's avatar
osku committed
578 579 580 581
UNIV_INLINE
dict_index_t*
dict_table_get_next_index(
/*======================*/
582
	const dict_index_t*	index);	/*!< in: index */
583 584 585 586
#else /* UNIV_DEBUG */
# define dict_table_get_first_index(table) UT_LIST_GET_FIRST((table)->indexes)
# define dict_table_get_next_index(index) UT_LIST_GET_NEXT(indexes, index)
#endif /* UNIV_DEBUG */
587
#endif /* !UNIV_HOTBACKUP */
588 589 590 591 592 593 594 595 596 597 598 599 600 601

/* Skip corrupted index */
#define dict_table_skip_corrupt_index(index)			\
	while (index && dict_index_is_corrupted(index)) {	\
		index = dict_table_get_next_index(index);	\
	}

/* Get the next non-corrupt index */
#define dict_table_next_uncorrupted_index(index)		\
do {								\
	index = dict_table_get_next_index(index);		\
	dict_table_skip_corrupt_index(index);			\
} while (0)

602
/********************************************************************//**
603 604
Check whether the index is the clustered index.
@return	nonzero for clustered index, zero for other indexes */
605 606 607 608
UNIV_INLINE
ulint
dict_index_is_clust(
/*================*/
609
	const dict_index_t*	index)	/*!< in: index */
610
	__attribute__((nonnull, pure, warn_unused_result));
611
/********************************************************************//**
612 613
Check whether the index is unique.
@return	nonzero for unique index, zero for other indexes */
614 615 616 617
UNIV_INLINE
ulint
dict_index_is_unique(
/*=================*/
618
	const dict_index_t*	index)	/*!< in: index */
619
	__attribute__((nonnull, pure, warn_unused_result));
620
/********************************************************************//**
621 622
Check whether the index is the insert buffer tree.
@return	nonzero for insert buffer, zero for other indexes */
623 624 625 626
UNIV_INLINE
ulint
dict_index_is_ibuf(
/*===============*/
627
	const dict_index_t*	index)	/*!< in: index */
628
	__attribute__((nonnull, pure, warn_unused_result));
629
/********************************************************************//**
630 631
Check whether the index is a secondary index or the insert buffer tree.
@return	nonzero for insert buffer, zero for other indexes */
632 633 634 635
UNIV_INLINE
ulint
dict_index_is_sec_or_ibuf(
/*======================*/
636
	const dict_index_t*	index)	/*!< in: index */
637
	__attribute__((nonnull, pure, warn_unused_result));
638

639
/********************************************************************//**
osku's avatar
osku committed
640
Gets the number of user-defined columns in a table in the dictionary
641 642
cache.
@return	number of user-defined (e.g., not ROW_ID) columns of a table */
osku's avatar
osku committed
643 644 645 646
UNIV_INLINE
ulint
dict_table_get_n_user_cols(
/*=======================*/
647 648
	const dict_table_t*	table)	/*!< in: table */
	__attribute__((nonnull, pure, warn_unused_result));
649
/********************************************************************//**
650 651
Gets the number of system columns in a table in the dictionary cache.
@return	number of system (e.g., ROW_ID) columns of a table */
osku's avatar
osku committed
652 653 654 655
UNIV_INLINE
ulint
dict_table_get_n_sys_cols(
/*======================*/
656 657
	const dict_table_t*	table)	/*!< in: table */
	__attribute__((nonnull, pure, warn_unused_result));
658
/********************************************************************//**
osku's avatar
osku committed
659
Gets the number of all columns (also system) in a table in the dictionary
660 661
cache.
@return	number of columns of a table */
osku's avatar
osku committed
662 663 664 665
UNIV_INLINE
ulint
dict_table_get_n_cols(
/*==================*/
666 667
	const dict_table_t*	table)	/*!< in: table */
	__attribute__((nonnull, pure, warn_unused_result));
668
#ifdef UNIV_DEBUG
669
/********************************************************************//**
670 671
Gets the nth column of a table.
@return	pointer to column object */
osku's avatar
osku committed
672
UNIV_INLINE
673
dict_col_t*
osku's avatar
osku committed
674 675
dict_table_get_nth_col(
/*===================*/
676 677
	const dict_table_t*	table,	/*!< in: table */
	ulint			pos);	/*!< in: position of column */
678
/********************************************************************//**
679 680
Gets the given system column of a table.
@return	pointer to column object */
681 682 683 684
UNIV_INLINE
dict_col_t*
dict_table_get_sys_col(
/*===================*/
685 686
	const dict_table_t*	table,	/*!< in: table */
	ulint			sys);	/*!< in: DATA_ROW_ID, ... */
687 688 689 690 691 692
#else /* UNIV_DEBUG */
#define dict_table_get_nth_col(table, pos) \
((table)->cols + (pos))
#define dict_table_get_sys_col(table, sys) \
((table)->cols + (table)->n_cols + (sys) - DATA_N_SYS_COLS)
#endif /* UNIV_DEBUG */
693
/********************************************************************//**
694 695
Gets the given system column number of a table.
@return	column number */
osku's avatar
osku committed
696 697 698 699
UNIV_INLINE
ulint
dict_table_get_sys_col_no(
/*======================*/
700 701
	const dict_table_t*	table,	/*!< in: table */
	ulint			sys);	/*!< in: DATA_ROW_ID, ... */
702
#ifndef UNIV_HOTBACKUP
703
/********************************************************************//**
704 705
Returns the minimum data size of an index record.
@return	minimum data size in bytes */
706 707 708 709
UNIV_INLINE
ulint
dict_index_get_min_size(
/*====================*/
710
	const dict_index_t*	index);	/*!< in: index */
711
#endif /* !UNIV_HOTBACKUP */
712
/********************************************************************//**
713 714
Check whether the table uses the compact page format.
@return	TRUE if table uses the compact page format */
715 716 717 718
UNIV_INLINE
ibool
dict_table_is_comp(
/*===============*/
719
	const dict_table_t*	table);	/*!< in: table */
720
/********************************************************************//**
721 722
Determine the file format of a table.
@return	file format version */
723 724 725 726
UNIV_INLINE
ulint
dict_table_get_format(
/*==================*/
727
	const dict_table_t*	table);	/*!< in: table */
728
/********************************************************************//**
729 730 731 732 733
Set the file format of a table. */
UNIV_INLINE
void
dict_table_set_format(
/*==================*/
734 735
	dict_table_t*	table,	/*!< in/out: table */
	ulint		format);/*!< in: file format version */
736
/********************************************************************//**
737 738
Extract the compressed page size from table flags.
@return	compressed page size, or 0 if not compressed */
739 740 741 742
UNIV_INLINE
ulint
dict_table_flags_to_zip_size(
/*=========================*/
743
	ulint	flags)	/*!< in: flags */
744
	__attribute__((const));
745
/********************************************************************//**
746 747
Check whether the table uses the compressed compact page format.
@return	compressed page size, or 0 if not compressed */
748
UNIV_INLINE
749 750 751
ulint
dict_table_zip_size(
/*================*/
752
	const dict_table_t*	table);	/*!< in: table */
753
#ifndef UNIV_HOTBACKUP
754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769
/*********************************************************************//**
Obtain exclusive locks on all index trees of the table. This is to prevent
accessing index trees while InnoDB is updating internal metadata for
operations such as truncate tables. */
UNIV_INLINE
void
dict_table_x_lock_indexes(
/*======================*/
	dict_table_t*	table);	/*!< in: table */
/*********************************************************************//**
Release the exclusive locks on all index tree. */
UNIV_INLINE
void
dict_table_x_unlock_indexes(
/*========================*/
	dict_table_t*	table);	/*!< in: table */
770
#endif /* !UNIV_HOTBACKUP */
771
/********************************************************************//**
osku's avatar
osku committed
772
Checks if a column is in the ordering columns of the clustered index of a
773 774
table. Column prefixes are treated like whole columns.
@return	TRUE if the column, or its prefix, is in the clustered key */
775
UNIV_INTERN
osku's avatar
osku committed
776 777 778
ibool
dict_table_col_in_clustered_key(
/*============================*/
779 780
	const dict_table_t*	table,	/*!< in: table */
	ulint			n);	/*!< in: column number */
781
#ifndef UNIV_HOTBACKUP
782
/*******************************************************************//**
783 784 785
Copies types of columns contained in table to tuple and sets all
fields of the tuple to the SQL NULL value.  This function should
be called right after dtuple_create(). */
786
UNIV_INTERN
osku's avatar
osku committed
787 788 789
void
dict_table_copy_types(
/*==================*/
790 791
	dtuple_t*		tuple,	/*!< in/out: data tuple */
	const dict_table_t*	table);	/*!< in: table */
792
/**********************************************************************//**
osku's avatar
osku committed
793 794
Looks for an index with the given id. NOTE that we do not reserve
the dictionary mutex: this function is for emergency purposes like
795 796
printing info of a corrupt database page!
@return	index or NULL if not found from cache */
797
UNIV_INTERN
osku's avatar
osku committed
798 799 800
dict_index_t*
dict_index_find_on_id_low(
/*======================*/
801
	index_id_t	id);	/*!< in: index id */
802
/**********************************************************************//**
803
Adds an index to the dictionary cache.
804
@return	DB_SUCCESS, DB_TOO_BIG_RECORD, or DB_CORRUPTION */
805
UNIV_INTERN
806
ulint
osku's avatar
osku committed
807 808
dict_index_add_to_cache(
/*====================*/
809 810
	dict_table_t*	table,	/*!< in: table on which the index is */
	dict_index_t*	index,	/*!< in, own: index; NOTE! The index memory
osku's avatar
osku committed
811
				object is freed in this function! */
812 813
	ulint		page_no,/*!< in: root page number of the index */
	ibool		strict);/*!< in: TRUE=refuse to create the index
814 815
				if records could be too big to fit in
				an B-tree page */
816
/**********************************************************************//**
817
Removes an index from the dictionary cache. */
818
UNIV_INTERN
819 820 821
void
dict_index_remove_from_cache(
/*=========================*/
822 823
	dict_table_t*	table,	/*!< in/out: table */
	dict_index_t*	index);	/*!< in, own: index */
824
#endif /* !UNIV_HOTBACKUP */
825
/********************************************************************//**
osku's avatar
osku committed
826
Gets the number of fields in the internal representation of an index,
827 828
including fields added by the dictionary system.
@return	number of fields */
osku's avatar
osku committed
829 830 831 832
UNIV_INLINE
ulint
dict_index_get_n_fields(
/*====================*/
833
	const dict_index_t*	index);	/*!< in: an internal
834 835
					representation of index (in
					the dictionary cache) */
836
/********************************************************************//**
osku's avatar
osku committed
837 838 839
Gets the number of fields in the internal representation of an index
that uniquely determine the position of an index entry in the index, if
we do not take multiversioning into account: in the B-tree use the value
840 841
returned by dict_index_get_n_unique_in_tree.
@return	number of fields */
osku's avatar
osku committed
842 843 844 845
UNIV_INLINE
ulint
dict_index_get_n_unique(
/*====================*/
846
	const dict_index_t*	index);	/*!< in: an internal representation
847
					of index (in the dictionary cache) */
848
/********************************************************************//**
osku's avatar
osku committed
849 850
Gets the number of fields in the internal representation of an index
which uniquely determine the position of an index entry in the index, if
851 852
we also take multiversioning into account.
@return	number of fields */
osku's avatar
osku committed
853 854 855 856
UNIV_INLINE
ulint
dict_index_get_n_unique_in_tree(
/*============================*/
857
	const dict_index_t*	index);	/*!< in: an internal representation
858
					of index (in the dictionary cache) */
859
/********************************************************************//**
osku's avatar
osku committed
860 861 862
Gets the number of user-defined ordering fields in the index. In the internal
representation we add the row id to the ordering fields to make all indexes
unique, but this function returns the number of fields the user defined
863 864
in the index as ordering fields.
@return	number of fields */
osku's avatar
osku committed
865 866 867 868
UNIV_INLINE
ulint
dict_index_get_n_ordering_defined_by_user(
/*======================================*/
869
	const dict_index_t*	index);	/*!< in: an internal representation
870
					of index (in the dictionary cache) */
871
#ifdef UNIV_DEBUG
872
/********************************************************************//**
873 874
Gets the nth field of an index.
@return	pointer to field object */
osku's avatar
osku committed
875 876 877 878
UNIV_INLINE
dict_field_t*
dict_index_get_nth_field(
/*=====================*/
879 880
	const dict_index_t*	index,	/*!< in: index */
	ulint			pos);	/*!< in: position of field */
881 882 883
#else /* UNIV_DEBUG */
# define dict_index_get_nth_field(index, pos) ((index)->fields + (pos))
#endif /* UNIV_DEBUG */
884
/********************************************************************//**
885 886
Gets pointer to the nth column in an index.
@return	column */
osku's avatar
osku committed
887
UNIV_INLINE
888 889 890
const dict_col_t*
dict_index_get_nth_col(
/*===================*/
891 892
	const dict_index_t*	index,	/*!< in: index */
	ulint			pos);	/*!< in: position of the field */
893
/********************************************************************//**
894 895
Gets the column number of the nth field in an index.
@return	column number */
osku's avatar
osku committed
896 897 898 899
UNIV_INLINE
ulint
dict_index_get_nth_col_no(
/*======================*/
900 901
	const dict_index_t*	index,	/*!< in: index */
	ulint			pos);	/*!< in: position of the field */
902
/********************************************************************//**
903
Looks for column n in an index.
904 905
@return position in internal representation of the index;
ULINT_UNDEFINED if not contained */
906
UNIV_INTERN
osku's avatar
osku committed
907 908 909
ulint
dict_index_get_nth_col_pos(
/*=======================*/
910 911
	const dict_index_t*	index,	/*!< in: index */
	ulint			n);	/*!< in: column number */
912
/********************************************************************//**
913 914
Returns TRUE if the index contains a column or a prefix of that column.
@return	TRUE if contains the column or its prefix */
915
UNIV_INTERN
osku's avatar
osku committed
916 917 918
ibool
dict_index_contains_col_or_prefix(
/*==============================*/
919 920
	const dict_index_t*	index,	/*!< in: index */
	ulint			n);	/*!< in: column number */
921
/********************************************************************//**
osku's avatar
osku committed
922 923 924
Looks for a matching field in an index. The column has to be the same. The
column in index must be complete, or must contain a prefix longer than the
column in index2. That is, we must be able to construct the prefix in index2
925
from the prefix in index.
926 927
@return position in internal representation of the index;
ULINT_UNDEFINED if not contained */
928
UNIV_INTERN
osku's avatar
osku committed
929 930 931
ulint
dict_index_get_nth_field_pos(
/*=========================*/
932 933 934
	const dict_index_t*	index,	/*!< in: index from which to search */
	const dict_index_t*	index2,	/*!< in: index */
	ulint			n);	/*!< in: field number in index2 */
935
/********************************************************************//**
936 937
Looks for column n position in the clustered index.
@return	position in internal representation of the clustered index */
938
UNIV_INTERN
osku's avatar
osku committed
939 940 941
ulint
dict_table_get_nth_col_pos(
/*=======================*/
942 943
	const dict_table_t*	table,	/*!< in: table */
	ulint			n);	/*!< in: column number */
944
/********************************************************************//**
945 946
Returns the position of a system column in an index.
@return	position, ULINT_UNDEFINED if not contained */
osku's avatar
osku committed
947 948 949 950
UNIV_INLINE
ulint
dict_index_get_sys_col_pos(
/*=======================*/
951 952
	const dict_index_t*	index,	/*!< in: index */
	ulint			type);	/*!< in: DATA_ROW_ID, ... */
953
/*******************************************************************//**
osku's avatar
osku committed
954
Adds a column to index. */
955
UNIV_INTERN
osku's avatar
osku committed
956 957 958
void
dict_index_add_col(
/*===============*/
959 960 961 962
	dict_index_t*		index,		/*!< in/out: index */
	const dict_table_t*	table,		/*!< in: table */
	dict_col_t*		col,		/*!< in: column */
	ulint			prefix_len);	/*!< in: column prefix length */
963
#ifndef UNIV_HOTBACKUP
964
/*******************************************************************//**
osku's avatar
osku committed
965
Copies types of fields contained in index to tuple. */
966
UNIV_INTERN
osku's avatar
osku committed
967 968 969
void
dict_index_copy_types(
/*==================*/
970 971 972
	dtuple_t*		tuple,		/*!< in/out: data tuple */
	const dict_index_t*	index,		/*!< in: index */
	ulint			n_fields);	/*!< in: number of
973
						field types to copy */
974
#endif /* !UNIV_HOTBACKUP */
975
/*********************************************************************//**
976 977
Gets the field column.
@return	field->col, pointer to the table column */
osku's avatar
osku committed
978
UNIV_INLINE
979
const dict_col_t*
osku's avatar
osku committed
980 981
dict_field_get_col(
/*===============*/
982
	const dict_field_t*	field);	/*!< in: index field */
983
#ifndef UNIV_HOTBACKUP
984
/**********************************************************************//**
985
Returns an index object if it is found in the dictionary cache.
986 987
Assumes that dict_sys->mutex is already being held.
@return	index, NULL if not found */
988
UNIV_INTERN
989 990 991
dict_index_t*
dict_index_get_if_in_cache_low(
/*===========================*/
992
	index_id_t	index_id);	/*!< in: index id */
993
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
994
/**********************************************************************//**
995 996
Returns an index object if it is found in the dictionary cache.
@return	index, NULL if not found */
997
UNIV_INTERN
osku's avatar
osku committed
998 999 1000
dict_index_t*
dict_index_get_if_in_cache(
/*=======================*/
1001
	index_id_t	index_id);	/*!< in: index id */
1002 1003
#endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
#ifdef UNIV_DEBUG
1004
/**********************************************************************//**
osku's avatar
osku committed
1005
Checks that a tuple has n_fields_cmp value in a sensible range, so that
1006 1007
no comparison can occur with the page number field in a node pointer.
@return	TRUE if ok */
1008
UNIV_INTERN
osku's avatar
osku committed
1009
ibool
1010 1011
dict_index_check_search_tuple(
/*==========================*/
1012 1013
	const dict_index_t*	index,	/*!< in: index tree */
	const dtuple_t*		tuple);	/*!< in: tuple used in a search */
1014
/**********************************************************************//**
1015
Check for duplicate index entries in a table [using the index name] */
1016
UNIV_INTERN
1017 1018 1019
void
dict_table_check_for_dup_indexes(
/*=============================*/
1020
	const dict_table_t*	table,	/*!< in: Check for dup indexes
1021
					in this table */
1022 1023
	ibool			tmp_ok);/*!< in: TRUE=allow temporary
					index names */
1024
#endif /* UNIV_DEBUG */
1025
/**********************************************************************//**
1026 1027
Builds a node pointer out of a physical record and a page number.
@return	own: node pointer */
1028
UNIV_INTERN
osku's avatar
osku committed
1029
dtuple_t*
1030 1031
dict_index_build_node_ptr(
/*======================*/
1032 1033
	const dict_index_t*	index,	/*!< in: index */
	const rec_t*		rec,	/*!< in: record for which to build node
1034
					pointer */
1035
	ulint			page_no,/*!< in: page number to put in node
1036
					pointer */
1037
	mem_heap_t*		heap,	/*!< in: memory heap where pointer
1038
					created */
1039
	ulint			level);	/*!< in: level of rec in tree:
1040
					0 means leaf level */
1041
/**********************************************************************//**
osku's avatar
osku committed
1042
Copies an initial segment of a physical record, long enough to specify an
1043 1044
index entry uniquely.
@return	pointer to the prefix record */
1045
UNIV_INTERN
osku's avatar
osku committed
1046
rec_t*
1047 1048
dict_index_copy_rec_order_prefix(
/*=============================*/
1049 1050
	const dict_index_t*	index,	/*!< in: index */
	const rec_t*		rec,	/*!< in: record for which to
1051
					copy prefix */
1052 1053
	ulint*			n_fields,/*!< out: number of fields copied */
	byte**			buf,	/*!< in/out: memory buffer for the
1054
					copied prefix, or NULL */
1055
	ulint*			buf_size);/*!< in/out: buffer size */
1056
/**********************************************************************//**
1057 1058
Builds a typed data tuple out of a physical record.
@return	own: data tuple */
1059
UNIV_INTERN
osku's avatar
osku committed
1060
dtuple_t*
1061 1062
dict_index_build_data_tuple(
/*========================*/
1063 1064 1065 1066
	dict_index_t*	index,	/*!< in: index */
	rec_t*		rec,	/*!< in: record for which to build data tuple */
	ulint		n_fields,/*!< in: number of data fields */
	mem_heap_t*	heap);	/*!< in: memory heap where tuple created */
1067
/*********************************************************************//**
1068 1069
Gets the space id of the root of the index tree.
@return	space id */
osku's avatar
osku committed
1070 1071
UNIV_INLINE
ulint
1072 1073
dict_index_get_space(
/*=================*/
1074
	const dict_index_t*	index);	/*!< in: index */
1075
/*********************************************************************//**
osku's avatar
osku committed
1076 1077 1078
Sets the space id of the root of the index tree. */
UNIV_INLINE
void
1079 1080
dict_index_set_space(
/*=================*/
1081 1082
	dict_index_t*	index,	/*!< in/out: index */
	ulint		space);	/*!< in: space id */
1083
/*********************************************************************//**
1084 1085
Gets the page number of the root of the index tree.
@return	page number */
osku's avatar
osku committed
1086 1087
UNIV_INLINE
ulint
1088 1089
dict_index_get_page(
/*================*/
1090
	const dict_index_t*	tree);	/*!< in: index */
1091
/*********************************************************************//**
1092 1093
Gets the read-write lock of the index tree.
@return	read-write lock */
osku's avatar
osku committed
1094 1095
UNIV_INLINE
rw_lock_t*
1096 1097
dict_index_get_lock(
/*================*/
1098
	dict_index_t*	index);	/*!< in: index */
1099
/********************************************************************//**
osku's avatar
osku committed
1100 1101
Returns free space reserved for future updates of records. This is
relevant only in the case of many consecutive inserts, as updates
1102 1103
which make the records bigger might fragment the index.
@return	number of free bytes on page, reserved for updates */
osku's avatar
osku committed
1104 1105
UNIV_INLINE
ulint
1106 1107
dict_index_get_space_reserve(void);
/*==============================*/
1108
/*********************************************************************//**
osku's avatar
osku committed
1109
Calculates the minimum record length in an index. */
1110
UNIV_INTERN
osku's avatar
osku committed
1111 1112 1113
ulint
dict_index_calc_min_rec_len(
/*========================*/
1114
	const dict_index_t*	index);	/*!< in: index */
1115
/*********************************************************************//**
osku's avatar
osku committed
1116 1117
Calculates new estimates for table and index statistics. The statistics
are used in query optimization. */
1118
UNIV_INTERN
osku's avatar
osku committed
1119 1120 1121
void
dict_update_statistics(
/*===================*/
1122
	dict_table_t*	table,		/*!< in/out: table */
1123 1124 1125 1126
	ibool		only_calc_if_missing_stats);/*!< in: only
					update/recalc the stats if they have
					not been initialized yet, otherwise
					do nothing */
1127
/********************************************************************//**
osku's avatar
osku committed
1128
Reserves the dictionary system mutex for MySQL. */
1129
UNIV_INTERN
osku's avatar
osku committed
1130 1131 1132
void
dict_mutex_enter_for_mysql(void);
/*============================*/
1133
/********************************************************************//**
osku's avatar
osku committed
1134
Releases the dictionary system mutex for MySQL. */
1135
UNIV_INTERN
osku's avatar
osku committed
1136 1137 1138
void
dict_mutex_exit_for_mysql(void);
/*===========================*/
Vasil Dimov's avatar
Vasil Dimov committed
1139
/**********************************************************************//**
1140 1141 1142
Lock the appropriate latch to protect a given table's statistics.
table->id is used to pick the corresponding latch from a global array of
latches. */
Vasil Dimov's avatar
Vasil Dimov committed
1143 1144
UNIV_INTERN
void
1145 1146 1147 1148 1149
dict_table_stats_lock(
/*==================*/
	const dict_table_t*	table,		/*!< in: table */
	ulint			latch_mode);	/*!< in: RW_S_LATCH or
						RW_X_LATCH */
Vasil Dimov's avatar
Vasil Dimov committed
1150
/**********************************************************************//**
1151
Unlock the latch that has been locked by dict_table_stats_lock() */
Vasil Dimov's avatar
Vasil Dimov committed
1152 1153
UNIV_INTERN
void
1154 1155 1156 1157 1158
dict_table_stats_unlock(
/*====================*/
	const dict_table_t*	table,		/*!< in: table */
	ulint			latch_mode);	/*!< in: RW_S_LATCH or
						RW_X_LATCH */
1159
/********************************************************************//**
1160 1161
Checks if the database name in two table names is the same.
@return	TRUE if same db name */
1162
UNIV_INTERN
osku's avatar
osku committed
1163 1164 1165
ibool
dict_tables_have_same_db(
/*=====================*/
1166
	const char*	name1,	/*!< in: table name in the form
osku's avatar
osku committed
1167
				dbname '/' tablename */
1168
	const char*	name2);	/*!< in: table name in the form
osku's avatar
osku committed
1169
				dbname '/' tablename */
1170
/*********************************************************************//**
1171
Removes an index from the cache */
1172
UNIV_INTERN
1173 1174 1175
void
dict_index_remove_from_cache(
/*=========================*/
1176 1177
	dict_table_t*	table,	/*!< in/out: table */
	dict_index_t*	index);	/*!< in, own: index */
1178
/**********************************************************************//**
1179 1180
Get index by name
@return	index, NULL if does not exist */
1181
UNIV_INTERN
1182 1183 1184
dict_index_t*
dict_table_get_index_on_name(
/*=========================*/
1185 1186
	dict_table_t*	table,	/*!< in: table */
	const char*	name);	/*!< in: name of the index to find */
1187
/**********************************************************************//**
1188
In case there is more than one index with the same name return the index
1189 1190
with the min(id).
@return	index, NULL if does not exist */
1191
UNIV_INTERN
1192 1193 1194
dict_index_t*
dict_table_get_index_on_name_and_min_id(
/*====================================*/
1195 1196
	dict_table_t*	table,	/*!< in: table */
	const char*	name);	/*!< in: name of the index to find */
osku's avatar
osku committed
1197 1198 1199 1200 1201
/* Buffers for storing detailed information about the latest foreign key
and unique key errors */
extern FILE*	dict_foreign_err_file;
extern mutex_t	dict_foreign_err_mutex; /* mutex protecting the buffers */

1202 1203 1204
/** the dictionary system */
extern dict_sys_t*	dict_sys;
/** the data dictionary rw-latch protecting dict_sys */
osku's avatar
osku committed
1205 1206 1207 1208
extern rw_lock_t	dict_operation_lock;

/* Dictionary system struct */
struct dict_sys_struct{
1209
	mutex_t		mutex;		/*!< mutex protecting the data
osku's avatar
osku committed
1210 1211 1212 1213 1214 1215
					dictionary; protects also the
					disk-based dictionary system tables;
					this mutex serializes CREATE TABLE
					and DROP TABLE, as well as reading
					the dictionary data for a table from
					system tables */
1216
	row_id_t	row_id;		/*!< the next row id to assign;
osku's avatar
osku committed
1217 1218 1219 1220 1221
					NOTE that at a checkpoint this
					must be written to the dict system
					header and flushed to a file; in
					recovery this must be derived from
					the log records */
1222
	hash_table_t*	table_hash;	/*!< hash table of the tables, based
osku's avatar
osku committed
1223
					on name */
1224
	hash_table_t*	table_id_hash;	/*!< hash table of the tables, based
osku's avatar
osku committed
1225 1226
					on id */
	UT_LIST_BASE_NODE_T(dict_table_t)
1227 1228
			table_LRU;	/*!< LRU list of tables */
	ulint		size;		/*!< varying space in bytes occupied
osku's avatar
osku committed
1229 1230
					by the data dictionary table and
					index objects */
1231 1232 1233 1234
	dict_table_t*	sys_tables;	/*!< SYS_TABLES table */
	dict_table_t*	sys_columns;	/*!< SYS_COLUMNS table */
	dict_table_t*	sys_indexes;	/*!< SYS_INDEXES table */
	dict_table_t*	sys_fields;	/*!< SYS_FIELDS table */
osku's avatar
osku committed
1235
};
1236 1237
#endif /* !UNIV_HOTBACKUP */

1238
/** dummy index for ROW_FORMAT=REDUNDANT supremum and infimum records */
1239
extern dict_index_t*	dict_ind_redundant;
1240
/** dummy index for ROW_FORMAT=COMPACT supremum and infimum records */
1241 1242
extern dict_index_t*	dict_ind_compact;

1243
/**********************************************************************//**
1244 1245 1246 1247 1248
Inits dict_ind_redundant and dict_ind_compact. */
UNIV_INTERN
void
dict_ind_init(void);
/*===============*/
osku's avatar
osku committed
1249

1250 1251 1252 1253 1254 1255
/**********************************************************************//**
Closes the data dictionary module. */
UNIV_INTERN
void
dict_close(void);
/*============*/
1256
#ifndef UNIV_HOTBACKUP
1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276
/**********************************************************************//**
Check whether the table is corrupted.
@return	nonzero for corrupted table, zero for valid tables */
UNIV_INLINE
ulint
dict_table_is_corrupted(
/*====================*/
	const dict_table_t*	table)	/*!< in: table */
	__attribute__((nonnull, pure, warn_unused_result));

/**********************************************************************//**
Check whether the index is corrupted.
@return	nonzero for corrupted index, zero for valid indexes */
UNIV_INLINE
ulint
dict_index_is_corrupted(
/*====================*/
	const dict_index_t*	index)	/*!< in: index */
	__attribute__((nonnull, pure, warn_unused_result));

1277
#endif /* !UNIV_HOTBACKUP */
1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295
/**********************************************************************//**
Flags an index and table corrupted both in the data dictionary cache
and in the system table SYS_INDEXES. */
UNIV_INTERN
void
dict_set_corrupted(
/*===============*/
	dict_index_t*	index)		/*!< in/out: index */
	UNIV_COLD __attribute__((nonnull));

/**********************************************************************//**
Flags an index corrupted in the data dictionary cache only. This
is used mostly to mark a corrupted index when index's own dictionary
is corrupted, and we force to load such index for repair purpose */
UNIV_INTERN
void
dict_set_corrupted_index_cache_only(
/*================================*/
1296 1297
	dict_index_t*	index,		/*!< in/out: index */
	dict_table_t*	table);		/*!< in/out: table */
1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308

/**********************************************************************//**
Flags a table with specified space_id corrupted in the table dictionary
cache.
@return TRUE if successful */
UNIV_INTERN
ibool
dict_set_corrupted_by_space(
/*========================*/
	ulint		space_id);	/*!< in: space ID */

osku's avatar
osku committed
1309 1310 1311 1312 1313
#ifndef UNIV_NONINL
#include "dict0dict.ic"
#endif

#endif