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