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