~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

Made the_query_id private. Thanks Jay.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
/***********************************************************************
27
27
Frees the blob heap in prebuilt when no longer needed. */
28
 
 
 
28
UNIV_INTERN
29
29
void
30
30
row_mysql_prebuilt_free_blob_heap(
31
31
/*==============================*/
34
34
/***********************************************************************
35
35
Stores a >= 5.0.3 format true VARCHAR length to dest, in the MySQL row
36
36
format. */
37
 
 
 
37
UNIV_INTERN
38
38
byte*
39
39
row_mysql_store_true_var_len(
40
40
/*=========================*/
47
47
Reads a >= 5.0.3 format true VARCHAR length, in the MySQL row format, and
48
48
returns a pointer to the data. */
49
49
 
50
 
byte*
 
50
const byte*
51
51
row_mysql_read_true_varchar(
52
52
/*========================*/
53
 
                        /* out: pointer to the data, we skip the 1 or 2 bytes
54
 
                        at the start that are used to store the len */
55
 
        ulint*  len,    /* out: variable-length field length */
56
 
        byte*   field,  /* in: field in the MySQL format */
57
 
        ulint   lenlen);/* in: storage length of len: either 1 or 2 bytes */
 
53
                                /* out: pointer to the data, we skip
 
54
                                the 1 or 2 bytes at the start that are
 
55
                                used to store the len */
 
56
        ulint*          len,    /* out: variable-length field length */
 
57
        const byte*     field,  /* in: field in the MySQL format */
 
58
        ulint           lenlen);/* in: storage length of len: either 1
 
59
                                or 2 bytes */
58
60
/***********************************************************************
59
61
Stores a reference to a BLOB in the MySQL format. */
60
 
 
 
62
UNIV_INTERN
61
63
void
62
64
row_mysql_store_blob_ref(
63
65
/*=====================*/
64
 
        byte*   dest,           /* in: where to store */
65
 
        ulint   col_len,        /* in: dest buffer size: determines into
 
66
        byte*           dest,   /* in: where to store */
 
67
        ulint           col_len,/* in: dest buffer size: determines into
66
68
                                how many bytes the BLOB length is stored,
67
 
                                this may vary from 1 to 4 bytes */
68
 
        byte*   data,           /* in: BLOB data */
69
 
        ulint   len);           /* in: BLOB length */
 
69
                                the space for the length may vary from 1
 
70
                                to 4 bytes */
 
71
        const void*     data,   /* in: BLOB data; if the value to store
 
72
                                is SQL NULL this should be NULL pointer */
 
73
        ulint           len);   /* in: BLOB length; if the value to store
 
74
                                is SQL NULL this should be 0; remember
 
75
                                also to set the NULL bit in the MySQL record
 
76
                                header! */
70
77
/***********************************************************************
71
78
Reads a reference to a BLOB in the MySQL format. */
72
79
 
73
 
byte*
 
80
const byte*
74
81
row_mysql_read_blob_ref(
75
82
/*====================*/
76
 
                                /* out: pointer to BLOB data */
77
 
        ulint*  len,            /* out: BLOB length */
78
 
        byte*   ref,            /* in: BLOB reference in the MySQL format */
79
 
        ulint   col_len);       /* in: BLOB reference length (not BLOB
80
 
                                length) */
 
83
                                        /* out: pointer to BLOB data */
 
84
        ulint*          len,            /* out: BLOB length */
 
85
        const byte*     ref,            /* in: BLOB reference in the
 
86
                                        MySQL format */
 
87
        ulint           col_len);       /* in: BLOB reference length
 
88
                                        (not BLOB length) */
81
89
/******************************************************************
82
90
Stores a non-SQL-NULL field given in the MySQL format in the InnoDB format.
83
91
The counterpart of this function is row_sel_field_store_in_mysql_format() in
84
92
row0sel.c. */
85
 
 
 
93
UNIV_INTERN
86
94
byte*
87
95
row_mysql_store_col_in_innobase_format(
88
96
/*===================================*/
101
109
                                        format differs in a row and in a
102
110
                                        key value: in a key value the length
103
111
                                        is always stored in 2 bytes! */
104
 
        byte*           mysql_data,     /* in: MySQL column value, not
 
112
        const byte*     mysql_data,     /* in: MySQL column value, not
105
113
                                        SQL NULL; NOTE that dfield may also
106
114
                                        get a pointer to mysql_data,
107
115
                                        therefore do not discard this as long
115
123
        ulint           comp);          /* in: nonzero=compact format */
116
124
/********************************************************************
117
125
Handles user errors and lock waits detected by the database engine. */
118
 
 
 
126
UNIV_INTERN
119
127
ibool
120
128
row_mysql_handle_errors(
121
129
/*====================*/
129
137
        trx_savept_t*   savept);/* in: savepoint */
130
138
/************************************************************************
131
139
Create a prebuilt struct for a MySQL table handle. */
132
 
 
 
140
UNIV_INTERN
133
141
row_prebuilt_t*
134
142
row_create_prebuilt(
135
143
/*================*/
137
145
        dict_table_t*   table); /* in: Innobase table handle */
138
146
/************************************************************************
139
147
Free a prebuilt struct for a MySQL table handle. */
140
 
 
 
148
UNIV_INTERN
141
149
void
142
150
row_prebuilt_free(
143
151
/*==============*/
144
 
        row_prebuilt_t* prebuilt);      /* in, own: prebuilt struct */
 
152
        row_prebuilt_t* prebuilt,       /* in, own: prebuilt struct */
 
153
        ibool           dict_locked);   /* in: TRUE=data dictionary locked */
145
154
/*************************************************************************
146
155
Updates the transaction pointers in query graphs stored in the prebuilt
147
156
struct. */
148
 
 
 
157
UNIV_INTERN
149
158
void
150
159
row_update_prebuilt_trx(
151
160
/*====================*/
155
164
        trx_t*          trx);           /* in: transaction handle */
156
165
/*************************************************************************
157
166
Unlocks an AUTO_INC type lock possibly reserved by trx. */
158
 
 
 
167
UNIV_INTERN
159
168
void
160
169
row_unlock_table_autoinc_for_mysql(
161
170
/*===============================*/
166
175
table. The lock is reserved only for the duration of an SQL statement.
167
176
It is not compatible with another AUTO_INC or exclusive lock on the
168
177
table. */
169
 
 
 
178
UNIV_INTERN
170
179
int
171
180
row_lock_table_autoinc_for_mysql(
172
181
/*=============================*/
175
184
                                        table handle */
176
185
/*************************************************************************
177
186
Sets a table lock on the table mentioned in prebuilt. */
178
 
 
 
187
UNIV_INTERN
179
188
int
180
189
row_lock_table_for_mysql(
181
190
/*=====================*/
191
200
 
192
201
/*************************************************************************
193
202
Does an insert for MySQL. */
194
 
 
 
203
UNIV_INTERN
195
204
int
196
205
row_insert_for_mysql(
197
206
/*=================*/
201
210
                                        handle */
202
211
/*************************************************************************
203
212
Builds a dummy query graph used in selects. */
204
 
 
 
213
UNIV_INTERN
205
214
void
206
215
row_prebuild_sel_graph(
207
216
/*===================*/
211
220
Gets pointer to a prebuilt update vector used in updates. If the update
212
221
graph has not yet been built in the prebuilt struct, then this function
213
222
first builds it. */
214
 
 
 
223
UNIV_INTERN
215
224
upd_t*
216
225
row_get_prebuilt_update_vector(
217
226
/*===========================*/
221
230
/*************************************************************************
222
231
Checks if a table is such that we automatically created a clustered
223
232
index on it (on row id). */
224
 
 
 
233
UNIV_INTERN
225
234
ibool
226
235
row_table_got_default_clust_index(
227
236
/*==============================*/
228
 
        dict_table_t*   table);
 
237
        const dict_table_t*     table);
229
238
/*************************************************************************
230
239
Calculates the key number used inside MySQL for an Innobase index. We have
231
240
to take into account if we generated a default clustered index for the table */
232
 
 
 
241
UNIV_INTERN
233
242
ulint
234
243
row_get_mysql_key_number_for_index(
235
244
/*===============================*/
236
 
        dict_index_t*   index);
 
245
        const dict_index_t*     index);
237
246
/*************************************************************************
238
247
Does an update or delete of a row for MySQL. */
239
 
 
 
248
UNIV_INTERN
240
249
int
241
250
row_update_for_mysql(
242
251
/*=================*/
256
265
LOCK_X type.
257
266
Thus, this implements a 'mini-rollback' that releases the latest record
258
267
locks we set. */
259
 
 
 
268
UNIV_INTERN
260
269
int
261
270
row_unlock_for_mysql(
262
271
/*=================*/
270
279
/*************************************************************************
271
280
Creates an query graph node of 'update' type to be used in the MySQL
272
281
interface. */
273
 
 
 
282
UNIV_INTERN
274
283
upd_node_t*
275
284
row_create_update_node_for_mysql(
276
285
/*=============================*/
279
288
        mem_heap_t*     heap);  /* in: mem heap from which allocated */
280
289
/**************************************************************************
281
290
Does a cascaded delete or set null in a foreign key operation. */
282
 
 
 
291
UNIV_INTERN
283
292
ulint
284
293
row_update_cascade_for_mysql(
285
294
/*=========================*/
291
300
/*************************************************************************
292
301
Locks the data dictionary exclusively for performing a table create or other
293
302
data dictionary modification operation. */
294
 
 
 
303
UNIV_INTERN
295
304
void
296
305
row_mysql_lock_data_dictionary(
297
306
/*===========================*/
298
307
        trx_t*  trx);   /* in: transaction */
299
308
/*************************************************************************
300
309
Unlocks the data dictionary exclusive lock. */
301
 
 
 
310
UNIV_INTERN
302
311
void
303
312
row_mysql_unlock_data_dictionary(
304
313
/*=============================*/
306
315
/*************************************************************************
307
316
Locks the data dictionary in shared mode from modifications, for performing
308
317
foreign key check, rollback, or other operation invisible to MySQL. */
309
 
 
 
318
UNIV_INTERN
310
319
void
311
320
row_mysql_freeze_data_dictionary(
312
321
/*=============================*/
313
322
        trx_t*  trx);   /* in: transaction */
314
323
/*************************************************************************
315
324
Unlocks the data dictionary shared lock. */
316
 
 
 
325
UNIV_INTERN
317
326
void
318
327
row_mysql_unfreeze_data_dictionary(
319
328
/*===============================*/
320
329
        trx_t*  trx);   /* in: transaction */
 
330
#ifndef UNIV_HOTBACKUP
321
331
/*************************************************************************
322
 
Drops a table for MySQL. If the name of the table ends in
 
332
Creates a table for MySQL. If the name of the table ends in
323
333
one of "innodb_monitor", "innodb_lock_monitor", "innodb_tablespace_monitor",
324
334
"innodb_table_monitor", then this will also start the printing of monitor
325
335
output by the master thread. If the table name ends in "innodb_mem_validate",
326
336
InnoDB will try to invoke mem_validate(). */
327
 
 
 
337
UNIV_INTERN
328
338
int
329
339
row_create_table_for_mysql(
330
340
/*=======================*/
335
345
Does an index creation operation for MySQL. TODO: currently failure
336
346
to create an index results in dropping the whole table! This is no problem
337
347
currently as all indexes must be created at the same time as the table. */
338
 
 
 
348
UNIV_INTERN
339
349
int
340
350
row_create_index_for_mysql(
341
351
/*=======================*/
355
365
Each foreign key constraint must be accompanied with indexes in
356
366
bot participating tables. The indexes are allowed to contain more
357
367
fields than mentioned in the constraint. */
358
 
 
 
368
UNIV_INTERN
359
369
int
360
370
row_table_add_foreign_constraints(
361
371
/*==============================*/
377
387
The master thread in srv0srv.c calls this regularly to drop tables which
378
388
we must drop in background after queries to them have ended. Such lazy
379
389
dropping of tables is needed in ALTER TABLE on Unix. */
380
 
 
 
390
UNIV_INTERN
381
391
ulint
382
392
row_drop_tables_for_mysql_in_background(void);
383
393
/*=========================================*/
386
396
/*************************************************************************
387
397
Get the background drop list length. NOTE: the caller must own the kernel
388
398
mutex! */
389
 
 
 
399
UNIV_INTERN
390
400
ulint
391
401
row_get_background_drop_list_len_low(void);
392
402
/*======================================*/
393
403
                                        /* out: how many tables in list */
394
404
/*************************************************************************
395
405
Truncates a table for MySQL. */
396
 
 
 
406
UNIV_INTERN
397
407
int
398
408
row_truncate_table_for_mysql(
399
409
/*=========================*/
405
415
one of "innodb_monitor", "innodb_lock_monitor", "innodb_tablespace_monitor",
406
416
"innodb_table_monitor", then this will also stop the printing of monitor
407
417
output by the master thread. */
408
 
 
 
418
UNIV_INTERN
409
419
int
410
420
row_drop_table_for_mysql(
411
421
/*=====================*/
415
425
        ibool           drop_db);/* in: TRUE=dropping whole database */
416
426
 
417
427
/*************************************************************************
 
428
Drops a table for MySQL but does not commit the transaction.  If the
 
429
name of the dropped table ends in one of "innodb_monitor",
 
430
"innodb_lock_monitor", "innodb_tablespace_monitor",
 
431
"innodb_table_monitor", then this will also stop the printing of
 
432
monitor output by the master thread. */
 
433
UNIV_INTERN
 
434
int
 
435
row_drop_table_for_mysql_no_commit(
 
436
/*===============================*/
 
437
                                /* out: error code or DB_SUCCESS */
 
438
        const char*     name,   /* in: table name */
 
439
        trx_t*          trx,    /* in: transaction handle */
 
440
        ibool           drop_db);/* in: TRUE=dropping whole database */
 
441
/*************************************************************************
418
442
Discards the tablespace of a table which stored in an .ibd file. Discarding
419
443
means that this function deletes the .ibd file and assigns a new table id for
420
444
the table. Also the flag table->ibd_file_missing is set TRUE. */
421
 
 
 
445
UNIV_INTERN
422
446
int
423
447
row_discard_tablespace_for_mysql(
424
448
/*=============================*/
428
452
/*********************************************************************
429
453
Imports a tablespace. The space id in the .ibd file must match the space id
430
454
of the table in the data dictionary. */
431
 
 
 
455
UNIV_INTERN
432
456
int
433
457
row_import_tablespace_for_mysql(
434
458
/*============================*/
437
461
        trx_t*          trx);   /* in: transaction handle */
438
462
/*************************************************************************
439
463
Drops a database for MySQL. */
440
 
 
 
464
UNIV_INTERN
441
465
int
442
466
row_drop_database_for_mysql(
443
467
/*========================*/
446
470
        trx_t*          trx);   /* in: transaction handle */
447
471
/*************************************************************************
448
472
Renames a table for MySQL. */
449
 
 
450
 
int
 
473
UNIV_INTERN
 
474
ulint
451
475
row_rename_table_for_mysql(
452
476
/*=======================*/
453
477
                                        /* out: error code or DB_SUCCESS */
454
478
        const char*     old_name,       /* in: old table name */
455
479
        const char*     new_name,       /* in: new table name */
456
 
        trx_t*          trx);           /* in: transaction handle */
 
480
        trx_t*          trx,            /* in: transaction handle */
 
481
        ibool           commit);        /* in: if TRUE then commit trx */
457
482
/*************************************************************************
458
483
Checks a table for corruption. */
459
 
 
 
484
UNIV_INTERN
460
485
ulint
461
486
row_check_table_for_mysql(
462
487
/*======================*/
463
488
                                        /* out: DB_ERROR or DB_SUCCESS */
464
489
        row_prebuilt_t* prebuilt);      /* in: prebuilt struct in MySQL
465
490
                                        handle */
 
491
#endif /* !UNIV_HOTBACKUP */
 
492
 
 
493
/*************************************************************************
 
494
Determines if a table is a magic monitor table. */
 
495
UNIV_INTERN
 
496
ibool
 
497
row_is_magic_monitor_table(
 
498
/*=======================*/
 
499
                                        /* out: TRUE if monitor table */
 
500
        const char*     table_name);    /* in: name of the table, in the
 
501
                                        form database/table_name */
466
502
 
467
503
/* A struct describing a place for an individual column in the MySQL
468
504
row format which is presented to the table handler in ha_innobase.
475
511
        ulint   rec_field_no;           /* field number of the column in an
476
512
                                        Innobase record in the current index;
477
513
                                        not defined if template_type is
478
 
                                        ROW_DRIZZLE_WHOLE_ROW */
 
514
                                        ROW_MYSQL_WHOLE_ROW */
479
515
        ulint   mysql_col_offset;       /* offset of the column in the MySQL
480
516
                                        row format */
481
517
        ulint   mysql_col_len;          /* length of the column in the MySQL
489
525
        ulint   mysql_type;             /* MySQL type code; this is always
490
526
                                        < 256 */
491
527
        ulint   mysql_length_bytes;     /* if mysql_type
492
 
                                        == DATA_DRIZZLE_TRUE_VARCHAR, this tells
 
528
                                        == DATA_MYSQL_TRUE_VARCHAR, this tells
493
529
                                        whether we should use 1 or 2 bytes to
494
530
                                        store the MySQL true VARCHAR data
495
531
                                        length at the start of row in the MySQL
507
543
                                        it is an unsigned integer type */
508
544
};
509
545
 
510
 
#define DRIZZLE_FETCH_CACHE_SIZE                8
 
546
#define MYSQL_FETCH_CACHE_SIZE          8
511
547
/* After fetching this many rows, we start caching them in fetch_cache */
512
 
#define DRIZZLE_FETCH_CACHE_THRESHOLD   4
 
548
#define MYSQL_FETCH_CACHE_THRESHOLD     4
513
549
 
514
550
#define ROW_PREBUILT_ALLOCATED  78540783
515
551
#define ROW_PREBUILT_FREED      26423527
521
557
 
522
558
struct row_prebuilt_struct {
523
559
        ulint           magic_n;        /* this magic number is set to
524
 
                                        ROW_PREBUILT_ALLOCATED when created
525
 
                                        and to ROW_PREBUILT_FREED when the
526
 
                                        struct has been freed; used in
527
 
                                        debugging */
 
560
                                        ROW_PREBUILT_ALLOCATED when created,
 
561
                                        or ROW_PREBUILT_FREED when the
 
562
                                        struct has been freed */
528
563
        dict_table_t*   table;          /* Innobase table handle */
529
564
        trx_t*          trx;            /* current transaction handle */
530
565
        ibool           sql_stat_start; /* TRUE when we start processing of
557
592
                                        unique search from a clustered index,
558
593
                                        because HANDLER allows NEXT and PREV
559
594
                                        in such a situation */
560
 
        ulint           template_type;  /* ROW_DRIZZLE_WHOLE_ROW,
561
 
                                        ROW_DRIZZLE_REC_FIELDS,
562
 
                                        ROW_DRIZZLE_DUMMY_TEMPLATE, or
563
 
                                        ROW_DRIZZLE_NO_TEMPLATE */
 
595
        ulint           template_type;  /* ROW_MYSQL_WHOLE_ROW,
 
596
                                        ROW_MYSQL_REC_FIELDS,
 
597
                                        ROW_MYSQL_DUMMY_TEMPLATE, or
 
598
                                        ROW_MYSQL_NO_TEMPLATE */
564
599
        ulint           n_template;     /* number of elements in the
565
600
                                        template */
566
601
        ulint           null_bitmap_len;/* number of bytes in the SQL NULL
653
688
        ulint           n_rows_fetched; /* number of rows fetched after
654
689
                                        positioning the current cursor */
655
690
        ulint           fetch_direction;/* ROW_SEL_NEXT or ROW_SEL_PREV */
656
 
        byte*           fetch_cache[DRIZZLE_FETCH_CACHE_SIZE];
 
691
        byte*           fetch_cache[MYSQL_FETCH_CACHE_SIZE];
657
692
                                        /* a cache for fetched rows if we
658
693
                                        fetch many rows from the same cursor:
659
694
                                        it saves CPU time to fetch them in a
675
710
                                        to this heap */
676
711
        mem_heap_t*     old_vers_heap;  /* memory heap where a previous
677
712
                                        version is built in consistent read */
678
 
        uint64_t        last_value;     /* last value of AUTO-INC interval */
679
 
 
680
 
        index_cond_func_t idx_cond_func;/* Index Condition Pushdown function,
 
713
        ib_uint64_t     last_value;     /* last value of AUTO-INC interval */
 
714
        UT_LIST_NODE_T(row_prebuilt_t)  prebuilts;
 
715
                                        /* list node of table->prebuilts */
 
716
        index_cond_func_t idx_cond_func;/* Index Condition Pushdown function,
681
717
                                        or NULL if there is none set */
682
 
        void*           idx_cond_func_arg;/* ICP function  argument */
 
718
        void*           idx_cond_func_arg;/* ICP function  argument */
683
719
        ulint           n_index_fields; /* Number of fields at the start of
684
720
                                        mysql_template. Valid only when using
685
721
                                        ICP. */
689
725
 
690
726
#define ROW_PREBUILT_FETCH_MAGIC_N      465765687
691
727
 
692
 
#define ROW_DRIZZLE_WHOLE_ROW   0
693
 
#define ROW_DRIZZLE_REC_FIELDS  1
694
 
#define ROW_DRIZZLE_NO_TEMPLATE 2
695
 
#define ROW_DRIZZLE_DUMMY_TEMPLATE 3    /* dummy template used in
 
728
#define ROW_MYSQL_WHOLE_ROW     0
 
729
#define ROW_MYSQL_REC_FIELDS    1
 
730
#define ROW_MYSQL_NO_TEMPLATE   2
 
731
#define ROW_MYSQL_DUMMY_TEMPLATE 3      /* dummy template used in
696
732
                                        row_scan_and_check_index */
697
733
 
698
734
/* Values for hint_need_to_fetch_extra_cols */