~jaypipes/drizzle/new-test-runner

« back to all changes in this revision

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

  • Committer: Jay Pipes
  • Date: 2008-12-11 17:52:34 UTC
  • mfrom: (482.16.152 testable)
  • Revision ID: jpipes@serialcoder-20081211175234-uqsfvmgxejvmellq
merge with trunk

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