~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Monty Taylor
  • Date: 2009-09-30 07:01:32 UTC
  • mto: This revision was merged to the branch mainline in revision 1184.
  • Revision ID: mordred@inaugust.com-20090930070132-b1ol1xu1rpajdddy
Small namespace cleanup.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/******************************************************
2
 
Interface between Innobase row operations and MySQL.
3
 
Contains also create table and other data dictionary operations.
4
 
 
5
 
(c) 2000 Innobase Oy
6
 
 
7
 
Created 9/17/2000 Heikki Tuuri
8
 
*******************************************************/
9
 
 
10
 
#ifndef row0mysql_h
11
 
#define row0mysql_h
12
 
 
13
 
#include "univ.i"
14
 
#include "data0data.h"
15
 
#include "que0types.h"
16
 
#include "dict0types.h"
17
 
#include "trx0types.h"
18
 
#include "row0types.h"
19
 
#include "btr0pcur.h"
20
 
#include "trx0types.h"
21
 
 
22
 
extern ibool row_rollback_on_timeout;
23
 
 
24
 
typedef struct row_prebuilt_struct row_prebuilt_t;
25
 
 
26
 
/***********************************************************************
27
 
Frees the blob heap in prebuilt when no longer needed. */
28
 
UNIV_INTERN
29
 
void
30
 
row_mysql_prebuilt_free_blob_heap(
31
 
/*==============================*/
32
 
        row_prebuilt_t* prebuilt);      /* in: prebuilt struct of a
33
 
                                        ha_innobase:: table handle */
34
 
/***********************************************************************
35
 
Stores a >= 5.0.3 format true VARCHAR length to dest, in the MySQL row
36
 
format. */
37
 
UNIV_INTERN
38
 
byte*
39
 
row_mysql_store_true_var_len(
40
 
/*=========================*/
41
 
                        /* out: pointer to the data, we skip the 1 or 2 bytes
42
 
                        at the start that are used to store the len */
43
 
        byte*   dest,   /* in: where to store */
44
 
        ulint   len,    /* in: length, must fit in two bytes */
45
 
        ulint   lenlen);/* in: storage length of len: either 1 or 2 bytes */
46
 
/***********************************************************************
47
 
Reads a >= 5.0.3 format true VARCHAR length, in the MySQL row format, and
48
 
returns a pointer to the data. */
49
 
 
50
 
const byte*
51
 
row_mysql_read_true_varchar(
52
 
/*========================*/
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 */
60
 
/***********************************************************************
61
 
Stores a reference to a BLOB in the MySQL format. */
62
 
UNIV_INTERN
63
 
void
64
 
row_mysql_store_blob_ref(
65
 
/*=====================*/
66
 
        byte*           dest,   /* in: where to store */
67
 
        ulint           col_len,/* in: dest buffer size: determines into
68
 
                                how many bytes the BLOB length is stored,
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! */
77
 
/***********************************************************************
78
 
Reads a reference to a BLOB in the MySQL format. */
79
 
 
80
 
const byte*
81
 
row_mysql_read_blob_ref(
82
 
/*====================*/
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) */
89
 
/******************************************************************
90
 
Stores a non-SQL-NULL field given in the MySQL format in the InnoDB format.
91
 
The counterpart of this function is row_sel_field_store_in_mysql_format() in
92
 
row0sel.c. */
93
 
UNIV_INTERN
94
 
byte*
95
 
row_mysql_store_col_in_innobase_format(
96
 
/*===================================*/
97
 
                                        /* out: up to which byte we used
98
 
                                        buf in the conversion */
99
 
        dfield_t*       dfield,         /* in/out: dfield where dtype
100
 
                                        information must be already set when
101
 
                                        this function is called! */
102
 
        byte*           buf,            /* in/out: buffer for a converted
103
 
                                        integer value; this must be at least
104
 
                                        col_len long then! */
105
 
        ibool           row_format_col, /* TRUE if the mysql_data is from
106
 
                                        a MySQL row, FALSE if from a MySQL
107
 
                                        key value;
108
 
                                        in MySQL, a true VARCHAR storage
109
 
                                        format differs in a row and in a
110
 
                                        key value: in a key value the length
111
 
                                        is always stored in 2 bytes! */
112
 
        const byte*     mysql_data,     /* in: MySQL column value, not
113
 
                                        SQL NULL; NOTE that dfield may also
114
 
                                        get a pointer to mysql_data,
115
 
                                        therefore do not discard this as long
116
 
                                        as dfield is used! */
117
 
        ulint           col_len,        /* in: MySQL column length; NOTE that
118
 
                                        this is the storage length of the
119
 
                                        column in the MySQL format row, not
120
 
                                        necessarily the length of the actual
121
 
                                        payload data; if the column is a true
122
 
                                        VARCHAR then this is irrelevant */
123
 
        ulint           comp);          /* in: nonzero=compact format */
124
 
/********************************************************************
125
 
Handles user errors and lock waits detected by the database engine. */
126
 
UNIV_INTERN
127
 
ibool
128
 
row_mysql_handle_errors(
129
 
/*====================*/
130
 
                                /* out: TRUE if it was a lock wait and
131
 
                                we should continue running the query thread */
132
 
        ulint*          new_err,/* out: possible new error encountered in
133
 
                                rollback, or the old error which was
134
 
                                during the function entry */
135
 
        trx_t*          trx,    /* in: transaction */
136
 
        que_thr_t*      thr,    /* in: query thread */
137
 
        trx_savept_t*   savept);/* in: savepoint */
138
 
/************************************************************************
139
 
Create a prebuilt struct for a MySQL table handle. */
140
 
UNIV_INTERN
141
 
row_prebuilt_t*
142
 
row_create_prebuilt(
143
 
/*================*/
144
 
                                /* out, own: a prebuilt struct */
145
 
        dict_table_t*   table); /* in: Innobase table handle */
146
 
/************************************************************************
147
 
Free a prebuilt struct for a MySQL table handle. */
148
 
UNIV_INTERN
149
 
void
150
 
row_prebuilt_free(
151
 
/*==============*/
152
 
        row_prebuilt_t* prebuilt,       /* in, own: prebuilt struct */
153
 
        ibool           dict_locked);   /* in: TRUE=data dictionary locked */
154
 
/*************************************************************************
155
 
Updates the transaction pointers in query graphs stored in the prebuilt
156
 
struct. */
157
 
UNIV_INTERN
158
 
void
159
 
row_update_prebuilt_trx(
160
 
/*====================*/
161
 
                                        /* out: prebuilt dtuple */
162
 
        row_prebuilt_t* prebuilt,       /* in: prebuilt struct in MySQL
163
 
                                        handle */
164
 
        trx_t*          trx);           /* in: transaction handle */
165
 
/*************************************************************************
166
 
Unlocks an AUTO_INC type lock possibly reserved by trx. */
167
 
UNIV_INTERN
168
 
void
169
 
row_unlock_table_autoinc_for_mysql(
170
 
/*===============================*/
171
 
        trx_t*  trx);   /* in: transaction */
172
 
/*************************************************************************
173
 
Sets an AUTO_INC type lock on the table mentioned in prebuilt. The
174
 
AUTO_INC lock gives exclusive access to the auto-inc counter of the
175
 
table. The lock is reserved only for the duration of an SQL statement.
176
 
It is not compatible with another AUTO_INC or exclusive lock on the
177
 
table. */
178
 
UNIV_INTERN
179
 
int
180
 
row_lock_table_autoinc_for_mysql(
181
 
/*=============================*/
182
 
                                        /* out: error code or DB_SUCCESS */
183
 
        row_prebuilt_t* prebuilt);      /* in: prebuilt struct in the MySQL
184
 
                                        table handle */
185
 
/*************************************************************************
186
 
Sets a table lock on the table mentioned in prebuilt. */
187
 
UNIV_INTERN
188
 
int
189
 
row_lock_table_for_mysql(
190
 
/*=====================*/
191
 
                                        /* out: error code or DB_SUCCESS */
192
 
        row_prebuilt_t* prebuilt,       /* in: prebuilt struct in the MySQL
193
 
                                        table handle */
194
 
        dict_table_t*   table,          /* in: table to lock, or NULL
195
 
                                        if prebuilt->table should be
196
 
                                        locked as
197
 
                                        prebuilt->select_lock_type */
198
 
        ulint           mode);          /* in: lock mode of table
199
 
                                        (ignored if table==NULL) */
200
 
 
201
 
/*************************************************************************
202
 
Does an insert for MySQL. */
203
 
UNIV_INTERN
204
 
int
205
 
row_insert_for_mysql(
206
 
/*=================*/
207
 
                                        /* out: error code or DB_SUCCESS */
208
 
        byte*           mysql_rec,      /* in: row in the MySQL format */
209
 
        row_prebuilt_t* prebuilt);      /* in: prebuilt struct in MySQL
210
 
                                        handle */
211
 
/*************************************************************************
212
 
Builds a dummy query graph used in selects. */
213
 
UNIV_INTERN
214
 
void
215
 
row_prebuild_sel_graph(
216
 
/*===================*/
217
 
        row_prebuilt_t* prebuilt);      /* in: prebuilt struct in MySQL
218
 
                                        handle */
219
 
/*************************************************************************
220
 
Gets pointer to a prebuilt update vector used in updates. If the update
221
 
graph has not yet been built in the prebuilt struct, then this function
222
 
first builds it. */
223
 
UNIV_INTERN
224
 
upd_t*
225
 
row_get_prebuilt_update_vector(
226
 
/*===========================*/
227
 
                                        /* out: prebuilt update vector */
228
 
        row_prebuilt_t* prebuilt);      /* in: prebuilt struct in MySQL
229
 
                                        handle */
230
 
/*************************************************************************
231
 
Checks if a table is such that we automatically created a clustered
232
 
index on it (on row id). */
233
 
UNIV_INTERN
234
 
ibool
235
 
row_table_got_default_clust_index(
236
 
/*==============================*/
237
 
        const dict_table_t*     table);
238
 
/*************************************************************************
239
 
Calculates the key number used inside MySQL for an Innobase index. We have
240
 
to take into account if we generated a default clustered index for the table */
241
 
UNIV_INTERN
242
 
ulint
243
 
row_get_mysql_key_number_for_index(
244
 
/*===============================*/
245
 
        const dict_index_t*     index);
246
 
/*************************************************************************
247
 
Does an update or delete of a row for MySQL. */
248
 
UNIV_INTERN
249
 
int
250
 
row_update_for_mysql(
251
 
/*=================*/
252
 
                                        /* out: error code or DB_SUCCESS */
253
 
        byte*           mysql_rec,      /* in: the row to be updated, in
254
 
                                        the MySQL format */
255
 
        row_prebuilt_t* prebuilt);      /* in: prebuilt struct in MySQL
256
 
                                        handle */
257
 
/*************************************************************************
258
 
This can only be used when srv_locks_unsafe_for_binlog is TRUE or
259
 
session is using a READ COMMITTED isolation level. Before
260
 
calling this function we must use trx_reset_new_rec_lock_info() and
261
 
trx_register_new_rec_lock() to store the information which new record locks
262
 
really were set. This function removes a newly set lock under prebuilt->pcur,
263
 
and also under prebuilt->clust_pcur. Currently, this is only used and tested
264
 
in the case of an UPDATE or a DELETE statement, where the row lock is of the
265
 
LOCK_X type.
266
 
Thus, this implements a 'mini-rollback' that releases the latest record
267
 
locks we set. */
268
 
UNIV_INTERN
269
 
int
270
 
row_unlock_for_mysql(
271
 
/*=================*/
272
 
                                        /* out: error code or DB_SUCCESS */
273
 
        row_prebuilt_t* prebuilt,       /* in: prebuilt struct in MySQL
274
 
                                        handle */
275
 
        ibool           has_latches_on_recs);/* TRUE if called so that we have
276
 
                                        the latches on the records under pcur
277
 
                                        and clust_pcur, and we do not need to
278
 
                                        reposition the cursors. */
279
 
/*************************************************************************
280
 
Creates an query graph node of 'update' type to be used in the MySQL
281
 
interface. */
282
 
UNIV_INTERN
283
 
upd_node_t*
284
 
row_create_update_node_for_mysql(
285
 
/*=============================*/
286
 
                                /* out, own: update node */
287
 
        dict_table_t*   table,  /* in: table to update */
288
 
        mem_heap_t*     heap);  /* in: mem heap from which allocated */
289
 
/**************************************************************************
290
 
Does a cascaded delete or set null in a foreign key operation. */
291
 
UNIV_INTERN
292
 
ulint
293
 
row_update_cascade_for_mysql(
294
 
/*=========================*/
295
 
                                /* out: error code or DB_SUCCESS */
296
 
        que_thr_t*      thr,    /* in: query thread */
297
 
        upd_node_t*     node,   /* in: update node used in the cascade
298
 
                                or set null operation */
299
 
        dict_table_t*   table); /* in: table where we do the operation */
300
 
/*************************************************************************
301
 
Locks the data dictionary exclusively for performing a table create or other
302
 
data dictionary modification operation. */
303
 
UNIV_INTERN
304
 
void
305
 
row_mysql_lock_data_dictionary(
306
 
/*===========================*/
307
 
        trx_t*  trx);   /* in: transaction */
308
 
/*************************************************************************
309
 
Unlocks the data dictionary exclusive lock. */
310
 
UNIV_INTERN
311
 
void
312
 
row_mysql_unlock_data_dictionary(
313
 
/*=============================*/
314
 
        trx_t*  trx);   /* in: transaction */
315
 
/*************************************************************************
316
 
Locks the data dictionary in shared mode from modifications, for performing
317
 
foreign key check, rollback, or other operation invisible to MySQL. */
318
 
UNIV_INTERN
319
 
void
320
 
row_mysql_freeze_data_dictionary(
321
 
/*=============================*/
322
 
        trx_t*  trx);   /* in: transaction */
323
 
/*************************************************************************
324
 
Unlocks the data dictionary shared lock. */
325
 
UNIV_INTERN
326
 
void
327
 
row_mysql_unfreeze_data_dictionary(
328
 
/*===============================*/
329
 
        trx_t*  trx);   /* in: transaction */
330
 
#ifndef UNIV_HOTBACKUP
331
 
/*************************************************************************
332
 
Creates a table for MySQL. If the name of the table ends in
333
 
one of "innodb_monitor", "innodb_lock_monitor", "innodb_tablespace_monitor",
334
 
"innodb_table_monitor", then this will also start the printing of monitor
335
 
output by the master thread. If the table name ends in "innodb_mem_validate",
336
 
InnoDB will try to invoke mem_validate(). */
337
 
UNIV_INTERN
338
 
int
339
 
row_create_table_for_mysql(
340
 
/*=======================*/
341
 
                                        /* out: error code or DB_SUCCESS */
342
 
        dict_table_t*   table,          /* in: table definition */
343
 
        trx_t*          trx);           /* in: transaction handle */
344
 
/*************************************************************************
345
 
Does an index creation operation for MySQL. TODO: currently failure
346
 
to create an index results in dropping the whole table! This is no problem
347
 
currently as all indexes must be created at the same time as the table. */
348
 
UNIV_INTERN
349
 
int
350
 
row_create_index_for_mysql(
351
 
/*=======================*/
352
 
                                        /* out: error number or DB_SUCCESS */
353
 
        dict_index_t*   index,          /* in: index definition */
354
 
        trx_t*          trx,            /* in: transaction handle */
355
 
        const ulint*    field_lengths); /* in: if not NULL, must contain
356
 
                                        dict_index_get_n_fields(index)
357
 
                                        actual field lengths for the
358
 
                                        index columns, which are
359
 
                                        then checked for not being too
360
 
                                        large. */
361
 
/*************************************************************************
362
 
Scans a table create SQL string and adds to the data dictionary
363
 
the foreign key constraints declared in the string. This function
364
 
should be called after the indexes for a table have been created.
365
 
Each foreign key constraint must be accompanied with indexes in
366
 
bot participating tables. The indexes are allowed to contain more
367
 
fields than mentioned in the constraint. */
368
 
UNIV_INTERN
369
 
int
370
 
row_table_add_foreign_constraints(
371
 
/*==============================*/
372
 
                                        /* out: error code or DB_SUCCESS */
373
 
        trx_t*          trx,            /* in: transaction */
374
 
        const char*     sql_string,     /* in: table create statement where
375
 
                                        foreign keys are declared like:
376
 
                                FOREIGN KEY (a, b) REFERENCES table2(c, d),
377
 
                                        table2 can be written also with the
378
 
                                        database name before it: test.table2 */
379
 
        const char*     name,           /* in: table full name in the
380
 
                                        normalized form
381
 
                                        database_name/table_name */
382
 
        ibool           reject_fks);    /* in: if TRUE, fail with error
383
 
                                        code DB_CANNOT_ADD_CONSTRAINT if
384
 
                                        any foreign keys are found. */
385
 
 
386
 
/*************************************************************************
387
 
The master thread in srv0srv.c calls this regularly to drop tables which
388
 
we must drop in background after queries to them have ended. Such lazy
389
 
dropping of tables is needed in ALTER TABLE on Unix. */
390
 
UNIV_INTERN
391
 
ulint
392
 
row_drop_tables_for_mysql_in_background(void);
393
 
/*=========================================*/
394
 
                                        /* out: how many tables dropped
395
 
                                        + remaining tables in list */
396
 
/*************************************************************************
397
 
Get the background drop list length. NOTE: the caller must own the kernel
398
 
mutex! */
399
 
UNIV_INTERN
400
 
ulint
401
 
row_get_background_drop_list_len_low(void);
402
 
/*======================================*/
403
 
                                        /* out: how many tables in list */
404
 
/*************************************************************************
405
 
Truncates a table for MySQL. */
406
 
UNIV_INTERN
407
 
int
408
 
row_truncate_table_for_mysql(
409
 
/*=========================*/
410
 
                                /* out: error code or DB_SUCCESS */
411
 
        dict_table_t*   table,  /* in: table handle */
412
 
        trx_t*          trx);   /* in: transaction handle */
413
 
/*************************************************************************
414
 
Drops a table for MySQL. If the name of the dropped table ends in
415
 
one of "innodb_monitor", "innodb_lock_monitor", "innodb_tablespace_monitor",
416
 
"innodb_table_monitor", then this will also stop the printing of monitor
417
 
output by the master thread. */
418
 
UNIV_INTERN
419
 
int
420
 
row_drop_table_for_mysql(
421
 
/*=====================*/
422
 
                                /* out: error code or DB_SUCCESS */
423
 
        const char*     name,   /* in: table name */
424
 
        trx_t*          trx,    /* in: transaction handle */
425
 
        ibool           drop_db);/* in: TRUE=dropping whole database */
426
 
 
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
 
/*************************************************************************
442
 
Discards the tablespace of a table which stored in an .ibd file. Discarding
443
 
means that this function deletes the .ibd file and assigns a new table id for
444
 
the table. Also the flag table->ibd_file_missing is set TRUE. */
445
 
UNIV_INTERN
446
 
int
447
 
row_discard_tablespace_for_mysql(
448
 
/*=============================*/
449
 
                                /* out: error code or DB_SUCCESS */
450
 
        const char*     name,   /* in: table name */
451
 
        trx_t*          trx);   /* in: transaction handle */
452
 
/*********************************************************************
453
 
Imports a tablespace. The space id in the .ibd file must match the space id
454
 
of the table in the data dictionary. */
455
 
UNIV_INTERN
456
 
int
457
 
row_import_tablespace_for_mysql(
458
 
/*============================*/
459
 
                                /* out: error code or DB_SUCCESS */
460
 
        const char*     name,   /* in: table name */
461
 
        trx_t*          trx);   /* in: transaction handle */
462
 
/*************************************************************************
463
 
Drops a database for MySQL. */
464
 
UNIV_INTERN
465
 
int
466
 
row_drop_database_for_mysql(
467
 
/*========================*/
468
 
                                /* out: error code or DB_SUCCESS */
469
 
        const char*     name,   /* in: database name which ends to '/' */
470
 
        trx_t*          trx);   /* in: transaction handle */
471
 
/*************************************************************************
472
 
Renames a table for MySQL. */
473
 
UNIV_INTERN
474
 
ulint
475
 
row_rename_table_for_mysql(
476
 
/*=======================*/
477
 
                                        /* out: error code or DB_SUCCESS */
478
 
        const char*     old_name,       /* in: old table name */
479
 
        const char*     new_name,       /* in: new table name */
480
 
        trx_t*          trx,            /* in: transaction handle */
481
 
        ibool           commit);        /* in: if TRUE then commit trx */
482
 
/*************************************************************************
483
 
Checks a table for corruption. */
484
 
UNIV_INTERN
485
 
ulint
486
 
row_check_table_for_mysql(
487
 
/*======================*/
488
 
                                        /* out: DB_ERROR or DB_SUCCESS */
489
 
        row_prebuilt_t* prebuilt);      /* in: prebuilt struct in MySQL
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 */
502
 
 
503
 
/* A struct describing a place for an individual column in the MySQL
504
 
row format which is presented to the table handler in ha_innobase.
505
 
This template struct is used to speed up row transformations between
506
 
Innobase and MySQL. */
507
 
 
508
 
typedef struct mysql_row_templ_struct mysql_row_templ_t;
509
 
struct mysql_row_templ_struct {
510
 
        ulint   col_no;                 /* column number of the column */
511
 
        ulint   rec_field_no;           /* field number of the column in an
512
 
                                        Innobase record in the current index;
513
 
                                        not defined if template_type is
514
 
                                        ROW_MYSQL_WHOLE_ROW */
515
 
        ulint   mysql_col_offset;       /* offset of the column in the MySQL
516
 
                                        row format */
517
 
        ulint   mysql_col_len;          /* length of the column in the MySQL
518
 
                                        row format */
519
 
        ulint   mysql_null_byte_offset; /* MySQL NULL bit byte offset in a
520
 
                                        MySQL record */
521
 
        ulint   mysql_null_bit_mask;    /* bit mask to get the NULL bit,
522
 
                                        zero if column cannot be NULL */
523
 
        ulint   type;                   /* column type in Innobase mtype
524
 
                                        numbers DATA_CHAR... */
525
 
        ulint   mysql_type;             /* MySQL type code; this is always
526
 
                                        < 256 */
527
 
        ulint   mysql_length_bytes;     /* if mysql_type
528
 
                                        == DATA_MYSQL_TRUE_VARCHAR, this tells
529
 
                                        whether we should use 1 or 2 bytes to
530
 
                                        store the MySQL true VARCHAR data
531
 
                                        length at the start of row in the MySQL
532
 
                                        format (NOTE that the MySQL key value
533
 
                                        format always uses 2 bytes for the data
534
 
                                        len) */
535
 
        ulint   charset;                /* MySQL charset-collation code
536
 
                                        of the column, or zero */
537
 
        ulint   mbminlen;               /* minimum length of a char, in bytes,
538
 
                                        or zero if not a char type */
539
 
        ulint   mbmaxlen;               /* maximum length of a char, in bytes,
540
 
                                        or zero if not a char type */
541
 
        ulint   is_unsigned;            /* if a column type is an integer
542
 
                                        type and this field is != 0, then
543
 
                                        it is an unsigned integer type */
544
 
};
545
 
 
546
 
#define MYSQL_FETCH_CACHE_SIZE          8
547
 
/* After fetching this many rows, we start caching them in fetch_cache */
548
 
#define MYSQL_FETCH_CACHE_THRESHOLD     4
549
 
 
550
 
#define ROW_PREBUILT_ALLOCATED  78540783
551
 
#define ROW_PREBUILT_FREED      26423527
552
 
 
553
 
typedef int64_t (*index_cond_func_t)(void *param);
554
 
 
555
 
/* A struct for (sometimes lazily) prebuilt structures in an Innobase table
556
 
handle used within MySQL; these are used to save CPU time. */
557
 
 
558
 
struct row_prebuilt_struct {
559
 
        ulint           magic_n;        /* this magic number is set to
560
 
                                        ROW_PREBUILT_ALLOCATED when created,
561
 
                                        or ROW_PREBUILT_FREED when the
562
 
                                        struct has been freed */
563
 
        dict_table_t*   table;          /* Innobase table handle */
564
 
        trx_t*          trx;            /* current transaction handle */
565
 
        ibool           sql_stat_start; /* TRUE when we start processing of
566
 
                                        an SQL statement: we may have to set
567
 
                                        an intention lock on the table,
568
 
                                        create a consistent read view etc. */
569
 
        ibool           mysql_has_locked; /* this is set TRUE when MySQL
570
 
                                        calls external_lock on this handle
571
 
                                        with a lock flag, and set FALSE when
572
 
                                        with the F_UNLOCK flag */
573
 
        ibool           clust_index_was_generated;
574
 
                                        /* if the user did not define a
575
 
                                        primary key in MySQL, then Innobase
576
 
                                        automatically generated a clustered
577
 
                                        index where the ordering column is
578
 
                                        the row id: in this case this flag
579
 
                                        is set to TRUE */
580
 
        dict_index_t*   index;          /* current index for a search, if
581
 
                                        any */
582
 
        ulint           read_just_key;  /* set to 1 when MySQL calls
583
 
                                        ha_innobase::extra with the
584
 
                                        argument HA_EXTRA_KEYREAD; it is enough
585
 
                                        to read just columns defined in
586
 
                                        the index (i.e., no read of the
587
 
                                        clustered index record necessary) */
588
 
        ibool           used_in_HANDLER;/* TRUE if we have been using this
589
 
                                        handle in a MySQL HANDLER low level
590
 
                                        index cursor command: then we must
591
 
                                        store the pcur position even in a
592
 
                                        unique search from a clustered index,
593
 
                                        because HANDLER allows NEXT and PREV
594
 
                                        in such a situation */
595
 
        ulint           template_type;  /* ROW_MYSQL_WHOLE_ROW,
596
 
                                        ROW_MYSQL_REC_FIELDS,
597
 
                                        ROW_MYSQL_DUMMY_TEMPLATE, or
598
 
                                        ROW_MYSQL_NO_TEMPLATE */
599
 
        ulint           n_template;     /* number of elements in the
600
 
                                        template */
601
 
        ulint           null_bitmap_len;/* number of bytes in the SQL NULL
602
 
                                        bitmap at the start of a row in the
603
 
                                        MySQL format */
604
 
        ibool           need_to_access_clustered; /* if we are fetching
605
 
                                        columns through a secondary index
606
 
                                        and at least one column is not in
607
 
                                        the secondary index, then this is
608
 
                                        set to TRUE */
609
 
        ibool           templ_contains_blob;/* TRUE if the template contains
610
 
                                        BLOB column(s) */
611
 
        mysql_row_templ_t* mysql_template;/* template used to transform
612
 
                                        rows fast between MySQL and Innobase
613
 
                                        formats; memory for this template
614
 
                                        is not allocated from 'heap' */
615
 
        mem_heap_t*     heap;           /* memory heap from which
616
 
                                        these auxiliary structures are
617
 
                                        allocated when needed */
618
 
        ins_node_t*     ins_node;       /* Innobase SQL insert node
619
 
                                        used to perform inserts
620
 
                                        to the table */
621
 
        byte*           ins_upd_rec_buff;/* buffer for storing data converted
622
 
                                        to the Innobase format from the MySQL
623
 
                                        format */
624
 
        ulint           hint_need_to_fetch_extra_cols;
625
 
                                        /* normally this is set to 0; if this
626
 
                                        is set to ROW_RETRIEVE_PRIMARY_KEY,
627
 
                                        then we should at least retrieve all
628
 
                                        columns in the primary key; if this
629
 
                                        is set to ROW_RETRIEVE_ALL_COLS, then
630
 
                                        we must retrieve all columns in the
631
 
                                        key (if read_just_key == 1), or all
632
 
                                        columns in the table */
633
 
        upd_node_t*     upd_node;       /* Innobase SQL update node used
634
 
                                        to perform updates and deletes */
635
 
        que_fork_t*     ins_graph;      /* Innobase SQL query graph used
636
 
                                        in inserts */
637
 
        que_fork_t*     upd_graph;      /* Innobase SQL query graph used
638
 
                                        in updates or deletes */
639
 
        btr_pcur_t*     pcur;           /* persistent cursor used in selects
640
 
                                        and updates */
641
 
        btr_pcur_t*     clust_pcur;     /* persistent cursor used in
642
 
                                        some selects and updates */
643
 
        que_fork_t*     sel_graph;      /* dummy query graph used in
644
 
                                        selects */
645
 
        dtuple_t*       search_tuple;   /* prebuilt dtuple used in selects */
646
 
        byte            row_id[DATA_ROW_ID_LEN];
647
 
                                        /* if the clustered index was
648
 
                                        generated, the row id of the
649
 
                                        last row fetched is stored
650
 
                                        here */
651
 
        dtuple_t*       clust_ref;      /* prebuilt dtuple used in
652
 
                                        sel/upd/del */
653
 
        ulint           select_lock_type;/* LOCK_NONE, LOCK_S, or LOCK_X */
654
 
        ulint           stored_select_lock_type;/* this field is used to
655
 
                                        remember the original select_lock_type
656
 
                                        that was decided in ha_innodb.cc,
657
 
                                        ::store_lock(), ::external_lock(),
658
 
                                        etc. */
659
 
        ulint           row_read_type;  /* ROW_READ_WITH_LOCKS if row locks
660
 
                                        should be the obtained for records
661
 
                                        under an UPDATE or DELETE cursor.
662
 
                                        If innodb_locks_unsafe_for_binlog
663
 
                                        is TRUE, this can be set to
664
 
                                        ROW_READ_TRY_SEMI_CONSISTENT, so that
665
 
                                        if the row under an UPDATE or DELETE
666
 
                                        cursor was locked by another
667
 
                                        transaction, InnoDB will resort
668
 
                                        to reading the last committed value
669
 
                                        ('semi-consistent read').  Then,
670
 
                                        this field will be set to
671
 
                                        ROW_READ_DID_SEMI_CONSISTENT to
672
 
                                        indicate that.  If the row does not
673
 
                                        match the WHERE condition, MySQL will
674
 
                                        invoke handler::unlock_row() to
675
 
                                        clear the flag back to
676
 
                                        ROW_READ_TRY_SEMI_CONSISTENT and
677
 
                                        to simply skip the row.  If
678
 
                                        the row matches, the next call to
679
 
                                        row_search_for_mysql() will lock
680
 
                                        the row.
681
 
                                        This eliminates lock waits in some
682
 
                                        cases; note that this breaks
683
 
                                        serializability. */
684
 
        ulint           mysql_prefix_len;/* byte offset of the end of
685
 
                                        the last requested column */
686
 
        ulint           mysql_row_len;  /* length in bytes of a row in the
687
 
                                        MySQL format */
688
 
        ulint           n_rows_fetched; /* number of rows fetched after
689
 
                                        positioning the current cursor */
690
 
        ulint           fetch_direction;/* ROW_SEL_NEXT or ROW_SEL_PREV */
691
 
        byte*           fetch_cache[MYSQL_FETCH_CACHE_SIZE];
692
 
                                        /* a cache for fetched rows if we
693
 
                                        fetch many rows from the same cursor:
694
 
                                        it saves CPU time to fetch them in a
695
 
                                        batch; we reserve mysql_row_len
696
 
                                        bytes for each such row; these
697
 
                                        pointers point 4 bytes past the
698
 
                                        allocated mem buf start, because
699
 
                                        there is a 4 byte magic number at the
700
 
                                        start and at the end */
701
 
        ibool           keep_other_fields_on_keyread; /* when using fetch
702
 
                                        cache with HA_EXTRA_KEYREAD, don't
703
 
                                        overwrite other fields in mysql row
704
 
                                        row buffer.*/
705
 
        ulint           fetch_cache_first;/* position of the first not yet
706
 
                                        fetched row in fetch_cache */
707
 
        ulint           n_fetch_cached; /* number of not yet fetched rows
708
 
                                        in fetch_cache */
709
 
        mem_heap_t*     blob_heap;      /* in SELECTS BLOB fields are copied
710
 
                                        to this heap */
711
 
        mem_heap_t*     old_vers_heap;  /* memory heap where a previous
712
 
                                        version is built in consistent read */
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,
717
 
                                        or NULL if there is none set */
718
 
        void*           idx_cond_func_arg;/* ICP function  argument */
719
 
        ulint           n_index_fields; /* Number of fields at the start of
720
 
                                        mysql_template. Valid only when using
721
 
                                        ICP. */
722
 
        ulint           magic_n2;       /* this should be the same as
723
 
                                        magic_n */
724
 
};
725
 
 
726
 
#define ROW_PREBUILT_FETCH_MAGIC_N      465765687
727
 
 
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
732
 
                                        row_scan_and_check_index */
733
 
 
734
 
/* Values for hint_need_to_fetch_extra_cols */
735
 
#define ROW_RETRIEVE_PRIMARY_KEY        1
736
 
#define ROW_RETRIEVE_ALL_COLS           2
737
 
 
738
 
/* Values for row_read_type */
739
 
#define ROW_READ_WITH_LOCKS             0
740
 
#define ROW_READ_TRY_SEMI_CONSISTENT    1
741
 
#define ROW_READ_DID_SEMI_CONSISTENT    2
742
 
 
743
 
#ifndef UNIV_NONINL
744
 
#include "row0mysql.ic"
745
 
#endif
746
 
 
747
 
#endif