MySQL  8.0.24
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:
196  virtual ~Partition_handler() {}
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  HA_CREATE_INFO *info MY_ATTRIBUTE((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(
232  partition_info *part_info MY_ATTRIBUTE((unused))) {}
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 MY_ATTRIBUTE((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 MY_ATTRIBUTE((unused))) const {
306  return 0;
307  }
308 
309  /**
310  Get partition row type from SE
311  @param table partition table
312  @param part_id Id of partition for which row type to be retrieved
313  @return Partition row type.
314  */
315  virtual enum row_type get_partition_row_type(const dd::Table *table,
316  uint part_id) = 0;
317 
318  private:
319  /**
320  Truncate partition.
321 
322  Low-level primitive for handler, implementing
323  Partition_handler::truncate_partition().
324 
325  @sa Partition_handler::truncate_partition().
326  */
328  return HA_ERR_WRONG_COMMAND;
329  }
330 
331  /**
332  Exchange partition.
333 
334  Low-level primitive which implementation to be provided by SE.
335 
336  @sa Partition_handler::exchange_partition().
337  */
339  uint part_id MY_ATTRIBUTE((unused)),
340  dd::Table *part_table_def MY_ATTRIBUTE((unused)),
341  dd::Table *swap_table_def MY_ATTRIBUTE((unused))) {
342  return HA_ERR_WRONG_COMMAND;
343  }
344 
345  /**
346  Return the table handler.
347 
348  For some partitioning specific functions it is still needed to access
349  the handler directly for transaction handling (mark_trx_read_write())
350  and to assert correct locking.
351 
352  @return handler or NULL if not supported.
353  */
354  virtual handler *get_handler() { return nullptr; }
355 };
356 
357 /// Maps compare function to strict weak ordering required by Priority_queue.
358 struct Key_rec_less {
359  typedef int (*key_compare_fun)(KEY **, uchar *, uchar *);
360 
361  explicit Key_rec_less(KEY **keys)
362  : m_keys(keys), m_fun(key_rec_cmp), m_max_at_top(false) {}
363 
364  bool operator()(uchar *first, uchar *second) {
365  const int cmpval =
366  (*m_fun)(m_keys, first + m_rec_offset, second + m_rec_offset);
367  return m_max_at_top ? cmpval < 0 : cmpval > 0;
368  }
369 
374 };
375 
376 /**
377  Partition_helper is a helper class that implements most generic partitioning
378  functionality such as:
379  table scan, index scan (both ordered and non-ordered),
380  insert (write_row()), delete and update.
381  And includes ALTER TABLE ... ADD/COALESCE/DROP/REORGANIZE/... PARTITION
382  support.
383  It also implements a cache for the auto increment value and check/repair for
384  rows in wrong partition.
385 
386  How to use it:
387  Inherit it and implement:
388  - *_in_part() functions for row operations.
389  - write_row_in_new_part() for handling 'fast' alter partition.
390 */
394 
395  public:
396  Partition_helper(handler *main_handler);
397  virtual ~Partition_helper();
398 
399  /**
400  Set partition info.
401 
402  To be called from Partition_handler.
403 
404  @param part_info Partition info to use.
405  @param early True if called when part_info only created and parsed,
406  but not setup, checked or fixed.
407  */
408  virtual void set_part_info_low(partition_info *part_info, bool early);
409  /**
410  Initialize variables used before the table is opened.
411 
412  @param mem_root Memory root to allocate things from (not yet used).
413 
414  @return Operation status.
415  @retval false success.
416  @retval true failure.
417  */
418  bool init_partitioning(MEM_ROOT *mem_root MY_ATTRIBUTE((unused))) {
419 #ifndef NDEBUG
421 #endif
422  return false;
423  }
424 
425  /**
426  INSERT/UPDATE/DELETE functions.
427  @see handler.h
428  @{
429  */
430 
431  /**
432  Insert a row to the partitioned table.
433  @returns Operation status.
434  @returns 0 Success
435  @returns != 0 Error code
436  */
437  int ph_write_row(uchar *buf);
438  /**
439  Update an existing row in the partitioned table.
440 
441  Yes, update_row() does what you expect, it updates a row. old_data will
442  have the previous row record in it, while new_data will have the newest
443  data in it.
444  Keep in mind that the server can do updates based on ordering if an
445  ORDER BY clause was used. Consecutive ordering is not guaranteed.
446 
447  If the new record belongs to a different partition than the old record
448  then it will be inserted into the new partition and deleted from the old.
449 
450  new_data is always record[0]
451  old_data is always record[1]
452 
453  @return Operation status.
454  @returns 0 Success
455  @returns != 0 Error code
456  */
457  int ph_update_row(const uchar *old_data, uchar *new_data);
458  /**
459  Delete an existing row in the partitioned table.
460 
461  This will delete a row. buf will contain a copy of the row to be deleted.
462  The server will call this right after the current row has been read
463  (from either a previous rnd_xxx() or index_xxx() call).
464  If you keep a pointer to the last row or can access a primary key it will
465  make doing the deletion quite a bit easier.
466  Keep in mind that the server does no guarantee consecutive deletions.
467  ORDER BY clauses can be used.
468 
469  buf is either record[0] or record[1]
470 
471  @param buf The record in MySQL Row Format.
472 
473  @return Operation status.
474  @retval 0 Success
475  @retval != 0 Error code
476  */
477  int ph_delete_row(const uchar *buf);
478 
479  /** @} */
480 
481  /** Release unused auto increment values. */
483  /**
484  Calculate key hash value from an null terminated array of fields.
485  Support function for KEY partitioning.
486 
487  @param field_array An array of the fields in KEY partitioning
488 
489  @return hash_value calculated
490 
491  @note Uses the hash function on the character set of the field.
492  Integer and floating point fields use the binary character set by default.
493  */
494  static uint32 ph_calculate_key_hash_value(Field **field_array);
495 
496  /**
497  MODULE full table scan
498 
499  This module is used for the most basic access method for any table
500  handler. This is to fetch all data through a full table scan. No
501  indexes are needed to implement this part.
502  It contains one method to start the scan (rnd_init) that can also be
503  called multiple times (typical in a nested loop join). Then proceeding
504  to the next record (rnd_next) and closing the scan (rnd_end).
505  To remember a record for later access there is a method (position)
506  and there is a method used to retrieve the record based on the stored
507  position.
508  The position can be a file position, a primary key, a ROWID dependent
509  on the handler below.
510 
511  unlike index_init(), rnd_init() can be called two times
512  without rnd_end() in between (it only makes sense if scan=1).
513  then the second call should prepare for the new table scan
514  (e.g if rnd_init allocates the cursor, second call should
515  position it to the start of the table, no need to deallocate
516  and allocate it again.
517  @see handler.h
518  @{
519  */
520 
521  int ph_rnd_init(bool scan);
522  int ph_rnd_end();
523  int ph_rnd_next(uchar *buf);
524  void ph_position(const uchar *record);
525 
526  /** @} */
527 
528  /**
529  MODULE index scan
530 
531  This part of the handler interface is used to perform access through
532  indexes. The interface is defined as a scan interface but the handler
533  can also use key lookup if the index is a unique index or a primary
534  key index.
535  Index scans are mostly useful for SELECT queries but are an important
536  part also of UPDATE, DELETE, REPLACE and CREATE TABLE table AS SELECT
537  and so forth.
538  Naturally an index is needed for an index scan and indexes can either
539  be ordered, hash based. Some ordered indexes can return data in order
540  but not necessarily all of them.
541  There are many flags that define the behavior of indexes in the
542  various handlers. These methods are found in the optimizer module.
543  -------------------------------------------------------------------------
544 
545  index_read is called to start a scan of an index. The find_flag defines
546  the semantics of the scan. These flags are defined in
547  include/my_base.h
548  index_read_idx is the same but also initializes index before calling doing
549  the same thing as index_read. Thus it is similar to index_init followed
550  by index_read. This is also how we implement it.
551 
552  index_read/index_read_idx does also return the first row. Thus for
553  key lookups, the index_read will be the only call to the handler in
554  the index scan.
555 
556  index_init initializes an index before using it and index_end does
557  any end processing needed.
558  @{
559  */
560 
561  int ph_index_init_setup(uint key_nr, bool sorted);
562  /*
563  These methods are used to jump to next or previous entry in the index
564  scan. There are also methods to jump to first and last entry.
565  */
566  int ph_index_first(uchar *buf);
567  int ph_index_last(uchar *buf);
568  int ph_index_next(uchar *buf);
569  int ph_index_next_same(uchar *buf, uint keylen);
570  int ph_index_prev(uchar *buf);
571  int ph_index_read_map(uchar *buf, const uchar *key, key_part_map keypart_map,
572  enum ha_rkey_function find_flag);
574  key_part_map keypart_map);
575  int ph_index_read_idx_map(uchar *buf, uint index, const uchar *key,
576  key_part_map keypart_map,
577  enum ha_rkey_function find_flag);
578  int ph_read_range_first(const key_range *start_key, const key_range *end_key,
579  bool eq_range_arg, bool sorted);
580  int ph_read_range_next();
581  /** @} */
582 
583  /**
584  Functions matching Partition_handler API.
585  @{
586  */
587 
588  /**
589  Get statistics from a specific partition.
590  @param[out] stat_info Area to report values into.
591  @param[out] check_sum Check sum of partition.
592  @param[in] part_id Partition to report from.
593  */
594  virtual void get_dynamic_partition_info_low(ha_statistics *stat_info,
595  ha_checksum *check_sum,
596  uint part_id);
597 
598  /**
599  Prepare for reorganizing partitions by setting up
600  partition_info::read_partitions according to the partition_info
601  mark-up.
602 
603  This is helper method which can also be used by SEs implementing
604  support for reorganizing partitions through ALTER TABLE INPLACE
605  SE API.
606  */
608 
609  /** @} */
610 
611  protected:
612  /* Common helper functions to be used by inheriting engines. */
613 
614  /*
615  open/close functions.
616  */
617 
618  /**
619  Set m_part_share, Allocate internal bitmaps etc. used by open tables.
620 
621  @return Operation status.
622  @returns false success.
623  @returns true failure.
624  */
625  bool open_partitioning(Partition_share *part_share);
626  /**
627  Close partitioning for a table.
628 
629  Frees memory and release other resources.
630  */
631  void close_partitioning();
632 
633  /**
634  Lock auto increment value if needed.
635  */
636  void lock_auto_increment();
637 
638  /**
639  unlock auto increment.
640  */
641  inline void unlock_auto_increment() {
642  /*
643  If m_auto_increment_safe_stmt_log_lock is true, we have to keep the lock.
644  It will be set to false and thus unlocked at the end of the statement by
645  ha_partition::release_auto_increment.
646  */
649  m_auto_increment_lock = false;
650  }
651  }
652 
653  /**
654  Get a range of auto increment values.
655 
656  Can only be used if the auto increment field is the first field in an index.
657 
658  This method is called by update_auto_increment which in turn is called
659  by the individual handlers as part of write_row. We use the
660  part_share->next_auto_inc_val, or search all
661  partitions for the highest auto_increment_value if not initialized or
662  if auto_increment field is a secondary part of a key, we must search
663  every partition when holding a mutex to be sure of correctness.
664 
665  @param[in] increment Increment value.
666  @param[in] nb_desired_values Number of desired values.
667  @param[out] first_value First auto inc value reserved
668  or MAX if failure.
669  @param[out] nb_reserved_values Number of values reserved.
670  */
672  ulonglong nb_desired_values,
673  ulonglong *first_value,
674  ulonglong *nb_reserved_values);
675 
676  /**
677  Initialize the record priority queue used for sorted index scans.
678  @return Operation status.
679  @retval 0 Success.
680  @retval != 0 Error code.
681  */
683  /**
684  Destroy the record priority queue used for sorted index scans.
685  */
687  /*
688  Administrative support functions.
689  */
690 
691  /** Print partitioning specific error.
692  @param error Error code.
693  @return false if error is printed else true.
694  */
695  bool print_partition_error(int error);
696  /**
697  Print a message row formatted for ANALYZE/CHECK/OPTIMIZE/REPAIR TABLE.
698 
699  Modeled after mi_check_print_msg.
700 
701  @param thd Thread context.
702  @param len Needed length for message buffer.
703  @param msg_type Message type.
704  @param db_name Database name.
705  @param table_name Table name.
706  @param op_name Operation name.
707  @param fmt Message (in printf format with additional arguments).
708 
709  @return Operation status.
710  @retval false for success else true.
711  */
712  bool print_admin_msg(THD *thd, uint len, const char *msg_type,
713  const char *db_name, const char *table_name,
714  const char *op_name, const char *fmt, ...)
715  MY_ATTRIBUTE((format(printf, 8, 9)));
716 
717  /**
718  Check/fix misplaced rows.
719 
720  @param read_part_id Partition to check/fix.
721  @param repair If true, move misplaced rows to correct partition.
722 
723  @return Operation status.
724  @retval 0 Success
725  @retval != 0 Error
726  */
727  int check_misplaced_rows(uint read_part_id, bool repair);
728  /**
729  Set used partitions bitmap from Alter_info.
730 
731  @return false if success else true.
732  */
733  bool set_altered_partitions();
734 
735  /**
736  Copy partitions as part of ALTER TABLE of partitions.
737 
738  SE and prepare_change_partitions has done all the preparations,
739  now it is time to actually copy the data from the reorganized
740  partitions to the new partitions.
741 
742  @param[out] deleted Number of records deleted.
743 
744  @return Operation status
745  @retval 0 Success
746  @retval >0 Error code
747  */
748  virtual int copy_partitions(ulonglong *const deleted);
749 
750  private:
759  };
760 
761  /** handler to use (ha_innopart etc.) */
763  /*
764  Access methods to protected areas in handler to avoid adding
765  friend class Partition_helper in class handler.
766  */
767  virtual THD *get_thd() const = 0;
768  virtual TABLE *get_table() const = 0;
769  virtual bool get_eq_range() const = 0;
770  virtual void set_eq_range(bool eq_range) = 0;
771  virtual void set_range_key_part(KEY_PART_INFO *key_part) = 0;
772 
773  /*
774  Implementation of per partition operation by instantiated engine.
775  These must be implemented in the 'real' partition_helper subclass.
776  */
777 
778  /**
779  Write a row in the specified partition.
780 
781  @see handler::write_row().
782 
783  @param part_id Partition to write to.
784  @param buf Buffer with data to write.
785 
786  @return Operation status.
787  @retval 0 Success.
788  @retval != 0 Error code.
789  */
790  virtual int write_row_in_part(uint part_id, uchar *buf) = 0;
791  /**
792  Update a row in the specified partition.
793 
794  @see handler::update_row().
795 
796  @param part_id Partition to update in.
797  @param old_data Buffer containing old row.
798  @param new_data Buffer containing new row.
799 
800  @return Operation status.
801  @retval 0 Success.
802  @retval != 0 Error code.
803  */
804  virtual int update_row_in_part(uint part_id, const uchar *old_data,
805  uchar *new_data) = 0;
806  /**
807  Delete an existing row in the specified partition.
808 
809  @see handler::delete_row().
810 
811  @param part_id Partition to delete from.
812  @param buf Buffer containing row to delete.
813 
814  @return Operation status.
815  @retval 0 Success.
816  @retval != 0 Error code.
817  */
818  virtual int delete_row_in_part(uint part_id, const uchar *buf) = 0;
819  /**
820  Initialize the shared auto increment value.
821 
822  @param no_lock If HA_STATUS_NO_LOCK should be used in info(HA_STATUS_AUTO).
823 
824  Also sets stats.auto_increment_value.
825  */
826  virtual int initialize_auto_increment(bool no_lock) = 0;
827  /** Release auto_increment in all underlying partitions. */
829  /** Save or persist the current max auto increment. */
830  virtual void save_auto_increment(ulonglong nr MY_ATTRIBUTE((unused))) {}
831  /**
832  Per partition equivalent of rnd_* and index_* functions.
833 
834  @see class handler.
835  */
836  virtual int rnd_init_in_part(uint part_id, bool table_scan) = 0;
837  int ph_rnd_next_in_part(uint part_id, uchar *buf);
838  virtual int rnd_next_in_part(uint part_id, uchar *buf) = 0;
839  virtual int rnd_end_in_part(uint part_id, bool scan) = 0;
840  virtual void position_in_last_part(uchar *ref, const uchar *row) = 0;
841  virtual int index_first_in_part(uint part, uchar *buf) = 0;
842  virtual int index_last_in_part(uint part, uchar *buf) = 0;
843  virtual int index_prev_in_part(uint part, uchar *buf) = 0;
844  virtual int index_next_in_part(uint part, uchar *buf) = 0;
845  virtual int index_next_same_in_part(uint part, uchar *buf, const uchar *key,
846  uint length) = 0;
847  virtual int index_read_map_in_part(uint part, uchar *buf, const uchar *key,
848  key_part_map keypart_map,
849  enum ha_rkey_function find_flag) = 0;
851  const uchar *key,
852  key_part_map keypart_map) = 0;
853  /**
854  Do read_range_first in the specified partition.
855  If buf is set, then copy the result there instead of table->record[0].
856  */
858  const key_range *start_key,
859  const key_range *end_key,
860  bool sorted) = 0;
861  /**
862  Do read_range_next in the specified partition.
863  If buf is set, then copy the result there instead of table->record[0].
864  */
865  virtual int read_range_next_in_part(uint part, uchar *buf) = 0;
866  virtual int index_read_idx_map_in_part(uint part, uchar *buf, uint index,
867  const uchar *key,
868  key_part_map keypart_map,
869  enum ha_rkey_function find_flag) = 0;
870  /**
871  Initialize engine specific resources for the record priority queue
872  used duing ordered index reads for multiple partitions.
873 
874  @param used_parts Number of partitions used in query
875  (number of set bits in m_part_info->read_partitions).
876 
877  @return Operation status.
878  @retval 0 Success.
879  @retval != 0 Error code.
880  */
882  uint used_parts MY_ATTRIBUTE((unused))) {
883  return 0;
884  }
885  /**
886  Destroy and release engine specific resources used by the record
887  priority queue.
888  */
890  /**
891  Checksum for a partition.
892 
893  @param part_id Partition to checksum.
894  */
896  uint part_id MY_ATTRIBUTE((unused))) const {
897  assert(0);
898  return 0;
899  }
900  /**
901  Copy a cached row.
902 
903  Used when copying a row from the record priority queue to the return buffer.
904  For some engines, like InnoDB, only marked columns must be copied,
905  to preserve non-read columns.
906 
907  @param[out] to_rec Buffer to copy to.
908  @param[in] from_rec Buffer to copy from.
909  */
910  virtual void copy_cached_row(uchar *to_rec, const uchar *from_rec) {
911  memcpy(to_rec, from_rec, m_rec_length);
912  }
913 
914  /**
915  write row to new partition.
916  @param new_part New partition to write to.
917 
918  @return Operation status.
919  @retval 0 Success.
920  @retval != 0 Error code.
921  */
922  virtual int write_row_in_new_part(uint new_part) = 0;
923 
924  /* Internal helper functions*/
925  /**
926  Update auto increment value if current row contains a higher value.
927  */
928  inline void set_auto_increment_if_higher();
929  /**
930  Common routine to set up index scans.
931 
932  Find out which partitions we'll need to read when scanning the specified
933  range.
934 
935  If we need to scan only one partition, set m_ordered_scan_ongoing=false
936  as we will not need to do merge ordering.
937 
938  @return Operation status.
939  @returns 0 Success
940  @returns !=0 Error code
941  */
942  int partition_scan_set_up(uchar *buf, bool idx_read_flag);
943  /**
944  Common routine to handle index_next with unordered results.
945 
946  These routines are used to scan partitions without considering order.
947  This is performed in two situations.
948  1) In read_multi_range this is the normal case
949  2) When performing any type of index_read, index_first, index_last where
950  all fields in the partition function is bound. In this case the index
951  scan is performed on only one partition and thus it isn't necessary to
952  perform any sort.
953 
954  @return Operation status.
955  @returns HA_ERR_END_OF_FILE End of scan
956  @returns 0 Success
957  @returns other Error code
958  */
959  int handle_unordered_next(uchar *buf, bool is_next_same);
960  /**
961  Handle index_next when changing to new partition.
962 
963  This routine is used to start the index scan on the next partition.
964  Both initial start and after completing scan on one partition.
965 
966  @param[out] buf Read row in MySQL Row Format
967 
968  @return Operation status.
969  @retval HA_ERR_END_OF_FILE End of scan
970  @retval 0 Success
971  @retval other Error code
972  */
974  /**
975  Common routine to start index scan with ordered results.
976 
977 
978  @returns Operation status
979  @returns HA_ERR_END_OF_FILE End of scan
980  @returns HA_ERR_KEY_NOT_FOUND End of scan
981  @returns 0 Success
982  @returns other Error code
983  */
985  /**
986  Add index_next/prev results from partitions without exact match.
987 
988  If there where any partitions that returned HA_ERR_KEY_NOT_FOUND when
989  ha_index_read_map was done, those partitions must be included in the
990  following index_next/prev call.
991 
992  @returns Operation status
993  @returns HA_ERR_END_OF_FILE End of scan
994  @returns 0 Success
995  @returns other Error code
996  */
998  /**
999  Common routine to handle index_prev with ordered results.
1000 
1001  @param[out] buf Read row in MySQL Row Format.
1002 
1003  @return Operation status.
1004  @retval HA_ERR_END_OF_FILE End of scan
1005  @retval 0 Success
1006  @retval other Error code
1007  */
1009  /**
1010  Common routine to handle index_next with ordered results.
1011 
1012  @param[out] buf Read row in MySQL Row Format.
1013  @param[in] is_next_same Called from index_next_same.
1014 
1015  @return Operation status.
1016  @retval HA_ERR_END_OF_FILE End of scan
1017  @retval 0 Success
1018  @retval other Error code
1019  */
1020  int handle_ordered_next(uchar *buf, bool is_next_same);
1021  /**
1022  Common routine for a number of index_read variants.
1023 
1024  @param[out] buf Buffer where the record should be returned.
1025  @param[in] have_start_key true <=> the left endpoint is available, i.e.
1026  we're in index_read call or in read_range_first
1027  call and the range has left endpoint.
1028  false <=> there is no left endpoint (we're in
1029  read_range_first() call and the range has no
1030  left endpoint).
1031 
1032  @return Operation status
1033  @retval 0 OK
1034  @retval HA_ERR_END_OF_FILE Whole index scanned, without finding the
1035  record.
1036  @retval HA_ERR_KEY_NOT_FOUND Record not found, but index cursor
1037  positioned.
1038  @retval other Error code.
1039 
1040  @details
1041  Start scanning the range (when invoked from read_range_first()) or doing
1042  an index lookup (when invoked from index_read_XXX):
1043  - If possible, perform partition selection
1044  - Find the set of partitions we're going to use
1045  - Depending on whether we need ordering:
1046  NO: Get the first record from first used partition (see
1047  handle_unordered_scan_next_partition)
1048  YES: Fill the priority queue and get the record that is the first in
1049  the ordering
1050  */
1051  int common_index_read(uchar *buf, bool have_start_key);
1052  /**
1053  Common routine for index_first/index_last.
1054 
1055  @param[out] buf Read row in MySQL Row Format.
1056 
1057  @return Operation status.
1058  @retval 0 Success
1059  @retval != 0 Error code
1060  */
1061  int common_first_last(uchar *buf);
1062  /**
1063  Return the top record in sort order.
1064 
1065  @param[out] buf Row returned in MySQL Row Format.
1066  */
1067  void return_top_record(uchar *buf);
1068 
1069  /**
1070  Set table->read_set taking partitioning expressions into account.
1071  */
1072  void set_partition_read_set();
1073 
1074  /*
1075  These could be private as well,
1076  but easier to expose them to derived classes to use.
1077  */
1078  protected:
1079  /** Convenience pointer to table from m_handler (i.e. m_handler->table). */
1081 
1082  /** All internal partitioning data! @{ */
1083  /** Tables partitioning info (same as table->part_info) */
1085  /** Is primary key clustered. */
1087  /** Cached value of m_part_info->is_sub_partitioned(). */
1089  /** Total number of partitions. */
1091  uint m_last_part; // Last accessed partition.
1092  const uchar *m_err_rec; // record which gave error.
1095  part_id_range m_part_spec; // Which parts to scan
1096  uint m_scan_value; // Value passed in rnd_init
1097  // call
1098  key_range m_start_key; // index read key range
1099  enum partition_index_scan_type m_index_scan_type; // What type of index
1100  // scan
1101  uint m_rec_length; // Local copy of record length
1102 
1103  bool m_ordered; // Ordered/Unordered index scan.
1104  bool m_ordered_scan_ongoing; // Ordered index scan ongoing.
1105  bool m_reverse_order; // Scanning in reverse order (prev).
1106  /** Row and key buffer for ordered index scan. */
1108  /** Prio queue used by sorted read. */
1110  /** Which partition is to deliver next result. */
1112  /** Offset in m_ordered_rec_buffer from part buffer to its record buffer. */
1114  /**
1115  Current index used for sorting.
1116  If clustered PK exists, then it will be used as secondary index to
1117  sort on if the first is equal in key_rec_cmp.
1118  So if clustered pk: m_curr_key_info[0]= current index and
1119  m_curr_key_info[1]= pk and [2]= NULL.
1120  Otherwise [0]= current index, [1]= NULL, and we will
1121  sort by rowid as secondary sort key if equal first key.
1122  */
1125  /** handler::ref is not copied to the PQ. */
1127  /**
1128  handler::ref is copied to the PQ but does not need to be used in sorting.
1129  */
1131  /** handler::ref is copied to the PQ and must be used during sorting. */
1133  };
1134  /** How handler::ref is used in the priority queue. */
1136  /** Set if previous index_* call returned HA_ERR_KEY_NOT_FOUND. */
1138  /** Partitions that returned HA_ERR_KEY_NOT_FOUND. */
1140  /** @} */
1141 
1142  private:
1143  /** Partition share for auto_inc handling. */
1145 };
1146 #endif /* PARTITION_HANDLER_INCLUDED */
app_data_ptr new_data(u_int n, char *val, cons_type consensus)
Definition: app_data.cc:363
Definition: field.h:568
Base class to be used by handlers different shares.
Definition: handler.h:3665
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:354
int truncate_partition(dd::Table *table_def)
Truncate partitions.
Definition: partition_handler.cc:320
virtual bool get_num_parts(const char *name, uint *num_parts)
Get number of partitions for table in SE.
Definition: partition_handler.h:243
virtual int truncate_partition_low(dd::Table *)
Truncate partition.
Definition: partition_handler.h:327
virtual int get_default_num_partitions(HA_CREATE_INFO *info)
Get default number of partitions.
Definition: partition_handler.h:219
virtual ~Partition_handler()
Definition: partition_handler.h:196
Partition_handler()
Definition: partition_handler.h:195
virtual uint alter_flags(uint flags) const
Alter flags.
Definition: partition_handler.h:305
virtual enum row_type get_partition_row_type(const dd::Table *table, uint part_id)=0
Get partition row type from SE.
virtual int exchange_partition_low(uint part_id, dd::Table *part_table_def, dd::Table *swap_table_def)
Exchange partition.
Definition: partition_handler.h:338
virtual void set_part_info(partition_info *part_info, bool early)=0
Set the partition info object to be used by the handler.
virtual void get_dynamic_partition_info(ha_statistics *stat_info, ha_checksum *check_sum, uint part_id)=0
Get dynamic table information from partition.
virtual void set_auto_partitions(partition_info *part_info)
Setup auto partitioning.
Definition: partition_handler.h:231
Partition_helper is a helper class that implements most generic partitioning functionality such as: t...
Definition: partition_handler.h:391
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:1109
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:1095
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:889
uint m_rec_length
Definition: partition_handler.h:1101
virtual void save_auto_increment(ulonglong nr)
Save or persist the current max auto increment.
Definition: partition_handler.h:830
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:1111
virtual int write_row_in_new_part(uint new_part)=0
write row to new partition.
Priority_queue< uchar *, std::vector< uchar * >, Key_rec_less > Prio_queue
Definition: partition_handler.h:393
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:1103
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:1124
@ REF_USED_FOR_SORT
handler::ref is copied to the PQ and must be used during sorting.
Definition: partition_handler.h:1132
@ REF_STORED_IN_PQ
handler::ref is copied to the PQ but does not need to be used in sorting.
Definition: partition_handler.h:1130
@ REF_NOT_USED
handler::ref is not copied to the PQ.
Definition: partition_handler.h:1126
const uchar * m_err_rec
Definition: partition_handler.h:1092
bool m_auto_increment_lock
Definition: partition_handler.h:1094
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:910
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:641
partition_info * m_part_info
All internal partitioning data!
Definition: partition_handler.h:1084
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:1105
virtual void set_eq_range(bool eq_range)=0
handler * m_handler
handler to use (ha_innopart etc.)
Definition: partition_handler.h:762
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:1090
uint m_scan_value
Definition: partition_handler.h:1096
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:1139
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:1088
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 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:1144
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:1086
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:1093
bool m_ordered_scan_ongoing
Definition: partition_handler.h:1104
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:828
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
virtual int init_record_priority_queue_for_parts(uint used_parts)
Initialize engine specific resources for the record priority queue used duing ordered index reads for...
Definition: partition_handler.h:881
TABLE * m_table
Convenience pointer to table from m_handler (i.e.
Definition: partition_handler.h:1080
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:751
@ PARTITION_INDEX_FIRST_UNORDERED
Definition: partition_handler.h:754
@ PARTITION_INDEX_READ
Definition: partition_handler.h:752
@ PARTITION_INDEX_FIRST
Definition: partition_handler.h:753
@ PARTITION_INDEX_LAST
Definition: partition_handler.h:755
@ PARTITION_READ_RANGE
Definition: partition_handler.h:757
@ PARTITION_NO_INDEX_SCAN
Definition: partition_handler.h:758
@ PARTITION_INDEX_READ_LAST
Definition: partition_handler.h:756
uint m_last_part
Definition: partition_handler.h:1091
enum partition_index_scan_type m_index_scan_type
Definition: partition_handler.h:1099
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:1113
uchar * m_ordered_rec_buffer
Row and key buffer for ordered index scan.
Definition: partition_handler.h:1107
virtual int index_prev_in_part(uint part, uchar *buf)=0
key_range m_start_key
Definition: partition_handler.h:1098
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
int ph_index_next(uchar *buf)
Read next record in a forward index scan.
Definition: partition_handler.cc:2076
bool init_partitioning(MEM_ROOT *mem_root)
Initialize variables used before the table is opened.
Definition: partition_handler.h:418
bool m_key_not_found
Set if previous index_* call returned HA_ERR_KEY_NOT_FOUND.
Definition: partition_handler.h:1137
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:1135
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:1123
virtual ha_checksum checksum_in_part(uint part_id) const
Checksum for a partition.
Definition: partition_handler.h:895
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:93
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:813
std::unordered_map, but with my_malloc and collation-aware comparison.
Definition: map_helpers.h:239
Definition: table.h:46
Definition: handler.h:3586
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:4123
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
static uchar key[100]
Definition: mi_test2.cc:58
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:1004
#define HA_ERR_WRONG_COMMAND
Command not supported.
Definition: my_base.h:837
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.
row_type
Definition: handler.h:669
case opt name
Definition: sslopt-case.h:32
Definition: handler.h:2743
Maps compare function to strict weak ordering required by Priority_queue.
Definition: partition_handler.h:358
KEY ** m_keys
Definition: partition_handler.h:370
Key_rec_less(KEY **keys)
Definition: partition_handler.h:361
bool m_max_at_top
Definition: partition_handler.h:373
key_compare_fun m_fun
Definition: partition_handler.h:371
int(* key_compare_fun)(KEY **, uchar *, uchar *)
Definition: partition_handler.h:359
bool operator()(uchar *first, uchar *second)
Definition: partition_handler.h:364
uint m_rec_offset
Definition: partition_handler.h:372
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:687
Definition: table.h:1389
Definition: my_base.h:1120
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