| 1 |
/***************************************************************************** |
| 2 |
|
| 3 |
Copyright (c) 2000, 2026, Oracle and/or its affiliates. |
| 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, version 2.0, as published by the |
| 7 |
Free Software Foundation. |
| 8 |
|
| 9 |
This program is designed to work with certain software (including |
| 10 |
but not limited to OpenSSL) that is licensed under separate terms, |
| 11 |
as designated in a particular file or component or in included license |
| 12 |
documentation. The authors of MySQL hereby grant you an additional |
| 13 |
permission to link the program and your derivative works with the |
| 14 |
separately licensed software that they have either included with |
| 15 |
the program or referenced in the documentation. |
| 16 |
|
| 17 |
This program is distributed in the hope that it will be useful, but WITHOUT |
| 18 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 19 |
FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0, |
| 20 |
for more details. |
| 21 |
|
| 22 |
You should have received a copy of the GNU General Public License along with |
| 23 |
this program; if not, write to the Free Software Foundation, Inc., |
| 24 |
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 25 |
|
| 26 |
*****************************************************************************/ |
| 27 |
|
| 28 |
/** @file include/row0mysql.h |
| 29 |
Interface between Innobase row operations and MySQL. |
| 30 |
Contains also create table and other data dictionary operations. |
| 31 |
|
| 32 |
Created 9/17/2000 Heikki Tuuri |
| 33 |
*******************************************************/ |
| 34 |
|
| 35 |
#ifndef row0mysql_h |
| 36 |
#define row0mysql_h |
| 37 |
|
| 38 |
#ifndef UNIV_HOTBACKUP |
| 39 |
#include "ha_prototypes.h" |
| 40 |
#endif /* !UNIV_HOTBACKUP */ |
| 41 |
|
| 42 |
#include <stddef.h> |
| 43 |
#include <sys/types.h> |
| 44 |
#include <algorithm> |
| 45 |
|
| 46 |
#include "btr0pcur.h" |
| 47 |
#include "data0data.h" |
| 48 |
#include "data0type.h" |
| 49 |
#include "db0err.h" |
| 50 |
#include "dict0types.h" |
| 51 |
#include "fts0fts.h" |
| 52 |
#include "gis0type.h" |
| 53 |
#include "lob0undo.h" |
| 54 |
#include "lock0types.h" |
| 55 |
#include "mem0mem.h" |
| 56 |
#include "my_compiler.h" |
| 57 |
#include "my_inttypes.h" |
| 58 |
#include "que0types.h" |
| 59 |
#include "rem0types.h" |
| 60 |
#include "row0types.h" |
| 61 |
#include "sess0sess.h" |
| 62 |
#include "sql_cmd.h" |
| 63 |
#include "trx0types.h" |
| 64 |
#include "univ.i" |
| 65 |
#include "ut0bool_scope_guard.h" |
| 66 |
|
| 67 |
// Forward declarations |
| 68 |
class THD; |
| 69 |
class ha_innobase; |
| 70 |
class innodb_session_t; |
| 71 |
namespace dd { |
| 72 |
class Table; |
| 73 |
} |
| 74 |
struct TABLE; |
| 75 |
struct btr_pcur_t; |
| 76 |
struct dfield_t; |
| 77 |
struct dict_field_t; |
| 78 |
struct dict_foreign_t; |
| 79 |
struct dict_index_t; |
| 80 |
struct dict_table_t; |
| 81 |
struct dict_v_col_t; |
| 82 |
struct dtuple_t; |
| 83 |
struct ins_node_t; |
| 84 |
struct mtr_t; |
| 85 |
struct que_fork_t; |
| 86 |
struct que_thr_t; |
| 87 |
struct trx_t; |
| 88 |
struct upd_node_t; |
| 89 |
struct upd_t; |
| 90 |
|
| 91 |
#ifndef UNIV_HOTBACKUP |
| 92 |
extern bool row_rollback_on_timeout; |
| 93 |
|
| 94 |
struct row_prebuilt_t; |
| 95 |
|
| 96 |
/** Frees the blob heap in prebuilt when no longer needed. */ |
| 97 |
void row_mysql_prebuilt_free_blob_heap( |
| 98 |
row_prebuilt_t *prebuilt); /*!< in: prebuilt struct of a |
| 99 |
ha_innobase:: table handle */ |
| 100 |
/** Stores a >= 5.0.3 format true VARCHAR length to dest, in the MySQL row |
| 101 |
format. |
| 102 |
@return pointer to the data, we skip the 1 or 2 bytes at the start |
| 103 |
that are used to store the len */ |
| 104 |
byte *row_mysql_store_true_var_len( |
| 105 |
byte *dest, /*!< in: where to store */ |
| 106 |
ulint len, /*!< in: length, must fit in two bytes */ |
| 107 |
ulint lenlen); /*!< in: storage length of len: either 1 or 2 bytes */ |
| 108 |
/** Reads a >= 5.0.3 format true VARCHAR length, in the MySQL row format, and |
| 109 |
returns a pointer to the data. |
| 110 |
@return pointer to the data, we skip the 1 or 2 bytes at the start |
| 111 |
that are used to store the len */ |
| 112 |
const byte *row_mysql_read_true_varchar( |
| 113 |
ulint *len, /*!< out: variable-length field length */ |
| 114 |
const byte *field, /*!< in: field in the MySQL format */ |
| 115 |
ulint lenlen); /*!< in: storage length of len: either 1 |
| 116 |
or 2 bytes */ |
| 117 |
|
| 118 |
/** Stores a reference to a BLOB in the MySQL format. |
| 119 |
@param[in] dest Where to store |
| 120 |
@param[in,out] col_len Dest buffer size: determines into how many bytes the blob |
| 121 |
length is stored, the space for the length may vary from 1 to 4 bytes |
| 122 |
@param[in] data Blob data; if the value to store is sql null this should be null |
| 123 |
pointer |
| 124 |
@param[in] len Blob length; if the value to store is sql null this should be 0; |
| 125 |
remember also to set the null bit in the mysql record header! */ |
| 126 |
void row_mysql_store_blob_ref(byte *dest, ulint col_len, const void *data, |
| 127 |
ulint len); |
| 128 |
|
| 129 |
/** Reads a reference to a BLOB in the MySQL format. |
| 130 |
@param[out] len BLOB length. |
| 131 |
@param[in] ref BLOB reference in the MySQL format. |
| 132 |
@param[in] col_len BLOB reference length (not BLOB length). |
| 133 |
@return pointer to BLOB data */ |
| 134 |
const byte *row_mysql_read_blob_ref(ulint *len, const byte *ref, ulint col_len); |
| 135 |
|
| 136 |
/** Converts InnoDB geometry data format to MySQL data format. */ |
| 137 |
void row_mysql_store_geometry( |
| 138 |
byte *dest, /*!< in/out: where to store */ |
| 139 |
ulint dest_len, /*!< in: dest buffer size: determines into |
| 140 |
how many bytes the geometry length is stored, |
| 141 |
the space for the length may vary from 1 |
| 142 |
to 4 bytes */ |
| 143 |
const byte *src, /*!< in: geometry data; if the value to store |
| 144 |
is SQL NULL this should be NULL pointer */ |
| 145 |
ulint src_len); /*!< in: geometry length; if the value to store |
| 146 |
is SQL NULL this should be 0; remember |
| 147 |
also to set the NULL bit in the MySQL record |
| 148 |
header! */ |
| 149 |
|
| 150 |
/** Pad a column with spaces. |
| 151 |
@param[in] mbminlen Minimum size of a character, in bytes |
| 152 |
@param[out] pad Padded buffer |
| 153 |
@param[in] len Number of bytes to pad */ |
| 154 |
void row_mysql_pad_col(ulint mbminlen, byte *pad, ulint len); |
| 155 |
|
| 156 |
/** Stores a non-SQL-NULL field given in the MySQL format in the InnoDB format. |
| 157 |
The counterpart of this function is row_sel_field_store_in_mysql_format() in |
| 158 |
row0sel.cc. |
| 159 |
@return up to which byte we used buf in the conversion */ |
| 160 |
byte *row_mysql_store_col_in_innobase_format( |
| 161 |
dfield_t *dfield, /*!< in/out: dfield where dtype |
| 162 |
information must be already set when |
| 163 |
this function is called! */ |
| 164 |
byte *buf, /*!< in/out: buffer for a converted |
| 165 |
integer value; this must be at least |
| 166 |
col_len long then! NOTE that dfield |
| 167 |
may also get a pointer to 'buf', |
| 168 |
therefore do not discard this as long |
| 169 |
as dfield is used! */ |
| 170 |
bool row_format_col, /*!< true if the mysql_data is from |
| 171 |
a MySQL row, false if from a MySQL |
| 172 |
key value; |
| 173 |
in MySQL, a true VARCHAR storage |
| 174 |
format differs in a row and in a |
| 175 |
key value: in a key value the length |
| 176 |
is always stored in 2 bytes! */ |
| 177 |
const byte *mysql_data, /*!< in: MySQL column value, not |
| 178 |
SQL NULL; NOTE that dfield may also |
| 179 |
get a pointer to mysql_data, |
| 180 |
therefore do not discard this as long |
| 181 |
as dfield is used! */ |
| 182 |
ulint col_len, /*!< in: MySQL column length; NOTE that |
| 183 |
this is the storage length of the |
| 184 |
column in the MySQL format row, not |
| 185 |
necessarily the length of the actual |
| 186 |
payload data; if the column is a true |
| 187 |
VARCHAR then this is irrelevant */ |
| 188 |
ulint comp); /*!< in: nonzero=compact format */ |
| 189 |
/** Handles user errors and lock waits detected by the database engine. |
| 190 |
@return true if it was a lock wait and we should continue running the |
| 191 |
query thread */ |
| 192 |
bool row_mysql_handle_errors( |
| 193 |
dberr_t *new_err, /*!< out: possible new error encountered in |
| 194 |
rollback, or the old error which was |
| 195 |
during the function entry */ |
| 196 |
trx_t *trx, /*!< in: transaction */ |
| 197 |
que_thr_t *thr, /*!< in: query thread, or NULL */ |
| 198 |
trx_savept_t *savept); /*!< in: savepoint, or NULL */ |
| 199 |
/** Create a prebuilt struct for a MySQL table handle. |
| 200 |
@return own: a prebuilt struct */ |
| 201 |
row_prebuilt_t *row_create_prebuilt( |
| 202 |
dict_table_t *table, /*!< in: Innobase table handle */ |
| 203 |
ulint mysql_row_len); /*!< in: length in bytes of a row in |
| 204 |
the MySQL format */ |
| 205 |
|
| 206 |
/** Free a prebuilt struct for a MySQL table handle. |
| 207 |
@param[in,out] prebuilt Prebuilt struct |
| 208 |
@param[in] dict_locked True=data dictionary locked */ |
| 209 |
void row_prebuilt_free(row_prebuilt_t *prebuilt, bool dict_locked); |
| 210 |
|
| 211 |
/** Updates the transaction pointers in query graphs stored in the prebuilt |
| 212 |
struct. |
| 213 |
@param[in,out] prebuilt Prebuilt struct in MySQL handle. |
| 214 |
@param[in,out] trx Transaction handle. */ |
| 215 |
void row_update_prebuilt_trx(row_prebuilt_t *prebuilt, trx_t *trx); |
| 216 |
|
| 217 |
/** Sets an AUTO_INC type lock on the table mentioned in prebuilt. The |
| 218 |
AUTO_INC lock gives exclusive access to the auto-inc counter of the |
| 219 |
table. The lock is reserved only for the duration of an SQL statement. |
| 220 |
It is not compatible with another AUTO_INC or exclusive lock on the |
| 221 |
table. |
| 222 |
@return error code or DB_SUCCESS */ |
| 223 |
[[nodiscard]] dberr_t row_lock_table_autoinc_for_mysql( |
| 224 |
row_prebuilt_t *prebuilt); /*!< in: prebuilt struct in the MySQL |
| 225 |
table handle */ |
| 226 |
|
| 227 |
/** Sets a table lock on the table mentioned in prebuilt. |
| 228 |
@param[in,out] prebuilt table handle |
| 229 |
@return error code or DB_SUCCESS */ |
| 230 |
dberr_t row_lock_table(row_prebuilt_t *prebuilt); |
| 231 |
|
| 232 |
/** Does an insert for MySQL. |
| 233 |
@param[in] mysql_rec row in the MySQL format |
| 234 |
@param[in,out] prebuilt prebuilt struct in MySQL handle |
| 235 |
@return error code or DB_SUCCESS*/ |
| 236 |
[[nodiscard]] dberr_t row_insert_for_mysql(const byte *mysql_rec, |
| 237 |
row_prebuilt_t *prebuilt); |
| 238 |
|
| 239 |
/** Builds a dummy query graph used in selects. */ |
| 240 |
void row_prebuild_sel_graph(row_prebuilt_t *prebuilt); /*!< in: prebuilt struct |
| 241 |
in MySQL handle */ |
| 242 |
/** Gets pointer to a prebuilt update vector used in updates. If the update |
| 243 |
graph has not yet been built in the prebuilt struct, then this function |
| 244 |
first builds it. |
| 245 |
@return prebuilt update vector */ |
| 246 |
upd_t *row_get_prebuilt_update_vector( |
| 247 |
row_prebuilt_t *prebuilt); /*!< in: prebuilt struct in MySQL |
| 248 |
handle */ |
| 249 |
/** Checks if a table is such that we automatically created a clustered |
| 250 |
index on it (on row id). |
| 251 |
@return true if the clustered index was generated automatically */ |
| 252 |
bool row_table_got_default_clust_index( |
| 253 |
const dict_table_t *table); /*!< in: table */ |
| 254 |
|
| 255 |
/** Does an update or delete of a row for MySQL. |
| 256 |
@param[in] mysql_rec row in the MySQL format |
| 257 |
@param[in,out] prebuilt prebuilt struct in MySQL handle |
| 258 |
@return error code or DB_SUCCESS */ |
| 259 |
[[nodiscard]] dberr_t row_update_for_mysql(const byte *mysql_rec, |
| 260 |
row_prebuilt_t *prebuilt); |
| 261 |
|
| 262 |
/** Delete all rows for the given table by freeing/truncating indexes. |
| 263 |
@param[in,out] table table handler */ |
| 264 |
void row_delete_all_rows(dict_table_t *table); |
| 265 |
|
| 266 |
#endif /* !UNIV_HOTBACKUP */ |
| 267 |
|
| 268 |
/** Checks if a table name contains the string "/#sql" which denotes temporary |
| 269 |
tables in MySQL. |
| 270 |
@return true if temporary table */ |
| 271 |
[[nodiscard]] bool row_is_mysql_tmp_table_name(const char *name); |
| 272 |
/*!< in: table name in the form |
| 273 |
'database/tablename' */ |
| 274 |
|
| 275 |
#ifndef UNIV_HOTBACKUP |
| 276 |
/** Creates an query graph node of 'update' type to be used in the MySQL |
| 277 |
interface. |
| 278 |
@return own: update node */ |
| 279 |
upd_node_t *row_create_update_node_for_mysql( |
| 280 |
dict_table_t *table, /*!< in: table to update */ |
| 281 |
mem_heap_t *heap); /*!< in: mem heap from which allocated */ |
| 282 |
/** Does a cascaded delete or set null in a foreign key operation. |
| 283 |
@return error code or DB_SUCCESS */ |
| 284 |
[[nodiscard]] dberr_t row_update_cascade_for_mysql( |
| 285 |
que_thr_t *thr, /*!< in: query thread */ |
| 286 |
upd_node_t *node, /*!< in: update node used in the cascade |
| 287 |
or set null operation */ |
| 288 |
dict_table_t *table) /*!< in: table where we do the operation */ |
| 289 |
MY_ATTRIBUTE((nonnull)); |
| 290 |
|
| 291 |
/** Locks the data dictionary exclusively for performing a table create or other |
| 292 |
data dictionary modification operation. |
| 293 |
@param[in,out] trx Transaction |
| 294 |
@param[in] location Location */ |
| 295 |
void row_mysql_lock_data_dictionary(trx_t *trx, ut::Location location); |
| 296 |
|
| 297 |
/** Unlocks the data dictionary exclusive lock. */ |
| 298 |
void row_mysql_unlock_data_dictionary(trx_t *trx); /*!< in/out: transaction */ |
| 299 |
|
| 300 |
/** Locks the data dictionary in shared mode from modifications, for performing |
| 301 |
foreign key check, rollback, or other operation invisible to MySQL. |
| 302 |
@param[in,out] trx Transaction |
| 303 |
@param[in] location Location */ |
| 304 |
void row_mysql_freeze_data_dictionary(trx_t *trx, ut::Location location); |
| 305 |
|
| 306 |
/** Unlocks the data dictionary shared lock. */ |
| 307 |
void row_mysql_unfreeze_data_dictionary(trx_t *trx); /*!< in/out: transaction */ |
| 308 |
|
| 309 |
/** Creates a table for MySQL. On success the in-memory table could be |
| 310 |
kept in non-LRU list while on failure the 'table' object will be freed. |
| 311 |
@param[in,out] table table definition(will be freed, or on |
| 312 |
DB_SUCCESS added to the data dictionary cache) |
| 313 |
@param[in] compression compression algorithm to use, can be nullptr |
| 314 |
@param[in] create_info HA_CREATE_INFO object |
| 315 |
@param[in,out] trx transaction |
| 316 |
@param[in] heap temp memory heap or nullptr |
| 317 |
@return error code or DB_SUCCESS */ |
| 318 |
[[nodiscard]] dberr_t row_create_table_for_mysql( |
| 319 |
dict_table_t *&table, const char *compression, |
| 320 |
const HA_CREATE_INFO *create_info, trx_t *trx, mem_heap_t *heap); |
| 321 |
|
| 322 |
/** Does an index creation operation for MySQL. TODO: currently failure |
| 323 |
to create an index results in dropping the whole table! This is no problem |
| 324 |
currently as all indexes must be created at the same time as the table. |
| 325 |
@return error number or DB_SUCCESS */ |
| 326 |
[[nodiscard]] dberr_t row_create_index_for_mysql( |
| 327 |
dict_index_t *index, /*!< in, own: index definition |
| 328 |
(will be freed) */ |
| 329 |
trx_t *trx, /*!< in: transaction handle */ |
| 330 |
const ulint *field_lengths, /*!< in: if not NULL, must contain |
| 331 |
dict_index_get_n_fields(index) |
| 332 |
actual field lengths for the |
| 333 |
index columns, which are |
| 334 |
then checked for not being too |
| 335 |
large. */ |
| 336 |
dict_table_t *handler); /* ! in/out: table handler. */ |
| 337 |
|
| 338 |
/** Loads foreign key constraints for the table being created. This |
| 339 |
function should be called after the indexes for a table have been |
| 340 |
created. Each foreign key constraint must be accompanied with indexes |
| 341 |
in both participating tables. The indexes are allowed to contain more |
| 342 |
fields than mentioned in the constraint. |
| 343 |
|
| 344 |
@param[in] trx transaction |
| 345 |
@param[in] name table full name in normalized form |
| 346 |
@param[in] dd_table MySQL dd::Table for the table |
| 347 |
@return error code or DB_SUCCESS */ |
| 348 |
[[nodiscard]] dberr_t row_table_load_foreign_constraints( |
| 349 |
trx_t *trx, const char *name, const dd::Table *dd_table); |
| 350 |
|
| 351 |
/** The master thread in srv0srv.cc calls this regularly to drop tables which |
| 352 |
we must drop in background after queries to them have ended. Such lazy |
| 353 |
dropping of tables is needed in ALTER TABLE on Unix. |
| 354 |
@return how many tables dropped + remaining tables in list */ |
| 355 |
ulint row_drop_tables_for_mysql_in_background(void); |
| 356 |
|
| 357 |
/** Sets an exclusive lock on a table. |
| 358 |
@return error code or DB_SUCCESS */ |
| 359 |
[[nodiscard]] dberr_t row_mysql_lock_table( |
| 360 |
trx_t *trx, /*!< in/out: transaction */ |
| 361 |
dict_table_t *table, /*!< in: table to lock */ |
| 362 |
enum lock_mode mode, /*!< in: LOCK_X or LOCK_S */ |
| 363 |
const char *op_info); /*!< in: string for trx->op_info */ |
| 364 |
|
| 365 |
/** Drop a tablespace as part of dropping or renaming a table. |
| 366 |
This deletes the fil_space_t if found and the file on disk. |
| 367 |
@param[in] space_id Tablespace ID |
| 368 |
@param[in] filepath File path of tablespace to delete |
| 369 |
@return error code or DB_SUCCESS */ |
| 370 |
dberr_t row_drop_tablespace(space_id_t space_id, const char *filepath); |
| 371 |
|
| 372 |
/** Drop a table for MySQL. If the data dictionary was not already locked |
| 373 |
by the transaction, the transaction will be committed. Otherwise, the |
| 374 |
data dictionary will remain locked. |
| 375 |
@param[in] name Table name |
| 376 |
@param[in] trx Transaction handle |
| 377 |
@param[in] nonatomic Whether it is permitted to release |
| 378 |
and reacquire dict_operation_lock |
| 379 |
@param[in,out] handler Table handler or NULL |
| 380 |
@return error code or DB_SUCCESS */ |
| 381 |
dberr_t row_drop_table_for_mysql(const char *name, trx_t *trx, bool nonatomic, |
| 382 |
dict_table_t *handler = nullptr); |
| 383 |
/** Drop a table for MySQL. If the data dictionary was not already locked |
| 384 |
by the transaction, the transaction will be committed. Otherwise, the |
| 385 |
data dictionary will remain locked. |
| 386 |
@param[in] name table name |
| 387 |
@param[in,out] trx data dictionary transaction |
| 388 |
@return error code or DB_SUCCESS */ |
| 389 |
inline dberr_t row_drop_table_for_mysql(const char *name, trx_t *trx) { |
| 390 |
return (row_drop_table_for_mysql(name, trx, true, nullptr)); |
| 391 |
} |
| 392 |
|
| 393 |
/** Discards the tablespace of a table which stored in an .ibd file. Discarding |
| 394 |
means that this function deletes the .ibd file and assigns a new table id for |
| 395 |
the table. Also the flag table->ibd_file_missing is set true. |
| 396 |
@return error code or DB_SUCCESS */ |
| 397 |
[[nodiscard]] dberr_t row_discard_tablespace_for_mysql( |
| 398 |
const char *name, /*!< in: table name */ |
| 399 |
trx_t *trx); /*!< in: transaction handle */ |
| 400 |
|
| 401 |
/** Drop a database for MySQL. |
| 402 |
@param[in] name database name which ends at '/' |
| 403 |
@param[in] trx transaction handle |
| 404 |
@param[out] found number of dropped tables |
| 405 |
@return error code or DB_SUCCESS */ |
| 406 |
dberr_t row_drop_database_for_mysql(const char *name, trx_t *trx, ulint *found); |
| 407 |
|
| 408 |
/** Renames a table for MySQL. |
| 409 |
@param[in] old_name old table name |
| 410 |
@param[in] new_name new table name |
| 411 |
@param[in] dd_table dd::Table for new table |
| 412 |
@param[in,out] trx transaction |
| 413 |
@param[in] replay whether in replay stage |
| 414 |
@return error code or DB_SUCCESS */ |
| 415 |
[[nodiscard]] dberr_t row_rename_table_for_mysql(const char *old_name, |
| 416 |
const char *new_name, |
| 417 |
const dd::Table *dd_table, |
| 418 |
trx_t *trx, bool replay); |
| 419 |
|
| 420 |
/** Read the total number of records in a consistent view. |
| 421 |
@param[in,out] trx Covering transaction. |
| 422 |
@param[in] indexes Indexes to scan. |
| 423 |
@param[in] max_threads Maximum number of threads to use. |
| 424 |
@param[out] n_rows Number of rows seen. |
| 425 |
@return DB_SUCCESS or error code. */ |
| 426 |
dberr_t row_mysql_parallel_select_count_star( |
| 427 |
trx_t *trx, std::vector<dict_index_t *> &indexes, size_t max_threads, |
| 428 |
ulint *n_rows); |
| 429 |
|
| 430 |
/** Scans an index for either COUNT(*) or CHECK TABLE. |
| 431 |
If CHECK TABLE; Checks that the index contains entries in an ascending order, |
| 432 |
unique constraint is not broken, and calculates the number of index entries |
| 433 |
in the read view of the current transaction. |
| 434 |
@param[in,out] prebuilt Prebuilt struct in MySQL handle. |
| 435 |
@param[in,out] index Index to scan. |
| 436 |
@param[in] n_threads Number of threads to use for the scan |
| 437 |
@param[in] check_keys True if called form check table. |
| 438 |
@param[out] n_rows Number of entries seen in the consistent read. |
| 439 |
@return DB_SUCCESS or other error */ |
| 440 |
[[nodiscard]] dberr_t row_scan_index_for_mysql(row_prebuilt_t *prebuilt, |
| 441 |
dict_index_t *index, |
| 442 |
size_t n_threads, |
| 443 |
bool check_keys, ulint *n_rows); |
| 444 |
/** Initialize this module */ |
| 445 |
void row_mysql_init(void); |
| 446 |
|
| 447 |
/** Close this module */ |
| 448 |
void row_mysql_close(void); |
| 449 |
|
| 450 |
/* A struct describing a place for an individual column in the MySQL |
| 451 |
row format which is presented to the table handler in ha_innobase. |
| 452 |
This template struct is used to speed up row transformations between |
| 453 |
Innobase and MySQL. */ |
| 454 |
|
| 455 |
struct mysql_row_templ_t { |
| 456 |
ulint col_no; /*!< column number of the column */ |
| 457 |
ulint rec_field_no; /*!< field number of the column in an |
| 458 |
Innobase record in the current index; |
| 459 |
not defined if template_type is |
| 460 |
ROW_MYSQL_WHOLE_ROW */ |
| 461 |
ulint clust_rec_field_no; /*!< field number of the column in an |
| 462 |
Innobase record in the clustered index; |
| 463 |
not defined if template_type is |
| 464 |
ROW_MYSQL_WHOLE_ROW */ |
| 465 |
ulint icp_rec_field_no; /*!< field number of the column in an |
| 466 |
Innobase record in the current index; |
| 467 |
only defined for columns that could be |
| 468 |
used to evaluate a pushed down index |
| 469 |
condition and/or end-range condition */ |
| 470 |
ulint mysql_col_offset; /*!< offset of the column in the MySQL |
| 471 |
row format */ |
| 472 |
ulint mysql_col_len; /*!< length of the column in the MySQL |
| 473 |
row format */ |
| 474 |
ulint mysql_mvidx_len; /*!< index length on multi-value array */ |
| 475 |
ulint mysql_null_byte_offset; /*!< MySQL NULL bit byte offset in a |
| 476 |
MySQL record */ |
| 477 |
ulint mysql_null_bit_mask; /*!< bit mask to get the NULL bit, |
| 478 |
zero if column cannot be NULL */ |
| 479 |
ulint type; /*!< column type in Innobase mtype |
| 480 |
numbers DATA_CHAR... */ |
| 481 |
ulint mysql_type; /*!< MySQL type code; this is always |
| 482 |
< 256 */ |
| 483 |
ulint mysql_length_bytes; /*!< if mysql_type |
| 484 |
== DATA_MYSQL_TRUE_VARCHAR, this tells |
| 485 |
whether we should use 1 or 2 bytes to |
| 486 |
store the MySQL true VARCHAR data |
| 487 |
length at the start of row in the MySQL |
| 488 |
format (NOTE that the MySQL key value |
| 489 |
format always uses 2 bytes for the data |
| 490 |
len) */ |
| 491 |
ulint charset; /*!< MySQL charset-collation code |
| 492 |
of the column, or zero */ |
| 493 |
ulint mbminlen; /*!< minimum length of a char, in bytes, |
| 494 |
or zero if not a char type */ |
| 495 |
ulint mbmaxlen; /*!< maximum length of a char, in bytes, |
| 496 |
or zero if not a char type */ |
| 497 |
ulint is_unsigned; /*!< if a column type is an integer |
| 498 |
type and this field is != 0, then |
| 499 |
it is an unsigned integer type */ |
| 500 |
ulint is_virtual; /*!< if a column is a virtual column */ |
| 501 |
ulint is_multi_val; /*!< if a column is a Multi-Value Array virtual |
| 502 |
column */ |
| 503 |
}; |
| 504 |
|
| 505 |
constexpr uint32_t MYSQL_FETCH_CACHE_SIZE = 8; |
| 506 |
/* After fetching this many rows, we start caching them in fetch_cache */ |
| 507 |
constexpr uint32_t MYSQL_FETCH_CACHE_THRESHOLD = 4; |
| 508 |
|
| 509 |
constexpr uint32_t ROW_PREBUILT_ALLOCATED = 78540783; |
| 510 |
constexpr uint32_t ROW_PREBUILT_FREED = 26423527; |
| 511 |
|
| 512 |
/** A struct for (sometimes lazily) prebuilt structures in an Innobase table |
| 513 |
handle used within MySQL; these are used to save CPU time. */ |
| 514 |
|
| 515 |
struct row_prebuilt_t { |
| 516 |
ulint magic_n; /*!< this magic number is set to |
| 517 |
ROW_PREBUILT_ALLOCATED when created, |
| 518 |
or ROW_PREBUILT_FREED when the |
| 519 |
struct has been freed */ |
| 520 |
dict_table_t *table; /*!< Innobase table handle */ |
| 521 |
dict_index_t *index; /*!< current index for a search, if |
| 522 |
any */ |
| 523 |
trx_t *trx; /*!< current transaction handle */ |
| 524 |
unsigned sql_stat_start : 1; /*!< true when we start processing of |
| 525 |
an SQL statement: we may have to set |
| 526 |
an intention lock on the table, |
| 527 |
create a consistent read view etc. */ |
| 528 |
unsigned clust_index_was_generated : 1; |
| 529 |
/*!< if the user did not define a |
| 530 |
primary key in MySQL, then Innobase |
| 531 |
automatically generated a clustered |
| 532 |
index where the ordering column is |
| 533 |
the row id: in this case this flag |
| 534 |
is set to true */ |
| 535 |
unsigned index_usable : 1; /*!< caches the value of |
| 536 |
index->is_usable(trx) */ |
| 537 |
unsigned read_just_key : 1; /*!< set to 1 when MySQL calls |
| 538 |
ha_innobase::extra with the |
| 539 |
argument HA_EXTRA_KEYREAD; it is enough |
| 540 |
to read just columns defined in |
| 541 |
the index (i.e., no read of the |
| 542 |
clustered index record necessary) */ |
| 543 |
unsigned used_in_HANDLER : 1; /*!< true if we have been using this |
| 544 |
handle in a MySQL HANDLER low level |
| 545 |
index cursor command: then we must |
| 546 |
store the pcur position even in a |
| 547 |
unique search from a clustered index, |
| 548 |
because HANDLER allows NEXT and PREV |
| 549 |
in such a situation */ |
| 550 |
unsigned template_type : 2; /*!< ROW_MYSQL_WHOLE_ROW, |
| 551 |
ROW_MYSQL_REC_FIELDS, |
| 552 |
ROW_MYSQL_DUMMY_TEMPLATE, or |
| 553 |
ROW_MYSQL_NO_TEMPLATE */ |
| 554 |
unsigned n_template : 10; /*!< number of elements in the |
| 555 |
template */ |
| 556 |
unsigned null_bitmap_len : 10; /*!< number of bytes in the SQL NULL |
| 557 |
bitmap at the start of a row in the |
| 558 |
MySQL format */ |
| 559 |
unsigned need_to_access_clustered : 1; /*!< if we are fetching |
| 560 |
columns through a secondary index |
| 561 |
and at least one column is not in |
| 562 |
the secondary index, then this is |
| 563 |
set to true */ |
| 564 |
unsigned templ_contains_blob : 1; /*!< true if the template contains |
| 565 |
a column with DATA_LARGE_MTYPE( |
| 566 |
get_innobase_type_from_mysql_type()) |
| 567 |
is true; |
| 568 |
not to be confused with InnoDB |
| 569 |
externally stored columns |
| 570 |
(VARCHAR can be off-page too) */ |
| 571 |
unsigned templ_contains_fixed_point : 1; /*!< true if the |
| 572 |
template contains a column with |
| 573 |
DATA_POINT. Since InnoDB regards |
| 574 |
DATA_POINT as non-BLOB type, the |
| 575 |
templ_contains_blob can't tell us |
| 576 |
if there is DATA_POINT */ |
| 577 |
|
| 578 |
/** 1 if extra(HA_EXTRA_INSERT_WITH_UPDATE) was requested, which happens |
| 579 |
when ON DUPLICATE KEY UPDATE clause is present, 0 otherwise */ |
| 580 |
unsigned on_duplicate_key_update : 1; |
| 581 |
|
| 582 |
/** 1 if extra(HA_EXTRA_WRITE_CAN_REPLACE) was requested, which happen when |
| 583 |
REPLACE is done instead of regular INSERT, 0 otherwise */ |
| 584 |
unsigned replace : 1; |
| 585 |
|
| 586 |
/** template used to transform rows fast between MySQL and Innobase formats; |
| 587 |
memory for this template is not allocated from 'heap' */ |
| 588 |
mysql_row_templ_t *mysql_template; |
| 589 |
|
| 590 |
/** memory heap from which these auxiliary structures are allocated when |
| 591 |
needed */ |
| 592 |
mem_heap_t *heap; |
| 593 |
|
| 594 |
/** memory heap from which innodb_api_buf is allocated per session */ |
| 595 |
mem_heap_t *cursor_heap; |
| 596 |
|
| 597 |
/** Innobase SQL insert node used to perform inserts to the table */ |
| 598 |
ins_node_t *ins_node; |
| 599 |
|
| 600 |
/** buffer for storing data converted to the Innobase format from the MySQL |
| 601 |
format */ |
| 602 |
byte *ins_upd_rec_buff; |
| 603 |
|
| 604 |
/* buffer for converting data format for multi-value virtual columns */ |
| 605 |
multi_value_data *mv_data; |
| 606 |
const byte *default_rec; /*!< the default values of all columns |
| 607 |
(a "default row") in MySQL format */ |
| 608 |
ulint hint_need_to_fetch_extra_cols; |
| 609 |
/*!< normally this is set to 0; if this |
| 610 |
is set to ROW_RETRIEVE_PRIMARY_KEY, |
| 611 |
then we should at least retrieve all |
| 612 |
columns in the primary key; if this |
| 613 |
is set to ROW_RETRIEVE_ALL_COLS, then |
| 614 |
we must retrieve all columns in the |
| 615 |
key (if read_just_key == 1), or all |
| 616 |
columns in the table */ |
| 617 |
upd_node_t *upd_node; /*!< Innobase SQL update node used |
| 618 |
to perform updates and deletes */ |
| 619 |
trx_id_t trx_id; /*!< The table->def_trx_id when |
| 620 |
ins_graph was built */ |
| 621 |
que_fork_t *ins_graph; /*!< Innobase SQL query graph used |
| 622 |
in inserts. Will be rebuilt on |
| 623 |
trx_id or n_indexes mismatch. */ |
| 624 |
que_fork_t *upd_graph; /*!< Innobase SQL query graph used |
| 625 |
in updates or deletes */ |
| 626 |
btr_pcur_t *pcur; /*!< persistent cursor used in selects |
| 627 |
and updates */ |
| 628 |
btr_pcur_t *clust_pcur; /*!< persistent cursor used in |
| 629 |
some selects and updates */ |
| 630 |
que_fork_t *sel_graph; /*!< dummy query graph used in |
| 631 |
selects */ |
| 632 |
dtuple_t *search_tuple; /*!< prebuilt dtuple used in selects */ |
| 633 |
|
| 634 |
/** prebuilt dtuple used in selects where the end of range is known */ |
| 635 |
dtuple_t *m_stop_tuple; |
| 636 |
|
| 637 |
/** Set to true in row_search_mvcc when a row matching exactly the length and |
| 638 |
value of stop_tuple was found, so that the next iteration of row_search_mvcc |
| 639 |
knows it can simply return DB_RECORD_NOT_FOUND. If true, then for sure, at |
| 640 |
least one such matching row was seen. If false, it might be false negative, as |
| 641 |
not all control paths lead to setting this field to true in case a matching |
| 642 |
row is visited. */ |
| 643 |
bool m_stop_tuple_found; |
| 644 |
|
| 645 |
private: |
| 646 |
/** Set to true iff we are inside read_range_first() or read_range_next() */ |
| 647 |
bool m_is_reading_range; |
| 648 |
|
| 649 |
public: |
| 650 |
bool is_reading_range() const { return m_is_reading_range; } |
| 651 |
|
| 652 |
class row_is_reading_range_guard_t : private ut::bool_scope_guard_t { |
| 653 |
public: |
| 654 |
explicit row_is_reading_range_guard_t(row_prebuilt_t &prebuilt) |
| 655 |
: ut::bool_scope_guard_t(prebuilt.m_is_reading_range) {} |
| 656 |
}; |
| 657 |
|
| 658 |
row_is_reading_range_guard_t get_is_reading_range_guard() { |
| 659 |
/* We implement row_is_reading_range_guard_t as a simple bool_scope_guard_t |
| 660 |
because we trust that scopes are never nested and thus we don't need to |
| 661 |
count their "openings" and "closings", so we assert that.*/ |
| 662 |
ut_ad(!m_is_reading_range); |
| 663 |
return row_is_reading_range_guard_t(*this); |
| 664 |
} |
| 665 |
|
| 666 |
byte row_id[DATA_ROW_ID_LEN]; |
| 667 |
/*!< if the clustered index was |
| 668 |
generated, the row id of the |
| 669 |
last row fetched is stored |
| 670 |
here */ |
| 671 |
doc_id_t fts_doc_id; /* if the table has an FTS index on |
| 672 |
it then we fetch the doc_id. |
| 673 |
FTS-FIXME: Currently we fetch it always |
| 674 |
but in the future we must only fetch |
| 675 |
it when FTS columns are being |
| 676 |
updated */ |
| 677 |
dtuple_t *clust_ref; /*!< prebuilt dtuple used in |
| 678 |
sel/upd/del */ |
| 679 |
ulint select_lock_type; /*!< LOCK_NONE, LOCK_S, or LOCK_X */ |
| 680 |
enum select_mode select_mode; /*!< SELECT_ORDINARY, |
| 681 |
SELECT_SKIP_LOKCED, or SELECT_NO_WAIT */ |
| 682 |
ulint row_read_type; /*!< ROW_READ_WITH_LOCKS if row locks |
| 683 |
should be the obtained for records |
| 684 |
under an UPDATE or DELETE cursor. |
| 685 |
If trx_t::allow_semi_consistent() |
| 686 |
returns true, this can be set to |
| 687 |
ROW_READ_TRY_SEMI_CONSISTENT, so that |
| 688 |
if the row under an UPDATE or DELETE |
| 689 |
cursor was locked by another |
| 690 |
transaction, InnoDB will resort |
| 691 |
to reading the last committed value |
| 692 |
('semi-consistent read'). Then, |
| 693 |
this field will be set to |
| 694 |
ROW_READ_DID_SEMI_CONSISTENT to |
| 695 |
indicate that. If the row does not |
| 696 |
match the WHERE condition, MySQL will |
| 697 |
invoke handler::unlock_row() to |
| 698 |
clear the flag back to |
| 699 |
ROW_READ_TRY_SEMI_CONSISTENT and |
| 700 |
to simply skip the row. If |
| 701 |
the row matches, the next call to |
| 702 |
row_search_for_mysql() will lock |
| 703 |
the row. |
| 704 |
This eliminates lock waits in some |
| 705 |
cases; note that this breaks |
| 706 |
serializability. */ |
| 707 |
|
| 708 |
/** byte offset of the end of the last requested column*/ |
| 709 |
ulint mysql_prefix_len; |
| 710 |
|
| 711 |
/** length in bytes of a row in the MySQL format */ |
| 712 |
ulint mysql_row_len; |
| 713 |
|
| 714 |
/** number of rows fetched after positioning the current cursor */ |
| 715 |
ulint n_rows_fetched; |
| 716 |
|
| 717 |
/** ROW_SEL_NEXT or ROW_SEL_PREV */ |
| 718 |
ulint fetch_direction; |
| 719 |
|
| 720 |
byte *fetch_cache[MYSQL_FETCH_CACHE_SIZE]; |
| 721 |
/*!< a cache for fetched rows if we |
| 722 |
fetch many rows from the same cursor: |
| 723 |
it saves CPU time to fetch them in a |
| 724 |
batch; we reserve mysql_row_len |
| 725 |
bytes for each such row; these |
| 726 |
pointers point 4 bytes past the |
| 727 |
allocated mem buf start, because |
| 728 |
there is a 4 byte magic number at the |
| 729 |
start and at the end */ |
| 730 |
ulint fetch_cache_first; /*!< position of the first not yet |
| 731 |
fetched row in fetch_cache */ |
| 732 |
ulint n_fetch_cached; /*!< number of not yet fetched rows |
| 733 |
in fetch_cache */ |
| 734 |
mem_heap_t *blob_heap; /*!< in SELECTS BLOB fields are copied |
| 735 |
to this heap */ |
| 736 |
mem_heap_t *old_vers_heap; /*!< memory heap where a previous |
| 737 |
version is built in consistent read */ |
| 738 |
enum { |
| 739 |
LOCK_PCUR, |
| 740 |
LOCK_CLUST_PCUR, |
| 741 |
LOCK_COUNT, |
| 742 |
}; |
| 743 |
/** normally false; |
| 744 |
if session is using READ COMMITTED or READ UNCOMMITTED isolation level, set in |
| 745 |
row_search_for_mysql() if we set a new record lock on the secondary or |
| 746 |
clustered index; |
| 747 |
this is used in row_try_unlock() when releasing the lock under the cursor if |
| 748 |
we determine after retrieving the row that it does not need to be locked |
| 749 |
('mini-rollback') |
| 750 |
|
| 751 |
[LOCK_PCUR] corresponds to pcur, the first index we looked up |
| 752 |
(can be secondary or clustered!) |
| 753 |
|
| 754 |
[LOCK_CLUST_PCUR] corresponds to clust_pcur, which if used at all, is always |
| 755 |
the clustered index. |
| 756 |
|
| 757 |
The meaning of these booleans is: |
| 758 |
true = we've created a rec lock, which we might release as we "own" it |
| 759 |
false = we should not release any lock for this index as we either reused |
| 760 |
some existing lock, or there is some other reason, we should keep it |
| 761 |
*/ |
| 762 |
std::bitset<LOCK_COUNT> new_rec_lock; |
| 763 |
bool keep_other_fields_on_keyread; /*!< when using fetch |
| 764 |
cache with HA_EXTRA_KEYREAD, don't |
| 765 |
overwrite other fields in mysql row |
| 766 |
row buffer.*/ |
| 767 |
bool in_fts_query; /*!< Whether we are in a FTS query */ |
| 768 |
bool fts_doc_id_in_read_set; /*!< true if table has externally |
| 769 |
defined FTS_DOC_ID coulmn. */ |
| 770 |
/*----------------------*/ |
| 771 |
ulonglong autoinc_last_value; |
| 772 |
/*!< last value of AUTO-INC interval */ |
| 773 |
ulonglong autoinc_increment; /*!< The increment step of the auto |
| 774 |
increment column. Value must be |
| 775 |
greater than or equal to 1. Required to |
| 776 |
calculate the next value */ |
| 777 |
ulonglong autoinc_offset; /*!< The offset passed to |
| 778 |
get_auto_increment() by MySQL. Required |
| 779 |
to calculate the next value */ |
| 780 |
dberr_t autoinc_error; /*!< The actual error code encountered |
| 781 |
while trying to init or read the |
| 782 |
autoinc value from the table. We |
| 783 |
store it here so that we can return |
| 784 |
it to MySQL */ |
| 785 |
/*----------------------*/ |
| 786 |
bool idx_cond; /*!< True if index condition pushdown |
| 787 |
is used, false otherwise. */ |
| 788 |
ulint idx_cond_n_cols; /*!< Number of fields in idx_cond_cols. |
| 789 |
0 if and only if idx_cond == false. */ |
| 790 |
/*----------------------*/ |
| 791 |
unsigned innodb_api : 1; /*!< whether this is a InnoDB API |
| 792 |
query */ |
| 793 |
const rec_t *innodb_api_rec; /*!< InnoDB API search result */ |
| 794 |
void *innodb_api_buf; /*!< Buffer holding copy of the physical |
| 795 |
Innodb API search record */ |
| 796 |
ulint innodb_api_rec_size; /*!< Size of the Innodb API record */ |
| 797 |
/*----------------------*/ |
| 798 |
|
| 799 |
/*----------------------*/ |
| 800 |
rtr_info_t *rtr_info; /*!< R-tree Search Info */ |
| 801 |
/*----------------------*/ |
| 802 |
|
| 803 |
ulint magic_n2; /*!< this should be the same as |
| 804 |
magic_n */ |
| 805 |
|
| 806 |
bool ins_sel_stmt; /*!< if true then ins_sel_statement. */ |
| 807 |
|
| 808 |
innodb_session_t *session; /*!< InnoDB session handler. */ |
| 809 |
byte *srch_key_val1; /*!< buffer used in converting |
| 810 |
search key values from MySQL format |
| 811 |
to InnoDB format.*/ |
| 812 |
byte *srch_key_val2; /*!< buffer used in converting |
| 813 |
search key values from MySQL format |
| 814 |
to InnoDB format.*/ |
| 815 |
uint srch_key_val_len; /*!< Size of search key */ |
| 816 |
/** Disable prefetch. */ |
| 817 |
bool m_no_prefetch; |
| 818 |
|
| 819 |
/** true, if server has called ha_extra(HA_EXTRA_NO_READ_LOCKING) */ |
| 820 |
bool no_read_locking; |
| 821 |
|
| 822 |
/** true, if we were asked to skip AUTOINC locking for the table. */ |
| 823 |
bool no_autoinc_locking; |
| 824 |
|
| 825 |
/** Return materialized key for secondary index scan */ |
| 826 |
bool m_read_virtual_key; |
| 827 |
|
| 828 |
/** Whether this is a temporary(intrinsic) table read to keep the position |
| 829 |
for this MySQL TABLE object */ |
| 830 |
bool m_temp_read_shared; |
| 831 |
|
| 832 |
/** Whether tree modifying operation happened on a temporary (intrinsic) |
| 833 |
table index tree. In this case, it could be split, but no shrink. */ |
| 834 |
bool m_temp_tree_modified; |
| 835 |
|
| 836 |
/** The MySQL table object */ |
| 837 |
TABLE *m_mysql_table; |
| 838 |
|
| 839 |
/** The MySQL handler object. */ |
| 840 |
ha_innobase *m_mysql_handler; |
| 841 |
|
| 842 |
/** limit value to avoid fts result overflow */ |
| 843 |
ulonglong m_fts_limit; |
| 844 |
|
| 845 |
/** True if exceeded the end_range while filling the prefetch cache. */ |
| 846 |
bool m_end_range; |
| 847 |
|
| 848 |
/** Undo information for LOB mvcc */ |
| 849 |
lob::undo_vers_t m_lob_undo; |
| 850 |
|
| 851 |
lob::undo_vers_t *get_lob_undo() { return (&m_lob_undo); } |
| 852 |
|
| 853 |
void lob_undo_reset() { m_lob_undo.reset(); } |
| 854 |
|
| 855 |
/** Can a record buffer or a prefetch cache be utilized for prefetching |
| 856 |
records in this scan? |
| 857 |
@retval true if records can be prefetched |
| 858 |
@retval false if records cannot be prefetched */ |
| 859 |
bool can_prefetch_records() const; |
| 860 |
|
| 861 |
/** Determines if the query is REPLACE or ON DUPLICATE KEY UPDATE in which |
| 862 |
case duplicate values should be allowed (and further processed) instead of |
| 863 |
causing an error. |
| 864 |
@return true iff duplicated values should be allowed */ |
| 865 |
bool allow_duplicates() { return (replace || on_duplicate_key_update); } |
| 866 |
|
| 867 |
/** This is an no-op unless trx is using a READ COMMITTED or READ UNCOMMITTED |
| 868 |
isolation level. |
| 869 |
Before calling this function row_search_for_mysql() must have stored to |
| 870 |
new_rec_locks[] the information which new record locks really were set. |
| 871 |
This function removes a newly set index record locks under pcur or clust_pcur. |
| 872 |
Thus, this implements a 'mini-rollback' that releases the latest index record |
| 873 |
locks we've just set. |
| 874 |
|
| 875 |
@param[in] has_latches_on_recs true if called so that we have the |
| 876 |
latches on the records under pcur |
| 877 |
and clust_pcur, and we do not need |
| 878 |
to reposition the cursors. */ |
| 879 |
void try_unlock(bool has_latches_on_recs); |
| 880 |
|
| 881 |
private: |
| 882 |
/** A helper function for init_search_tuples_types() which prepares the shape |
| 883 |
of the tuple to match the index |
| 884 |
@param[in] tuple this->search_tuple or this->m_stop_tuple */ |
| 885 |
void init_tuple_types(dtuple_t *tuple) { |
| 886 |
dtuple_set_n_fields(tuple, index->n_fields); |
| 887 |
dict_index_copy_types(tuple, index, index->n_fields); |
| 888 |
} |
| 889 |
|
| 890 |
public: |
| 891 |
/** Counts how many elements of @see new_rec_lock[] array are set to true. */ |
| 892 |
size_t new_rec_locks_count() const { return new_rec_lock.count(); } |
| 893 |
|
| 894 |
/** Initializes search_tuple and m_stop_tuple shape so they match the index */ |
| 895 |
void init_search_tuples_types() { |
| 896 |
init_tuple_types(search_tuple); |
| 897 |
init_tuple_types(m_stop_tuple); |
| 898 |
} |
| 899 |
|
| 900 |
/** Resets both search_tuple and m_stop_tuple */ |
| 901 |
void clear_search_tuples() { |
| 902 |
dtuple_set_n_fields(search_tuple, 0); |
| 903 |
dtuple_set_n_fields(m_stop_tuple, 0); |
| 904 |
} |
| 905 |
|
| 906 |
/** Inside this function perform activity that needs to be done at the |
| 907 |
end of statement. */ |
| 908 |
void end_stmt(); |
| 909 |
|
| 910 |
/** @return true iff the operation can skip concurrency ticket. */ |
| 911 |
bool skip_concurrency_ticket() const; |
| 912 |
|
| 913 |
/** It is unsafe to copy this struct, and moving it would be non-trivial, |
| 914 |
because we want to keep in sync with row_is_reading_range_guard_t. Therefore |
| 915 |
it is much safer/easier to just forbid such operations. */ |
| 916 |
row_prebuilt_t(row_prebuilt_t const &) = delete; |
| 917 |
row_prebuilt_t &operator=(row_prebuilt_t const &) = delete; |
| 918 |
row_prebuilt_t &operator=(row_prebuilt_t &&) = delete; |
| 919 |
row_prebuilt_t(row_prebuilt_t &&) = delete; |
| 920 |
}; |
| 921 |
|
| 922 |
/** Callback for row_mysql_sys_index_iterate() */ |
| 923 |
struct SysIndexCallback { |
| 924 |
virtual ~SysIndexCallback() = default; |
| 925 |
|
| 926 |
/** Callback method |
| 927 |
@param mtr current mini-transaction |
| 928 |
@param pcur persistent cursor. */ |
| 929 |
virtual void operator()(mtr_t *mtr, btr_pcur_t *pcur) noexcept = 0; |
| 930 |
}; |
| 931 |
|
| 932 |
/** Get the computed value by supplying the base column values. |
| 933 |
@param[in,out] row the data row |
| 934 |
@param[in] col virtual column |
| 935 |
@param[in] table the table on which the virtual column is |
| 936 |
defined |
| 937 |
@param[in,out] local_heap heap memory for processing large data etc. |
| 938 |
@param[in,out] heap memory heap that copies the actual index row |
| 939 |
@param[in] thd MySQL thread handle |
| 940 |
@param[in,out] mysql_table mysql table object |
| 941 |
@param[in] ifield metadata for secondary index field into which |
| 942 |
the computed value is to be materialized, |
| 943 |
nullptr if not applicable |
| 944 |
@param[in] old_table during ALTER TABLE, this is the old table |
| 945 |
or nullptr. |
| 946 |
@param[in] row_update update vector for the row, supersedes row |
| 947 |
values |
| 948 |
@return the field filled with computed value, or nullptr on failure */ |
| 949 |
dfield_t *innobase_get_computed_value( |
| 950 |
const dtuple_t *row, const dict_v_col_t *col, const dict_table_t *table, |
| 951 |
mem_heap_t **local_heap, mem_heap_t *heap, THD *thd, TABLE *mysql_table, |
| 952 |
const dict_field_t *ifield = nullptr, |
| 953 |
const dict_table_t *old_table = nullptr, upd_t *row_update = nullptr); |
| 954 |
|
| 955 |
/** Parse out multi-values from a MySQL record |
| 956 |
@param[in] mysql_table MySQL table structure |
| 957 |
@param[in] f_idx field index of the multi-value column |
| 958 |
@param[in,out] dfield field structure to store parsed multi-value |
| 959 |
@param[in,out] value nullptr or the multi-value structure |
| 960 |
to store the parsed values |
| 961 |
@param[in] old_val old value if exists |
| 962 |
@param[in] comp true if InnoDB table uses compact row format |
| 963 |
@param[in,out] heap memory heap */ |
| 964 |
void innobase_get_multi_value(const TABLE *mysql_table, ulint f_idx, |
| 965 |
dfield_t *dfield, multi_value_data *value, |
| 966 |
uint old_val, ulint comp, mem_heap_t *heap); |
| 967 |
|
| 968 |
/** Get the computed value by supplying the base column values. |
| 969 |
@param[in,out] table the table whose virtual column template to be built */ |
| 970 |
void innobase_init_vc_templ(dict_table_t *table); |
| 971 |
|
| 972 |
/** Change dbname and table name in table->vc_templ. |
| 973 |
@param[in,out] table the table whose virtual column template |
| 974 |
dbname and tbname to be renamed. */ |
| 975 |
void innobase_rename_vc_templ(dict_table_t *table); |
| 976 |
|
| 977 |
constexpr uint32_t ROW_PREBUILT_FETCH_MAGIC_N = 465765687; |
| 978 |
|
| 979 |
constexpr uint32_t ROW_MYSQL_WHOLE_ROW = 0; |
| 980 |
constexpr uint32_t ROW_MYSQL_REC_FIELDS = 1; |
| 981 |
constexpr uint32_t ROW_MYSQL_NO_TEMPLATE = 2; |
| 982 |
/** dummy template used in row_scan_and_check_index */ |
| 983 |
constexpr uint32_t ROW_MYSQL_DUMMY_TEMPLATE = 3; |
| 984 |
|
| 985 |
/* Values for hint_need_to_fetch_extra_cols */ |
| 986 |
constexpr uint32_t ROW_RETRIEVE_PRIMARY_KEY = 1; |
| 987 |
constexpr uint32_t ROW_RETRIEVE_ALL_COLS = 2; |
| 988 |
|
| 989 |
/* Values for row_read_type */ |
| 990 |
constexpr uint32_t ROW_READ_WITH_LOCKS = 0; |
| 991 |
constexpr uint32_t ROW_READ_TRY_SEMI_CONSISTENT = 1; |
| 992 |
constexpr uint32_t ROW_READ_DID_SEMI_CONSISTENT = 2; |
| 993 |
|
| 994 |
#ifdef UNIV_DEBUG |
| 995 |
/** Wait for the background drop list to become empty. */ |
| 996 |
void row_wait_for_background_drop_list_empty(); |
| 997 |
#endif /* UNIV_DEBUG */ |
| 998 |
#endif /* !UNIV_HOTBACKUP */ |
| 999 |
|
| 1000 |
#endif /* row0mysql.h */ |