~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/include/dict0dict.h

  • Committer: Monty Taylor
  • Date: 2010-12-24 02:13:05 UTC
  • mto: This revision was merged to the branch mainline in revision 2038.
  • Revision ID: mordred@inaugust.com-20101224021305-e3slv1cyjczqorij
Changed the bzrignore file.

Show diffs side-by-side

added added

removed removed

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