~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

Tags: innodb-plugin-1.0.1
Imported 1.0.1 with clean - with no changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************
 
2
Data dictionary memory object creation
 
3
 
 
4
(c) 1996 Innobase Oy
 
5
 
 
6
Created 1/8/1996 Heikki Tuuri
 
7
*******************************************************/
 
8
 
 
9
#ifndef dict0mem_h
 
10
#define dict0mem_h
 
11
 
 
12
#include "univ.i"
 
13
#include "dict0types.h"
 
14
#include "data0type.h"
 
15
#include "data0data.h"
 
16
#include "mem0mem.h"
 
17
#include "rem0types.h"
 
18
#include "btr0types.h"
 
19
#include "ut0mem.h"
 
20
#include "ut0lst.h"
 
21
#include "ut0rnd.h"
 
22
#include "ut0byte.h"
 
23
#include "sync0rw.h"
 
24
#include "lock0types.h"
 
25
#include "hash0hash.h"
 
26
#include "que0types.h"
 
27
 
 
28
/* Type flags of an index: OR'ing of the flags is allowed to define a
 
29
combination of types */
 
30
#define DICT_CLUSTERED  1       /* clustered index */
 
31
#define DICT_UNIQUE     2       /* unique index */
 
32
#define DICT_UNIVERSAL  4       /* index which can contain records from any
 
33
                                other index */
 
34
#define DICT_IBUF       8       /* insert buffer tree */
 
35
 
 
36
/* Types for a table object */
 
37
#define DICT_TABLE_ORDINARY             1
 
38
#if 0 /* not implemented */
 
39
#define DICT_TABLE_CLUSTER_MEMBER       2
 
40
#define DICT_TABLE_CLUSTER              3 /* this means that the table is
 
41
                                          really a cluster definition */
 
42
#endif
 
43
 
 
44
/* Table flags.  All unused bits must be 0. */
 
45
#define DICT_TF_COMPACT                 1       /* Compact page format.
 
46
                                                This must be set for
 
47
                                                new file formats
 
48
                                                (later than
 
49
                                                DICT_TF_FORMAT_51). */
 
50
 
 
51
/* compressed page size (0=uncompressed, up to 15 compressed sizes) */
 
52
#define DICT_TF_ZSSIZE_SHIFT            1
 
53
#define DICT_TF_ZSSIZE_MASK             (15 << DICT_TF_ZSSIZE_SHIFT)
 
54
#define DICT_TF_ZSSIZE_MAX (UNIV_PAGE_SIZE_SHIFT - PAGE_ZIP_MIN_SIZE_SHIFT + 1)
 
55
 
 
56
 
 
57
#define DICT_TF_FORMAT_SHIFT            5       /* file format */
 
58
#define DICT_TF_FORMAT_MASK             (127 << DICT_TF_FORMAT_SHIFT)
 
59
#define DICT_TF_FORMAT_51               0       /* InnoDB/MySQL up to 5.1 */
 
60
#define DICT_TF_FORMAT_ZIP              1       /* InnoDB plugin for 5.1:
 
61
                                                compressed tables,
 
62
                                                new BLOB treatment */
 
63
#define DICT_TF_FORMAT_MAX              DICT_TF_FORMAT_ZIP
 
64
 
 
65
#define DICT_TF_BITS                    6       /* number of flag bits */
 
66
#if (1 << (DICT_TF_BITS - DICT_TF_FORMAT_SHIFT)) <= DICT_TF_FORMAT_MAX
 
67
# error "DICT_TF_BITS is insufficient for DICT_TF_FORMAT_MAX"
 
68
#endif
 
69
 
 
70
/**************************************************************************
 
71
Creates a table memory object. */
 
72
UNIV_INTERN
 
73
dict_table_t*
 
74
dict_mem_table_create(
 
75
/*==================*/
 
76
                                        /* out, own: table object */
 
77
        const char*     name,           /* in: table name */
 
78
        ulint           space,          /* in: space where the clustered index
 
79
                                        of the table is placed; this parameter
 
80
                                        is ignored if the table is made
 
81
                                        a member of a cluster */
 
82
        ulint           n_cols,         /* in: number of columns */
 
83
        ulint           flags);         /* in: table flags */
 
84
/********************************************************************
 
85
Free a table memory object. */
 
86
UNIV_INTERN
 
87
void
 
88
dict_mem_table_free(
 
89
/*================*/
 
90
        dict_table_t*   table);         /* in: table */
 
91
/**************************************************************************
 
92
Adds a column definition to a table. */
 
93
UNIV_INTERN
 
94
void
 
95
dict_mem_table_add_col(
 
96
/*===================*/
 
97
        dict_table_t*   table,  /* in: table */
 
98
        mem_heap_t*     heap,   /* in: temporary memory heap, or NULL */
 
99
        const char*     name,   /* in: column name, or NULL */
 
100
        ulint           mtype,  /* in: main datatype */
 
101
        ulint           prtype, /* in: precise type */
 
102
        ulint           len);   /* in: precision */
 
103
/**************************************************************************
 
104
Creates an index memory object. */
 
105
UNIV_INTERN
 
106
dict_index_t*
 
107
dict_mem_index_create(
 
108
/*==================*/
 
109
                                        /* out, own: index object */
 
110
        const char*     table_name,     /* in: table name */
 
111
        const char*     index_name,     /* in: index name */
 
112
        ulint           space,          /* in: space where the index tree is
 
113
                                        placed, ignored if the index is of
 
114
                                        the clustered type */
 
115
        ulint           type,           /* in: DICT_UNIQUE,
 
116
                                        DICT_CLUSTERED, ... ORed */
 
117
        ulint           n_fields);      /* in: number of fields */
 
118
/**************************************************************************
 
119
Adds a field definition to an index. NOTE: does not take a copy
 
120
of the column name if the field is a column. The memory occupied
 
121
by the column name may be released only after publishing the index. */
 
122
UNIV_INTERN
 
123
void
 
124
dict_mem_index_add_field(
 
125
/*=====================*/
 
126
        dict_index_t*   index,          /* in: index */
 
127
        const char*     name,           /* in: column name */
 
128
        ulint           prefix_len);    /* in: 0 or the column prefix length
 
129
                                        in a MySQL index like
 
130
                                        INDEX (textcol(25)) */
 
131
/**************************************************************************
 
132
Frees an index memory object. */
 
133
UNIV_INTERN
 
134
void
 
135
dict_mem_index_free(
 
136
/*================*/
 
137
        dict_index_t*   index); /* in: index */
 
138
/**************************************************************************
 
139
Creates and initializes a foreign constraint memory object. */
 
140
UNIV_INTERN
 
141
dict_foreign_t*
 
142
dict_mem_foreign_create(void);
 
143
/*=========================*/
 
144
                                /* out, own: foreign constraint struct */
 
145
 
 
146
/* Data structure for a column in a table */
 
147
struct dict_col_struct{
 
148
        /*----------------------*/
 
149
        /* The following are copied from dtype_t,
 
150
        so that all bit-fields can be packed tightly. */
 
151
        unsigned        mtype:8;        /* main data type */
 
152
        unsigned        prtype:24;      /* precise type; MySQL data
 
153
                                        type, charset code, flags to
 
154
                                        indicate nullability,
 
155
                                        signedness, whether this is a
 
156
                                        binary string, whether this is
 
157
                                        a true VARCHAR where MySQL
 
158
                                        uses 2 bytes to store the length */
 
159
 
 
160
        /* the remaining fields do not affect alphabetical ordering: */
 
161
 
 
162
        unsigned        len:16;         /* length; for MySQL data this
 
163
                                        is field->pack_length(),
 
164
                                        except that for a >= 5.0.3
 
165
                                        type true VARCHAR this is the
 
166
                                        maximum byte length of the
 
167
                                        string data (in addition to
 
168
                                        the string, MySQL uses 1 or 2
 
169
                                        bytes to store the string length) */
 
170
 
 
171
        unsigned        mbminlen:2;     /* minimum length of a
 
172
                                        character, in bytes */
 
173
        unsigned        mbmaxlen:3;     /* maximum length of a
 
174
                                        character, in bytes */
 
175
        /*----------------------*/
 
176
        /* End of definitions copied from dtype_t */
 
177
 
 
178
        unsigned        ind:10;         /* table column position
 
179
                                        (starting from 0) */
 
180
        unsigned        ord_part:1;     /* nonzero if this column
 
181
                                        appears in the ordering fields
 
182
                                        of an index */
 
183
};
 
184
 
 
185
/* DICT_MAX_INDEX_COL_LEN is measured in bytes and is the maximum
 
186
indexed column length (or indexed prefix length). It is set to 3*256,
 
187
so that one can create a column prefix index on 256 characters of a
 
188
TEXT or VARCHAR column also in the UTF-8 charset. In that charset,
 
189
a character may take at most 3 bytes.
 
190
This constant MUST NOT BE CHANGED, or the compatibility of InnoDB data
 
191
files would be at risk! */
 
192
 
 
193
#define DICT_MAX_INDEX_COL_LEN          REC_MAX_INDEX_COL_LEN
 
194
 
 
195
/* Data structure for a field in an index */
 
196
struct dict_field_struct{
 
197
        dict_col_t*     col;            /* pointer to the table column */
 
198
        const char*     name;           /* name of the column */
 
199
        unsigned        prefix_len:10;  /* 0 or the length of the column
 
200
                                        prefix in bytes in a MySQL index of
 
201
                                        type, e.g., INDEX (textcol(25));
 
202
                                        must be smaller than
 
203
                                        DICT_MAX_INDEX_COL_LEN; NOTE that
 
204
                                        in the UTF-8 charset, MySQL sets this
 
205
                                        to 3 * the prefix len in UTF-8 chars */
 
206
        unsigned        fixed_len:10;   /* 0 or the fixed length of the
 
207
                                        column if smaller than
 
208
                                        DICT_MAX_INDEX_COL_LEN */
 
209
};
 
210
 
 
211
/* Data structure for an index.  Most fields will be
 
212
initialized to 0, NULL or FALSE in dict_mem_index_create(). */
 
213
struct dict_index_struct{
 
214
        dulint          id;     /* id of the index */
 
215
        mem_heap_t*     heap;   /* memory heap */
 
216
        const char*     name;   /* index name */
 
217
        const char*     table_name; /* table name */
 
218
        dict_table_t*   table;  /* back pointer to table */
 
219
        unsigned        space:32;
 
220
                                /* space where the index tree is placed */
 
221
        unsigned        page:32;/* index tree root page number */
 
222
        unsigned        type:4; /* index type (DICT_CLUSTERED, DICT_UNIQUE,
 
223
                                DICT_UNIVERSAL, DICT_IBUF) */
 
224
        unsigned        trx_id_offset:10;/* position of the the trx id column
 
225
                                in a clustered index record, if the fields
 
226
                                before it are known to be of a fixed size,
 
227
                                0 otherwise */
 
228
        unsigned        n_user_defined_cols:10;
 
229
                                /* number of columns the user defined to
 
230
                                be in the index: in the internal
 
231
                                representation we add more columns */
 
232
        unsigned        n_uniq:10;/* number of fields from the beginning
 
233
                                which are enough to determine an index
 
234
                                entry uniquely */
 
235
        unsigned        n_def:10;/* number of fields defined so far */
 
236
        unsigned        n_fields:10;/* number of fields in the index */
 
237
        unsigned        n_nullable:10;/* number of nullable fields */
 
238
        unsigned        cached:1;/* TRUE if the index object is in the
 
239
                                dictionary cache */
 
240
        unsigned        to_be_dropped:1;
 
241
                                /* TRUE if this index is marked to be
 
242
                                dropped in ha_innobase::prepare_drop_index(),
 
243
                                otherwise FALSE */
 
244
        dict_field_t*   fields; /* array of field descriptions */
 
245
        UT_LIST_NODE_T(dict_index_t)
 
246
                        indexes;/* list of indexes of the table */
 
247
        btr_search_t*   search_info; /* info used in optimistic searches */
 
248
        /*----------------------*/
 
249
        ib_int64_t*     stat_n_diff_key_vals;
 
250
                                /* approximate number of different key values
 
251
                                for this index, for each n-column prefix
 
252
                                where n <= dict_get_n_unique(index); we
 
253
                                periodically calculate new estimates */
 
254
        ulint           stat_index_size;
 
255
                                /* approximate index size in database pages */
 
256
        ulint           stat_n_leaf_pages;
 
257
                                /* approximate number of leaf pages in the
 
258
                                index tree */
 
259
        rw_lock_t       lock;   /* read-write lock protecting the upper levels
 
260
                                of the index tree */
 
261
#ifdef ROW_MERGE_IS_INDEX_USABLE
 
262
        dulint          trx_id; /* id of the transaction that created this
 
263
                                index, or ut_dulint_zero if the index existed
 
264
                                when InnoDB was started up */
 
265
#endif /* ROW_MERGE_IS_INDEX_USABLE */
 
266
#ifdef UNIV_DEBUG
 
267
        ulint           magic_n;/* magic number */
 
268
# define DICT_INDEX_MAGIC_N     76789786
 
269
#endif
 
270
};
 
271
 
 
272
/* Data structure for a foreign key constraint; an example:
 
273
FOREIGN KEY (A, B) REFERENCES TABLE2 (C, D).  Most fields will be
 
274
initialized to 0, NULL or FALSE in dict_mem_foreign_create(). */
 
275
 
 
276
struct dict_foreign_struct{
 
277
        mem_heap_t*     heap;           /* this object is allocated from
 
278
                                        this memory heap */
 
279
        char*           id;             /* id of the constraint as a
 
280
                                        null-terminated string */
 
281
        unsigned        n_fields:10;    /* number of indexes' first fields
 
282
                                        for which the the foreign key
 
283
                                        constraint is defined: we allow the
 
284
                                        indexes to contain more fields than
 
285
                                        mentioned in the constraint, as long
 
286
                                        as the first fields are as mentioned */
 
287
        unsigned        type:6;         /* 0 or DICT_FOREIGN_ON_DELETE_CASCADE
 
288
                                        or DICT_FOREIGN_ON_DELETE_SET_NULL */
 
289
        char*           foreign_table_name;/* foreign table name */
 
290
        dict_table_t*   foreign_table;  /* table where the foreign key is */
 
291
        const char**    foreign_col_names;/* names of the columns in the
 
292
                                        foreign key */
 
293
        char*           referenced_table_name;/* referenced table name */
 
294
        dict_table_t*   referenced_table;/* table where the referenced key
 
295
                                        is */
 
296
        const char**    referenced_col_names;/* names of the referenced
 
297
                                        columns in the referenced table */
 
298
        dict_index_t*   foreign_index;  /* foreign index; we require that
 
299
                                        both tables contain explicitly defined
 
300
                                        indexes for the constraint: InnoDB
 
301
                                        does not generate new indexes
 
302
                                        implicitly */
 
303
        dict_index_t*   referenced_index;/* referenced index */
 
304
        UT_LIST_NODE_T(dict_foreign_t)
 
305
                        foreign_list;   /* list node for foreign keys of the
 
306
                                        table */
 
307
        UT_LIST_NODE_T(dict_foreign_t)
 
308
                        referenced_list;/* list node for referenced keys of the
 
309
                                        table */
 
310
};
 
311
 
 
312
/* The flags for ON_UPDATE and ON_DELETE can be ORed; the default is that
 
313
a foreign key constraint is enforced, therefore RESTRICT just means no flag */
 
314
#define DICT_FOREIGN_ON_DELETE_CASCADE  1
 
315
#define DICT_FOREIGN_ON_DELETE_SET_NULL 2
 
316
#define DICT_FOREIGN_ON_UPDATE_CASCADE  4
 
317
#define DICT_FOREIGN_ON_UPDATE_SET_NULL 8
 
318
#define DICT_FOREIGN_ON_DELETE_NO_ACTION 16
 
319
#define DICT_FOREIGN_ON_UPDATE_NO_ACTION 32
 
320
 
 
321
 
 
322
/* Data structure for a database table.  Most fields will be
 
323
initialized to 0, NULL or FALSE in dict_mem_table_create(). */
 
324
struct dict_table_struct{
 
325
        dulint          id;     /* id of the table */
 
326
        mem_heap_t*     heap;   /* memory heap */
 
327
        const char*     name;   /* table name */
 
328
        const char*     dir_path_of_temp_table;/* NULL or the directory path
 
329
                                where a TEMPORARY table that was explicitly
 
330
                                created by a user should be placed if
 
331
                                innodb_file_per_table is defined in my.cnf;
 
332
                                in Unix this is usually /tmp/..., in Windows
 
333
                                \temp\... */
 
334
        unsigned        space:32;
 
335
                                /* space where the clustered index of the
 
336
                                table is placed */
 
337
        unsigned        flags:DICT_TF_BITS;/* DICT_TF_COMPACT, ... */
 
338
        unsigned        ibd_file_missing:1;
 
339
                                /* TRUE if this is in a single-table
 
340
                                tablespace and the .ibd file is missing; then
 
341
                                we must return in ha_innodb.cc an error if the
 
342
                                user tries to query such an orphaned table */
 
343
        unsigned        tablespace_discarded:1;
 
344
                                /* this flag is set TRUE when the user
 
345
                                calls DISCARD TABLESPACE on this
 
346
                                table, and reset to FALSE in IMPORT
 
347
                                TABLESPACE */
 
348
        unsigned        cached:1;/* TRUE if the table object has been added
 
349
                                to the dictionary cache */
 
350
        unsigned        n_def:10;/* number of columns defined so far */
 
351
        unsigned        n_cols:10;/* number of columns */
 
352
        dict_col_t*     cols;   /* array of column descriptions */
 
353
        const char*     col_names;
 
354
                                /* Column names packed in a character string
 
355
                                "name1\0name2\0...nameN\0".  Until
 
356
                                the string contains n_cols, it will be
 
357
                                allocated from a temporary heap.  The final
 
358
                                string will be allocated from table->heap. */
 
359
        hash_node_t     name_hash; /* hash chain node */
 
360
        hash_node_t     id_hash; /* hash chain node */
 
361
        UT_LIST_BASE_NODE_T(dict_index_t)
 
362
                        indexes; /* list of indexes of the table */
 
363
        UT_LIST_BASE_NODE_T(dict_foreign_t)
 
364
                        foreign_list;/* list of foreign key constraints
 
365
                                in the table; these refer to columns
 
366
                                in other tables */
 
367
        UT_LIST_BASE_NODE_T(dict_foreign_t)
 
368
                        referenced_list;/* list of foreign key constraints
 
369
                                which refer to this table */
 
370
        UT_LIST_NODE_T(dict_table_t)
 
371
                        table_LRU; /* node of the LRU list of tables */
 
372
        ulint           n_mysql_handles_opened;
 
373
                                /* count of how many handles MySQL has opened
 
374
                                to this table; dropping of the table is
 
375
                                NOT allowed until this count gets to zero;
 
376
                                MySQL does NOT itself check the number of
 
377
                                open handles at drop */
 
378
        ulint           n_foreign_key_checks_running;
 
379
                                /* count of how many foreign key check
 
380
                                operations are currently being performed
 
381
                                on the table: we cannot drop the table while
 
382
                                there are foreign key checks running on
 
383
                                it! */
 
384
        lock_t*         auto_inc_lock;/* a buffer for an auto-inc lock
 
385
                                for this table: we allocate the memory here
 
386
                                so that individual transactions can get it
 
387
                                and release it without a need to allocate
 
388
                                space from the lock heap of the trx:
 
389
                                otherwise the lock heap would grow rapidly
 
390
                                if we do a large insert from a select */
 
391
        dulint          query_cache_inv_trx_id;
 
392
                                /* transactions whose trx id < than this
 
393
                                number are not allowed to store to the MySQL
 
394
                                query cache or retrieve from it; when a trx
 
395
                                with undo logs commits, it sets this to the
 
396
                                value of the trx id counter for the tables it
 
397
                                had an IX lock on */
 
398
        UT_LIST_BASE_NODE_T(lock_t)
 
399
                        locks; /* list of locks on the table */
 
400
#ifdef UNIV_DEBUG
 
401
        /*----------------------*/
 
402
        ibool           does_not_fit_in_memory;
 
403
                                /* this field is used to specify in simulations
 
404
                                tables which are so big that disk should be
 
405
                                accessed: disk access is simulated by
 
406
                                putting the thread to sleep for a while;
 
407
                                NOTE that this flag is not stored to the data
 
408
                                dictionary on disk, and the database will
 
409
                                forget about value TRUE if it has to reload
 
410
                                the table definition from disk */
 
411
#endif /* UNIV_DEBUG */
 
412
        /*----------------------*/
 
413
        unsigned        big_rows:1;
 
414
                                /* flag: TRUE if the maximum length of
 
415
                                a single row exceeds BIG_ROW_SIZE;
 
416
                                initialized in dict_table_add_to_cache() */
 
417
        unsigned        stat_initialized:1; /* TRUE if statistics have
 
418
                                been calculated the first time
 
419
                                after database startup or table creation */
 
420
        ib_int64_t      stat_n_rows;
 
421
                                /* approximate number of rows in the table;
 
422
                                we periodically calculate new estimates */
 
423
        ulint           stat_clustered_index_size;
 
424
                                /* approximate clustered index size in
 
425
                                database pages */
 
426
        ulint           stat_sum_of_other_index_sizes;
 
427
                                /* other indexes in database pages */
 
428
        ulint           stat_modified_counter;
 
429
                                /* when a row is inserted, updated, or deleted,
 
430
                                we add 1 to this number; we calculate new
 
431
                                estimates for the stat_... values for the
 
432
                                table and the indexes at an interval of 2 GB
 
433
                                or when about 1 / 16 of table has been
 
434
                                modified; also when the estimate operation is
 
435
                                called for MySQL SHOW TABLE STATUS; the
 
436
                                counter is reset to zero at statistics
 
437
                                calculation; this counter is not protected by
 
438
                                any latch, because this is only used for
 
439
                                heuristics */
 
440
        /*----------------------*/
 
441
        mutex_t         autoinc_mutex;
 
442
                                /* mutex protecting the autoincrement
 
443
                                counter */
 
444
        ibool           autoinc_inited;
 
445
                                /* TRUE if the autoinc counter has been
 
446
                                inited; MySQL gets the init value by executing
 
447
                                SELECT MAX(auto inc column) */
 
448
        ib_uint64_t     autoinc;/* autoinc counter value to give to the
 
449
                                next inserted row */
 
450
        ib_int64_t      autoinc_increment;
 
451
                                /* The increment step of the auto increment
 
452
                                column. Value must be greater than or equal
 
453
                                to 1 */
 
454
        /*----------------------*/
 
455
        ulong           n_waiting_or_granted_auto_inc_locks;
 
456
                                /* This counter is used to track the number
 
457
                                of granted and pending autoinc locks on this
 
458
                                table. This value is set after acquiring the
 
459
                                kernel mutex but we peek the contents to
 
460
                                determine whether other transactions have
 
461
                                acquired the AUTOINC lock or not. Of course
 
462
                                only one transaction can be granted the
 
463
                                lock but there can be multiple waiters. */
 
464
 
 
465
#ifdef UNIV_DEBUG
 
466
        ulint           magic_n;/* magic number */
 
467
# define DICT_TABLE_MAGIC_N     76333786
 
468
#endif /* UNIV_DEBUG */
 
469
};
 
470
 
 
471
#ifndef UNIV_NONINL
 
472
#include "dict0mem.ic"
 
473
#endif
 
474
 
 
475
#endif