~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/******************************************************
2
Data dictionary system
3
4
(c) 1996 Innobase Oy
5
6
Created 1/8/1996 Heikki Tuuri
7
*******************************************************/
8
9
#ifndef dict0dict_h
10
#define dict0dict_h
11
12
#include "univ.i"
13
#include "dict0types.h"
14
#include "dict0mem.h"
15
#include "data0type.h"
16
#include "data0data.h"
17
#include "sync0sync.h"
18
#include "sync0rw.h"
19
#include "mem0mem.h"
20
#include "rem0types.h"
21
#include "btr0types.h"
22
#include "ut0mem.h"
23
#include "ut0lst.h"
24
#include "hash0hash.h"
25
#include "ut0rnd.h"
26
#include "ut0byte.h"
27
#include "trx0types.h"
28
29
#ifndef UNIV_HOTBACKUP
30
/**********************************************************************
31
Makes all characters in a NUL-terminated UTF-8 string lower case. */
32
33
void
34
dict_casedn_str(
35
/*============*/
36
	char*	a);	/* in/out: string to put in lower case */
37
#endif /* !UNIV_HOTBACKUP */
38
/************************************************************************
39
Get the database name length in a table name. */
40
41
ulint
42
dict_get_db_name_len(
43
/*=================*/
44
				/* out: database name length */
45
	const char*	name);	/* in: table name in the form
46
				dbname '/' tablename */
47
/************************************************************************
48
Return the end of table name where we have removed dbname and '/'. */
49
50
const char*
51
dict_remove_db_name(
52
/*================*/
53
				/* out: table name */
54
	const char*	name);	/* in: table name in the form
55
				dbname '/' tablename */
56
/************************************************************************
57
Decrements the count of open MySQL handles to a table. */
58
59
void
60
dict_table_decrement_handle_count(
61
/*==============================*/
62
	dict_table_t*	table);	/* in: table */
63
/**************************************************************************
64
Inits the data dictionary module. */
65
66
void
67
dict_init(void);
68
/*===========*/
69
/************************************************************************
70
Gets the space id of every table of the data dictionary and makes a linear
71
list and a hash table of them to the data dictionary cache. This function
72
can be called at database startup if we did not need to do a crash recovery.
73
In crash recovery we must scan the space id's from the .ibd files in MySQL
74
database directories. */
75
76
void
77
dict_load_space_id_list(void);
78
/*=========================*/
79
/*************************************************************************
80
Gets the column data type. */
81
UNIV_INLINE
82
void
83
dict_col_copy_type(
84
/*===============*/
85
	const dict_col_t*	col,	/* in: column */
86
	dtype_t*		type);	/* out: data type */
87
/*************************************************************************
88
Gets the column data type. */
89
90
void
91
dict_col_copy_type_noninline(
92
/*=========================*/
93
	const dict_col_t*	col,	/* in: column */
94
	dtype_t*		type);	/* out: data type */
95
#ifdef UNIV_DEBUG
96
/*************************************************************************
97
Assert that a column and a data type match. */
98
UNIV_INLINE
99
ibool
100
dict_col_type_assert_equal(
101
/*=======================*/
102
					/* out: TRUE */
103
	const dict_col_t*	col,	/* in: column */
104
	const dtype_t*		type);	/* in: data type */
105
#endif /* UNIV_DEBUG */
106
/***************************************************************************
107
Returns the minimum size of the column. */
108
UNIV_INLINE
109
ulint
110
dict_col_get_min_size(
111
/*==================*/
112
					/* out: minimum size */
113
	const dict_col_t*	col);	/* in: column */
114
/***************************************************************************
115
Returns the maximum size of the column. */
116
UNIV_INLINE
117
ulint
118
dict_col_get_max_size(
119
/*==================*/
120
					/* out: maximum size */
121
	const dict_col_t*	col);	/* in: column */
122
/***************************************************************************
123
Returns the size of a fixed size column, 0 if not a fixed size column. */
124
UNIV_INLINE
125
ulint
126
dict_col_get_fixed_size(
127
/*====================*/
128
					/* out: fixed size, or 0 */
129
	const dict_col_t*	col);	/* in: column */
130
/***************************************************************************
131
Returns the ROW_FORMAT=REDUNDANT stored SQL NULL size of a column.
132
For fixed length types it is the fixed length of the type, otherwise 0. */
133
UNIV_INLINE
134
ulint
135
dict_col_get_sql_null_size(
136
/*=======================*/
137
					/* out: SQL null storage size
138
					in ROW_FORMAT=REDUNDANT */
139
	const dict_col_t*	col);	/* in: column */
140
141
/*************************************************************************
142
Gets the column number. */
143
UNIV_INLINE
144
ulint
145
dict_col_get_no(
146
/*============*/
147
	const dict_col_t*	col);
148
/*************************************************************************
149
Gets the column position in the clustered index. */
150
UNIV_INLINE
151
ulint
152
dict_col_get_clust_pos(
153
/*===================*/
154
	const dict_col_t*	col,		/* in: table column */
155
	const dict_index_t*	clust_index);	/* in: clustered index */
156
/*************************************************************************
157
Gets the column position in the clustered index. */
158
159
ulint
160
dict_col_get_clust_pos_noninline(
161
/*=============================*/
162
	const dict_col_t*	col,		/* in: table column */
163
	const dict_index_t*	clust_index);	/* in: clustered index */
164
/********************************************************************
165
If the given column name is reserved for InnoDB system columns, return
166
TRUE. */
167
168
ibool
169
dict_col_name_is_reserved(
170
/*======================*/
171
				/* out: TRUE if name is reserved */
172
	const char*	name);	/* in: column name */
173
/************************************************************************
174
Acquire the autoinc lock.*/
175
176
void
177
dict_table_autoinc_lock(
178
/*====================*/
179
	dict_table_t*	table);	/* in: table */
180
/************************************************************************
181
Initializes the autoinc counter. It is not an error to initialize an already
182
initialized counter. */
183
184
void
185
dict_table_autoinc_initialize(
186
/*==========================*/
187
	dict_table_t*	table,	/* in: table */
188
	ib_longlong	value);	/* in: next value to assign to a row */
189
/************************************************************************
190
Reads the next autoinc value (== autoinc counter value), 0 if not yet
191
initialized. */
192
193
ib_longlong
194
dict_table_autoinc_read(
195
/*====================*/
196
				/* out: value for a new row, or 0 */
197
	dict_table_t*	table);	/* in: table */
198
/************************************************************************
199
Updates the autoinc counter if the value supplied is equal or bigger than the
200
current value. If not inited, does nothing. */
201
202
void
203
dict_table_autoinc_update(
204
/*======================*/
205
206
	dict_table_t*	table,	/* in: table */
207
	ib_longlong	value);	/* in: value which was assigned to a row */
208
/************************************************************************
209
Release the autoinc lock.*/
210
211
void
212
dict_table_autoinc_unlock(
213
/*======================*/
214
	dict_table_t*	table);	/* in: table */
215
/**************************************************************************
216
Adds system columns to a table object. */
217
218
void
219
dict_table_add_system_columns(
220
/*==========================*/
221
	dict_table_t*	table,	/* in/out: table */
222
	mem_heap_t*	heap);	/* in: temporary heap */
223
/**************************************************************************
224
Adds a table object to the dictionary cache. */
225
226
void
227
dict_table_add_to_cache(
228
/*====================*/
229
	dict_table_t*	table,	/* in: table */
230
	mem_heap_t*	heap);	/* in: temporary heap */
231
/**************************************************************************
232
Removes a table object from the dictionary cache. */
233
234
void
235
dict_table_remove_from_cache(
236
/*=========================*/
237
	dict_table_t*	table);	/* in, own: table */
238
/**************************************************************************
239
Renames a table object. */
240
241
ibool
242
dict_table_rename_in_cache(
243
/*=======================*/
244
					/* out: TRUE if success */
245
	dict_table_t*	table,		/* in: table */
246
	const char*	new_name,	/* in: new name */
247
	ibool		rename_also_foreigns);/* in: in ALTER TABLE we want
248
					to preserve the original table name
249
					in constraints which reference it */
250
/**************************************************************************
251
Change the id of a table object in the dictionary cache. This is used in
252
DISCARD TABLESPACE. */
253
254
void
255
dict_table_change_id_in_cache(
256
/*==========================*/
257
	dict_table_t*	table,	/* in: table object already in cache */
258
	dulint		new_id);/* in: new id to set */
259
/**************************************************************************
260
Adds a foreign key constraint object to the dictionary cache. May free
261
the object if there already is an object with the same identifier in.
262
At least one of foreign table or referenced table must already be in
263
the dictionary cache! */
264
265
ulint
266
dict_foreign_add_to_cache(
267
/*======================*/
268
					/* out: DB_SUCCESS or error code */
269
	dict_foreign_t*	foreign,	/* in, own: foreign key constraint */
270
	ibool		check_charsets);/* in: TRUE=check charset
271
					compatibility */
272
/*************************************************************************
273
Checks if a table is referenced by foreign keys. */
274
275
ibool
276
dict_table_referenced_by_foreign_key(
277
/*=================================*/
278
				/* out: TRUE if table is referenced by a
279
				foreign key */
280
	dict_table_t*	table);	/* in: InnoDB table */
281
/**************************************************************************
282
Determines whether a string starts with the specified keyword. */
283
284
ibool
285
dict_str_starts_with_keyword(
286
/*=========================*/
287
					/* out: TRUE if str starts
288
					with keyword */
289
	void*		mysql_thd,	/* in: MySQL thread handle */
290
	const char*	str,		/* in: string to scan for keyword */
291
	const char*	keyword);	/* in: keyword to look for */
292
/*************************************************************************
293
Scans a table create SQL string and adds to the data dictionary
294
the foreign key constraints declared in the string. This function
295
should be called after the indexes for a table have been created.
296
Each foreign key constraint must be accompanied with indexes in
297
bot participating tables. The indexes are allowed to contain more
298
fields than mentioned in the constraint. */
299
300
ulint
301
dict_create_foreign_constraints(
302
/*============================*/
303
					/* out: error code or DB_SUCCESS */
304
	trx_t*		trx,		/* in: transaction */
305
	const char*	sql_string,	/* in: table create statement where
306
					foreign keys are declared like:
307
					FOREIGN KEY (a, b) REFERENCES
308
					table2(c, d), table2 can be written
309
					also with the database
310
					name before it: test.table2; the
311
					default database id the database of
312
					parameter name */
313
	const char*	name,		/* in: table full name in the
314
					normalized form
315
					database_name/table_name */
316
	ibool		reject_fks);	/* in: if TRUE, fail with error
317
					code DB_CANNOT_ADD_CONSTRAINT if
318
					any foreign keys are found. */
319
/**************************************************************************
320
Parses the CONSTRAINT id's to be dropped in an ALTER TABLE statement. */
321
322
ulint
323
dict_foreign_parse_drop_constraints(
324
/*================================*/
325
						/* out: DB_SUCCESS or
326
						DB_CANNOT_DROP_CONSTRAINT if
327
						syntax error or the constraint
328
						id does not match */
329
	mem_heap_t*	heap,			/* in: heap from which we can
330
						allocate memory */
331
	trx_t*		trx,			/* in: transaction */
332
	dict_table_t*	table,			/* in: table */
333
	ulint*		n,			/* out: number of constraints
334
						to drop */
335
	const char***	constraints_to_drop);	/* out: id's of the
336
						constraints to drop */
337
/**************************************************************************
338
Returns a table object and optionally increment its MySQL open handle count.
339
NOTE! This is a high-level function to be used mainly from outside the
340
'dict' directory. Inside this directory dict_table_get_low is usually the
341
appropriate function. */
342
343
dict_table_t*
344
dict_table_get(
345
/*===========*/
346
					/* out: table, NULL if
347
					does not exist */
348
	const char*	table_name,	/* in: table name */
349
	ibool		inc_mysql_count);
350
					/* in: whether to increment the open
351
					handle count on the table */
352
/**************************************************************************
353
Returns a table object based on table id. */
354
355
dict_table_t*
356
dict_table_get_on_id(
357
/*=================*/
358
				/* out: table, NULL if does not exist */
359
	dulint	table_id,	/* in: table id */
360
	trx_t*	trx);		/* in: transaction handle */
361
/**************************************************************************
362
Returns a table object based on table id. */
363
UNIV_INLINE
364
dict_table_t*
365
dict_table_get_on_id_low(
366
/*=====================*/
367
				/* out: table, NULL if does not exist */
368
	dulint	table_id);	/* in: table id */
369
/**************************************************************************
370
Checks if a table is in the dictionary cache. */
371
UNIV_INLINE
372
dict_table_t*
373
dict_table_check_if_in_cache_low(
374
/*=============================*/
375
					/* out: table, NULL if not found */
376
	const char*	table_name);	/* in: table name */
377
/**************************************************************************
378
Gets a table; loads it to the dictionary cache if necessary. A low-level
379
function. */
380
UNIV_INLINE
381
dict_table_t*
382
dict_table_get_low(
383
/*===============*/
384
					/* out: table, NULL if not found */
385
	const char*	table_name);	/* in: table name */
386
/**************************************************************************
387
A noninlined version of dict_table_get_low. */
388
389
dict_table_t*
390
dict_table_get_low_noninlined(
391
/*==========================*/
392
					/* out: table, NULL if not found */
393
	const char*	table_name);	/* in: table name */
394
/**************************************************************************
395
Returns an index object. */
396
UNIV_INLINE
397
dict_index_t*
398
dict_table_get_index(
399
/*=================*/
400
				/* out: index, NULL if does not exist */
401
	dict_table_t*	table,	/* in: table */
402
	const char*	name);	/* in: index name */
403
/**************************************************************************
404
Returns an index object. */
405
406
dict_index_t*
407
dict_table_get_index_noninline(
408
/*===========================*/
409
				/* out: index, NULL if does not exist */
410
	dict_table_t*	table,	/* in: table */
411
	const char*	name);	/* in: index name */
412
/**************************************************************************
413
Returns a column's name. */
414
415
const char*
416
dict_table_get_col_name(
417
/*====================*/
418
					/* out: column name. NOTE: not
419
					guaranteed to stay valid if table is
420
					modified in any way (columns added,
421
					etc.). */
422
	const dict_table_t*	table,	/* in: table */
423
	ulint			col_nr);/* in: column number */
424
425
/**************************************************************************
426
Prints a table definition. */
427
428
void
429
dict_table_print(
430
/*=============*/
431
	dict_table_t*	table);	/* in: table */
432
/**************************************************************************
433
Prints a table data. */
434
435
void
436
dict_table_print_low(
437
/*=================*/
438
	dict_table_t*	table);	/* in: table */
439
/**************************************************************************
440
Prints a table data when we know the table name. */
441
442
void
443
dict_table_print_by_name(
444
/*=====================*/
445
	const char*	name);
446
/**************************************************************************
447
Outputs info on foreign keys of a table. */
448
449
void
450
dict_print_info_on_foreign_keys(
451
/*============================*/
452
	ibool		create_table_format, /* in: if TRUE then print in
453
				a format suitable to be inserted into
454
				a CREATE TABLE, otherwise in the format
455
				of SHOW TABLE STATUS */
456
	FILE*		file,	/* in: file where to print */
457
	trx_t*		trx,	/* in: transaction */
458
	dict_table_t*	table);	/* in: table */
459
/**************************************************************************
460
Outputs info on a foreign key of a table in a format suitable for
461
CREATE TABLE. */
462
void
463
dict_print_info_on_foreign_key_in_create_format(
464
/*============================================*/
465
	FILE*		file,		/* in: file where to print */
466
	trx_t*		trx,		/* in: transaction */
467
	dict_foreign_t*	foreign,	/* in: foreign key constraint */
468
	ibool		add_newline);	/* in: whether to add a newline */
469
/************************************************************************
470
Displays the names of the index and the table. */
471
void
472
dict_index_name_print(
473
/*==================*/
474
	FILE*			file,	/* in: output stream */
475
	trx_t*			trx,	/* in: transaction */
476
	const dict_index_t*	index);	/* in: index to print */
477
/************************************************************************
478
Gets the first index on the table (the clustered index). */
479
UNIV_INLINE
480
dict_index_t*
481
dict_table_get_first_index(
482
/*=======================*/
483
				/* out: index, NULL if none exists */
484
	dict_table_t*	table);	/* in: table */
485
/************************************************************************
486
Gets the first index on the table (the clustered index). */
487
488
dict_index_t*
489
dict_table_get_first_index_noninline(
490
/*=================================*/
491
				/* out: index, NULL if none exists */
492
	dict_table_t*	table);	/* in: table */
493
/************************************************************************
494
Gets the next index on the table. */
495
UNIV_INLINE
496
dict_index_t*
497
dict_table_get_next_index(
498
/*======================*/
499
				/* out: index, NULL if none left */
500
	dict_index_t*	index);	/* in: index */
501
/************************************************************************
502
Gets the next index on the table. */
503
504
dict_index_t*
505
dict_table_get_next_index_noninline(
506
/*================================*/
507
				/* out: index, NULL if none left */
508
	dict_index_t*	index);	/* in: index */
509
/************************************************************************
510
Gets the number of user-defined columns in a table in the dictionary
511
cache. */
512
UNIV_INLINE
513
ulint
514
dict_table_get_n_user_cols(
515
/*=======================*/
516
				/* out: number of user-defined (e.g., not
517
				ROW_ID) columns of a table */
518
	dict_table_t*	table);	/* in: table */
519
/************************************************************************
520
Gets the number of system columns in a table in the dictionary cache. */
521
UNIV_INLINE
522
ulint
523
dict_table_get_n_sys_cols(
524
/*======================*/
525
				/* out: number of system (e.g.,
526
				ROW_ID) columns of a table */
527
	dict_table_t*	table);	/* in: table */
528
/************************************************************************
529
Gets the number of all columns (also system) in a table in the dictionary
530
cache. */
531
UNIV_INLINE
532
ulint
533
dict_table_get_n_cols(
534
/*==================*/
535
				/* out: number of columns of a table */
536
	dict_table_t*	table);	/* in: table */
537
/************************************************************************
538
Gets the nth column of a table. */
539
UNIV_INLINE
540
const dict_col_t*
541
dict_table_get_nth_col(
542
/*===================*/
543
					/* out: pointer to column object */
544
	const dict_table_t*	table,	/* in: table */
545
	ulint			pos);	/* in: position of column */
546
/************************************************************************
547
Gets the nth column of a table. */
548
549
const dict_col_t*
550
dict_table_get_nth_col_noninline(
551
/*=============================*/
552
					/* out: pointer to column object */
553
	const dict_table_t*	table,	/* in: table */
554
	ulint			pos);	/* in: position of column */
555
/************************************************************************
556
Gets the given system column of a table. */
557
UNIV_INLINE
558
const dict_col_t*
559
dict_table_get_sys_col(
560
/*===================*/
561
					/* out: pointer to column object */
562
	const dict_table_t*	table,	/* in: table */
563
	ulint			sys);	/* in: DATA_ROW_ID, ... */
564
/************************************************************************
565
Gets the given system column number of a table. */
566
UNIV_INLINE
567
ulint
568
dict_table_get_sys_col_no(
569
/*======================*/
570
				/* out: column number */
571
	dict_table_t*	table,	/* in: table */
572
	ulint		sys);	/* in: DATA_ROW_ID, ... */
573
/************************************************************************
574
Check whether the table uses the compact page format. */
575
UNIV_INLINE
576
ibool
577
dict_table_is_comp(
578
/*===============*/
579
					/* out: TRUE if table uses the
580
					compact page format */
581
	const dict_table_t*	table);	/* in: table */
582
/************************************************************************
583
Check whether the table uses the compact page format. */
584
585
ibool
586
dict_table_is_comp_noninline(
587
/*=========================*/
588
					/* out: TRUE if table uses the
589
					compact page format */
590
	const dict_table_t*	table);	/* in: table */
591
/************************************************************************
592
Checks if a column is in the ordering columns of the clustered index of a
593
table. Column prefixes are treated like whole columns. */
594
595
ibool
596
dict_table_col_in_clustered_key(
597
/*============================*/
598
				/* out: TRUE if the column, or its prefix, is
599
				in the clustered key */
600
	dict_table_t*	table,	/* in: table */
601
	ulint		n);	/* in: column number */
602
/***********************************************************************
603
Copies types of columns contained in table to tuple. */
604
605
void
606
dict_table_copy_types(
607
/*==================*/
608
	dtuple_t*	tuple,	/* in: data tuple */
609
	dict_table_t*	table);	/* in: index */
610
/**************************************************************************
611
Looks for an index with the given id. NOTE that we do not reserve
612
the dictionary mutex: this function is for emergency purposes like
613
printing info of a corrupt database page! */
614
615
dict_index_t*
616
dict_index_find_on_id_low(
617
/*======================*/
618
			/* out: index or NULL if not found from cache */
619
	dulint	id);	/* in: index id */
620
/**************************************************************************
621
Adds an index to the dictionary cache. */
622
623
void
624
dict_index_add_to_cache(
625
/*====================*/
626
	dict_table_t*	table,	/* in: table on which the index is */
627
	dict_index_t*	index,	/* in, own: index; NOTE! The index memory
628
				object is freed in this function! */
629
	ulint		page_no);/* in: root page number of the index */
630
/************************************************************************
631
Gets the number of fields in the internal representation of an index,
632
including fields added by the dictionary system. */
633
UNIV_INLINE
634
ulint
635
dict_index_get_n_fields(
636
/*====================*/
637
				/* out: number of fields */
638
	dict_index_t*	index);	/* in: an internal representation of index
639
				(in the dictionary cache) */
640
/************************************************************************
641
Gets the number of fields in the internal representation of an index
642
that uniquely determine the position of an index entry in the index, if
643
we do not take multiversioning into account: in the B-tree use the value
644
returned by dict_index_get_n_unique_in_tree. */
645
UNIV_INLINE
646
ulint
647
dict_index_get_n_unique(
648
/*====================*/
649
				/* out: number of fields */
650
	dict_index_t*	index);	/* in: an internal representation of index
651
				(in the dictionary cache) */
652
/************************************************************************
653
Gets the number of fields in the internal representation of an index
654
which uniquely determine the position of an index entry in the index, if
655
we also take multiversioning into account. */
656
UNIV_INLINE
657
ulint
658
dict_index_get_n_unique_in_tree(
659
/*============================*/
660
				/* out: number of fields */
661
	dict_index_t*	index);	/* in: an internal representation of index
662
				(in the dictionary cache) */
663
/************************************************************************
664
Gets the number of user-defined ordering fields in the index. In the internal
665
representation we add the row id to the ordering fields to make all indexes
666
unique, but this function returns the number of fields the user defined
667
in the index as ordering fields. */
668
UNIV_INLINE
669
ulint
670
dict_index_get_n_ordering_defined_by_user(
671
/*======================================*/
672
				/* out: number of fields */
673
	dict_index_t*	index);	/* in: an internal representation of index
674
				(in the dictionary cache) */
675
/************************************************************************
676
Gets the nth field of an index. */
677
UNIV_INLINE
678
dict_field_t*
679
dict_index_get_nth_field(
680
/*=====================*/
681
				/* out: pointer to field object */
682
	dict_index_t*	index,	/* in: index */
683
	ulint		pos);	/* in: position of field */
684
/************************************************************************
685
Gets pointer to the nth column in an index. */
686
UNIV_INLINE
687
const dict_col_t*
688
dict_index_get_nth_col(
689
/*===================*/
690
					/* out: column */
691
	const dict_index_t*	index,	/* in: index */
692
	ulint			pos);	/* in: position of the field */
693
/************************************************************************
694
Gets the column number of the nth field in an index. */
695
UNIV_INLINE
696
ulint
697
dict_index_get_nth_col_no(
698
/*======================*/
699
					/* out: column number */
700
	const dict_index_t*	index,	/* in: index */
701
	ulint			pos);	/* in: position of the field */
702
/************************************************************************
703
Looks for column n in an index. */
704
705
ulint
706
dict_index_get_nth_col_pos(
707
/*=======================*/
708
				/* out: position in internal representation
709
				of the index; if not contained, returns
710
				ULINT_UNDEFINED */
711
	dict_index_t*	index,	/* in: index */
712
	ulint		n);	/* in: column number */
713
/************************************************************************
714
Returns TRUE if the index contains a column or a prefix of that column. */
715
716
ibool
717
dict_index_contains_col_or_prefix(
718
/*==============================*/
719
				/* out: TRUE if contains the column or its
720
				prefix */
721
	dict_index_t*	index,	/* in: index */
722
	ulint		n);	/* in: column number */
723
/************************************************************************
724
Looks for a matching field in an index. The column has to be the same. The
725
column in index must be complete, or must contain a prefix longer than the
726
column in index2. That is, we must be able to construct the prefix in index2
727
from the prefix in index. */
728
729
ulint
730
dict_index_get_nth_field_pos(
731
/*=========================*/
732
				/* out: position in internal representation
733
				of the index; if not contained, returns
734
				ULINT_UNDEFINED */
735
	dict_index_t*	index,	/* in: index from which to search */
736
	dict_index_t*	index2,	/* in: index */
737
	ulint		n);	/* in: field number in index2 */
738
/************************************************************************
739
Looks for column n position in the clustered index. */
740
741
ulint
742
dict_table_get_nth_col_pos(
743
/*=======================*/
744
				/* out: position in internal representation
745
				of the clustered index */
746
	dict_table_t*	table,	/* in: table */
747
	ulint		n);	/* in: column number */
748
/************************************************************************
749
Returns the position of a system column in an index. */
750
UNIV_INLINE
751
ulint
752
dict_index_get_sys_col_pos(
753
/*=======================*/
754
				/* out: position, ULINT_UNDEFINED if not
755
				contained */
756
	dict_index_t*	index,	/* in: index */
757
	ulint		type);	/* in: DATA_ROW_ID, ... */
758
/***********************************************************************
759
Adds a column to index. */
760
761
void
762
dict_index_add_col(
763
/*===============*/
764
	dict_index_t*	index,		/* in: index */
765
	dict_table_t*	table,		/* in: table */
766
	dict_col_t*	col,		/* in: column */
767
	ulint		prefix_len);	/* in: column prefix length */
768
/***********************************************************************
769
Copies types of fields contained in index to tuple. */
770
771
void
772
dict_index_copy_types(
773
/*==================*/
774
	dtuple_t*	tuple,		/* in: data tuple */
775
	dict_index_t*	index,		/* in: index */
776
	ulint		n_fields);	/* in: number of field types to copy */
777
/*************************************************************************
778
Gets the field column. */
779
UNIV_INLINE
780
const dict_col_t*
781
dict_field_get_col(
782
/*===============*/
783
	const dict_field_t*	field);
784
785
#ifdef UNIV_DEBUG
786
/**************************************************************************
787
Returns an index object if it is found in the dictionary cache. */
788
789
dict_index_t*
790
dict_index_get_if_in_cache(
791
/*=======================*/
792
				/* out: index, NULL if not found */
793
	dulint	index_id);	/* in: index id */
794
/**************************************************************************
795
Checks that a tuple has n_fields_cmp value in a sensible range, so that
796
no comparison can occur with the page number field in a node pointer. */
797
798
ibool
799
dict_index_check_search_tuple(
800
/*==========================*/
801
				/* out: TRUE if ok */
802
	dict_index_t*	index,	/* in: index */
803
	dtuple_t*	tuple);	/* in: tuple used in a search */
804
#endif /* UNIV_DEBUG */
805
/**************************************************************************
806
Builds a node pointer out of a physical record and a page number. */
807
808
dtuple_t*
809
dict_index_build_node_ptr(
810
/*======================*/
811
				/* out, own: node pointer */
812
	dict_index_t*	index,	/* in: index */
813
	rec_t*		rec,	/* in: record for which to build node
814
				pointer */
815
	ulint		page_no,/* in: page number to put in node pointer */
816
	mem_heap_t*	heap,	/* in: memory heap where pointer created */
817
	ulint		level);	 /* in: level of rec in tree: 0 means leaf
818
				level */
819
/**************************************************************************
820
Copies an initial segment of a physical record, long enough to specify an
821
index entry uniquely. */
822
823
rec_t*
824
dict_index_copy_rec_order_prefix(
825
/*=============================*/
826
				/* out: pointer to the prefix record */
827
	dict_index_t*	index,	/* in: index */
828
	rec_t*		rec,	/* in: record for which to copy prefix */
829
	ulint*		n_fields,/* out: number of fields copied */
830
	byte**		buf,	/* in/out: memory buffer for the copied prefix,
831
				or NULL */
832
	ulint*		buf_size);/* in/out: buffer size */
833
/**************************************************************************
834
Builds a typed data tuple out of a physical record. */
835
836
dtuple_t*
837
dict_index_build_data_tuple(
838
/*========================*/
839
				/* out, own: data tuple */
840
	dict_index_t*	index,	/* in: index */
841
	rec_t*		rec,	/* in: record for which to build data tuple */
842
	ulint		n_fields,/* in: number of data fields */
843
	mem_heap_t*	heap);	/* in: memory heap where tuple created */
844
/*************************************************************************
845
Gets the space id of the root of the index tree. */
846
UNIV_INLINE
847
ulint
848
dict_index_get_space(
849
/*=================*/
850
				/* out: space id */
851
	dict_index_t*	index);	/* in: index */
852
/*************************************************************************
853
Sets the space id of the root of the index tree. */
854
UNIV_INLINE
855
void
856
dict_index_set_space(
857
/*=================*/
858
	dict_index_t*	index,	/* in: index */
859
	ulint		space);	/* in: space id */
860
/*************************************************************************
861
Gets the page number of the root of the index tree. */
862
UNIV_INLINE
863
ulint
864
dict_index_get_page(
865
/*================*/
866
				/* out: page number */
867
	dict_index_t*	tree);	/* in: index */
868
/*************************************************************************
869
Sets the page number of the root of index tree. */
870
UNIV_INLINE
871
void
872
dict_index_set_page(
873
/*================*/
874
	dict_index_t*	index,	/* in: index */
875
	ulint		page);	/* in: page number */
876
/*************************************************************************
877
Gets the type of the index tree. */
878
UNIV_INLINE
879
ulint
880
dict_index_get_type(
881
/*================*/
882
				/* out: type */
883
	dict_index_t*	index);	/* in: index */
884
/*************************************************************************
885
Gets the read-write lock of the index tree. */
886
UNIV_INLINE
887
rw_lock_t*
888
dict_index_get_lock(
889
/*================*/
890
				/* out: read-write lock */
891
	dict_index_t*	index);	/* in: index */
892
/************************************************************************
893
Returns free space reserved for future updates of records. This is
894
relevant only in the case of many consecutive inserts, as updates
895
which make the records bigger might fragment the index. */
896
UNIV_INLINE
897
ulint
898
dict_index_get_space_reserve(void);
899
/*==============================*/
900
				/* out: number of free bytes on page,
901
				reserved for updates */
902
/*************************************************************************
903
Calculates the minimum record length in an index. */
904
905
ulint
906
dict_index_calc_min_rec_len(
907
/*========================*/
908
	dict_index_t*	index);	/* in: index */
909
/*************************************************************************
910
Calculates new estimates for table and index statistics. The statistics
911
are used in query optimization. */
912
913
void
914
dict_update_statistics_low(
915
/*=======================*/
916
	dict_table_t*	table,		/* in: table */
917
	ibool		has_dict_mutex);/* in: TRUE if the caller has the
918
					dictionary mutex */
919
/*************************************************************************
920
Calculates new estimates for table and index statistics. The statistics
921
are used in query optimization. */
922
923
void
924
dict_update_statistics(
925
/*===================*/
926
	dict_table_t*	table);	/* in: table */
927
/************************************************************************
928
Reserves the dictionary system mutex for MySQL. */
929
930
void
931
dict_mutex_enter_for_mysql(void);
932
/*============================*/
933
/************************************************************************
934
Releases the dictionary system mutex for MySQL. */
935
936
void
937
dict_mutex_exit_for_mysql(void);
938
/*===========================*/
939
/************************************************************************
940
Checks if the database name in two table names is the same. */
941
942
ibool
943
dict_tables_have_same_db(
944
/*=====================*/
945
				/* out: TRUE if same db name */
946
	const char*	name1,	/* in: table name in the form
947
				dbname '/' tablename */
948
	const char*	name2);	/* in: table name in the form
949
				dbname '/' tablename */
950
/*************************************************************************
951
Scans from pointer onwards. Stops if is at the start of a copy of
952
'string' where characters are compared without case sensitivity. Stops
953
also at '\0'. */
954
955
const char*
956
dict_scan_to(
957
/*=========*/
958
				/* out: scanned up to this */
959
	const char*	ptr,	/* in: scan from */
960
	const char*	string);/* in: look for this */
961
/* Buffers for storing detailed information about the latest foreign key
962
and unique key errors */
963
extern FILE*	dict_foreign_err_file;
964
extern mutex_t	dict_foreign_err_mutex; /* mutex protecting the buffers */
965
966
extern dict_sys_t*	dict_sys;	/* the dictionary system */
967
extern rw_lock_t	dict_operation_lock;
968
969
/* Dictionary system struct */
970
struct dict_sys_struct{
971
	mutex_t		mutex;		/* mutex protecting the data
972
					dictionary; protects also the
973
					disk-based dictionary system tables;
974
					this mutex serializes CREATE TABLE
975
					and DROP TABLE, as well as reading
976
					the dictionary data for a table from
977
					system tables */
978
	dulint		row_id;		/* the next row id to assign;
979
					NOTE that at a checkpoint this
980
					must be written to the dict system
981
					header and flushed to a file; in
982
					recovery this must be derived from
983
					the log records */
984
	hash_table_t*	table_hash;	/* hash table of the tables, based
985
					on name */
986
	hash_table_t*	table_id_hash;	/* hash table of the tables, based
987
					on id */
988
	UT_LIST_BASE_NODE_T(dict_table_t)
989
			table_LRU;	/* LRU list of tables */
990
	ulint		size;		/* varying space in bytes occupied
991
					by the data dictionary table and
992
					index objects */
993
	dict_table_t*	sys_tables;	/* SYS_TABLES table */
994
	dict_table_t*	sys_columns;	/* SYS_COLUMNS table */
995
	dict_table_t*	sys_indexes;	/* SYS_INDEXES table */
996
	dict_table_t*	sys_fields;	/* SYS_FIELDS table */
997
};
998
999
#ifndef UNIV_NONINL
1000
#include "dict0dict.ic"
1001
#endif
1002
1003
#endif