MySQL  8.0.27
Source Code Documentation
partition_handler.h
Go to the documentation of this file.
1 #ifndef PARTITION_HANDLER_INCLUDED
2 #define PARTITION_HANDLER_INCLUDED
3 
4 /*
5  Copyright (c) 2005, 2021, Oracle and/or its affiliates.
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License, version 2.0,
9  as published by the Free Software Foundation.
10 
11  This program is also distributed with certain software (including
12  but not limited to OpenSSL) that is licensed under separate terms,
13  as designated in a particular file or component or in included license
14  documentation. The authors of MySQL hereby grant you an additional
15  permission to link the program and your derivative works with the
16  separately licensed software that they have included with MySQL.
17 
18  This program is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  GNU General Public License, version 2.0, for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with this program; if not, write to the Free Software
25  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 */
27 
28 #include <assert.h>
29 #include <string.h>
30 #include <sys/types.h>
31 #include <memory>
32 #include <string>
33 #include <vector>
34 
35 #include "my_base.h" // ha_rows.
36 #include "my_bitmap.h"
37 #include "my_compiler.h"
38 
39 #include "my_inttypes.h"
40 #include "my_sys.h"
41 #include "mysql/psi/mysql_mutex.h"
42 #include "priority_queue.h"
43 #include "sql/handler.h" // Handler_share
44 #include "sql/key.h" // key_rec_cmp
45 #include "sql/sql_partition.h" // part_id_range
46 
47 class Field;
48 class THD;
49 class partition_info;
50 struct mysql_mutex_t;
51 template <class Key, class Value>
53 
54 namespace dd {
55 class Table;
56 } // namespace dd
57 struct TABLE;
58 struct TABLE_SHARE;
59 
60 #define PARTITION_BYTES_IN_POS 2
61 
62 struct MEM_ROOT;
63 
65 
66 /**
67  bits in Partition_handler::alter_flags():
68 
69  HA_PARTITION_FUNCTION_SUPPORTED indicates that the function is
70  supported at all.
71  HA_INPLACE_CHANGE_PARTITION means that changes to partitioning can be done
72  through in-place ALTER TABLE API but special mark-up in partition_info
73  object is required for this.
74 */
75 #define HA_PARTITION_FUNCTION_SUPPORTED (1L << 0)
76 #define HA_INPLACE_CHANGE_PARTITION (1L << 1)
77 
85 };
86 
87 /** Struct used for partition_name_hash */
88 struct PART_NAME_DEF {
92  bool is_subpart;
93 };
94 
95 /**
96  Initialize partitioning (currently only PSI keys).
97 */
98 void partitioning_init();
99 
100 /**
101  Partition specific Handler_share.
102 */
104  public:
105  Partition_share();
106  ~Partition_share() override;
107 
108  /** Set if auto increment is used an initialized. */
110  /**
111  Mutex protecting next_auto_inc_val.
112  Initialized if table uses auto increment.
113  */
115  /** First non reserved auto increment value. */
117  /**
118  Hash of partition names. Initialized by the first handler instance of a
119  table_share calling populate_partition_name_hash().
120  After that it is read-only, i.e. no locking required for reading.
121  */
122  std::unique_ptr<
125 
126  /**
127  Initializes and sets auto_inc_mutex.
128  Only needed to be called if the table have an auto increment.
129  Must hold TABLE_SHARE::LOCK_ha_data when calling.
130  */
131  bool init_auto_inc_mutex(TABLE_SHARE *table_share);
132  /**
133  Release reserved auto increment values not used.
134  @param thd Thread.
135  @param table_share Table Share
136  @param next_insert_id Next insert id (first non used auto inc value).
137  @param max_reserved End of reserved auto inc range.
138  */
139  void release_auto_inc_if_possible(THD *thd, TABLE_SHARE *table_share,
140  const ulonglong next_insert_id,
141  const ulonglong max_reserved);
142 
143  /** lock mutex protecting auto increment value next_auto_inc_val. */
144  inline void lock_auto_inc() {
145  assert(auto_inc_mutex);
147  }
148  /** unlock mutex protecting auto increment value next_auto_inc_val. */
149  inline void unlock_auto_inc() {
150  assert(auto_inc_mutex);
152  }
153  /**
154  Populate partition_name_hash with partition and subpartition names
155  from part_info.
156  @param part_info Partition info containing all partitions metadata.
157 
158  @return Operation status.
159  @retval false Success.
160  @retval true Failure.
161  */
163  /** Get partition name.
164 
165  @param part_id Partition id (for subpartitioned table only subpartition
166  names will be returned.)
167 
168  @return partition name or NULL if error.
169  */
170  const char *get_partition_name(size_t part_id) const;
171 
172  private:
174  /**
175  Insert [sub]partition name into partition_name_hash
176  @param name Partition name.
177  @param part_id Partition id.
178  @param is_subpart True if subpartition else partition.
179 
180  @return Operation status.
181  @retval false Success.
182  @retval true Failure.
183  */
184  bool insert_partition_name_in_hash(const char *name, uint part_id,
185  bool is_subpart);
186 };
187 
188 /**
189  Class for partitioning specific operations.
190 
191  Returned from handler::get_partition_handler().
192 */
194  public:
195  Partition_handler() = default;
196  virtual ~Partition_handler() = default;
197 
198  /**
199  Get dynamic table information from partition.
200 
201  @param[out] stat_info Statistics struct to fill in.
202  @param[out] check_sum Check sum value to fill in if supported.
203  @param[in] part_id Partition to report for.
204 
205  @note stat_info and check_sum are initialized by caller.
206  check_sum is only expected to be updated if HA_HAS_CHECKSUM.
207  */
208  virtual void get_dynamic_partition_info(ha_statistics *stat_info,
209  ha_checksum *check_sum,
210  uint part_id) = 0;
211  /**
212  Get default number of partitions.
213 
214  Used during creating a partitioned table.
215 
216  @param info Create info.
217  @return Number of default partitions.
218  */
220  [[maybe_unused]]) {
221  return 1;
222  }
223  /**
224  Setup auto partitioning.
225 
226  Called for engines with HA_USE_AUTO_PARTITION to setup the partition info
227  object
228 
229  @param[in,out] part_info Partition object to setup.
230  */
231  virtual void set_auto_partitions(partition_info *part_info [[maybe_unused]]) {
232  }
233  /**
234  Get number of partitions for table in SE
235 
236  @param name normalized path(same as open) to the table
237 
238  @param[out] num_parts Number of partitions
239 
240  @retval false for success
241  @retval true for failure, for example table didn't exist in engine
242  */
243  virtual bool get_num_parts(const char *name [[maybe_unused]],
244  uint *num_parts) {
245  *num_parts = 0;
246  return false;
247  }
248  /**
249  Set the partition info object to be used by the handler.
250 
251  @param part_info Partition info to be used by the handler.
252  @param early True if called when part_info only created and parsed,
253  but not setup, checked or fixed.
254  */
255  virtual void set_part_info(partition_info *part_info, bool early) = 0;
256 
257  /**
258  Truncate partitions.
259 
260  Truncate all partitions matching table->part_info->read_partitions.
261  Handler level wrapper for truncating partitions, will ensure that
262  mark_trx_read_write() is called and also checks locking assertions.
263 
264  @param[in,out] table_def dd::Table object for the table. Engines
265  which support atomic DDL are allowed to
266  adjust this object. Changes will be saved
267  to the data-dictionary.
268 
269  @return Operation status.
270  @retval 0 Success.
271  @retval != 0 Error code.
272  */
274 
275  /**
276  Exchange partition.
277 
278  @param[in] part_id Id of partition to be exchanged.
279  @param[in,out] part_table_def dd::Table object for partitioned table.
280  @param[in,out] swap_table_def dd::Table object for non-partitioned
281  table.
282 
283  @note Both tables are locked in exclusive mode.
284 
285  @note Changes to dd::Table object done by this method will be saved
286  to data-dictionary only if storage engine supporting atomic
287  DDL (i.e. with HTON_SUPPORTS_ATOMIC_DDL flag).
288 
289  @return Operation status.
290  @retval 0 Success.
291  @retval != 0 Error code.
292  */
293  int exchange_partition(uint part_id, dd::Table *part_table_def,
294  dd::Table *swap_table_def);
295 
296  /**
297  Alter flags.
298 
299  Given a set of alter table flags, return which is supported.
300 
301  @param flags Alter table operation flags.
302 
303  @return Supported alter table flags.
304  */
305  virtual uint alter_flags(uint flags [[maybe_unused]]) const { return 0; }
306 
307  /**
308  Get partition row type from SE
309  @param table partition table
310  @param part_id Id of partition for which row type to be retrieved
311  @return Partition row type.
312  */
313  virtual enum row_type get_partition_row_type(const dd::Table *table,
314  uint part_id) = 0;
315 
316  private:
317  /**
318  Truncate partition.
319 
320  Low-level primitive for handler, implementing
321  Partition_handler::truncate_partition().
322 
323  @sa Partition_handler::truncate_partition().
324  */
326  return HA_ERR_WRONG_COMMAND;
327  }
328 
329  /**
330  Exchange partition.
331 
332  Low-level primitive which implementation to be provided by SE.
333 
334  @sa Partition_handler::exchange_partition().
335  */
336  virtual int exchange_partition_low(uint part_id [[maybe_unused]],
337  dd::Table *part_table_def [[maybe_unused]],
338  dd::Table *swap_table_def
339  [[maybe_unused]]) {
340  return HA_ERR_WRONG_COMMAND;
341  }
342 
343  /**
344  Return the table handler.
345 
346  For some partitioning specific functions it is still needed to access
347  the handler directly for transaction handling (mark_trx_read_write())
348  and to assert correct locking.
349 
350  @return handler or NULL if not supported.
351  */
352  virtual handler *get_handler() { return nullptr; }
353 };
354 
355 /// Maps compare function to strict weak ordering required by Priority_queue.
356 struct Key_rec_less {
357  typedef int (*key_compare_fun)(KEY **, uchar *, uchar *);
358 
359  explicit Key_rec_less(KEY **keys)
360  : m_keys(keys), m_fun(key_rec_cmp), m_max_at_top(false) {}
361 
362  bool operator()(uchar *first, uchar *second) {
363  const int cmpval =
364  (*m_fun)(m_keys, first + m_rec_offset, second + m_rec_offset);
365  return m_max_at_top ? cmpval < 0 : cmpval > 0;
366  }
367 
372 };
373 
374 /**
375  Partition_helper is a helper class that implements most generic partitioning
376  functionality such as:
377  table scan, index scan (both ordered and non-ordered),
378  insert (write_row()), delete and update.
379  And includes ALTER TABLE ... ADD/COALESCE/DROP/REORGANIZE/... PARTITION
380  support.
381  It also implements a cache for the auto increment value and check/repair for
382  rows in wrong partition.
383 
384  How to use it:
385  Inherit it and implement:
386  - *_in_part() functions for row operations.
387  - write_row_in_new_part() for handling 'fast' alter partition.
388 */
392 
393  public:
394  Partition_helper(handler *main_handler);
395  virtual ~Partition_helper();
396 
397  /**
398  Set partition info.
399 
400  To be called from Partition_handler.
401 
402  @param part_info Partition info to use.
403  @param early True if called when part_info only created and parsed,
404  but not setup, checked or fixed.
405  */
406  virtual void set_part_info_low(partition_info *part_info, bool early);
407  /**
408  Initialize variables used before the table is opened.
409 
410  @param mem_root Memory root to allocate things from (not yet used).
411 
412  @return Operation status.
413  @retval false success.
414  @retval true failure.
415  */
416  bool init_partitioning(MEM_ROOT *mem_root [[maybe_unused]]) {
417 #ifndef NDEBUG
419 #endif
420  return false;
421  }
422 
423  /**
424  INSERT/UPDATE/DELETE functions.
425  @see handler.h
426  @{
427  */
428 
429  /**
430  Insert a row to the partitioned table.
431  @returns Operation status.
432  @returns 0 Success
433  @returns != 0 Error code
434  */
435  int ph_write_row(uchar *buf);
436  /**
437  Update an existing row in the partitioned table.
438 
439  Yes, update_row() does what you expect, it updates a row. old_data will
440  have the previous row record in it, while new_data will have the newest
441  data in it.
442  Keep in mind that the server can do updates based on ordering if an
443  ORDER BY clause was used. Consecutive ordering is not guaranteed.
444 
445  If the new record belongs to a different partition than the old record
446  then it will be inserted into the new partition and deleted from the old.
447 
448  new_data is always record[0]
449  old_data is always record[1]
450 
451  @return Operation status.
452  @returns 0 Success
453  @returns != 0 Error code
454  */
455  int ph_update_row(const uchar *old_data, uchar *new_data);
456  /**
457  Delete an existing row in the partitioned table.
458 
459  This will delete a row. buf will contain a copy of the row to be deleted.
460  The server will call this right after the current row has been read
461  (from either a previous rnd_xxx() or index_xxx() call).
462  If you keep a pointer to the last row or can access a primary key it will
463  make doing the deletion quite a bit easier.
464  Keep in mind that the server does no guarantee consecutive deletions.
465  ORDER BY clauses can be used.
466 
467  buf is either record[0] or record[1]
468 
469  @param buf The record in MySQL Row Format.
470 
471  @return Operation status.
472  @retval 0 Success
473  @retval != 0 Error code
474  */
475  int ph_delete_row(const uchar *buf);
476 
477  /** @} */
478 
479  /** Release unused auto increment values. */
481  /**
482  Calculate key hash value from an null terminated array of fields.
483  Support function for KEY partitioning.
484 
485  @param field_array An array of the fields in KEY partitioning
486 
487  @return hash_value calculated
488 
489  @note Uses the hash function on the character set of the field.
490  Integer and floating point fields use the binary character set by default.
491  */
492  static uint32 ph_calculate_key_hash_value(Field **field_array);
493 
494  /**
495  MODULE full table scan
496 
497  This module is used for the most basic access method for any table
498  handler. This is to fetch all data through a full table scan. No
499  indexes are needed to implement this part.
500  It contains one method to start the scan (rnd_init) that can also be
501  called multiple times (typical in a nested loop join). Then proceeding
502  to the next record (rnd_next) and closing the scan (rnd_end).
503  To remember a record for later access there is a method (position)
504  and there is a method used to retrieve the record based on the stored
505  position.
506  The position can be a file position, a primary key, a ROWID dependent
507  on the handler below.
508 
509  unlike index_init(), rnd_init() can be called two times
510  without rnd_end() in between (it only makes sense if scan=1).
511  then the second call should prepare for the new table scan
512  (e.g if rnd_init allocates the cursor, second call should
513  position it to the start of the table, no need to deallocate
514  and allocate it again.
515  @see handler.h
516  @{
517  */
518 
519  int ph_rnd_init(bool scan);
520  int ph_rnd_end();
521  int ph_rnd_next(uchar *buf);
522  void ph_position(const uchar *record);
523 
524  /** @} */
525 
526  /**
527  MODULE index scan
528 
529  This part of the handler interface is used to perform access through
530  indexes. The interface is defined as a scan interface but the handler
531  can also use key lookup if the index is a unique index or a primary
532  key index.
533  Index scans are mostly useful for SELECT queries but are an important
534  part also of UPDATE, DELETE, REPLACE and CREATE TABLE table AS SELECT
535  and so forth.
536  Naturally an index is needed for an index scan and indexes can either
537  be ordered, hash based. Some ordered indexes can return data in order
538  but not necessarily all of them.
539  There are many flags that define the behavior of indexes in the
540  various handlers. These methods are found in the optimizer module.
541  -------------------------------------------------------------------------
542 
543  index_read is called to start a scan of an index. The find_flag defines
544  the semantics of the scan. These flags are defined in
545  include/my_base.h
546  index_read_idx is the same but also initializes index before calling doing
547  the same thing as index_read. Thus it is similar to index_init followed
548  by index_read. This is also how we implement it.
549 
550  index_read/index_read_idx does also return the first row. Thus for
551  key lookups, the index_read will be the only call to the handler in
552  the index scan.
553 
554  index_init initializes an index before using it and index_end does
555  any end processing needed.
556  @{
557  */
558 
559  int ph_index_init_setup(uint key_nr, bool sorted);
560  /*
561  These methods are used to jump to next or previous entry in the index
562  scan. There are also methods to jump to first and last entry.
563  */
564  int ph_index_first(uchar *buf);
565  int ph_index_last(uchar *buf);
566  int ph_index_next(uchar *buf);
567  int ph_index_next_same(uchar *buf, uint keylen);
568  int ph_index_prev(uchar *buf);
569  int ph_index_read_map(uchar *buf, const uchar *key, key_part_map keypart_map,
570  enum ha_rkey_function find_flag);
572  key_part_map keypart_map);
573  int ph_index_read_idx_map(uchar *buf, uint index, const uchar *key,
574  key_part_map keypart_map,
575  enum ha_rkey_function find_flag);
576  int ph_read_range_first(const key_range *start_key, const key_range *end_key,
577  bool eq_range_arg, bool sorted);
578  int ph_read_range_next();
579  /** @} */
580 
581  /**
582  Functions matching Partition_handler API.
583  @{
584  */
585 
586  /**
587  Get statistics from a specific partition.
588  @param[out] stat_info Area to report values into.
589  @param[out] check_sum Check sum of partition.
590  @param[in] part_id Partition to report from.
591  */
592  virtual void get_dynamic_partition_info_low(ha_statistics *stat_info,
593  ha_checksum *check_sum,
594  uint part_id);
595 
596  /**
597  Prepare for reorganizing partitions by setting up
598  partition_info::read_partitions according to the partition_info
599  mark-up.
600 
601  This is helper method which can also be used by SEs implementing
602  support for reorganizing partitions through ALTER TABLE INPLACE
603  SE API.
604  */
606 
607  /** @} */
608 
609  protected:
610  /* Common helper functions to be used by inheriting engines. */
611 
612  /*
613  open/close functions.
614  */
615 
616  /**
617  Set m_part_share, Allocate internal bitmaps etc. used by open tables.
618 
619  @return Operation status.
620  @returns false success.
621  @returns true failure.
622  */
623  bool open_partitioning(Partition_share *part_share);
624  /**
625  Close partitioning for a table.
626 
627  Frees memory and release other resources.
628  */
629  void close_partitioning();
630 
631  /**
632  Lock auto increment value if needed.
633  */
634  void lock_auto_increment();
635 
636  /**
637  unlock auto increment.
638  */
639  inline void unlock_auto_increment() {
640  /*
641  If m_auto_increment_safe_stmt_log_lock is true, we have to keep the lock.
642  It will be set to false and thus unlocked at the end of the statement by
643  ha_partition::release_auto_increment.
644  */
647  m_auto_increment_lock = false;
648  }
649  }
650 
651  /**
652  Get a range of auto increment values.
653 
654  Can only be used if the auto increment field is the first field in an index.
655 
656  This method is called by update_auto_increment which in turn is called
657  by the individual handlers as part of write_row. We use the
658  part_share->next_auto_inc_val, or search all
659  partitions for the highest auto_increment_value if not initialized or
660  if auto_increment field is a secondary part of a key, we must search
661  every partition when holding a mutex to be sure of correctness.
662 
663  @param[in] increment Increment value.
664  @param[in] nb_desired_values Number of desired values.
665  @param[out] first_value First auto inc value reserved
666  or MAX if failure.
667  @param[out] nb_reserved_values Number of values reserved.
668  */
670  ulonglong nb_desired_values,
671  ulonglong *first_value,
672  ulonglong *nb_reserved_values);
673 
674  /**
675  Initialize the record priority queue used for sorted index scans.
676  @return Operation status.
677  @retval 0 Success.
678  @retval != 0 Error code.
679  */
681  /**
682  Destroy the record priority queue used for sorted index scans.
683  */
685  /*
686  Administrative support functions.
687  */
688 
689  /** Print partitioning specific error.
690  @param error Error code.
691  @return false if error is printed else true.
692  */
693  bool print_partition_error(int error);
694  /**
695  Print a message row formatted for ANALYZE/CHECK/OPTIMIZE/REPAIR TABLE.
696 
697  Modeled after mi_check_print_msg.
698 
699  @param thd Thread context.
700  @param len Needed length for message buffer.
701  @param msg_type Message type.
702  @param db_name Database name.
703  @param table_name Table name.
704  @param op_name Operation name.
705  @param fmt Message (in printf format with additional arguments).
706 
707  @return Operation status.
708  @retval false for success else true.
709  */
710  bool print_admin_msg(THD *thd, uint len, const char *msg_type,
711  const char *db_name, const char *table_name,
712  const char *op_name, const char *fmt, ...)
713  MY_ATTRIBUTE((format(printf, 8, 9)));
714 
715  /**
716  Check/fix misplaced rows.
717 
718  @param read_part_id Partition to check/fix.
719  @param repair If true, move misplaced rows to correct partition.
720 
721  @return Operation status.
722  @retval 0 Success
723  @retval != 0 Error
724  */
725  int check_misplaced_rows(uint read_part_id, bool repair);
726  /**
727  Set used partitions bitmap from Alter_info.
728 
729  @return false if success else true.
730  */
731  bool set_altered_partitions();
732 
733  /**
734  Copy partitions as part of ALTER TABLE of partitions.
735 
736  SE and prepare_change_partitions has done all the preparations,
737  now it is time to actually copy the data from the reorganized
738  partitions to the new partitions.
739 
740  @param[out] deleted Number of records deleted.
741 
742  @return Operation status
743  @retval 0 Success
744  @retval >0 Error code
745  */
746  virtual int copy_partitions(ulonglong *const deleted);
747 
748  private:
757  };
758 
759  /** handler to use (ha_innopart etc.) */
761  /*
762  Access methods to protected areas in handler to avoid adding
763  friend class Partition_helper in class handler.
764  */
765  virtual THD *get_thd() const = 0;
766  virtual TABLE *get_table() const = 0;
767  virtual bool get_eq_range() const = 0;
768  virtual void set_eq_range(bool eq_range) = 0;
769  virtual void set_range_key_part(KEY_PART_INFO *key_part) = 0;
770 
771  /*
772  Implementation of per partition operation by instantiated engine.
773  These must be implemented in the 'real' partition_helper subclass.
774  */
775 
776  /**
777  Write a row in the specified partition.
778 
779  @see handler::write_row().
780 
781  @param part_id Partition to write to.
782  @param buf Buffer with data to write.
783 
784  @return Operation status.
785  @retval 0 Success.
786  @retval != 0 Error code.
787  */
788  virtual int write_row_in_part(uint part_id, uchar *buf) = 0;
789  /**
790  Update a row in the specified partition.
791 
792  @see handler::update_row().
793 
794  @param part_id Partition to update in.
795  @param old_data Buffer containing old row.
796  @param new_data Buffer containing new row.
797 
798  @return Operation status.
799  @retval 0 Success.
800  @retval != 0 Error code.
801  */
802  virtual int update_row_in_part(uint part_id, const uchar *old_data,
803  uchar *new_data) = 0;
804  /**
805  Delete an existing row in the specified partition.
806 
807  @see handler::delete_row().
808 
809  @param part_id Partition to delete from.
810  @param buf Buffer containing row to delete.
811 
812  @return Operation status.
813  @retval 0 Success.
814  @retval != 0 Error code.
815  */
816  virtual int delete_row_in_part(uint part_id, const uchar *buf) = 0;
817  /**
818  Initialize the shared auto increment value.
819 
820  @param no_lock If HA_STATUS_NO_LOCK should be used in info(HA_STATUS_AUTO).
821 
822  Also sets stats.auto_increment_value.
823  */
824  virtual int initialize_auto_increment(bool no_lock) = 0;
825  /** Release auto_increment in all underlying partitions. */
827  /** Save or persist the current max auto increment. */
828  virtual void save_auto_increment(ulonglong nr [[maybe_unused]]) {}
829  /**
830  Per partition equivalent of rnd_* and index_* functions.
831 
832  @see class handler.
833  */
834  virtual int rnd_init_in_part(uint part_id, bool table_scan) = 0;
835  int ph_rnd_next_in_part(uint part_id, uchar *buf);
836  virtual int rnd_next_in_part(uint part_id, uchar *buf) = 0;
837  virtual int rnd_end_in_part(uint part_id, bool scan) = 0;
838  virtual void position_in_last_part(uchar *ref, const uchar *row) = 0;
839  virtual int index_first_in_part(uint part, uchar *buf) = 0;
840  virtual int index_last_in_part(uint part, uchar *buf) = 0;
841  virtual int index_prev_in_part(uint part, uchar *buf) = 0;
842  virtual int index_next_in_part(uint part, uchar *buf) = 0;
843  virtual int index_next_same_in_part(uint part, uchar *buf, const uchar *key,
844  uint length) = 0;
845  virtual int index_read_map_in_part(uint part, uchar *buf, const uchar *key,
846  key_part_map keypart_map,
847  enum ha_rkey_function find_flag) = 0;
849  const uchar *key,
850  key_part_map keypart_map) = 0;
851  /**
852  Do read_range_first in the specified partition.
853  If buf is set, then copy the result there instead of table->record[0].
854  */
856  const key_range *start_key,
857  const key_range *end_key,
858  bool sorted) = 0;
859  /**
860  Do read_range_next in the specified partition.
861  If buf is set, then copy the result there instead of table->record[0].
862  */
863  virtual int read_range_next_in_part(uint part, uchar *buf) = 0;
864  virtual int index_read_idx_map_in_part(uint part, uchar *buf, uint index,
865  const uchar *key,
866  key_part_map keypart_map,
867  enum ha_rkey_function find_flag) = 0;
868  /**
869  Initialize engine specific resources for the record priority queue
870  used duing ordered index reads for multiple partitions.
871 
872  @param used_parts Number of partitions used in query
873  (number of set bits in m_part_info->read_partitions).
874 
875  @return Operation status.
876  @retval 0 Success.
877  @retval != 0 Error code.
878  */
880  [[maybe_unused]]) {
881  return 0;
882  }
883  /**
884  Destroy and release engine specific resources used by the record
885  priority queue.
886  */
888  /**
889  Checksum for a partition.
890 
891  @param part_id Partition to checksum.
892  */
893  virtual ha_checksum checksum_in_part(uint part_id [[maybe_unused]]) const {
894  assert(0);
895  return 0;
896  }
897  /**
898  Copy a cached row.
899 
900  Used when copying a row from the record priority queue to the return buffer.
901  For some engines, like InnoDB, only marked columns must be copied,
902  to preserve non-read columns.
903 
904  @param[out] to_rec Buffer to copy to.
905  @param[in] from_rec Buffer to copy from.
906  */
907  virtual void copy_cached_row(uchar *to_rec, const uchar *from_rec) {
908  memcpy(to_rec, from_rec, m_rec_length);
909  }
910 
911  /**
912  write row to new partition.
913  @param new_part New partition to write to.
914 
915  @return Operation status.
916  @retval 0 Success.
917  @retval != 0 Error code.
918  */
919  virtual int write_row_in_new_part(uint new_part) = 0;
920 
921  /* Internal helper functions*/
922  /**
923  Update auto increment value if current row contains a higher value.
924  */
925  inline void set_auto_increment_if_higher();
926  /**
927  Common routine to set up index scans.
928 
929  Find out which partitions we'll need to read when scanning the specified
930  range.
931 
932  If we need to scan only one partition, set m_ordered_scan_ongoing=false
933  as we will not need to do merge ordering.
934 
935  @return Operation status.
936  @returns 0 Success
937  @returns !=0 Error code
938  */
939  int partition_scan_set_up(uchar *buf, bool idx_read_flag);
940  /**
941  Common routine to handle index_next with unordered results.
942 
943  These routines are used to scan partitions without considering order.
944  This is performed in two situations.
945  1) In read_multi_range this is the normal case
946  2) When performing any type of index_read, index_first, index_last where
947  all fields in the partition function is bound. In this case the index
948  scan is performed on only one partition and thus it isn't necessary to
949  perform any sort.
950 
951  @return Operation status.
952  @returns HA_ERR_END_OF_FILE End of scan
953  @returns 0 Success
954  @returns other Error code
955  */
956  int handle_unordered_next(uchar *buf, bool is_next_same);
957  /**
958  Handle index_next when changing to new partition.
959 
960  This routine is used to start the index scan on the next partition.
961  Both initial start and after completing scan on one partition.
962 
963  @param[out] buf Read row in MySQL Row Format
964 
965  @return Operation status.
966  @retval HA_ERR_END_OF_FILE End of scan
967  @retval 0 Success
968  @retval other Error code
969  */
971  /**
972  Common routine to start index scan with ordered results.
973 
974 
975  @returns Operation status
976  @returns HA_ERR_END_OF_FILE End of scan
977  @returns HA_ERR_KEY_NOT_FOUND End of scan
978  @returns 0 Success
979  @returns other Error code
980  */
982  /**
983  Add index_next/prev results from partitions without exact match.
984 
985  If there where any partitions that returned HA_ERR_KEY_NOT_FOUND when
986  ha_index_read_map was done, those partitions must be included in the
987  following index_next/prev call.
988 
989  @returns Operation status
990  @returns HA_ERR_END_OF_FILE End of scan
991  @returns 0 Success
992  @returns other Error code
993  */
995  /**
996  Common routine to handle index_prev with ordered results.
997 
998  @param[out] buf Read row in MySQL Row Format.
999 
1000  @return Operation status.
1001  @retval HA_ERR_END_OF_FILE End of scan
1002  @retval 0 Success
1003  @retval other Error code
1004  */
1006  /**
1007  Common routine to handle index_next with ordered results.
1008 
1009  @param[out] buf Read row in MySQL Row Format.
1010  @param[in] is_next_same Called from index_next_same.
1011 
1012  @return Operation status.
1013  @retval HA_ERR_END_OF_FILE End of scan
1014  @retval 0 Success
1015  @retval other Error code
1016  */
1017  int handle_ordered_next(uchar *buf, bool is_next_same);
1018  /**
1019  Common routine for a number of index_read variants.
1020 
1021  @param[out] buf Buffer where the record should be returned.
1022  @param[in] have_start_key true <=> the left endpoint is available, i.e.
1023  we're in index_read call or in read_range_first
1024  call and the range has left endpoint.
1025  false <=> there is no left endpoint (we're in
1026  read_range_first() call and the range has no
1027  left endpoint).
1028 
1029  @return Operation status
1030  @retval 0 OK
1031  @retval HA_ERR_END_OF_FILE Whole index scanned, without finding the
1032  record.
1033  @retval HA_ERR_KEY_NOT_FOUND Record not found, but index cursor
1034  positioned.
1035  @retval other Error code.
1036 
1037  @details
1038  Start scanning the range (when invoked from read_range_first()) or doing
1039  an index lookup (when invoked from index_read_XXX):
1040  - If possible, perform partition selection
1041  - Find the set of partitions we're going to use
1042  - Depending on whether we need ordering:
1043  NO: Get the first record from first used partition (see
1044  handle_unordered_scan_next_partition)
1045  YES: Fill the priority queue and get the record that is the first in
1046  the ordering
1047  */
1048  int common_index_read(uchar *buf, bool have_start_key);
1049  /**
1050  Common routine for index_first/index_last.
1051 
1052  @param[out] buf Read row in MySQL Row Format.
1053 
1054  @return Operation status.
1055  @retval 0 Success
1056  @retval != 0 Error code
1057  */
1058  int common_first_last(uchar *buf);
1059  /**
1060  Return the top record in sort order.
1061 
1062  @param[out] buf Row returned in MySQL Row Format.
1063  */
1064  void return_top_record(uchar *buf);
1065 
1066  /**
1067  Set table->read_set taking partitioning expressions into account.
1068  */
1069  void set_partition_read_set();
1070 
1071  /*
1072  These could be private as well,
1073  but easier to expose them to derived classes to use.
1074  */
1075  protected:
1076  /** Convenience pointer to table from m_handler (i.e. m_handler->table). */
1078 
1079  /** All internal partitioning data! @{ */
1080  /** Tables partitioning info (same as table->part_info) */
1082  /** Is primary key clustered. */
1084  /** Cached value of m_part_info->is_sub_partitioned(). */
1086  /** Total number of partitions. */
1088  uint m_last_part; // Last accessed partition.
1089  const uchar *m_err_rec; // record which gave error.
1092  part_id_range m_part_spec; // Which parts to scan
1093  uint m_scan_value; // Value passed in rnd_init
1094  // call
1095  key_range m_start_key; // index read key range
1096  enum partition_index_scan_type m_index_scan_type; // What type of index
1097  // scan
1098  uint m_rec_length; // Local copy of record length
1099 
1100  bool m_ordered; // Ordered/Unordered index scan.
1101  bool m_ordered_scan_ongoing; // Ordered index scan ongoing.
1102  bool m_reverse_order; // Scanning in reverse order (prev).
1103  /** Row and key buffer for ordered index scan. */
1105  /** Prio queue used by sorted read. */
1107  /** Which partition is to deliver next result. */
1109  /** Offset in m_ordered_rec_buffer from part buffer to its record buffer. */
1111  /**
1112  Current index used for sorting.
1113  If clustered PK exists, then it will be used as secondary index to
1114  sort on if the first is equal in key_rec_cmp.
1115  So if clustered pk: m_curr_key_info[0]= current index and
1116  m_curr_key_info[1]= pk and [2]= NULL.
1117  Otherwise [0]= current index, [1]= NULL, and we will
1118  sort by rowid as secondary sort key if equal first key.
1119  */
1122  /** handler::ref is not copied to the PQ. */
1124  /**
1125  handler::ref is copied to the PQ but does not need to be used in sorting.
1126  */
1128  /** handler::ref is copied to the PQ and must be used during sorting. */
1130  };
1131  /** How handler::ref is used in the priority queue. */
1133  /** Set if previous index_* call returned HA_ERR_KEY_NOT_FOUND. */
1135  /** Partitions that returned HA_ERR_KEY_NOT_FOUND. */
1137  /** @} */
1138 
1139  private:
1140  /** Partition share for auto_inc handling. */
1142 };
1143 #endif /* PARTITION_HANDLER_INCLUDED */
app_data_ptr new_data(u_int n, char *val, cons_type consensus)
Definition: field.h:590
Base class to be used by handlers different shares.
Definition: handler.h:3673
Definition: key.h:56
Definition: key.h:112
Class for partitioning specific operations.
Definition: partition_handler.h:193
int exchange_partition(uint part_id, dd::Table *part_table_def, dd::Table *swap_table_def)
Exchange partition.
Definition: partition_handler.cc:331
virtual handler * get_handler()
Return the table handler.
Definition: partition_handler.h:352
int truncate_partition(dd::Table *table_def)
Truncate partitions.
Definition: partition_handler.cc:320
virtual int truncate_partition_low(dd::Table *)
Truncate partition.
Definition: partition_handler.h:325
virtual ~Partition_handler()=default
virtual int get_default_num_partitions(HA_CREATE_INFO *info[[maybe_unused]])
Get default number of partitions.
Definition: partition_handler.h:219
virtual void set_auto_partitions(partition_info *part_info[[maybe_unused]])
Setup auto partitioning.
Definition: partition_handler.h:231
virtual enum row_type get_partition_row_type(const dd::Table *table, uint part_id)=0
Get partition row type from SE.
virtual uint alter_flags(uint flags[[maybe_unused]]) const
Alter flags.
Definition: partition_handler.h:305
virtual bool get_num_parts(const char *name[[maybe_unused]], uint *num_parts)
Get number of partitions for table in SE.
Definition: partition_handler.h:243
virtual void set_part_info(partition_info *part_info, bool early)=0
Set the partition info object to be used by the handler.
virtual int exchange_partition_low(uint part_id[[maybe_unused]], dd::Table *part_table_def[[maybe_unused]], dd::Table *swap_table_def[[maybe_unused]])
Exchange partition.
Definition: partition_handler.h:336
virtual void get_dynamic_partition_info(ha_statistics *stat_info, ha_checksum *check_sum, uint part_id)=0
Get dynamic table information from partition.
Partition_handler()=default
Partition_helper is a helper class that implements most generic partitioning functionality such as: t...
Definition: partition_handler.h:389
int ph_index_first(uchar *buf)
Start an index scan from leftmost record and return first record.
Definition: partition_handler.cc:1908
bool set_altered_partitions()
Set used partitions bitmap from Alter_info.
Definition: partition_handler.cc:1278
Prio_queue * m_queue
Prio queue used by sorted read.
Definition: partition_handler.h:1106
void return_top_record(uchar *buf)
Return the top record in sort order.
Definition: partition_handler.cc:2567
void close_partitioning()
Close partitioning for a table.
Definition: partition_handler.cc:426
virtual THD * get_thd() const =0
part_id_range m_part_spec
Definition: partition_handler.h:1092
int ph_index_read_map(uchar *buf, const uchar *key, key_part_map keypart_map, enum ha_rkey_function find_flag)
Read one record in an index scan and start an index scan.
Definition: partition_handler.cc:1833
virtual void destroy_record_priority_queue_for_parts()
Destroy and release engine specific resources used by the record priority queue.
Definition: partition_handler.h:887
uint m_rec_length
Definition: partition_handler.h:1098
Partition_helper(handler *main_handler)
Definition: partition_handler.cc:347
int common_first_last(uchar *buf)
Common routine for index_first/index_last.
Definition: partition_handler.cc:1955
void get_auto_increment_first_field(ulonglong increment, ulonglong nb_desired_values, ulonglong *first_value, ulonglong *nb_reserved_values)
Get a range of auto increment values.
Definition: partition_handler.cc:695
virtual int index_read_map_in_part(uint part, uchar *buf, const uchar *key, key_part_map keypart_map, enum ha_rkey_function find_flag)=0
uint m_top_entry
Which partition is to deliver next result.
Definition: partition_handler.h:1108
virtual int write_row_in_new_part(uint new_part)=0
write row to new partition.
virtual void save_auto_increment(ulonglong nr[[maybe_unused]])
Save or persist the current max auto increment.
Definition: partition_handler.h:828
Priority_queue< uchar *, std::vector< uchar * >, Key_rec_less > Prio_queue
Definition: partition_handler.h:391
int ph_index_prev(uchar *buf)
Read next record when performing index scan backwards.
Definition: partition_handler.cc:2129
int ph_update_row(const uchar *old_data, uchar *new_data)
Update an existing row in the partitioned table.
Definition: partition_handler.cc:561
bool m_ordered
Definition: partition_handler.h:1100
virtual int delete_row_in_part(uint part_id, const uchar *buf)=0
Delete an existing row in the specified partition.
enum_using_ref
Definition: partition_handler.h:1121
@ REF_USED_FOR_SORT
handler::ref is copied to the PQ and must be used during sorting.
Definition: partition_handler.h:1129
@ REF_STORED_IN_PQ
handler::ref is copied to the PQ but does not need to be used in sorting.
Definition: partition_handler.h:1127
@ REF_NOT_USED
handler::ref is not copied to the PQ.
Definition: partition_handler.h:1123
const uchar * m_err_rec
Definition: partition_handler.h:1089
bool m_auto_increment_lock
Definition: partition_handler.h:1091
int handle_ordered_next(uchar *buf, bool is_next_same)
Common routine to handle index_next with ordered results.
Definition: partition_handler.cc:2664
virtual void copy_cached_row(uchar *to_rec, const uchar *from_rec)
Copy a cached row.
Definition: partition_handler.h:907
virtual int rnd_end_in_part(uint part_id, bool scan)=0
int ph_write_row(uchar *buf)
INSERT/UPDATE/DELETE functions.
Definition: partition_handler.cc:456
void unlock_auto_increment()
unlock auto increment.
Definition: partition_handler.h:639
partition_info * m_part_info
All internal partitioning data!
Definition: partition_handler.h:1081
int ph_rnd_init(bool scan)
MODULE full table scan.
Definition: partition_handler.cc:1431
int handle_unordered_scan_next_partition(uchar *buf)
Handle index_next when changing to new partition.
Definition: partition_handler.cc:2340
bool m_reverse_order
Definition: partition_handler.h:1102
virtual void set_eq_range(bool eq_range)=0
virtual ha_checksum checksum_in_part(uint part_id[[maybe_unused]]) const
Checksum for a partition.
Definition: partition_handler.h:893
handler * m_handler
handler to use (ha_innopart etc.)
Definition: partition_handler.h:760
int handle_ordered_index_scan_key_not_found()
Add index_next/prev results from partitions without exact match.
Definition: partition_handler.cc:2588
int ph_index_next_same(uchar *buf, uint keylen)
Read next same record.
Definition: partition_handler.cc:2107
uint m_tot_parts
Total number of partitions.
Definition: partition_handler.h:1087
uint m_scan_value
Definition: partition_handler.h:1093
bool print_admin_msg(THD *thd, uint len, const char *msg_type, const char *db_name, const char *table_name, const char *op_name, const char *fmt,...)
Print a message row formatted for ANALYZE/CHECK/OPTIMIZE/REPAIR TABLE.
Definition: partition_handler.cc:1311
MY_BITMAP m_key_not_found_partitions
Partitions that returned HA_ERR_KEY_NOT_FOUND.
Definition: partition_handler.h:1136
bool print_partition_error(int error)
Print partitioning specific error.
Definition: partition_handler.cc:908
int handle_unordered_next(uchar *buf, bool is_next_same)
Common routine to handle index_next with unordered results.
Definition: partition_handler.cc:2292
bool m_is_sub_partitioned
Cached value of m_part_info->is_sub_partitioned().
Definition: partition_handler.h:1085
virtual ~Partition_helper()
Definition: partition_handler.cc:358
virtual int index_next_in_part(uint part, uchar *buf)=0
int ph_index_last(uchar *buf)
Start an index scan from rightmost record and return first record.
Definition: partition_handler.cc:1931
int ph_rnd_next(uchar *buf)
Read next row during full table scan (scan in random row order).
Definition: partition_handler.cc:1539
int ph_read_range_next()
Read next record in read of a range with start and end key.
Definition: partition_handler.cc:2192
int check_misplaced_rows(uint read_part_id, bool repair)
Check/fix misplaced rows.
Definition: partition_handler.cc:1096
virtual int index_read_idx_map_in_part(uint part, uchar *buf, uint index, const uchar *key, key_part_map keypart_map, enum ha_rkey_function find_flag)=0
int handle_ordered_prev(uchar *buf)
Common routine to handle index_prev with ordered results.
Definition: partition_handler.cc:2778
int common_index_read(uchar *buf, bool have_start_key)
Common routine for a number of index_read variants.
Definition: partition_handler.cc:1844
virtual int init_record_priority_queue_for_parts(uint used_parts[[maybe_unused]])
Initialize engine specific resources for the record priority queue used duing ordered index reads for...
Definition: partition_handler.h:879
virtual void position_in_last_part(uchar *ref, const uchar *row)=0
bool open_partitioning(Partition_share *part_share)
Set m_part_share, Allocate internal bitmaps etc.
Definition: partition_handler.cc:396
Partition_share * m_part_share
Partition share for auto_inc handling.
Definition: partition_handler.h:1141
virtual void set_part_info_low(partition_info *part_info, bool early)
Set partition info.
Definition: partition_handler.cc:372
static uint32 ph_calculate_key_hash_value(Field **field_array)
Calculate key hash value from an null terminated array of fields.
Definition: partition_handler.cc:805
void set_auto_increment_if_higher()
Update auto increment value if current row contains a higher value.
Definition: partition_handler.cc:754
bool m_pkey_is_clustered
Is primary key clustered.
Definition: partition_handler.h:1083
void ph_position(const uchar *record)
Save position of current row.
Definition: partition_handler.cc:1607
virtual TABLE * get_table() const =0
bool m_auto_increment_safe_stmt_log_lock
Definition: partition_handler.h:1090
bool m_ordered_scan_ongoing
Definition: partition_handler.h:1101
void destroy_record_priority_queue()
Destroy the record priority queue used for sorted index scans.
Definition: partition_handler.cc:1746
int ph_rnd_end()
End of a table scan.
Definition: partition_handler.cc:1492
virtual void release_auto_increment_all_parts()
Release auto_increment in all underlying partitions.
Definition: partition_handler.h:826
int ph_index_read_idx_map(uchar *buf, uint index, const uchar *key, key_part_map keypart_map, enum ha_rkey_function find_flag)
Read index by key and keymap.
Definition: partition_handler.cc:2015
virtual int write_row_in_part(uint part_id, uchar *buf)=0
Write a row in the specified partition.
void prepare_change_partitions()
Prepare for reorganizing partitions by setting up partition_info::read_partitions according to the pa...
Definition: partition_handler.cc:975
TABLE * m_table
Convenience pointer to table from m_handler (i.e.
Definition: partition_handler.h:1077
int ph_index_read_last_map(uchar *buf, const uchar *key, key_part_map keypart_map)
Read last using key.
Definition: partition_handler.cc:1983
virtual int index_first_in_part(uint part, uchar *buf)=0
partition_index_scan_type
Definition: partition_handler.h:749
@ PARTITION_INDEX_FIRST_UNORDERED
Definition: partition_handler.h:752
@ PARTITION_INDEX_READ
Definition: partition_handler.h:750
@ PARTITION_INDEX_FIRST
Definition: partition_handler.h:751
@ PARTITION_INDEX_LAST
Definition: partition_handler.h:753
@ PARTITION_READ_RANGE
Definition: partition_handler.h:755
@ PARTITION_NO_INDEX_SCAN
Definition: partition_handler.h:756
@ PARTITION_INDEX_READ_LAST
Definition: partition_handler.h:754
uint m_last_part
Definition: partition_handler.h:1088
enum partition_index_scan_type m_index_scan_type
Definition: partition_handler.h:1096
void ph_release_auto_increment()
Release unused auto increment values.
Definition: partition_handler.cc:770
int handle_ordered_index_scan(uchar *buf)
Common routine to start index scan with ordered results.
Definition: partition_handler.cc:2435
uint m_rec_offset
Offset in m_ordered_rec_buffer from part buffer to its record buffer.
Definition: partition_handler.h:1110
uchar * m_ordered_rec_buffer
Row and key buffer for ordered index scan.
Definition: partition_handler.h:1104
virtual int index_prev_in_part(uint part, uchar *buf)=0
key_range m_start_key
Definition: partition_handler.h:1095
virtual int read_range_next_in_part(uint part, uchar *buf)=0
Do read_range_next in the specified partition.
virtual int index_read_last_map_in_part(uint part, uchar *buf, const uchar *key, key_part_map keypart_map)=0
void lock_auto_increment()
Lock auto increment value if needed.
Definition: partition_handler.cc:432
bool init_partitioning(MEM_ROOT *mem_root[[maybe_unused]])
Initialize variables used before the table is opened.
Definition: partition_handler.h:416
int ph_index_next(uchar *buf)
Read next record in a forward index scan.
Definition: partition_handler.cc:2076
bool m_key_not_found
Set if previous index_* call returned HA_ERR_KEY_NOT_FOUND.
Definition: partition_handler.h:1134
virtual int index_next_same_in_part(uint part, uchar *buf, const uchar *key, uint length)=0
virtual int copy_partitions(ulonglong *const deleted)
Copy partitions as part of ALTER TABLE of partitions.
Definition: partition_handler.cc:1034
void set_partition_read_set()
Set table->read_set taking partitioning expressions into account.
Definition: partition_handler.cc:1367
int ph_rnd_next_in_part(uint part_id, uchar *buf)
Read next row during full partition scan (scan in random row order).
Definition: partition_handler.cc:1264
virtual int update_row_in_part(uint part_id, const uchar *old_data, uchar *new_data)=0
Update a row in the specified partition.
int ph_read_range_first(const key_range *start_key, const key_range *end_key, bool eq_range_arg, bool sorted)
Start a read of one range with start and end key.
Definition: partition_handler.cc:2156
virtual int initialize_auto_increment(bool no_lock)=0
Initialize the shared auto increment value.
int ph_index_init_setup(uint key_nr, bool sorted)
MODULE index scan.
Definition: partition_handler.cc:1775
enum_using_ref m_ref_usage
How handler::ref is used in the priority queue.
Definition: partition_handler.h:1132
virtual int index_last_in_part(uint part, uchar *buf)=0
int ph_delete_row(const uchar *buf)
Delete an existing row in the partitioned table.
Definition: partition_handler.cc:647
virtual int rnd_init_in_part(uint part_id, bool table_scan)=0
Per partition equivalent of rnd_* and index_* functions.
virtual int rnd_next_in_part(uint part_id, uchar *buf)=0
virtual void get_dynamic_partition_info_low(ha_statistics *stat_info, ha_checksum *check_sum, uint part_id)
Functions matching Partition_handler API.
Definition: partition_handler.cc:2862
virtual void set_range_key_part(KEY_PART_INFO *key_part)=0
int init_record_priority_queue()
Initialize the record priority queue used for sorted index scans.
Definition: partition_handler.cc:1660
int partition_scan_set_up(uchar *buf, bool idx_read_flag)
Common routine to set up index scans.
Definition: partition_handler.cc:2223
virtual int read_range_first_in_part(uint part, uchar *buf, const key_range *start_key, const key_range *end_key, bool sorted)=0
Do read_range_first in the specified partition.
KEY * m_curr_key_info[3]
Current index used for sorting.
Definition: partition_handler.h:1120
virtual bool get_eq_range() const =0
Partition specific Handler_share.
Definition: partition_handler.h:103
bool init_auto_inc_mutex(TABLE_SHARE *table_share)
Initializes and sets auto_inc_mutex.
Definition: partition_handler.cc:147
void release_auto_inc_if_possible(THD *thd, TABLE_SHARE *table_share, const ulonglong next_insert_id, const ulonglong max_reserved)
Release reserved auto increment values not used.
Definition: partition_handler.cc:173
~Partition_share() override
Definition: partition_handler.cc:129
ulonglong next_auto_inc_val
First non reserved auto increment value.
Definition: partition_handler.h:116
bool insert_partition_name_in_hash(const char *name, uint part_id, bool is_subpart)
Insert [sub]partition name into partition_name_hash.
Definition: partition_handler.cc:280
mysql_mutex_t * auto_inc_mutex
Mutex protecting next_auto_inc_val.
Definition: partition_handler.h:114
const uchar ** partition_names
Definition: partition_handler.h:173
bool auto_inc_initialized
Set if auto increment is used an initialized.
Definition: partition_handler.h:109
void unlock_auto_inc()
unlock mutex protecting auto increment value next_auto_inc_val.
Definition: partition_handler.h:149
const char * get_partition_name(size_t part_id) const
Get partition name.
Definition: partition_handler.cc:313
std::unique_ptr< collation_unordered_map< std::string, unique_ptr_my_free< PART_NAME_DEF > > > partition_name_hash
Hash of partition names.
Definition: partition_handler.h:124
void lock_auto_inc()
lock mutex protecting auto increment value next_auto_inc_val.
Definition: partition_handler.h:144
Partition_share()
Definition: partition_handler.cc:123
bool populate_partition_name_hash(partition_info *part_info)
Populate partition_name_hash with partition and subpartition names from part_info.
Definition: partition_handler.cc:202
Implements a priority queue using a vector-based max-heap.
Definition: priority_queue.h:91
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:821
std::unordered_map, but with my_malloc and collation-aware comparison.
Definition: map_helpers.h:209
Definition: table.h:46
Definition: handler.h:3594
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:4131
Definition: partition_info.h:208
A table definition from the master.
Definition: rpl_utility.h:247
static MEM_ROOT mem_root
Definition: client_plugin.cc:109
#define mysql_mutex_lock(M)
Definition: mysql_mutex.h:49
#define mysql_mutex_unlock(M)
Definition: mysql_mutex.h:56
static int flags[50]
Definition: hp_test1.cc:39
static uint keys
Definition: hp_test2.cc:45
int key_rec_cmp(KEY **key, uchar *first_rec, uchar *second_rec)
Compare two records in index order.
Definition: key.cc:582
This file includes constants used by all storage engines.
ha_rkey_function
Definition: my_base.h:77
ulong key_part_map
Definition: my_base.h:1006
#define HA_ERR_WRONG_COMMAND
Command not supported.
Definition: my_base.h:839
std::uint32_t ha_checksum
Definition: my_checksum.h:105
Header for compiler-dependent features.
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:55
unsigned char uchar
Definition: my_inttypes.h:51
uint32_t uint32
Definition: my_inttypes.h:66
#define UINT_MAX32
Definition: my_inttypes.h:78
Common header for many mysys elements.
Log info(cout, "NOTE")
Definition: buf0block_hint.cc:29
PT & ref(PT *tp)
Definition: tablespace_impl.cc:358
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:42
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:75
const char * table_name
Definition: rules_table_service.cc:55
const char * db_name
Definition: rules_table_service.cc:54
enum_part_operation
Definition: partition_handler.h:78
@ REPAIR_PARTS
Definition: partition_handler.h:82
@ PRELOAD_KEYS_PARTS
Definition: partition_handler.h:84
@ CHECK_PARTS
Definition: partition_handler.h:81
@ ASSIGN_KEYCACHE_PARTS
Definition: partition_handler.h:83
@ ANALYZE_PARTS
Definition: partition_handler.h:80
@ OPTIMIZE_PARTS
Definition: partition_handler.h:79
void partitioning_init()
Initialize partitioning (currently only PSI keys).
Definition: partition_handler.cc:109
static const uint NO_CURRENT_PART_ID
Definition: partition_handler.h:64
Instrumentation helpers for mutexes.
required string key
Definition: replication_asynchronous_connection_failover.proto:59
row_type
Definition: handler.h:669
case opt name
Definition: sslopt-case.h:32
Definition: handler.h:2764
Maps compare function to strict weak ordering required by Priority_queue.
Definition: partition_handler.h:356
KEY ** m_keys
Definition: partition_handler.h:368
Key_rec_less(KEY **keys)
Definition: partition_handler.h:359
bool m_max_at_top
Definition: partition_handler.h:371
key_compare_fun m_fun
Definition: partition_handler.h:369
int(* key_compare_fun)(KEY **, uchar *, uchar *)
Definition: partition_handler.h:357
bool operator()(uchar *first, uchar *second)
Definition: partition_handler.h:362
uint m_rec_offset
Definition: partition_handler.h:370
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:78
Definition: my_bitmap.h:41
my_bitmap_map * bitmap
Definition: my_bitmap.h:42
Struct used for partition_name_hash.
Definition: partition_handler.h:88
uint length
Definition: partition_handler.h:90
bool is_subpart
Definition: partition_handler.h:92
uchar * partition_name
Definition: partition_handler.h:89
uint32 part_id
Definition: partition_handler.h:91
This structure is shared between different table objects.
Definition: table.h:688
Definition: table.h:1394
Definition: my_base.h:1122
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:49
Definition: sql_partition.h:87
Definition: mi_test3.cc:54
unsigned int uint
Definition: uca-dump.cc:29