~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2009-02-12 22:45:08 UTC
  • Revision ID: brian@tangent.org-20090212224508-mrd9jwgn1zjdpqdk
Minor refactoring (we will need to disconnect the code from the include
file).

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