| 1 |
/***************************************************************************** |
| 2 |
|
| 3 |
Copyright (c) 2014, 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 |
/* The InnoDB Partition handler: the interface between MySQL and InnoDB. */ |
| 29 |
|
| 30 |
#ifndef ha_innopart_h |
| 31 |
#define ha_innopart_h |
| 32 |
|
| 33 |
#include <stddef.h> |
| 34 |
#include <sys/types.h> |
| 35 |
|
| 36 |
#include "ha_innodb.h" |
| 37 |
#include "my_compiler.h" |
| 38 |
#include "partitioning/partition_handler.h" |
| 39 |
#include "row0mysql.h" |
| 40 |
#include "ut0bitset.h" |
| 41 |
|
| 42 |
/* Forward declarations */ |
| 43 |
class Altered_partitions; |
| 44 |
class partition_info; |
| 45 |
|
| 46 |
/* Error Text */ |
| 47 |
static constexpr auto PARTITION_IN_SHARED_TABLESPACE = |
| 48 |
"InnoDB : A partitioned table" |
| 49 |
" is not allowed in a shared tablespace."; |
| 50 |
|
| 51 |
/** HA_DUPLICATE_POS and HA_READ_BEFORE_WRITE_REMOVAL is not |
| 52 |
set from ha_innobase, but cannot yet be supported in ha_innopart. |
| 53 |
Full text and geometry is not yet supported. */ |
| 54 |
const handler::Table_flags HA_INNOPART_DISABLED_TABLE_FLAGS = |
| 55 |
(HA_CAN_FULLTEXT | HA_CAN_FULLTEXT_EXT | HA_CAN_GEOMETRY | |
| 56 |
HA_DUPLICATE_POS | HA_READ_BEFORE_WRITE_REMOVAL); |
| 57 |
|
| 58 |
typedef Bitset<> Sql_stat_start_parts; |
| 59 |
|
| 60 |
/** InnoDB partition specific Handler_share. */ |
| 61 |
class Ha_innopart_share : public Partition_share { |
| 62 |
private: |
| 63 |
/** Array of all included table definitions (one per partition). */ |
| 64 |
dict_table_t **m_table_parts; |
| 65 |
|
| 66 |
/** Instead of INNOBASE_SHARE::idx_trans_tbl. Maps MySQL index number |
| 67 |
to InnoDB index per partition. */ |
| 68 |
dict_index_t **m_index_mapping; |
| 69 |
|
| 70 |
/** Total number of partitions. */ |
| 71 |
uint m_tot_parts; |
| 72 |
|
| 73 |
/** Number of indexes. */ |
| 74 |
uint m_index_count; |
| 75 |
|
| 76 |
/** Reference count. */ |
| 77 |
uint m_ref_count; |
| 78 |
|
| 79 |
/** Pointer back to owning TABLE_SHARE. */ |
| 80 |
TABLE_SHARE *m_table_share; |
| 81 |
|
| 82 |
public: |
| 83 |
Ha_innopart_share(TABLE_SHARE *table_share); |
| 84 |
|
| 85 |
~Ha_innopart_share() override; |
| 86 |
|
| 87 |
/** Set innodb table for given partition. |
| 88 |
@param[in] part_id Partition number. |
| 89 |
@param[in] table Table. */ |
| 90 |
inline void set_table_part(uint part_id, dict_table_t *table) { |
| 91 |
ut_ad(m_table_parts != nullptr); |
| 92 |
ut_ad(part_id < m_tot_parts); |
| 93 |
m_table_parts[part_id] = table; |
| 94 |
} |
| 95 |
/** Get table reference for given partition. |
| 96 |
@param[in] part_id Partition number |
| 97 |
@return InnoDB table reference. */ |
| 98 |
inline dict_table_t **get_table_part_ref(uint part_id) { |
| 99 |
return (&m_table_parts[part_id]); |
| 100 |
} |
| 101 |
|
| 102 |
/** Return innodb table for given partition. |
| 103 |
@param[in] part_id Partition number. |
| 104 |
@return InnoDB table. */ |
| 105 |
inline dict_table_t *get_table_part(uint part_id) const { |
| 106 |
ut_ad(m_table_parts != nullptr); |
| 107 |
ut_ad(part_id < m_tot_parts); |
| 108 |
return (m_table_parts[part_id]); |
| 109 |
} |
| 110 |
|
| 111 |
/** Return innodb index for given partition and key number. |
| 112 |
@param[in] part_id Partition number. |
| 113 |
@param[in] keynr Key number. |
| 114 |
@return InnoDB index. */ |
| 115 |
dict_index_t *get_index(uint part_id, uint keynr); |
| 116 |
|
| 117 |
/** Get MySQL key number corresponding to InnoDB index. |
| 118 |
Calculates the key number used inside MySQL for an Innobase index. We will |
| 119 |
first check the "index translation table" for a match of the index to get |
| 120 |
the index number. If there does not exist an "index translation table", |
| 121 |
or not able to find the index in the translation table, then we will fall back |
| 122 |
to the traditional way of looping through dict_index_t list to find a |
| 123 |
match. In this case, we have to take into account if we generated a |
| 124 |
default clustered index for the table |
| 125 |
@param[in] part_id Partition the index belongs to. |
| 126 |
@param[in] index Index to return MySQL key number for. |
| 127 |
@return the key number used inside MySQL or UINT_MAX if key is not |
| 128 |
found. */ |
| 129 |
uint get_mysql_key(uint part_id, const dict_index_t *index); |
| 130 |
|
| 131 |
/** Return whether share has opened InnoDB tables for partitions. */ |
| 132 |
bool has_table_parts() const { return (m_table_parts != nullptr); } |
| 133 |
|
| 134 |
/** Increment share and InnoDB tables reference counters. */ |
| 135 |
void increment_ref_counts(); |
| 136 |
|
| 137 |
/** Open InnoDB tables for partitions and return them as array. |
| 138 |
@param[in,out] thd Thread context |
| 139 |
@param[in] table MySQL table definition |
| 140 |
@param[in] dd_table Global DD table object |
| 141 |
@param[in] part_info Partition info (partition names to use) |
| 142 |
@param[in] table_name Table name (db/table_name) |
| 143 |
@return Array on InnoDB tables on success else nullptr. */ |
| 144 |
static dict_table_t **open_table_parts(THD *thd, const TABLE *table, |
| 145 |
const dd::Table *dd_table, |
| 146 |
partition_info *part_info, |
| 147 |
const char *table_name); |
| 148 |
|
| 149 |
/** Initialize the share with table and indexes per partition. |
| 150 |
@param[in] part_info Partition info (partition names to use). |
| 151 |
@param[in] table_parts Array of InnoDB tables for partitions. |
| 152 |
@return false on success else true. */ |
| 153 |
bool set_table_parts_and_indexes(partition_info *part_info, |
| 154 |
dict_table_t **table_parts); |
| 155 |
|
| 156 |
/** Close the table partitions. |
| 157 |
If all instances are closed, also release the resources.*/ |
| 158 |
void close_table_parts(); |
| 159 |
|
| 160 |
/** Close InnoDB tables for partitions. |
| 161 |
@param[in] table_parts Array of InnoDB tables for partitions. |
| 162 |
@param[in] tot_parts Number of partitions. */ |
| 163 |
static void close_table_parts(dict_table_t **table_parts, uint tot_parts); |
| 164 |
|
| 165 |
/** @return the TABLE SHARE object */ |
| 166 |
const TABLE_SHARE *get_table_share() const { return (m_table_share); } |
| 167 |
|
| 168 |
/** Get the number of partitions |
| 169 |
@return number of partitions */ |
| 170 |
uint get_num_parts() const { |
| 171 |
ut_ad(m_tot_parts != 0); |
| 172 |
return (m_tot_parts); |
| 173 |
} |
| 174 |
|
| 175 |
/** Set up the virtual column template for partition table, and points |
| 176 |
all m_table_parts[]->vc_templ to it. |
| 177 |
@param[in] table MySQL TABLE object |
| 178 |
@param[in] ib_table InnoDB dict_table_t |
| 179 |
@param[in] name Table name (db/table_name) */ |
| 180 |
void set_v_templ(TABLE *table, dict_table_t *ib_table, const char *name); |
| 181 |
|
| 182 |
private: |
| 183 |
/** Disable default constructor. */ |
| 184 |
Ha_innopart_share() = default; |
| 185 |
|
| 186 |
/** Open one partition |
| 187 |
@param[in,out] client Data dictionary client |
| 188 |
@param[in] thd Thread THD |
| 189 |
@param[in] table MySQL table definition |
| 190 |
@param[in] dd_part dd::Partition |
| 191 |
@param[in] part_name Table name of this partition |
| 192 |
@param[out] part_dict_table InnoDB table for partition |
| 193 |
@retval false On success |
| 194 |
@retval true On failure */ |
| 195 |
static bool open_one_table_part(dd::cache::Dictionary_client *client, |
| 196 |
THD *thd, const TABLE *table, |
| 197 |
const dd::Partition *dd_part, |
| 198 |
const char *part_name, |
| 199 |
dict_table_t **part_dict_table); |
| 200 |
}; |
| 201 |
|
| 202 |
/** Get explicit specified tablespace for one (sub)partition, checking |
| 203 |
from lowest level |
| 204 |
@param[in] tablespace table-level tablespace if specified |
| 205 |
@param[in] part Partition to check |
| 206 |
@param[in] sub_part Sub-partition to check, if no, just NULL |
| 207 |
@return Tablespace name, if nullptr or [0] = '\0' then nothing specified */ |
| 208 |
const char *partition_get_tablespace(const char *tablespace, |
| 209 |
const partition_element *part, |
| 210 |
const partition_element *sub_part); |
| 211 |
|
| 212 |
/** The class defining a partitioning aware handle to an InnoDB table. |
| 213 |
Based on ha_innobase and extended with |
| 214 |
- Partition_helper for re-using common partitioning functionality |
| 215 |
- Partition_handler for providing partitioning specific api calls. |
| 216 |
Generic partitioning functions are implemented in Partition_helper. |
| 217 |
Lower level storage functions are implemented in ha_innobase. |
| 218 |
Partition_handler is inherited for implementing the handler level interface |
| 219 |
for partitioning specific functions, like truncate_partition. |
| 220 |
InnoDB specific functions related to partitioning is implemented here. */ |
| 221 |
class ha_innopart : public ha_innobase, |
| 222 |
public Partition_helper, |
| 223 |
public Partition_handler { |
| 224 |
public: |
| 225 |
ha_innopart(handlerton *hton, TABLE_SHARE *table_arg); |
| 226 |
|
| 227 |
~ha_innopart() override = default; |
| 228 |
|
| 229 |
/** Clone this handler, used when needing more than one cursor |
| 230 |
to the same table. |
| 231 |
@param[in] name Table name. |
| 232 |
@param[in] mem_root mem_root to allocate from. |
| 233 |
@retval Pointer to clone or NULL if error. */ |
| 234 |
handler *clone(const char *name, MEM_ROOT *mem_root) override; |
| 235 |
|
| 236 |
/** \defgroup ONLINE_ALTER_TABLE_INTERFACE On-line ALTER TABLE interface |
| 237 |
@see handler0alter.cc |
| 238 |
@{ */ |
| 239 |
|
| 240 |
/** Check if InnoDB supports a particular alter table in-place. |
| 241 |
@param[in] altered_table TABLE object for new version of table. |
| 242 |
@param[in,out] ha_alter_info Structure describing changes to be done |
| 243 |
by ALTER TABLE and holding data used during in-place alter. |
| 244 |
@retval HA_ALTER_INPLACE_NOT_SUPPORTED Not supported |
| 245 |
@retval HA_ALTER_INPLACE_NO_LOCK Supported |
| 246 |
@retval HA_ALTER_INPLACE_SHARED_LOCK_AFTER_PREPARE Supported, but |
| 247 |
requires lock during main phase and exclusive lock during prepare |
| 248 |
phase. |
| 249 |
@retval HA_ALTER_INPLACE_NO_LOCK_AFTER_PREPARE Supported, prepare |
| 250 |
phase requires exclusive lock. */ |
| 251 |
enum_alter_inplace_result check_if_supported_inplace_alter( |
| 252 |
TABLE *altered_table, Alter_inplace_info *ha_alter_info) override; |
| 253 |
|
| 254 |
/** Prepare in-place ALTER for table. |
| 255 |
Allows InnoDB to update internal structures with concurrent |
| 256 |
writes blocked (provided that check_if_supported_inplace_alter() |
| 257 |
did not return HA_ALTER_INPLACE_NO_LOCK). |
| 258 |
This will be invoked before inplace_alter_table(). |
| 259 |
@param[in] altered_table TABLE object for new version of table. |
| 260 |
@param[in,out] ha_alter_info Structure describing changes to be done |
| 261 |
by ALTER TABLE and holding data used during in-place alter. |
| 262 |
@param[in] old_table_def dd::Table object describing old |
| 263 |
version of the table. |
| 264 |
@param[in,out] new_table_def dd::Table object for the new version |
| 265 |
of the table. Can be adjusted by this call. Changes to the table |
| 266 |
definition will be persisted in the data-dictionary at statement |
| 267 |
commit time. |
| 268 |
@retval true Failure. |
| 269 |
@retval false Success. */ |
| 270 |
bool prepare_inplace_alter_table(TABLE *altered_table, |
| 271 |
Alter_inplace_info *ha_alter_info, |
| 272 |
const dd::Table *old_table_def, |
| 273 |
dd::Table *new_table_def) override; |
| 274 |
|
| 275 |
/** Alter the table structure in-place. |
| 276 |
Alter the table structure in-place with operations |
| 277 |
specified using HA_ALTER_FLAGS and Alter_inplace_information. |
| 278 |
The level of concurrency allowed during this operation depends |
| 279 |
on the return value from check_if_supported_inplace_alter(). |
| 280 |
@param[in] altered_table TABLE object for new version of table. |
| 281 |
@param[in,out] ha_alter_info Structure describing changes to be done |
| 282 |
by ALTER TABLE and holding data used during in-place alter. |
| 283 |
@param[in] old_table_def dd::Table object describing old |
| 284 |
version of the table. |
| 285 |
@param[in,out] new_table_def dd::Table object for the new version |
| 286 |
of the table. Can be adjusted by this call. Changes to the table |
| 287 |
definition will be persisted in the data-dictionary at statement |
| 288 |
commit time. |
| 289 |
@retval true Failure. |
| 290 |
@retval false Success. */ |
| 291 |
bool inplace_alter_table(TABLE *altered_table, |
| 292 |
Alter_inplace_info *ha_alter_info, |
| 293 |
const dd::Table *old_table_def, |
| 294 |
dd::Table *new_table_def) override; |
| 295 |
|
| 296 |
/** Commit or rollback. |
| 297 |
Commit or rollback the changes made during |
| 298 |
prepare_inplace_alter_table() and inplace_alter_table() inside |
| 299 |
the storage engine. Note that the allowed level of concurrency |
| 300 |
during this operation will be the same as for |
| 301 |
inplace_alter_table() and thus might be higher than during |
| 302 |
prepare_inplace_alter_table(). (E.g concurrent writes were |
| 303 |
blocked during prepare, but might not be during commit). |
| 304 |
@param[in] altered_table TABLE object for new version of table. |
| 305 |
@param[in,out] ha_alter_info Structure describing changes to be done |
| 306 |
by ALTER TABLE and holding data used during |
| 307 |
in-place alter. |
| 308 |
@param[in] commit true => Commit, false => Rollback. |
| 309 |
@param[in] old_table_def dd::Table object describing old |
| 310 |
version of the table. |
| 311 |
@param[in,out] new_table_def dd::Table object for the new version |
| 312 |
of the table. Can be adjusted by this call. Changes to the table |
| 313 |
definition will be persisted in the data-dictionary at statement |
| 314 |
commit time. |
| 315 |
@retval true Failure. |
| 316 |
@retval false Success. */ |
| 317 |
bool commit_inplace_alter_table(TABLE *altered_table, |
| 318 |
Alter_inplace_info *ha_alter_info, |
| 319 |
bool commit, const dd::Table *old_table_def, |
| 320 |
dd::Table *new_table_def) override; |
| 321 |
/** @} */ |
| 322 |
|
| 323 |
/** Allows InnoDB to update internal structures with concurrent |
| 324 |
writes blocked (given that check_if_supported_inplace_alter() |
| 325 |
did not return HA_ALTER_INPLACE_NO_LOCK). |
| 326 |
This is for 'ALTER TABLE ... PARTITION' and a corresponding function |
| 327 |
to inplace_alter_table(). |
| 328 |
This will be invoked before inplace_alter_partition(). |
| 329 |
|
| 330 |
@param[in,out] altered_table TABLE object for new version of table |
| 331 |
@param[in,out] ha_alter_info Structure describing changes to be done |
| 332 |
by ALTER TABLE and holding data used during |
| 333 |
in-place alter. |
| 334 |
@param[in] old_dd_tab Table definition before the ALTER |
| 335 |
@param[in,out] new_dd_tab Table definition after the ALTER |
| 336 |
@retval true Failure |
| 337 |
@retval false Success */ |
| 338 |
bool prepare_inplace_alter_partition(TABLE *altered_table, |
| 339 |
Alter_inplace_info *ha_alter_info, |
| 340 |
const dd::Table *old_dd_tab, |
| 341 |
dd::Table *new_dd_tab); |
| 342 |
|
| 343 |
/** Alter the table structure in-place with operations |
| 344 |
specified using HA_ALTER_FLAGS and Alter_inplace_information. |
| 345 |
This is for 'ALTER TABLE ... PARTITION' and a corresponding function |
| 346 |
to inplace_alter_table(). |
| 347 |
The level of concurrency allowed during this operation depends |
| 348 |
on the return value from check_if_supported_inplace_alter(). |
| 349 |
|
| 350 |
@param[in,out] ha_alter_info Structure describing changes to be done |
| 351 |
by ALTER TABLE and holding data used |
| 352 |
during in-place alter. |
| 353 |
@retval true Failure |
| 354 |
@retval false Success */ |
| 355 |
bool inplace_alter_partition(Alter_inplace_info *ha_alter_info); |
| 356 |
|
| 357 |
/** Prepare to commit or roll back ALTER TABLE...ALGORITHM=INPLACE. |
| 358 |
This is for 'ALTER TABLE ... PARTITION' and a corresponding function |
| 359 |
to commit_inplace_alter_table(). |
| 360 |
@param[in,out] altered_table TABLE object for new version of table. |
| 361 |
@param[in,out] ha_alter_info ALGORITHM=INPLACE metadata |
| 362 |
@param[in] commit true=Commit, false=Rollback. |
| 363 |
@param[in] old_dd_tab old table |
| 364 |
@param[in,out] new_dd_tab new table |
| 365 |
@retval true on failure (my_error() will have been called) |
| 366 |
@retval false on success */ |
| 367 |
bool commit_inplace_alter_partition(TABLE *altered_table, |
| 368 |
Alter_inplace_info *ha_alter_info, |
| 369 |
bool commit, const dd::Table *old_dd_tab, |
| 370 |
dd::Table *new_dd_tab); |
| 371 |
|
| 372 |
// TODO: should we implement init_table_handle_for_HANDLER() ? |
| 373 |
// (or is sql_stat_start handled correctly anyway?) |
| 374 |
/** Optimize table. |
| 375 |
This is mapped to "ALTER TABLE tablename ENGINE=InnoDB", which rebuilds |
| 376 |
the table in MySQL. |
| 377 |
@param[in] thd Connection thread handle. |
| 378 |
@param[in] check_opt Currently ignored. |
| 379 |
@return 0 for success else error code. */ |
| 380 |
int optimize(THD *thd, HA_CHECK_OPT *check_opt) override; |
| 381 |
|
| 382 |
/** Set DD discard attribute for tablespace. |
| 383 |
@param[in] table_def dd table |
| 384 |
@param[in] discard True if this table is discarded |
| 385 |
@return 0 or error number. */ |
| 386 |
int set_dd_discard_attribute(dd::Table *table_def, bool discard); |
| 387 |
|
| 388 |
int discard_or_import_tablespace(bool discard, dd::Table *table_def) override; |
| 389 |
|
| 390 |
/** Compare key and rowid. |
| 391 |
Helper function for sorting records in the priority queue. |
| 392 |
a/b points to table->record[0] rows which must have the |
| 393 |
key fields set. The bytes before a and b store the rowid. |
| 394 |
This is used for comparing/sorting rows first according to |
| 395 |
KEY and if same KEY, by rowid (ref). |
| 396 |
|
| 397 |
@param[in] key_info Null terminated array of index |
| 398 |
information. |
| 399 |
@param[in] a Pointer to record+ref in first record. |
| 400 |
@param[in] b Pointer to record+ref in second record. |
| 401 |
@return Return value is SIGN(first_rec - second_rec) |
| 402 |
@retval 0 Keys are equal. |
| 403 |
@retval -1 second_rec is greater than first_rec. |
| 404 |
@retval +1 first_rec is greater than second_rec. */ |
| 405 |
static int key_and_rowid_cmp(KEY **key_info, uchar *a, uchar *b); |
| 406 |
|
| 407 |
int extra(enum ha_extra_function operation) override; |
| 408 |
|
| 409 |
void print_error(int error, myf errflag) override; |
| 410 |
|
| 411 |
bool is_ignorable_error(int error) override; |
| 412 |
|
| 413 |
int start_stmt(THD *thd, thr_lock_type lock_type) override; |
| 414 |
|
| 415 |
ha_rows records_in_range(uint inx, key_range *min_key, |
| 416 |
key_range *max_key) override; |
| 417 |
|
| 418 |
ha_rows estimate_rows_upper_bound() override; |
| 419 |
|
| 420 |
uint alter_table_flags(uint flags); |
| 421 |
|
| 422 |
void update_create_info(HA_CREATE_INFO *create_info) override; |
| 423 |
|
| 424 |
int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info, |
| 425 |
dd::Table *table_def) override; |
| 426 |
|
| 427 |
/** Drop a table. |
| 428 |
@param[in] name table name |
| 429 |
@param[in,out] dd_table data dictionary table |
| 430 |
@return error number |
| 431 |
@retval 0 on success */ |
| 432 |
int delete_table(const char *name, const dd::Table *dd_table) override; |
| 433 |
|
| 434 |
/** Rename a table. |
| 435 |
@param[in] from table name before rename |
| 436 |
@param[in] to table name after rename |
| 437 |
@param[in] from_table data dictionary table before rename |
| 438 |
@param[in,out] to_table data dictionary table after rename |
| 439 |
@return error number |
| 440 |
@retval 0 on success */ |
| 441 |
int rename_table(const char *from, const char *to, |
| 442 |
const dd::Table *from_table, dd::Table *to_table) override; |
| 443 |
|
| 444 |
int check(THD *thd, HA_CHECK_OPT *check_opt) override; |
| 445 |
|
| 446 |
/** Repair a partitioned table. |
| 447 |
Only repairs records in wrong partitions (moves them to the correct |
| 448 |
partition or deletes them if not in any partition). |
| 449 |
@param[in] thd MySQL THD object/thread handle. |
| 450 |
@param[in] repair_opt Repair options. |
| 451 |
@return 0 or error code. */ |
| 452 |
int repair(THD *thd, HA_CHECK_OPT *repair_opt) override; |
| 453 |
|
| 454 |
/** Get the current auto_increment value. |
| 455 |
@param[in] offset Table auto-inc offset. |
| 456 |
@param[in] increment Table auto-inc increment. |
| 457 |
@param[in] nb_desired_values Number of required values. |
| 458 |
@param[out] first_value The auto increment value. |
| 459 |
@param[out] nb_reserved_values Number of reserved values. */ |
| 460 |
void get_auto_increment(ulonglong offset, ulonglong increment, |
| 461 |
ulonglong nb_desired_values, ulonglong *first_value, |
| 462 |
ulonglong *nb_reserved_values) override; |
| 463 |
|
| 464 |
/* Get partition row type |
| 465 |
@param[in] partition_table partition table |
| 466 |
@param[in] part_id Id of partition for which row type to be retrieved |
| 467 |
@return Partition row type. */ |
| 468 |
enum row_type get_partition_row_type(const dd::Table *partition_table, |
| 469 |
uint part_id) override; |
| 470 |
|
| 471 |
int cmp_ref(const uchar *ref1, const uchar *ref2) const override; |
| 472 |
|
| 473 |
int read_range_first(const key_range *start_key, const key_range *end_key, |
| 474 |
bool eq_range_arg, bool sorted) override { |
| 475 |
return (Partition_helper::ph_read_range_first(start_key, end_key, |
| 476 |
eq_range_arg, sorted)); |
| 477 |
} |
| 478 |
|
| 479 |
void position(const uchar *record) override { |
| 480 |
Partition_helper::ph_position(record); |
| 481 |
} |
| 482 |
|
| 483 |
/* TODO: Implement these! */ |
| 484 |
bool check_if_incompatible_data(HA_CREATE_INFO *info [[maybe_unused]], |
| 485 |
uint table_changes |
| 486 |
[[maybe_unused]]) override { |
| 487 |
ut_d(ut_error); |
| 488 |
ut_o(return (COMPATIBLE_DATA_NO)); |
| 489 |
} |
| 490 |
|
| 491 |
int delete_all_rows() override { return (handler::delete_all_rows()); } |
| 492 |
|
| 493 |
int disable_indexes(uint mode [[maybe_unused]]) override { |
| 494 |
return (HA_ERR_WRONG_COMMAND); |
| 495 |
} |
| 496 |
|
| 497 |
int enable_indexes(uint mode [[maybe_unused]]) override { |
| 498 |
return (HA_ERR_WRONG_COMMAND); |
| 499 |
} |
| 500 |
|
| 501 |
int ft_init() override { |
| 502 |
ut_d(ut_error); |
| 503 |
ut_o(return (HA_ERR_WRONG_COMMAND)); |
| 504 |
} |
| 505 |
|
| 506 |
FT_INFO *ft_init_ext(uint flags [[maybe_unused]], uint inx [[maybe_unused]], |
| 507 |
String *key [[maybe_unused]]) override { |
| 508 |
ut_d(ut_error); |
| 509 |
ut_o(return (nullptr)); |
| 510 |
} |
| 511 |
|
| 512 |
FT_INFO *ft_init_ext_with_hints(uint inx [[maybe_unused]], |
| 513 |
String *key [[maybe_unused]], |
| 514 |
Ft_hints *hints [[maybe_unused]]) override { |
| 515 |
ut_d(ut_error); |
| 516 |
ut_o(return (nullptr)); |
| 517 |
} |
| 518 |
|
| 519 |
int ft_read(uchar *buf [[maybe_unused]]) override { |
| 520 |
ut_d(ut_error); |
| 521 |
ut_o(return (HA_ERR_WRONG_COMMAND)); |
| 522 |
} |
| 523 |
|
| 524 |
bool get_foreign_dup_key(char *child_table_name [[maybe_unused]], |
| 525 |
uint child_table_name_len [[maybe_unused]], |
| 526 |
char *child_key_name [[maybe_unused]], |
| 527 |
uint child_key_name_len [[maybe_unused]]) override { |
| 528 |
ut_d(ut_error); |
| 529 |
ut_o(return (false)); |
| 530 |
} |
| 531 |
|
| 532 |
int read_range_next() override { |
| 533 |
return (Partition_helper::ph_read_range_next()); |
| 534 |
} |
| 535 |
|
| 536 |
uint32_t calculate_key_hash_value(Field **field_array) override { |
| 537 |
return (Partition_helper::ph_calculate_key_hash_value(field_array)); |
| 538 |
} |
| 539 |
|
| 540 |
Table_flags table_flags() const override { |
| 541 |
return (ha_innobase::table_flags() | HA_CAN_REPAIR); |
| 542 |
} |
| 543 |
|
| 544 |
void release_auto_increment() override { |
| 545 |
Partition_helper::ph_release_auto_increment(); |
| 546 |
} |
| 547 |
|
| 548 |
/** Implementing Partition_handler interface @see partition_handler.h |
| 549 |
@{ */ |
| 550 |
|
| 551 |
/** See Partition_handler. */ |
| 552 |
void get_dynamic_partition_info(ha_statistics *stat_info, |
| 553 |
ha_checksum *check_sum, |
| 554 |
uint part_id) override { |
| 555 |
Partition_helper::get_dynamic_partition_info_low(stat_info, check_sum, |
| 556 |
part_id); |
| 557 |
} |
| 558 |
|
| 559 |
uint alter_flags(uint flags [[maybe_unused]]) const override { |
| 560 |
return (HA_PARTITION_FUNCTION_SUPPORTED | HA_INPLACE_CHANGE_PARTITION); |
| 561 |
} |
| 562 |
|
| 563 |
Partition_handler *get_partition_handler() override { |
| 564 |
return (static_cast<Partition_handler *>(this)); |
| 565 |
} |
| 566 |
|
| 567 |
void set_part_info(partition_info *part_info, bool early) override { |
| 568 |
Partition_helper::set_part_info_low(part_info, early); |
| 569 |
} |
| 570 |
|
| 571 |
void initialize_partitioning(partition_info *part_info, bool early) { |
| 572 |
Partition_helper::set_part_info_low(part_info, early); |
| 573 |
} |
| 574 |
|
| 575 |
handler *get_handler() override { return (static_cast<handler *>(this)); } |
| 576 |
/** @} */ |
| 577 |
|
| 578 |
/** Get number of threads that would be spawned for parallel read. |
| 579 |
@param[out] scan_ctx A scan context created by this method |
| 580 |
that has to be used in |
| 581 |
parallel_scan |
| 582 |
@param[out] num_threads Number of threads to be spawned |
| 583 |
@param[in] use_reserved_threads true if reserved threads are to be used |
| 584 |
if we exhaust the max cap of number of |
| 585 |
parallel read threads that can be |
| 586 |
spawned at a time |
| 587 |
@return error code |
| 588 |
@return 0 on success */ |
| 589 |
int parallel_scan_init(void *&scan_ctx, size_t *num_threads, |
| 590 |
bool use_reserved_threads) override; |
| 591 |
|
| 592 |
using Reader = Parallel_reader_adapter; |
| 593 |
|
| 594 |
/** Start parallel read of data. |
| 595 |
@param[in] scan_ctx Scan context created by parallel_scan_init |
| 596 |
@param[in] thread_ctxs context for each of the spawned threads |
| 597 |
@param[in] init_fn callback called by each parallel load |
| 598 |
thread at the beginning of the parallel load. |
| 599 |
@param[in] load_fn callback called by each parallel load |
| 600 |
thread when processing of rows is required. |
| 601 |
@param[in] end_fn callback called by each parallel load |
| 602 |
thread when processing of rows has ended. |
| 603 |
@return error code |
| 604 |
@return 0 on success */ |
| 605 |
int parallel_scan(void *scan_ctx, void **thread_ctxs, Reader::Init_fn init_fn, |
| 606 |
Reader::Load_fn load_fn, Reader::End_fn end_fn) override; |
| 607 |
/** Run the parallel read of data. |
| 608 |
@param[in] parallel_scan_ctx a scan context created by |
| 609 |
parallel_scan_init |
| 610 |
*/ |
| 611 |
void parallel_scan_end(void *parallel_scan_ctx) override; |
| 612 |
|
| 613 |
private: |
| 614 |
/** Pointer to Ha_innopart_share on the TABLE_SHARE. */ |
| 615 |
Ha_innopart_share *m_part_share; |
| 616 |
|
| 617 |
struct saved_prebuilt_t { |
| 618 |
/** saved m_prebuilt->ins_node */ |
| 619 |
ins_node_t *m_ins_node; |
| 620 |
|
| 621 |
/** saved m_prebuilt->upd_node */ |
| 622 |
upd_node_t *m_upd_node; |
| 623 |
|
| 624 |
/** saved m_prebuilt->blob_heap */ |
| 625 |
mem_heap_t *m_blob_heap; |
| 626 |
|
| 627 |
/** saved m_prebuilt->trx_id (which in turn reflects table->def_trx_id) */ |
| 628 |
trx_id_t m_trx_id; |
| 629 |
|
| 630 |
/** saved m_prebuilt->row_read_type */ |
| 631 |
ulint m_row_read_type; |
| 632 |
|
| 633 |
/** save m_prebuilt->new_rec_lock[] values */ |
| 634 |
decltype(row_prebuilt_t::new_rec_lock) m_new_rec_lock; |
| 635 |
}; |
| 636 |
/* Per partition information storing last values of m_prebuilt when we've last |
| 637 |
finished using given partition, so we can restore it when we return to it. |
| 638 |
Synchronized with m_prebuilt when changing partitions: |
| 639 |
set_partition(part_id) copies to m_prebuilt from m_parts[part_id] |
| 640 |
update_partition(part_id) copies to m_parts[part_id] from m_prebuilt |
| 641 |
|
| 642 |
NOTE: these are not the only fields synchronized with m_prebuilt. |
| 643 |
*/ |
| 644 |
ut::unique_ptr<saved_prebuilt_t[]> m_parts; |
| 645 |
|
| 646 |
/** byte array for sql_stat_start bitset */ |
| 647 |
byte *m_bitset; |
| 648 |
|
| 649 |
/** sql_stat_start per partition. */ |
| 650 |
Sql_stat_start_parts m_sql_stat_start_parts; |
| 651 |
|
| 652 |
/** persistent cursors per partition. */ |
| 653 |
btr_pcur_t *m_pcur_parts; |
| 654 |
|
| 655 |
/** persistent cluster cursors per partition. */ |
| 656 |
btr_pcur_t *m_clust_pcur_parts; |
| 657 |
|
| 658 |
/** map from part_id to offset in above two arrays. */ |
| 659 |
uint16_t *m_pcur_map; |
| 660 |
|
| 661 |
/** Original m_prebuilt->pcur. */ |
| 662 |
btr_pcur_t *m_pcur; |
| 663 |
|
| 664 |
/** Original m_prebuilt->clust_pcur. */ |
| 665 |
btr_pcur_t *m_clust_pcur; |
| 666 |
|
| 667 |
/** New partitions during ADD/REORG/... PARTITION. */ |
| 668 |
Altered_partitions *m_new_partitions; |
| 669 |
|
| 670 |
/** Can reuse the template for the previous partition. */ |
| 671 |
bool m_reuse_mysql_template; |
| 672 |
|
| 673 |
/** Clear used ins_nodes and upd_nodes. */ |
| 674 |
void clear_ins_upd_nodes(); |
| 675 |
|
| 676 |
/** Clear the blob heaps for all partitions */ |
| 677 |
void clear_blob_heaps(); |
| 678 |
|
| 679 |
/** Reset state of file to after 'open'. This function is called |
| 680 |
after every statement for all tables used by that statement. */ |
| 681 |
int reset() override; |
| 682 |
|
| 683 |
/** Changes the active index of a handle. |
| 684 |
@param[in] part_id Use this partition. |
| 685 |
@param[in] keynr Use this index; MAX_KEY means always clustered index, |
| 686 |
even if it was internally generated by InnoDB. |
| 687 |
@return 0 or error number. */ |
| 688 |
int change_active_index(uint part_id, uint keynr); |
| 689 |
|
| 690 |
/** Move to next partition and set its index. |
| 691 |
@return 0 for success else error number. */ |
| 692 |
int next_partition_index(); |
| 693 |
|
| 694 |
/** Internally called for initializing auto increment value. |
| 695 |
Should never be called, but defined to catch such errors. |
| 696 |
@return 0 on success else error code. */ |
| 697 |
int innobase_initialize_autoinc(); |
| 698 |
|
| 699 |
/** Get the index for the current partition |
| 700 |
@param[in] keynr MySQL index number. |
| 701 |
@return InnoDB index or NULL. */ |
| 702 |
dict_index_t *innobase_get_index(uint keynr) override; |
| 703 |
|
| 704 |
/** Get the index for a handle. |
| 705 |
Does not change active index. |
| 706 |
@param[in] keynr Use this index; MAX_KEY means always clustered index, |
| 707 |
even if it was internally generated by InnoDB. |
| 708 |
@param[in] part_id From this partition. |
| 709 |
@return NULL or index instance. */ |
| 710 |
dict_index_t *innopart_get_index(uint part_id, uint keynr); |
| 711 |
|
| 712 |
/** Change active partition. |
| 713 |
Copies needed info into m_prebuilt from the partition specific memory. |
| 714 |
@param[in] part_id Partition to set as active. */ |
| 715 |
void set_partition(uint part_id); |
| 716 |
|
| 717 |
/** Update active partition. |
| 718 |
Copies needed info from m_prebuilt into the partition specific memory. |
| 719 |
@param[in] part_id Partition to set as active. */ |
| 720 |
void update_partition(uint part_id); |
| 721 |
|
| 722 |
/** TRUNCATE an InnoDB partitioned table. |
| 723 |
@param[in] name table name |
| 724 |
@param[in] form table definition |
| 725 |
@param[in,out] table_def dd::Table describing table to be |
| 726 |
truncated. Can be adjusted by SE, the changes will be saved into |
| 727 |
the data-dictionary at statement commit time. |
| 728 |
@return error number |
| 729 |
@retval 0 on success */ |
| 730 |
int truncate_impl(const char *name, TABLE *form, dd::Table *table_def); |
| 731 |
|
| 732 |
/** @defgroup PARTITION_HANDLER_HELPERS Helpers needed by Partition_helper |
| 733 |
@see partition_handler.h |
| 734 |
@{ */ |
| 735 |
|
| 736 |
/** Set the autoinc column max value. |
| 737 |
This should only be called once from ha_innobase::open(). |
| 738 |
Therefore there's no need for a covering lock. |
| 739 |
@param[in] no_lock If locking should be skipped. Not used! |
| 740 |
@return 0 for success or error code. */ |
| 741 |
int initialize_auto_increment(bool no_lock) override; |
| 742 |
|
| 743 |
/** Save currently highest auto increment value. |
| 744 |
@param[in] nr Auto increment value to save. */ |
| 745 |
void save_auto_increment(ulonglong nr) override; |
| 746 |
|
| 747 |
/** Setup the ordered record buffer and the priority queue. |
| 748 |
@param[in] used_parts Number of used partitions in query. |
| 749 |
@return false for success, else true. */ |
| 750 |
int init_record_priority_queue_for_parts(uint used_parts) override; |
| 751 |
|
| 752 |
/** Destroy the ordered record buffer and the priority queue. */ |
| 753 |
void destroy_record_priority_queue_for_parts() override; |
| 754 |
|
| 755 |
/** Create the Altered_partitoins object |
| 756 |
@param[in] ha_alter_info thd DDL operation |
| 757 |
@retval true On failure |
| 758 |
@retval false On success */ |
| 759 |
bool prepare_for_copy_partitions(Alter_inplace_info *ha_alter_info); |
| 760 |
|
| 761 |
/** write row to new partition. |
| 762 |
@param[in] new_part New partition to write to. |
| 763 |
@return 0 for success else error code. */ |
| 764 |
int write_row_in_new_part(uint new_part) override; |
| 765 |
|
| 766 |
/** Write a row in specific partition. |
| 767 |
Stores a row in an InnoDB database, to the table specified in this |
| 768 |
handle. |
| 769 |
@param[in] part_id Partition to write to. |
| 770 |
@param[in] record A row in MySQL format. |
| 771 |
@return error code. */ |
| 772 |
int write_row_in_part(uint part_id, uchar *record) override; |
| 773 |
|
| 774 |
/** Update a row in partition. |
| 775 |
Updates a row given as a parameter to a new value. |
| 776 |
@param[in] part_id Partition to update row in. |
| 777 |
@param[in] old_row Old row in MySQL format. |
| 778 |
@param[in] new_row New row in MySQL format. |
| 779 |
@return 0 or error number. */ |
| 780 |
int update_row_in_part(uint part_id, const uchar *old_row, |
| 781 |
uchar *new_row) override; |
| 782 |
|
| 783 |
/** Deletes a row in partition. |
| 784 |
@param[in] part_id Partition to delete from. |
| 785 |
@param[in] record Row to delete in MySQL format. |
| 786 |
@return 0 or error number. */ |
| 787 |
int delete_row_in_part(uint part_id, const uchar *record) override; |
| 788 |
|
| 789 |
/** Return first record in index from a partition. |
| 790 |
@param[in] part Partition to read from. |
| 791 |
@param[out] record First record in index in the partition. |
| 792 |
@return error number or 0. */ |
| 793 |
int index_first_in_part(uint part, uchar *record) override; |
| 794 |
|
| 795 |
/** Return last record in index from a partition. |
| 796 |
@param[in] part Partition to read from. |
| 797 |
@param[out] record Last record in index in the partition. |
| 798 |
@return error number or 0. */ |
| 799 |
int index_last_in_part(uint part, uchar *record) override; |
| 800 |
|
| 801 |
/** Return previous record in index from a partition. |
| 802 |
@param[in] part Partition to read from. |
| 803 |
@param[out] record Last record in index in the partition. |
| 804 |
@return error number or 0. */ |
| 805 |
int index_prev_in_part(uint part, uchar *record) override; |
| 806 |
|
| 807 |
/** Return next record in index from a partition. |
| 808 |
@param[in] part Partition to read from. |
| 809 |
@param[out] record Last record in index in the partition. |
| 810 |
@return error number or 0. */ |
| 811 |
int index_next_in_part(uint part, uchar *record) override; |
| 812 |
|
| 813 |
/** Return next same record in index from a partition. |
| 814 |
This routine is used to read the next record, but only if the key is |
| 815 |
the same as supplied in the call. |
| 816 |
@param[in] part Partition to read from. |
| 817 |
@param[out] record Last record in index in the partition. |
| 818 |
@param[in] key Key to match. |
| 819 |
@param[in] length Length of key. |
| 820 |
@return error number or 0. */ |
| 821 |
int index_next_same_in_part(uint part, uchar *record, const uchar *key, |
| 822 |
uint length) override; |
| 823 |
|
| 824 |
/** Start index scan and return first record from a partition. |
| 825 |
This routine starts an index scan using a start key. The calling |
| 826 |
function will check the end key on its own. |
| 827 |
@param[in] part Partition to read from. |
| 828 |
@param[out] record First matching record in index in the partition. |
| 829 |
@param[in] key Key to match. |
| 830 |
@param[in] keypart_map Which part of the key to use. |
| 831 |
@param[in] find_flag Key condition/direction to use. |
| 832 |
@return error number or 0. */ |
| 833 |
int index_read_map_in_part(uint part, uchar *record, const uchar *key, |
| 834 |
key_part_map keypart_map, |
| 835 |
enum ha_rkey_function find_flag) override; |
| 836 |
|
| 837 |
/** Return last matching record in index from a partition. |
| 838 |
@param[in] part Partition to read from. |
| 839 |
@param[out] record Last matching record in index in the partition. |
| 840 |
@param[in] key Key to match. |
| 841 |
@param[in] keypart_map Which part of the key to use. |
| 842 |
@return error number or 0. */ |
| 843 |
int index_read_last_map_in_part(uint part, uchar *record, const uchar *key, |
| 844 |
key_part_map keypart_map) override; |
| 845 |
|
| 846 |
/** Start index scan and return first record from a partition. |
| 847 |
This routine starts an index scan using a start and end key. |
| 848 |
@param[in] part Partition to read from. |
| 849 |
@param[in,out] record First matching record in index in the |
| 850 |
partition, if NULL use table->record[0] as return buffer. |
| 851 |
@param[in] start_key Start key to match. |
| 852 |
@param[in] end_key End key to match. |
| 853 |
@param[in] sorted Return rows in sorted order. |
| 854 |
@return error number or 0. */ |
| 855 |
int read_range_first_in_part(uint part, uchar *record, |
| 856 |
const key_range *start_key, |
| 857 |
const key_range *end_key, bool sorted) override; |
| 858 |
|
| 859 |
/** Return next record in index range scan from a partition. |
| 860 |
@param[in] part Partition to read from. |
| 861 |
@param[in,out] record First matching record in index in the partition, |
| 862 |
if NULL use table->record[0] as return buffer. |
| 863 |
@return error number or 0. */ |
| 864 |
int read_range_next_in_part(uint part, uchar *record) override; |
| 865 |
|
| 866 |
/** Start index scan and return first record from a partition. |
| 867 |
This routine starts an index scan using a start key. The calling |
| 868 |
function will check the end key on its own. |
| 869 |
@param[in] part Partition to read from. |
| 870 |
@param[out] record First matching record in index in the partition. |
| 871 |
@param[in] index Index to read from. |
| 872 |
@param[in] key Key to match. |
| 873 |
@param[in] keypart_map Which part of the key to use. |
| 874 |
@param[in] find_flag Key condition/direction to use. |
| 875 |
@return error number or 0. */ |
| 876 |
int index_read_idx_map_in_part(uint part, uchar *record, uint index, |
| 877 |
const uchar *key, key_part_map keypart_map, |
| 878 |
enum ha_rkey_function find_flag) override; |
| 879 |
|
| 880 |
/** Initialize sampling. |
| 881 |
@param[out] scan_ctx A scan context created by this method that has to be |
| 882 |
used in sample_next |
| 883 |
@param[in] sampling_percentage percentage of records that need to be |
| 884 |
sampled |
| 885 |
@param[in] sampling_seed random seed that the random generator will |
| 886 |
use |
| 887 |
@param[in] sampling_method sampling method to be used; currently only |
| 888 |
SYSTEM sampling is supported |
| 889 |
@param[in] tablesample true if the sampling is for tablesample |
| 890 |
@return 0 for success, else one of the HA_xxx values in case of error. */ |
| 891 |
int sample_init(void *&scan_ctx, double sampling_percentage, |
| 892 |
int sampling_seed, enum_sampling_method sampling_method, |
| 893 |
const bool tablesample) override; |
| 894 |
|
| 895 |
/** Get the next record for sampling. |
| 896 |
@param[in] scan_ctx Scan context of the sampling |
| 897 |
@param[in] buf buffer to place the read record |
| 898 |
@return 0 for success, else one of the HA_xxx values in case of error. */ |
| 899 |
int sample_next(void *scan_ctx, uchar *buf) override; |
| 900 |
|
| 901 |
/** End sampling. |
| 902 |
@param[in] scan_ctx Scan context of the sampling |
| 903 |
@return 0 for success, else one of the HA_xxx values in case of error. */ |
| 904 |
int sample_end(void *scan_ctx) override; |
| 905 |
|
| 906 |
/** Initialize random read/scan of a specific partition. |
| 907 |
@param[in] part_id Partition to initialize. |
| 908 |
@param[in] scan True for scan else random access. |
| 909 |
@return error number or 0. */ |
| 910 |
int rnd_init_in_part(uint part_id, bool scan) override; |
| 911 |
|
| 912 |
/** Get next row during scan of a specific partition. |
| 913 |
Also used to read the FIRST row in a table scan. |
| 914 |
@param[in] part_id Partition to read from. |
| 915 |
@param[out] buf Next row. |
| 916 |
@return error number or 0. */ |
| 917 |
int rnd_next_in_part(uint part_id, uchar *buf) override; |
| 918 |
|
| 919 |
/** End random read/scan of a specific partition. |
| 920 |
@param[in] part_id Partition to end random read/scan. |
| 921 |
@param[in] scan True for scan else random access. |
| 922 |
@return error number or 0. */ |
| 923 |
int rnd_end_in_part(uint part_id, bool scan) override; |
| 924 |
|
| 925 |
/** Return position for cursor in last used partition. |
| 926 |
Stores a reference to the current row to 'ref' field of the handle. Note |
| 927 |
that in the case where we have generated the clustered index for the |
| 928 |
table, the function parameter is illogical: we MUST ASSUME that 'record' |
| 929 |
is the current 'position' of the handle, because if row ref is actually |
| 930 |
the row id internally generated in InnoDB, then 'record' does not contain |
| 931 |
it. We just guess that the row id must be for the record where the handle |
| 932 |
was positioned the last time. |
| 933 |
@param[out] ref_arg Pointer to buffer where to write the position. |
| 934 |
@param[in] record Record to position for. */ |
| 935 |
void position_in_last_part(uchar *ref_arg, const uchar *record) override; |
| 936 |
|
| 937 |
/** Read row using position using given record to find. |
| 938 |
This works as position()+rnd_pos() functions, but does some |
| 939 |
extra work,calculating m_last_part - the partition to where |
| 940 |
the 'record' should go. |
| 941 |
Only useful when position is based on primary key |
| 942 |
(HA_PRIMARY_KEY_REQUIRED_FOR_POSITION). |
| 943 |
@param[in] record Current record in MySQL Row Format. |
| 944 |
@return 0 for success else error code. */ |
| 945 |
int rnd_pos_by_record(uchar *record) override; |
| 946 |
|
| 947 |
/** Copy a cached MySQL row. |
| 948 |
If requested, also avoids overwriting non-read columns. |
| 949 |
@param[out] buf Row in MySQL format. |
| 950 |
@param[in] cached_row Which row to copy. */ |
| 951 |
void copy_cached_row(uchar *buf, const uchar *cached_row) override; |
| 952 |
/** @} */ |
| 953 |
|
| 954 |
/** @defgroup PRIVATE_HANDLER InnoDB Partitioning Private Handler |
| 955 |
Functions specific for native InnoDB partitioning. |
| 956 |
@see handler.h |
| 957 |
@{ */ |
| 958 |
|
| 959 |
/** Open an InnoDB table. |
| 960 |
@param[in] name table name |
| 961 |
@param[in] mode access mode |
| 962 |
@param[in] test_if_locked test if the file to be opened is locked |
| 963 |
@param[in] table_def dd::Table describing table to be opened |
| 964 |
@retval 1 if error |
| 965 |
@retval 0 if success */ |
| 966 |
int open(const char *name, int mode, uint test_if_locked, |
| 967 |
const dd::Table *table_def) override; |
| 968 |
|
| 969 |
int close() override; |
| 970 |
|
| 971 |
double scan_time() override; |
| 972 |
|
| 973 |
/** Was the last returned row semi consistent read. |
| 974 |
In an UPDATE or DELETE, if the row under the cursor was locked by |
| 975 |
another transaction, and the engine used an optimistic read of the last |
| 976 |
committed row value under the cursor, then the engine returns 1 from |
| 977 |
this function. MySQL must NOT try to update this optimistic value. If |
| 978 |
the optimistic value does not match the WHERE condition, MySQL can |
| 979 |
decide to skip over this row. This can be used to avoid unnecessary |
| 980 |
lock waits. |
| 981 |
|
| 982 |
If this method returns true, it will also signal the storage |
| 983 |
engine that the next read will be a locking re-read of the row. |
| 984 |
@see handler.h and row0mysql.h |
| 985 |
@return true if last read was semi consistent else false. */ |
| 986 |
bool was_semi_consistent_read() override; |
| 987 |
|
| 988 |
/** Try semi consistent read. |
| 989 |
Tell the engine whether it should avoid unnecessary lock waits. |
| 990 |
If yes, in an UPDATE or DELETE, if the row under the cursor was locked |
| 991 |
by another transaction, the engine may try an optimistic read of |
| 992 |
the last committed row value under the cursor. |
| 993 |
@see handler.h and row0mysql.h |
| 994 |
@param[in] yes Should semi-consistent read be used. */ |
| 995 |
void try_semi_consistent_read(bool yes) override; |
| 996 |
|
| 997 |
/** Removes a lock on a row. |
| 998 |
Removes a new lock set on a row, if it was not read optimistically. |
| 999 |
This can be called after a row has been read in the processing of |
| 1000 |
an UPDATE or a DELETE query. @see ha_innobase::unlock_row(). */ |
| 1001 |
void unlock_row() override; |
| 1002 |
|
| 1003 |
int index_init(uint index, bool sorted) override; |
| 1004 |
|
| 1005 |
int index_end() override; |
| 1006 |
|
| 1007 |
int rnd_init(bool scan) override { |
| 1008 |
return (Partition_helper::ph_rnd_init(scan)); |
| 1009 |
} |
| 1010 |
|
| 1011 |
int rnd_end() override { return (Partition_helper::ph_rnd_end()); } |
| 1012 |
|
| 1013 |
int external_lock(THD *thd, int lock_type) override; |
| 1014 |
|
| 1015 |
THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to, |
| 1016 |
thr_lock_type lock_type) override; |
| 1017 |
|
| 1018 |
int write_row(uchar *record) override { |
| 1019 |
bool entered = false; |
| 1020 |
auto trx = m_prebuilt->trx; |
| 1021 |
|
| 1022 |
/* Enter innodb to order Auto INC partition lock after Innodb. No need to |
| 1023 |
enter if there are tickets left. Currently we cannot handle re-enter |
| 1024 |
without exit if no more tickets left. |
| 1025 |
|
| 1026 |
1. We avoid consuming the last ticket as there could be another enter |
| 1027 |
call from innobase. |
| 1028 |
|
| 1029 |
2. If we enter innodb here, there is at least one more ticket left as |
| 1030 |
the minimum value for "innodb_concurrency_tickets" is 1 */ |
| 1031 |
|
| 1032 |
if (!trx->declared_to_be_inside_innodb) { |
| 1033 |
auto err = srv_concurrency_enter(); |
| 1034 |
if (err != 0) { |
| 1035 |
return (err); |
| 1036 |
} |
| 1037 |
entered = true; |
| 1038 |
} |
| 1039 |
|
| 1040 |
auto err = Partition_helper::ph_write_row(record); |
| 1041 |
|
| 1042 |
if (entered) { |
| 1043 |
srv_concurrency_exit(); |
| 1044 |
} |
| 1045 |
|
| 1046 |
return (err); |
| 1047 |
} |
| 1048 |
|
| 1049 |
int update_row(const uchar *old_record, uchar *new_record) override { |
| 1050 |
return (Partition_helper::ph_update_row(old_record, new_record)); |
| 1051 |
} |
| 1052 |
|
| 1053 |
int delete_row(const uchar *record) override { |
| 1054 |
return (Partition_helper::ph_delete_row(record)); |
| 1055 |
} |
| 1056 |
/** @} */ |
| 1057 |
|
| 1058 |
/** Delete all rows in the requested partitions. |
| 1059 |
Done by deleting the partitions and recreate them again. |
| 1060 |
@param[in,out] dd_table dd::Table object for partitioned table |
| 1061 |
which partitions need to be truncated. Can be adjusted by this call. |
| 1062 |
Changes to the table definition will be persisted in the data-dictionary |
| 1063 |
at statement commit time. |
| 1064 |
@return 0 or error number. */ |
| 1065 |
int truncate_partition_low(dd::Table *dd_table) override; |
| 1066 |
|
| 1067 |
/** Exchange partition. |
| 1068 |
Low-level primitive which implementation is provided here. |
| 1069 |
@param[in] part_id The id of the partition to be exchanged |
| 1070 |
@param[in] part_table partitioned table to be exchanged |
| 1071 |
@param[in] swap_table table to be exchanged |
| 1072 |
@return error number |
| 1073 |
@retval 0 on success */ |
| 1074 |
int exchange_partition_low(uint part_id, dd::Table *part_table, |
| 1075 |
dd::Table *swap_table) override; |
| 1076 |
|
| 1077 |
/** Access methods to protected areas in handler to avoid adding |
| 1078 |
friend class Partition_helper in class handler. |
| 1079 |
@see partition_handler.h |
| 1080 |
@{ */ |
| 1081 |
|
| 1082 |
THD *get_thd() const override { return ha_thd(); } |
| 1083 |
|
| 1084 |
TABLE *get_table() const override { return table; } |
| 1085 |
|
| 1086 |
bool get_eq_range() const override { return eq_range; } |
| 1087 |
|
| 1088 |
void set_eq_range(bool eq_range_arg) override { eq_range = eq_range_arg; } |
| 1089 |
|
| 1090 |
void set_range_key_part(KEY_PART_INFO *key_part) override { |
| 1091 |
range_key_part = key_part; |
| 1092 |
} |
| 1093 |
/** @} */ |
| 1094 |
|
| 1095 |
/** Fill in data_dir_path and tablespace name from internal data |
| 1096 |
dictionary. |
| 1097 |
@param[in,out] part_elem Partition element to fill. |
| 1098 |
@param[in] ib_table InnoDB table to copy from. |
| 1099 |
@param[in] display_tablespace Display tablespace name if |
| 1100 |
set. */ |
| 1101 |
void update_part_elem(partition_element *part_elem, dict_table_t *ib_table, |
| 1102 |
bool display_tablespace); |
| 1103 |
|
| 1104 |
protected: |
| 1105 |
/** Protected handler:: functions specific for native InnoDB partitioning. |
| 1106 |
@see handler.h |
| 1107 |
@{ */ |
| 1108 |
|
| 1109 |
int rnd_next(uchar *record) override { |
| 1110 |
return (Partition_helper::ph_rnd_next(record)); |
| 1111 |
} |
| 1112 |
|
| 1113 |
int rnd_pos(uchar *record, uchar *pos) override; |
| 1114 |
|
| 1115 |
int records(ha_rows *num_rows) override; |
| 1116 |
|
| 1117 |
int index_next(uchar *record) override { |
| 1118 |
return (Partition_helper::ph_index_next(record)); |
| 1119 |
} |
| 1120 |
|
| 1121 |
int index_next_same(uchar *record, const uchar *, uint keylen) override { |
| 1122 |
return (Partition_helper::ph_index_next_same(record, keylen)); |
| 1123 |
} |
| 1124 |
|
| 1125 |
int index_prev(uchar *record) override { |
| 1126 |
return (Partition_helper::ph_index_prev(record)); |
| 1127 |
} |
| 1128 |
|
| 1129 |
int index_first(uchar *record) override { |
| 1130 |
return (Partition_helper::ph_index_first(record)); |
| 1131 |
} |
| 1132 |
|
| 1133 |
int index_last(uchar *record) override { |
| 1134 |
return (Partition_helper::ph_index_last(record)); |
| 1135 |
} |
| 1136 |
|
| 1137 |
int index_read_last_map(uchar *record, const uchar *key, |
| 1138 |
key_part_map keypart_map) override { |
| 1139 |
return (Partition_helper::ph_index_read_last_map(record, key, keypart_map)); |
| 1140 |
} |
| 1141 |
|
| 1142 |
int index_read_map(uchar *buf, const uchar *key, key_part_map keypart_map, |
| 1143 |
enum ha_rkey_function find_flag) override { |
| 1144 |
return ( |
| 1145 |
Partition_helper::ph_index_read_map(buf, key, keypart_map, find_flag)); |
| 1146 |
} |
| 1147 |
|
| 1148 |
int index_read_idx_map(uchar *buf, uint index, const uchar *key, |
| 1149 |
key_part_map keypart_map, |
| 1150 |
enum ha_rkey_function find_flag) override { |
| 1151 |
return (Partition_helper::ph_index_read_idx_map(buf, index, key, |
| 1152 |
keypart_map, find_flag)); |
| 1153 |
} |
| 1154 |
/** @} */ |
| 1155 |
|
| 1156 |
/** Updates and return statistics. |
| 1157 |
Returns statistics information of the table to the MySQL interpreter, |
| 1158 |
in various fields of the handle object. |
| 1159 |
@param[in] flag Flags for what to update and return. |
| 1160 |
@param[in] is_analyze True if called from "::analyze()". |
| 1161 |
@return HA_ERR_* error code or 0. */ |
| 1162 |
int info_low(uint flag, bool is_analyze) override; |
| 1163 |
|
| 1164 |
bool can_reuse_mysql_template() const override { |
| 1165 |
return m_reuse_mysql_template; |
| 1166 |
} |
| 1167 |
}; |
| 1168 |
#endif /* ha_innopart_h */ |