MySQL  8.0.17
Source Code Documentation
opt_range.h
Go to the documentation of this file.
1 /* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License, version 2.0,
5  as published by the Free Software Foundation.
6 
7  This program is also distributed with certain software (including
8  but not limited to OpenSSL) that is licensed under separate terms,
9  as designated in a particular file or component or in included license
10  documentation. The authors of MySQL hereby grant you an additional
11  permission to link the program and your derivative works with the
12  separately licensed software that they have included with MySQL.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License, version 2.0, for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22 
23 /* classes to use when handling where clause */
24 
25 #ifndef _opt_range_h
26 #define _opt_range_h
27 
28 #include <stddef.h>
29 #include <sys/types.h>
30 #include <algorithm>
31 #include <memory>
32 #include <vector>
33 
34 #include "m_string.h"
35 #include "my_alloc.h"
36 #include "my_base.h"
37 #include "my_bitmap.h"
38 #include "my_compiler.h"
39 #include "my_dbug.h"
40 #include "my_inttypes.h"
41 #include "my_table_map.h"
42 #include "prealloced_array.h" // Prealloced_array
43 #include "priority_queue.h" // Priority_queue
44 #include "sql/field.h" // Field
45 #include "sql/handler.h"
46 #include "sql/key.h"
47 #include "sql/key_spec.h"
48 #include "sql/malloc_allocator.h" // IWYU pragma: keep
49 #include "sql/records.h" // READ_RECORD
50 #include "sql/sql_bitmap.h"
51 #include "sql/sql_const.h"
52 #include "sql/sql_list.h"
53 #include "sql/table.h"
54 #include "sql_string.h"
55 
56 class Item;
57 class Item_sum;
58 class JOIN;
59 class Opt_trace_context;
60 class THD;
61 class Unique;
62 struct TABLE_REF;
63 
64 struct KEY_PART {
66  /* See KEY_PART_INFO for meaning of the next two: */
69  /*
70  Keypart flags (0 when this structure is used by partition pruning code
71  for fake partitioning index description)
72  */
76 };
77 
78 class QUICK_RANGE {
79  public:
82 
83  /// Stores bitwise-or'ed bits defined in enum key_range_flags.
85 
86  /**
87  Stores one of the HA_READ_MBR_XXX items in enum ha_rkey_function, only
88  effective when flag has a GEOM_FLAG bit.
89  */
91  key_part_map min_keypart_map, // bitmap of used keyparts in min_key
92  max_keypart_map; // bitmap of used keyparts in max_key
93 
94  QUICK_RANGE(); /* Full range */
95  QUICK_RANGE(const uchar *min_key_arg, uint min_length_arg,
96  key_part_map min_keypart_map_arg, const uchar *max_key_arg,
97  uint max_length_arg, key_part_map max_keypart_map_arg,
98  uint flag_arg, enum ha_rkey_function rkey_func);
99 
100  /**
101  Initalizes a key_range object for communication with storage engine.
102 
103  This function facilitates communication with the Storage Engine API by
104  translating the minimum endpoint of the interval represented by this
105  QUICK_RANGE into an index range endpoint specifier for the engine.
106 
107  @param kr Pointer to an uninitialized key_range C struct.
108 
109  @param prefix_length The length of the search key prefix to be used for
110  lookup.
111 
112  @param keypart_map A set (bitmap) of keyparts to be used.
113  */
114  void make_min_endpoint(key_range *kr, uint prefix_length,
115  key_part_map keypart_map) {
116  make_min_endpoint(kr);
117  kr->length = std::min(kr->length, prefix_length);
118  kr->keypart_map &= keypart_map;
119  }
120 
121  /**
122  Initalizes a key_range object for communication with storage engine.
123 
124  This function facilitates communication with the Storage Engine API by
125  translating the minimum endpoint of the interval represented by this
126  QUICK_RANGE into an index range endpoint specifier for the engine.
127 
128  @param kr Pointer to an uninitialized key_range C struct.
129  */
131  kr->key = (const uchar *)min_key;
132  kr->length = min_length;
134  kr->flag = ((flag & NEAR_MIN) ? HA_READ_AFTER_KEY
137  }
138 
139  /**
140  Initalizes a key_range object for communication with storage engine.
141 
142  This function facilitates communication with the Storage Engine API by
143  translating the maximum endpoint of the interval represented by this
144  QUICK_RANGE into an index range endpoint specifier for the engine.
145 
146  @param kr Pointer to an uninitialized key_range C struct.
147 
148  @param prefix_length The length of the search key prefix to be used for
149  lookup.
150 
151  @param keypart_map A set (bitmap) of keyparts to be used.
152  */
153  void make_max_endpoint(key_range *kr, uint prefix_length,
154  key_part_map keypart_map) {
155  make_max_endpoint(kr);
156  kr->length = std::min(kr->length, prefix_length);
157  kr->keypart_map &= keypart_map;
158  }
159 
160  /**
161  Initalizes a key_range object for communication with storage engine.
162 
163  This function facilitates communication with the Storage Engine API by
164  translating the maximum endpoint of the interval represented by this
165  QUICK_RANGE into an index range endpoint specifier for the engine.
166 
167  @param kr Pointer to an uninitialized key_range C struct.
168  */
170  kr->key = (const uchar *)max_key;
171  kr->length = max_length;
173  /*
174  We use READ_AFTER_KEY here because if we are reading on a key
175  prefix we want to find all keys with this prefix
176  */
178  }
179 };
180 
181 /*
182  Quick select interface.
183  This class is a parent for all QUICK_*_SELECT classes.
184 
185  The usage scenario is as follows:
186  1. Create quick select
187  quick= new QUICK_XXX_SELECT(...);
188 
189  2. Perform lightweight initialization. This can be done in 2 ways:
190  2.a: Regular initialization
191  if (quick->init())
192  {
193  //the only valid action after failed init() call is delete
194  delete quick;
195  }
196  2.b: Special initialization for quick selects merged by QUICK_ROR_*_SELECT
197  if (quick->init_ror_merged_scan())
198  delete quick;
199 
200  3. Perform zero, one, or more scans.
201  while (...)
202  {
203  // initialize quick select for scan. This may allocate
204  // buffers and/or prefetch rows.
205  if (quick->reset())
206  {
207  //the only valid action after failed reset() call is delete
208  delete quick;
209  //abort query
210  }
211 
212  // perform the scan
213  do
214  {
215  res= quick->get_next();
216  } while (res && ...)
217  }
218 
219  4. Delete the select:
220  delete quick;
221 
222  NOTE
223  quick select doesn't use MEM_ROOT allocation because "range
224  checked for each record" functionality may create/destroy
225  O(#records_in_some_table) quick selects during query execution.
226  See Bug#18684036 ELIMINATE LAST FEW HEAP USAGE FROM THE
227  RANGE OPTIMIZER.
228 */
229 
231  public:
232  ha_rows records; /* estimate of # of records to be retrieved */
233  Cost_estimate cost_est; ///> cost to perform this retrieval
235  /*
236  Index this quick select uses, or MAX_KEY for quick selects
237  that use several indexes
238  */
240 
241  /*
242  Total length of first used_key_parts parts of the key.
243  Applicable if index!= MAX_KEY.
244  */
246 
247  /*
248  Max. number of (first) key parts this quick select uses for retrieval.
249  eg. for "(key1p1=c1 AND key1p2=c2) OR key1p1=c2" used_key_parts == 2.
250  Applicable if index!= MAX_KEY.
251 
252  For QUICK_GROUP_MIN_MAX_SELECT it includes MIN/MAX argument keyparts.
253  */
255  /**
256  true if creation of the object is forced by the hint.
257  The flag is used to skip ref evaluation in find_best_ref() function.
258  It also enables using of QUICK_SELECT object in
259  Optimize_table_order::best_access_path() regardless of the evaluation cost.
260  */
262 
263  QUICK_SELECT_I();
264  QUICK_SELECT_I(const QUICK_SELECT_I &) = default;
265  virtual ~QUICK_SELECT_I() {}
266 
267  /*
268  Do post-constructor initialization.
269  SYNOPSIS
270  init()
271 
272  init() performs initializations that should have been in constructor if
273  it was possible to return errors from constructors. The join optimizer may
274  create and then delete quick selects without retrieving any rows so init()
275  must not contain any IO or CPU intensive code.
276 
277  If init() call fails the only valid action is to delete this quick select,
278  reset() and get_next() must not be called.
279 
280  RETURN
281  0 OK
282  other Error code
283  */
284  virtual int init() = 0;
285 
286  /*
287  Initialize quick select for row retrieval.
288  SYNOPSIS
289  reset()
290 
291  reset() should be called when it is certain that row retrieval will be
292  necessary. This call may do heavyweight initialization like buffering first
293  N records etc. If reset() call fails get_next() must not be called.
294  Note that reset() may be called several times if
295  * the quick select is executed in a subselect
296  * a JOIN buffer is used
297 
298  RETURN
299  0 OK
300  other Error code
301  */
302  virtual int reset(void) = 0;
303 
304  virtual int get_next() = 0; /* get next record to retrieve */
305 
306  /* Range end should be called when we have looped over the whole index */
307  virtual void range_end() {}
308 
309  /**
310  Whether the range access method returns records in reverse order.
311  */
312  virtual bool reverse_sorted() const = 0;
313  /**
314  Whether the range access method is capable of returning records
315  in reverse order.
316  */
317  virtual bool reverse_sort_possible() const = 0;
318  virtual bool unique_key_range() { return false; }
319  virtual bool clustered_pk_range() { return false; }
320 
321  /*
322  Request that this quick select produces sorted output.
323  Not all quick selects can provide sorted output, the caller is responsible
324  for calling this function only for those quick selects that can.
325  The implementation is also allowed to provide sorted output even if it
326  was not requested if benificial, or required by implementation
327  internals.
328  */
329  virtual void need_sorted_output() = 0;
330  enum {
339  };
340 
341  /* Get type of this quick select - one of the QS_TYPE_* values */
342  virtual int get_type() const = 0;
343  virtual bool is_loose_index_scan() const = 0;
344  virtual bool is_agg_loose_index_scan() const = 0;
345 
346  /*
347  Initialize this quick select as a merged scan inside a ROR-union or a ROR-
348  intersection scan. The caller must not additionally call init() if this
349  function is called.
350  SYNOPSIS
351  init_ror_merged_scan()
352  reuse_handler If true, the quick select may use table->handler,
353  otherwise it must create and use a separate handler
354  object.
355  RETURN
356  0 Ok
357  other Error
358  */
359  virtual int init_ror_merged_scan(bool reuse_handler MY_ATTRIBUTE((unused))) {
360  DBUG_ASSERT(0);
361  return 1;
362  }
363 
364  /*
365  Save ROWID of last retrieved row in file->ref. This used in ROR-merging.
366  */
367  virtual void save_last_pos() {}
368 
369  /*
370  Append comma-separated list of keys this quick select uses to key_names;
371  append comma-separated list of corresponding used lengths to used_lengths.
372  This is used by select_describe.
373  */
374  virtual void add_keys_and_lengths(String *key_names,
375  String *used_lengths) = 0;
376 
377  /*
378  Append text representation of quick select structure (what and how is
379  merged) to str. The result is added to "Extra" field in EXPLAIN output.
380  This function is implemented only by quick selects that merge other quick
381  selects output and/or can produce output suitable for merging.
382  */
383  virtual void add_info_string(String *str MY_ATTRIBUTE((unused))) {}
384  /*
385  Return 1 if any index used by this quick select
386  uses field which is marked in passed bitmap.
387  */
388  virtual bool is_keys_used(const MY_BITMAP *fields);
389 
390  /**
391  Simple sanity check that the quick select has been set up
392  correctly. Function is overridden by quick selects that merge
393  indices.
394  */
395  virtual bool is_valid() { return index != MAX_KEY; }
396 
397  /*
398  rowid of last row retrieved by this quick select. This is used only when
399  doing ROR-index_merge selects
400  */
402 
403  /*
404  Table record buffer used by this quick select.
405  */
407 #ifndef DBUG_OFF
408  /*
409  Print quick select information to DBUG_FILE. Caller is responsible
410  for locking DBUG_FILE before this call and unlocking it afterwards.
411  */
412  virtual void dbug_dump(int indent, bool verbose) = 0;
413 #endif
414 
415  /*
416  Returns a QUICK_SELECT with reverse order of to the index.
417  */
419  uint used_key_parts_arg MY_ATTRIBUTE((unused))) {
420  return NULL;
421  }
422  virtual void set_handler(handler *file_arg MY_ATTRIBUTE((unused))) {}
423 
424  /**
425  Get the fields used by the range access method.
426 
427  @param[out] used_fields Bitmap of fields that this range access
428  method uses.
429  */
430  virtual void get_fields_used(MY_BITMAP *used_fields) = 0;
432 };
433 
434 class PARAM;
435 class SEL_ARG;
436 class SEL_ROOT;
437 
439 
440 /*
441  MRR range sequence, array<QUICK_RANGE> implementation: sequence traversal
442  context.
443 */
448 };
449 
450 range_seq_t quick_range_seq_init(void *init_param, uint n_ranges, uint flags);
452 
453 /*
454  Quick select that does a range scan on a single key. The records are
455  returned in key order if ::need_sorted_output() has been called.
456 */
458  protected:
460  /* Members to deal with case when this quick select is a ROR-merged scan */
462 
463  // TODO: pre-allocate space to avoid malloc/free for small number of columns.
465 
466  friend class TRP_ROR_INTERSECT;
467  friend bool get_quick_keys(PARAM *param, QUICK_RANGE_SELECT *quick,
468  KEY_PART *key, SEL_ARG *key_tree, uchar *min_key,
469  uint min_key_flag, uchar *max_key,
470  uint max_key_flag, uint *desc_flag);
472  SEL_ROOT *key_tree,
474  MEM_ROOT *alloc);
476  friend range_seq_t quick_range_seq_init(void *init_param, uint n_ranges,
477  uint flags);
478  friend class QUICK_SELECT_DESC;
482 
483  Quick_ranges ranges; /* ordered array of range ptrs */
484  bool free_file; /* TRUE <=> this->file is "owned" by this quick select */
485 
486  /* Range pointers to be used when not using MRR interface */
487  QUICK_RANGE **cur_range; /* current element in ranges */
489 
490  /* Members needed to use the MRR interface */
492 
493  public:
494  uint mrr_flags; /* Flags to be used with MRR interface */
495  protected:
496  uint mrr_buf_size; /* copy from thd->variables.read_rnd_buff_size */
497  HANDLER_BUFFER *mrr_buf_desc; /* the handler buffer */
498 
499  /* Info about index we're scanning */
502 
503  bool dont_free; /* Used by QUICK_SELECT_DESC */
504 
505  int cmp_next(QUICK_RANGE *range);
506  int cmp_prev(QUICK_RANGE *range);
507  bool row_in_ranges();
508 
509  public:
510  std::shared_ptr<MEM_ROOT> alloc;
511 
512  QUICK_RANGE_SELECT(THD *thd, TABLE *table, uint index_arg, bool no_alloc,
513  MEM_ROOT *parent_alloc, bool *create_error);
515 
516  void need_sorted_output();
517  int init();
518  int reset(void);
519  int get_next();
520  void range_end();
521  int get_next_prefix(uint prefix_length, uint group_key_parts,
522  uchar *cur_prefix);
523  bool reverse_sorted() const { return false; }
524  bool reverse_sort_possible() const { return true; }
525  bool unique_key_range();
526  int init_ror_merged_scan(bool reuse_handler);
528  int get_type() const { return QS_TYPE_RANGE; }
529  virtual bool is_loose_index_scan() const { return false; }
530  virtual bool is_agg_loose_index_scan() const { return false; }
531  void add_keys_and_lengths(String *key_names, String *used_lengths);
532  void add_info_string(String *str);
533 #ifndef DBUG_OFF
534  void dbug_dump(int indent, bool verbose);
535 #endif
536  QUICK_SELECT_I *make_reverse(uint used_key_parts_arg);
537  void set_handler(handler *file_arg) { file = file_arg; }
538 
539  virtual void get_fields_used(MY_BITMAP *used_fields) {
540  for (uint i = 0; i < used_key_parts; i++)
541  bitmap_set_bit(used_fields, key_parts[i].field->field_index);
542  }
543 
544  private:
545  /* Default copy ctor used by QUICK_SELECT_DESC */
546  QUICK_RANGE_SELECT(const QUICK_RANGE_SELECT &) = default;
547 };
548 
550  public:
551  QUICK_RANGE_SELECT_GEOM(THD *thd, TABLE *table, uint index_arg, bool no_alloc,
552  MEM_ROOT *parent_alloc, bool *create_error)
553  : QUICK_RANGE_SELECT(thd, table, index_arg, no_alloc, parent_alloc,
554  create_error) {}
555  virtual int get_next();
556 };
557 
558 /*
559  QUICK_INDEX_MERGE_SELECT - index_merge access method quick select.
560 
561  QUICK_INDEX_MERGE_SELECT uses
562  * QUICK_RANGE_SELECTs to get rows
563  * Unique class to remove duplicate rows
564 
565  INDEX MERGE OPTIMIZER
566  Current implementation doesn't detect all cases where index_merge could
567  be used, in particular:
568  * index_merge will never be used if range scan is possible (even if
569  range scan is more expensive)
570 
571  * index_merge+'using index' is not supported (this the consequence of
572  the above restriction)
573 
574  * If WHERE part contains complex nested AND and OR conditions, some ways
575  to retrieve rows using index_merge will not be considered. The choice
576  of read plan may depend on the order of conjuncts/disjuncts in WHERE
577  part of the query, see comments near imerge_list_or_list and
578  SEL_IMERGE::or_sel_tree_with_checks functions for details.
579 
580  * There is no "index_merge_ref" method (but index_merge on non-first
581  table in join is possible with 'range checked for each record').
582 
583  See comments around SEL_IMERGE class and test_quick_select for more
584  details.
585 
586  ROW RETRIEVAL ALGORITHM
587 
588  index_merge uses Unique class for duplicates removal. index_merge takes
589  advantage of Clustered Primary Key (CPK) if the table has one.
590  The index_merge algorithm consists of two phases:
591 
592  Phase 1 (implemented in QUICK_INDEX_MERGE_SELECT::prepare_unique):
593  prepare()
594  {
595  activate 'index only';
596  while(retrieve next row for non-CPK scan)
597  {
598  if (there is a CPK scan and row will be retrieved by it)
599  skip this row;
600  else
601  put its rowid into Unique;
602  }
603  deactivate 'index only';
604  }
605 
606  Phase 2 (implemented as sequence of QUICK_INDEX_MERGE_SELECT::get_next
607  calls):
608 
609  fetch()
610  {
611  retrieve all rows from row pointers stored in Unique;
612  free Unique;
613  retrieve all rows for CPK scan;
614  }
615 */
616 
619 
620  public:
623 
624  int init();
625  void need_sorted_output() { DBUG_ASSERT(false); /* Can't do it */ }
626  int reset(void);
627  int get_next();
628  bool reverse_sorted() const { return false; }
629  bool reverse_sort_possible() const { return false; }
630  bool unique_key_range() { return false; }
631  int get_type() const { return QS_TYPE_INDEX_MERGE; }
632  virtual bool is_loose_index_scan() const { return false; }
633  virtual bool is_agg_loose_index_scan() const { return false; }
634  void add_keys_and_lengths(String *key_names, String *used_lengths);
635  void add_info_string(String *str);
636  bool is_keys_used(const MY_BITMAP *fields);
637 #ifndef DBUG_OFF
638  void dbug_dump(int indent, bool verbose);
639 #endif
640 
641  bool push_quick_back(QUICK_RANGE_SELECT *quick_sel_range);
642 
643  /* range quick selects this index_merge read consists of */
645 
646  /* quick select that uses clustered primary key (NULL if none) */
648 
649  /* true if this select is currently doing a clustered PK scan */
651 
654  int read_keys_and_merge();
655 
657 
658  virtual bool is_valid() {
661  bool valid = true;
662  while ((quick = it++)) {
663  if (!quick->is_valid()) {
664  valid = false;
665  break;
666  }
667  }
668  return valid;
669  }
670 
671  virtual void get_fields_used(MY_BITMAP *used_fields) {
674  while ((quick = it++)) quick->get_fields_used(used_fields);
675 
677  }
678 
679  /* used to get rows collected in Unique */
681 };
682 
683 /*
684  Rowid-Ordered Retrieval (ROR) index intersection quick select.
685  This quick select produces intersection of row sequences returned
686  by several QUICK_RANGE_SELECTs it "merges".
687 
688  All merged QUICK_RANGE_SELECTs must return rowids in rowid order.
689  QUICK_ROR_INTERSECT_SELECT will return rows in rowid order, too.
690 
691  All merged quick selects retrieve {rowid, covered_fields} tuples (not full
692  table records).
693  QUICK_ROR_INTERSECT_SELECT retrieves full records if it is not being used
694  by QUICK_ROR_INTERSECT_SELECT and all merged quick selects together don't
695  cover needed all fields.
696 
697  If one of the merged quick selects is a Clustered PK range scan, it is
698  used only to filter rowid sequence produced by other merged quick selects.
699 */
700 
702  public:
703  QUICK_ROR_INTERSECT_SELECT(THD *thd, TABLE *table, bool retrieve_full_rows,
704  MEM_ROOT *parent_alloc);
706 
707  int init();
708  void need_sorted_output() { DBUG_ASSERT(false); /* Can't do it */ }
709  int reset(void);
710  int get_next();
711  bool reverse_sorted() const { return false; }
712  bool reverse_sort_possible() const { return false; }
713  bool unique_key_range() { return false; }
714  int get_type() const { return QS_TYPE_ROR_INTERSECT; }
715  virtual bool is_loose_index_scan() const { return false; }
716  virtual bool is_agg_loose_index_scan() const { return false; }
717  void add_keys_and_lengths(String *key_names, String *used_lengths);
718  void add_info_string(String *str);
719  bool is_keys_used(const MY_BITMAP *fields);
720 #ifndef DBUG_OFF
721  void dbug_dump(int indent, bool verbose);
722 #endif
723  int init_ror_merged_scan(bool reuse_handler);
724  bool push_quick_back(QUICK_RANGE_SELECT *quick_sel_range);
725 
726  /*
727  Range quick selects this intersection consists of, not including
728  cpk_quick.
729  */
731 
732  virtual bool is_valid() {
735  bool valid = true;
736  while ((quick = it++)) {
737  if (!quick->is_valid()) {
738  valid = false;
739  break;
740  }
741  }
742  return valid;
743  }
744 
745  virtual void get_fields_used(MY_BITMAP *used_fields) {
748  while ((quick = it++)) quick->get_fields_used(used_fields);
749  }
750 
751  /*
752  Merged quick select that uses Clustered PK, if there is one. This quick
753  select is not used for row retrieval, it is used for row retrieval.
754  */
756 
757  MEM_ROOT alloc; /* Memory pool for this and merged quick selects data. */
758  THD *thd; /* current thread */
759  bool need_to_fetch_row; /* if true, do retrieve full table records. */
760  /* in top-level quick select, true if merged scans where initialized */
762 };
763 
764 /*
765  Comparison function to be used QUICK_ROR_UNION_SELECT::queue priority
766  queue.
767 */
769  explicit Quick_ror_union_less(const QUICK_SELECT_I *me) : m_me(me) {}
771  return m_me->head->file->cmp_ref(a->last_rowid, b->last_rowid) > 0;
772  }
774 };
775 
776 /*
777  Rowid-Ordered Retrieval index union select.
778  This quick select produces union of row sequences returned by several
779  quick select it "merges".
780 
781  All merged quick selects must return rowids in rowid order.
782  QUICK_ROR_UNION_SELECT will return rows in rowid order, too.
783 
784  All merged quick selects are set not to retrieve full table records.
785  ROR-union quick select always retrieves full records.
786 
787 */
788 
790  public:
793 
794  int init();
795  void need_sorted_output() { DBUG_ASSERT(false); /* Can't do it */ }
796  int reset(void);
797  int get_next();
798  bool reverse_sorted() const { return false; }
799  bool reverse_sort_possible() const { return false; }
800  bool unique_key_range() { return false; }
801  int get_type() const { return QS_TYPE_ROR_UNION; }
802  virtual bool is_loose_index_scan() const { return false; }
803  virtual bool is_agg_loose_index_scan() const { return false; }
804  void add_keys_and_lengths(String *key_names, String *used_lengths);
805  void add_info_string(String *str);
806  bool is_keys_used(const MY_BITMAP *fields);
807 #ifndef DBUG_OFF
808  void dbug_dump(int indent, bool verbose);
809 #endif
810 
811  bool push_quick_back(QUICK_SELECT_I *quick_sel_range);
812 
813  List<QUICK_SELECT_I> quick_selects; /* Merged quick selects */
814 
815  virtual bool is_valid() {
818  bool valid = true;
819  while ((quick = it++)) {
820  if (!quick->is_valid()) {
821  valid = false;
822  break;
823  }
824  }
825  return valid;
826  }
827 
828  virtual void get_fields_used(MY_BITMAP *used_fields) {
831  while ((quick = it++)) quick->get_fields_used(used_fields);
832  }
833 
835  QUICK_SELECT_I *,
836  std::vector<QUICK_SELECT_I *, Malloc_allocator<QUICK_SELECT_I *>>,
838  queue; /* Priority queue for merge operation */
839  MEM_ROOT alloc; /* Memory pool for this and merged quick selects data. */
840 
841  THD *thd; /* current thread */
842  uchar *cur_rowid; /* buffer used in get_next() */
843  uchar *prev_rowid; /* rowid of last row returned by get_next() */
844  bool have_prev_rowid; /* true if prev_rowid has valid data */
845  uint rowid_length; /* table rowid length */
846 
847  private:
849 };
850 
851 /*
852  Index scan for GROUP-BY queries with MIN/MAX aggregate functions.
853 
854  This class provides a specialized index access method for GROUP-BY queries
855  of the forms:
856 
857  SELECT A_1,...,A_k, [B_1,...,B_m], [MIN(C)], [MAX(C)]
858  FROM T
859  WHERE [RNG(A_1,...,A_p ; where p <= k)]
860  [AND EQ(B_1,...,B_m)]
861  [AND PC(C)]
862  [AND PA(A_i1,...,A_iq)]
863  GROUP BY A_1,...,A_k;
864 
865  or
866 
867  SELECT DISTINCT A_i1,...,A_ik
868  FROM T
869  WHERE [RNG(A_1,...,A_p ; where p <= k)]
870  [AND PA(A_i1,...,A_iq)];
871 
872  where all selected fields are parts of the same index.
873  The class of queries that can be processed by this quick select is fully
874  specified in the description of get_best_trp_group_min_max() in opt_range.cc.
875 
876  The get_next() method directly produces result tuples, thus obviating the
877  need to call end_send_group() because all grouping is already done inside
878  get_next().
879 
880  Since one of the requirements is that all select fields are part of the same
881  index, this class produces only index keys, and not complete records.
882 */
883 
885  private:
886  JOIN *join; /* Descriptor of the current query */
887  KEY *index_info; /* The index chosen for data access */
888  uchar *tmp_record; /* Temporary storage for next_min(), next_max(). */
889  uchar *group_prefix; /* Key prefix consisting of the GROUP fields. */
890  const uint group_prefix_len; /* Length of the group prefix. */
891  uint group_key_parts; /* A number of keyparts in the group prefix */
892  uchar *last_prefix; /* Prefix of the last group for detecting EOF. */
893  bool have_min; /* Specify whether we are computing */
894  bool have_max; /* a MIN, a MAX, or both. */
895  bool have_agg_distinct; /* aggregate_function(DISTINCT ...). */
896  bool seen_first_key; /* Denotes whether the first key was retrieved.*/
897  KEY_PART_INFO *min_max_arg_part; /* The keypart of the only argument field */
898  /* of all MIN/MAX functions. */
899  uint min_max_arg_len; /* The length of the MIN/MAX argument field */
900  uchar *key_infix; /* Infix of constants from equality predicates. */
902  Quick_ranges min_max_ranges; /* Array of range ptrs for the MIN/MAX field. */
903  uint real_prefix_len; /* Length of key prefix extended with key_infix. */
904  uint real_key_parts; /* A number of keyparts in the above value. */
909  /*
910  Use index scan to get the next different key instead of jumping into it
911  through index read
912  */
914  /**
915  Whether used part of the index has desc key parts
916  */
918 
919  public:
920  /*
921  The following two members are public to allow easy access from
922  TRP_GROUP_MIN_MAX::make_quick()
923  */
924  MEM_ROOT alloc; /* Memory pool for this and quick_prefix_select data. */
926  *quick_prefix_select; /* For retrieval of group prefixes. */
927  private:
928  int next_prefix();
929  int next_min_in_range();
930  int next_max_in_range();
931  int next_min();
932  int next_max();
933  void update_min_result(bool reset);
934  void update_max_result(bool reset);
935 
936  public:
938  bool have_max, bool have_agg_distinct,
942  uint use_index, const Cost_estimate *cost_est,
944  uchar *key_infix, MEM_ROOT *parent_alloc,
945  bool is_index_scan);
947  bool add_range(SEL_ARG *sel_range);
948  void update_key_stat();
949  void adjust_prefix_ranges();
950  int init();
951  void need_sorted_output() { /* always do it */
952  }
953  int reset();
954  int get_next();
955  bool reverse_sorted() const { return false; }
956  bool reverse_sort_possible() const { return false; }
957  bool unique_key_range() { return false; }
958  int get_type() const { return QS_TYPE_GROUP_MIN_MAX; }
959  virtual bool is_loose_index_scan() const { return true; }
960  virtual bool is_agg_loose_index_scan() const { return is_agg_distinct(); }
961  void add_keys_and_lengths(String *key_names, String *used_lengths);
962 #ifndef DBUG_OFF
963  void dbug_dump(int indent, bool verbose);
964 #endif
965  bool is_agg_distinct() const { return have_agg_distinct; }
966  virtual void append_loose_scan_type(String *str) {
967  if (is_index_scan) str->append(STRING_WITH_LEN("scanning"));
968  }
969 
970  virtual void get_fields_used(MY_BITMAP *used_fields) {
971  for (uint i = 0; i < used_key_parts; i++)
973  }
974  void add_info_string(String *str);
975 };
976 
978  public:
980  int get_next();
981  bool reverse_sorted() const { return true; }
982  bool reverse_sort_possible() const { return true; }
983  int get_type() const { return QS_TYPE_RANGE_DESC; }
984  virtual bool is_loose_index_scan() const { return false; }
985  virtual bool is_agg_loose_index_scan() const { return false; }
987  return this; // is already reverse sorted
988  }
989 
990  private:
991  bool range_reads_after_key(QUICK_RANGE *range);
992  int reset(void) {
993  rev_it.rewind();
994  return QUICK_RANGE_SELECT::reset();
995  }
999 };
1000 
1001 /*
1002  Index scan for range queries that can use skip scans.
1003 
1004  This class provides a specialized index access method for the queries
1005  of the forms:
1006 
1007  SELECT A_1,...,A_k, B_1,...,B_m, C
1008  FROM T
1009  WHERE
1010  EQ(A_1,...,A_k)
1011  AND RNG(C);
1012 
1013  where all selected fields are parts of the same index.
1014  The class of queries that can be processed by this quick select is fully
1015  specified in the description of get_best_skip_scan() in opt_range.cc.
1016 
1017  Since one of the requirements is that all select fields are part of the same
1018  index, this class produces only index keys, and not complete records.
1019 */
1020 
1022  private:
1023  JOIN *join; /* Pointer to JOIN object */
1024  KEY *index_info; /* Index for skip scan */
1025  SEL_ROOT *index_range_tree; /* Range tree for skip scan */
1026  MY_BITMAP column_bitmap; /* Map of key parts to be read */
1027  /*
1028  This is an array of array of equality constants with length
1029  eq_prefix_key_parts. The length of array eq_key_prefixes[i] is
1030  eq_prefix_elements[i].
1031 
1032  For example, an equality predicate like "a IN (1, 2) AND b IN (2, 3, 4)",
1033  eq_key_prefixes will contain:
1034 
1035  [
1036  [ 1, 2 ],
1037  [ 2, 3, 4 ]
1038  ]
1039 
1040  eq_prefix_elements will contain:
1041  [ 2, 3 ]
1042  */
1045  const uint eq_prefix_len; /* Total length of the equality prefix. */
1046  uint eq_prefix_key_parts; /* A number of keyparts in skip scan prefix */
1047  uchar *eq_prefix; /* Storage for current equality prefix. */
1048 
1049  /*
1050  During skip scan, we will have to iterate through all possible
1051  equality prefixes. This is the product of all the elements in
1052  eq_prefix_elements. In the above example, there are 2 x 3 = 6 possible
1053  equality prefixes.
1054 
1055  To track which prefix we are on, we use the cur_eq_prefix array.
1056  For example, the array [1, 1] indicates that the current equality prefix
1057  is (2, 3).
1058  */
1060  uchar *distinct_prefix; /* Storage for prefix A_1, ... B_m. */
1063 
1064  KEY_PART_INFO *range_key_part; /* The keypart of range condition 'C'. */
1066  /*
1067  Denotes whether the first key for the current equality prefix was
1068  retrieved.
1069  */
1071 
1072  /* Storage for full lookup key for use with handler::read_range_first/next */
1078 
1081 
1083 
1084  bool next_eq_prefix();
1085 
1086  public:
1087  MEM_ROOT alloc; /* Memory pool for data in this class. */
1088  public:
1090  KEY_PART_INFO *range_part, SEL_ROOT *index_range_tree,
1091  uint eq_prefix_len, uint eq_prefix_parts,
1093  const Cost_estimate *read_cost_arg, ha_rows records,
1094  MEM_ROOT *parent_alloc, bool has_aggregate_function);
1096  bool set_range(SEL_ARG *sel_range);
1097  int init();
1099  int reset();
1100  int get_next();
1101  bool reverse_sorted() const { return false; }
1102  bool reverse_sort_possible() const { return false; }
1103  bool unique_key_range() { return false; }
1104  int get_type() const { return QS_TYPE_SKIP_SCAN; }
1105  virtual bool is_loose_index_scan() const { return true; }
1106  virtual bool is_agg_loose_index_scan() const {
1107  return has_aggregate_function;
1108  }
1109  void add_keys_and_lengths(String *key_names, String *used_lengths);
1110 #ifndef DBUG_OFF
1111  void dbug_dump(int indent, bool verbose);
1112 #endif
1113  virtual void get_fields_used(MY_BITMAP *used_fields) {
1114  for (uint i = 0; i < used_key_parts; i++)
1115  bitmap_set_bit(used_fields, index_info->key_part[i].field->field_index);
1116  }
1117  void add_info_string(String *str);
1118 };
1119 
1120 class QEP_shared_owner;
1121 
1122 int test_quick_select(THD *thd, Key_map keys, table_map prev_tables,
1123  ha_rows limit, bool force_quick_range,
1124  const enum_order interesting_order,
1125  const QEP_shared_owner *tab, Item *cond,
1126  Key_map *needed_reg, QUICK_SELECT_I **quick,
1127  bool ignore_table_scan);
1128 
1129 bool prune_partitions(THD *thd, TABLE *table, Item *pprune_cond);
1130 void store_key_image_to_rec(Field *field, uchar *ptr, uint len);
1131 
1132 extern String null_string;
1133 
1134 /// Global initialization of the null_element. Call on server start.
1135 void range_optimizer_init();
1136 
1137 /// Global destruction of the null_element. Call on server stop.
1138 void range_optimizer_free();
1139 
1140 #endif
int reset()
Definition: opt_range.cc:13282
uint16 flag
Definition: opt_range.h:73
void add_keys_and_lengths(String *key_names, String *used_lengths)
Definition: opt_range.cc:11465
void add_info_string(String *str)
Definition: opt_range.cc:11322
bool reverse_sorted() const
Whether the range access method returns records in reverse order.
Definition: opt_range.h:981
QUICK_SELECT_I * make_reverse(uint used_key_parts_arg)
Create a compatible quick select with the result ordered in an opposite way.
Definition: opt_range.cc:11276
int init()
Definition: opt_range.cc:13064
Definition: opt_range.h:331
READ_RECORD read_record
Definition: opt_range.h:680
uint real_prefix_len
Definition: opt_range.h:903
bool reverse_sorted() const
Whether the range access method returns records in reverse order.
Definition: opt_range.h:1101
bool range_reads_after_key(QUICK_RANGE *range)
Definition: opt_range.cc:11314
unsigned char uchar
Definition: my_inttypes.h:51
Definition: sql_optimizer.h:177
int get_type() const
Definition: opt_range.h:801
Our own string classes, used pervasively throughout the executor.
uint key_infix_len
Definition: opt_range.h:901
uint distinct_prefix_len
Definition: opt_range.h:1061
bool reverse_sorted() const
Whether the range access method returns records in reverse order.
Definition: opt_range.h:711
bool prune_partitions(THD *thd, TABLE *table, Item *pprune_cond)
Perform partition pruning for a given table and condition.
Definition: opt_range.cc:3712
uint mrr_buf_size
Definition: opt_range.h:496
bool need_to_fetch_row
Definition: opt_range.h:759
void update_key_stat()
Definition: opt_range.cc:13233
MEM_ROOT alloc
Definition: opt_range.h:757
ulonglong table_map
Definition: my_table_map.h:32
Prealloced_array< QUICK_RANGE *, 16 > Quick_ranges
Definition: opt_range.h:436
enum_order
Definition: key_spec.h:64
bool unique_key_range()
Definition: opt_range.h:800
uint length
Definition: my_base.h:1116
bool next_eq_prefix()
Increments cur_prefix and sets what the next equality prefix should be.
Definition: opt_range.cc:14711
void need_sorted_output()
Definition: opt_range.h:708
int get_type() const
Definition: opt_range.h:958
QUICK_RANGE()
Definition: opt_range.cc:2272
bool dont_free
Definition: opt_range.h:503
virtual void get_fields_used(MY_BITMAP *used_fields)
Get the fields used by the range access method.
Definition: opt_range.h:970
QUICK_SELECT_I()
Definition: opt_range.cc:1769
JOIN * join
Definition: opt_range.h:1023
bool push_quick_back(QUICK_RANGE_SELECT *quick_sel_range)
Definition: opt_range.cc:2149
bool reverse_sort_possible() const
Whether the range access method is capable of returning records in reverse order. ...
Definition: opt_range.h:982
JOIN * join
Definition: opt_range.h:886
virtual bool reverse_sorted() const =0
Whether the range access method returns records in reverse order.
bool add_range(SEL_ARG *sel_range)
Definition: opt_range.cc:13156
Priority_queue< QUICK_SELECT_I *, std::vector< QUICK_SELECT_I *, Malloc_allocator< QUICK_SELECT_I * > >, Quick_ror_union_less > queue
Definition: opt_range.h:838
int get_next_prefix(uint prefix_length, uint group_key_parts, uchar *cur_prefix)
Definition: opt_range.cc:10986
QUICK_RANGE_SELECT * quick_prefix_select
Definition: opt_range.h:926
int init_ror_merged_scan(bool reuse_handler)
Definition: opt_range.cc:1980
Definition: mi_test3.cc:54
friend QUICK_RANGE_SELECT * get_quick_select(PARAM *, uint idx, SEL_ROOT *key_tree, uint mrr_flags, uint mrr_buf_size, MEM_ROOT *alloc)
Definition: opt_range.cc:10186
uint mrr_flags
Definition: opt_range.h:494
void add_keys_and_lengths(String *key_names, String *used_lengths)
Definition: opt_range.cc:13932
File containing constants that can be used throughout the server.
Definition: records.h:41
virtual bool is_loose_index_scan() const
Definition: opt_range.h:529
ulong key_part_map
Definition: my_base.h:998
Quick_ranges ranges
Definition: opt_range.h:483
Some integer typedefs for easier portability.
key_range start_key
Definition: opt_range.h:1079
MY_BITMAP column_bitmap
Definition: opt_range.h:464
bool reverse_sorted() const
Whether the range access method returns records in reverse order.
Definition: opt_range.h:955
int init_ror_merged_scan(bool reuse_handler)
Definition: opt_range.cc:2075
friend uint quick_range_seq_next(range_seq_t rseq, KEY_MULTI_RANGE *range)
Definition: opt_range.cc:10886
Definition: opt_range.h:444
static uint verbose
Definition: mysqlcheck.cc:62
Definition: sql_bitmap.h:135
List< QUICK_RANGE_SELECT > quick_selects
Definition: opt_range.h:730
virtual bool unique_key_range()
Definition: opt_range.h:318
const uint group_prefix_len
Definition: opt_range.h:890
void make_min_endpoint(key_range *kr)
Initalizes a key_range object for communication with storage engine.
Definition: opt_range.h:130
bool scans_inited
Definition: opt_range.h:761
virtual void append_loose_scan_type(String *str)
Definition: opt_range.h:966
Unique – class for unique (removing of duplicates).
Definition: uniques.h:52
int reset(void)
Definition: opt_range.cc:1877
Owner of a QEP_shared; parent of JOIN_TAB and QEP_TAB.
Definition: sql_opt_exec_shared.h:463
void dbug_dump(int indent, bool verbose)
Definition: opt_range.cc:15504
imagetype
Definition: field.h:849
virtual bool is_valid()
Simple sanity check that the quick select has been set up correctly.
Definition: opt_range.h:815
uint range_key_len
Definition: opt_range.h:1065
Definition: field.h:709
Definition: opt_range.cc:2677
Definition: opt_range.h:457
QUICK_RANGE_SELECT_GEOM(THD *thd, TABLE *table, uint index_arg, bool no_alloc, MEM_ROOT *parent_alloc, bool *create_error)
Definition: opt_range.h:551
KEY_PART_INFO * range_key_part
Definition: opt_range.h:1064
String null_string
uint * eq_prefix_elements
Definition: opt_range.h:1044
int get_next()
Get the next row for skip scan.
Definition: opt_range.cc:14780
Definition: opt_range.h:884
int get_type() const
Definition: opt_range.h:1104
virtual void add_info_string(String *str)
Definition: opt_range.h:383
uint range_cond_flag
Definition: opt_range.h:1077
Definition: handler.h:3188
Sergei Dialog Client Authentication NULL
Definition: dialog.cc:352
uint16 length
Definition: opt_range.h:67
const uchar * key
Definition: my_base.h:1115
uchar * key_infix
Definition: opt_range.h:900
virtual void save_last_pos()
Definition: opt_range.h:367
uint real_key_parts
Definition: opt_range.h:904
void save_last_pos()
Definition: opt_range.h:527
virtual bool is_loose_index_scan() const
Definition: opt_range.h:632
virtual void set_handler(handler *file_arg)
Definition: opt_range.h:422
Definition: my_base.h:78
bool reverse_sorted() const
Whether the range access method returns records in reverse order.
Definition: opt_range.h:628
void add_keys_and_lengths(String *key_names, String *used_lengths)
Definition: opt_range.cc:11394
~QUICK_INDEX_MERGE_SELECT()
Definition: opt_range.cc:1897
virtual bool is_agg_loose_index_scan() const
Definition: opt_range.h:633
uint distinct_prefix_key_parts
Definition: opt_range.h:1062
virtual void get_fields_used(MY_BITMAP *used_fields)
Get the fields used by the range access method.
Definition: opt_range.h:828
MEM_ROOT alloc
Definition: opt_range.h:924
virtual bool is_agg_loose_index_scan() const
Definition: opt_range.h:716
int init()
Definition: opt_range.cc:2186
QUICK_GROUP_MIN_MAX_SELECT(TABLE *table, JOIN *join, bool have_min, bool have_max, bool have_agg_distinct, KEY_PART_INFO *min_max_arg_part, uint group_prefix_len, uint group_key_parts, uint used_key_parts, KEY *index_info, uint use_index, const Cost_estimate *cost_est, ha_rows records, uint key_infix_len, uchar *key_infix, MEM_ROOT *parent_alloc, bool is_index_scan)
Definition: opt_range.cc:12991
bool reverse_sort_possible() const
Whether the range access method is capable of returning records in reverse order. ...
Definition: opt_range.h:524
void dbug_dump(int indent, bool verbose)
Definition: opt_range.cc:15517
uchar * last_rowid
Definition: opt_range.h:401
bool unique_key_range()
Definition: opt_range.h:630
bool is_keys_used(const MY_BITMAP *fields)
Definition: opt_range.cc:10404
Definition: opt_range.h:977
uint index
Definition: opt_range.h:239
uchar *** eq_key_prefixes
Definition: opt_range.h:1043
int init()
Definition: opt_range.cc:1827
Definition: opt_range.h:64
void need_sorted_output()
Definition: opt_range.h:795
int get_next()
Definition: opt_range.cc:10554
int read_keys_and_merge()
Definition: opt_range.cc:10448
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:3987
ha_rkey_function
Definition: my_base.h:77
int next_max_in_range()
Definition: opt_range.cc:13770
uint max_used_key_length
Definition: opt_range.h:245
virtual bool is_loose_index_scan() const
Definition: opt_range.h:715
Using this class is fraught with peril, and you need to be very careful when doing so...
Definition: sql_string.h:159
virtual bool is_agg_loose_index_scan() const
Definition: opt_range.h:960
int get_type() const
Definition: opt_range.h:631
void adjust_prefix_ranges()
Definition: opt_range.cc:13202
Quick_ranges::const_iterator first
Definition: opt_range.h:445
int reset()
Initialize a quick skip scan index select for key retrieval.
Definition: opt_range.cc:14666
static bool quick
Definition: mysql.cc:151
Definition: table.h:1294
QUICK_SELECT_DESC(QUICK_RANGE_SELECT *q, uint used_key_parts)
Definition: opt_range.cc:11112
TABLE * head
cost to perform this retrieval
Definition: opt_range.h:234
void add_info_string(String *str)
Definition: opt_range.cc:11346
~QUICK_SKIP_SCAN_SELECT()
Definition: opt_range.cc:14577
uint16 max_length
Definition: opt_range.h:81
Cost_estimate cost_est
Definition: opt_range.h:233
bool seen_first_key
Definition: opt_range.h:896
virtual bool is_valid()
Simple sanity check that the quick select has been set up correctly.
Definition: opt_range.h:658
uchar * eq_prefix
Definition: opt_range.h:1047
uint16 part
Definition: opt_range.h:65
static void bitmap_set_bit(MY_BITMAP *map, uint bit)
Definition: my_bitmap.h:88
virtual ~QUICK_SELECT_I()
Definition: opt_range.h:265
virtual bool is_keys_used(const MY_BITMAP *fields)
Definition: opt_range.cc:10400
virtual QUICK_SELECT_I * make_reverse(uint used_key_parts_arg)
Definition: opt_range.h:418
uchar * cur_rowid
Definition: opt_range.h:842
QUICK_ROR_UNION_SELECT(THD *thd, TABLE *table)
Definition: opt_range.cc:2162
Quick_ror_union_less(const QUICK_SELECT_I *me)
Definition: opt_range.h:769
int next_prefix()
Definition: opt_range.cc:13588
virtual void position(const uchar *record)=0
uchar * prev_rowid
Definition: opt_range.h:843
bool push_quick_back(QUICK_SELECT_I *quick_sel_range)
Definition: opt_range.cc:2260
Definition: opt_range.cc:1349
int get_type() const
Definition: opt_range.h:983
This file includes constants used by all storage engines.
Definition: opt_range.cc:659
void dbug_dump(int indent, bool verbose)
Definition: opt_range.cc:15473
#define DBUG_ASSERT(A)
Definition: my_dbug.h:183
virtual void get_fields_used(MY_BITMAP *used_fields)
Get the fields used by the range access method.
Definition: opt_range.h:671
virtual bool is_loose_index_scan() const
Definition: opt_range.h:1105
void store_key_image_to_rec(Field *field, uchar *ptr, uint len)
Definition: opt_range.cc:3912
void need_sorted_output()
Definition: opt_range.h:1098
uchar * max_key
Definition: opt_range.h:80
Definition: opt_range.h:701
MY_BITMAP column_bitmap
Definition: opt_range.h:1026
QUICK_RANGE_SELECT(THD *thd, TABLE *table, uint index_arg, bool no_alloc, MEM_ROOT *parent_alloc, bool *create_error)
Definition: opt_range.cc:1781
int reset(void)
Definition: opt_range.cc:10748
SEL_ROOT * index_range_tree
Definition: opt_range.h:1025
~QUICK_RANGE_SELECT()
Definition: opt_range.cc:1838
virtual bool is_agg_loose_index_scan() const
Definition: opt_range.h:985
bool have_prev_rowid
Definition: opt_range.h:844
QUICK_RANGE * last_range
Definition: opt_range.h:488
uint16 flag
Stores bitwise-or&#39;ed bits defined in enum key_range_flags.
Definition: opt_range.h:84
void add_info_string(String *str)
Definition: opt_range.cc:11327
bool append(const String &s)
Definition: sql_string.cc:449
Definition: opt_range.h:337
virtual bool is_loose_index_scan() const
Definition: opt_range.h:959
bool is_keys_used(const MY_BITMAP *fields)
Definition: opt_range.cc:10413
enum ha_rkey_function flag
Definition: my_base.h:1118
Definition: opt_range.h:768
Definition: my_base.h:1073
bool has_desc_keyparts
Whether used part of the index has desc key parts.
Definition: opt_range.h:917
key_range end_key
Definition: opt_range.h:1080
uint min_max_arg_len
Definition: opt_range.h:899
int init()
Definition: opt_range.cc:1952
int next_min_in_range()
Definition: opt_range.cc:13642
virtual bool is_agg_loose_index_scan() const
Definition: opt_range.h:1106
void need_sorted_output()
Definition: opt_range.cc:1825
Definition: my_base.h:1121
#define MAX_KEY
Definition: sql_const.h:51
MEM_ROOT alloc
Definition: opt_range.h:839
uint group_key_parts
Definition: opt_range.h:891
bool reverse_sorted() const
Whether the range access method returns records in reverse order.
Definition: opt_range.h:523
const Element_type * const_iterator
Definition: prealloced_array.h:94
Definition: key.h:55
Class Item_sum is the base class used for special expressions that SQL calls &#39;set functions&#39;...
Definition: item_sum.h:385
QUICK_RANGE ** cur_range
Definition: opt_range.h:487
Definition: opt_range.h:78
Definition: my_bitmap.h:42
virtual int cmp_ref(const uchar *ref1, const uchar *ref2) const
Compare two positions.
Definition: handler.h:5436
QUICK_ROR_INTERSECT_SELECT(THD *thd, TABLE *table, bool retrieve_full_rows, MEM_ROOT *parent_alloc)
Definition: opt_range.cc:1922
int reset(void)
Definition: opt_range.cc:2208
bool reverse_sort_possible() const
Whether the range access method is capable of returning records in reverse order. ...
Definition: opt_range.h:1102
virtual void get_fields_used(MY_BITMAP *used_fields)
Get the fields used by the range access method.
Definition: opt_range.h:1113
int next_min()
Definition: opt_range.cc:13438
uint * cur_eq_prefix
Definition: opt_range.h:1059
void need_sorted_output()
Definition: opt_range.h:625
range_seq_t quick_range_seq_init(void *init_param, uint n_ranges, uint flags)
Definition: opt_range.cc:10843
QUICK_SELECT_I * make_reverse(uint)
Create a compatible quick select with the result ordered in an opposite way.
Definition: opt_range.h:986
KEY * index_info
Definition: opt_range.h:887
int test_quick_select(THD *thd, Key_map keys, table_map prev_tables, ha_rows limit, bool force_quick_range, const enum_order interesting_order, const QEP_shared_owner *tab, Item *cond, Key_map *needed_reg, QUICK_SELECT_I **quick, bool ignore_table_scan)
Definition: opt_range.cc:3115
ha_rows records
Definition: opt_range.h:232
virtual bool is_loose_index_scan() const =0
Header for compiler-dependent features.
int cmp_prev(QUICK_RANGE *range)
Definition: opt_range.cc:11300
int init()
Definition: opt_range.cc:1872
QUICK_RANGE_SELECT * pk_quick_select
Definition: opt_range.h:647
Definition: opt_range.h:335
enum ha_rkey_function rkey_func_flag
Stores one of the HA_READ_MBR_XXX items in enum ha_rkey_function, only effective when flag has a GEOM...
Definition: opt_range.h:90
void dbug_dump(int indent, bool verbose)
Definition: opt_range.cc:15578
static uint keys
Definition: hp_test2.cc:43
Quick_ranges::const_iterator cur
Definition: opt_range.h:446
unsigned int len
Definition: dbug_analyze.cc:216
uint16_t uint16
Definition: my_inttypes.h:60
List< QUICK_SELECT_I > quick_selects
Definition: opt_range.h:813
void * range_seq_t
Definition: handler.h:3194
Definition: item.h:666
uchar * last_prefix
Definition: opt_range.h:892
unsigned int uint
Definition: uca-dump.cc:29
Definition: opt_range.h:549
bool operator()(QUICK_SELECT_I *a, QUICK_SELECT_I *b)
Definition: opt_range.h:770
bool is_agg_distinct() const
Definition: opt_range.h:965
virtual bool is_agg_loose_index_scan() const =0
List< Item_sum > * min_functions
Definition: opt_range.h:905
void range_optimizer_init()
Global initialization of the null_element. Call on server start.
Definition: opt_range.cc:1493
int get_next()
Definition: opt_range.cc:10708
HANDLER_BUFFER * mrr_buf_desc
Definition: opt_range.h:497
uchar * group_prefix
Definition: opt_range.h:889
bool have_max
Definition: opt_range.h:894
THD * thd
Definition: opt_range.h:841
bool unique_key_range()
Definition: opt_range.h:1103
virtual void get_fields_used(MY_BITMAP *used_fields)=0
Get the fields used by the range access method.
bool forced_by_hint
true if creation of the object is forced by the hint.
Definition: opt_range.h:261
KEY_PART_INFO * key_part
Definition: key.h:147
KEY_PART_INFO * min_max_arg_part
Definition: opt_range.h:897
virtual void range_end()
Definition: opt_range.h:307
virtual bool reverse_sort_possible() const =0
Whether the range access method is capable of returning records in reverse order. ...
QUICK_RANGE_SELECT * cpk_quick
Definition: opt_range.h:755
void make_min_endpoint(key_range *kr, uint prefix_length, key_part_map keypart_map)
Initalizes a key_range object for communication with storage engine.
Definition: opt_range.h:114
Definition: opt_range.h:334
int cmp_next(QUICK_RANGE *range)
Definition: opt_range.cc:11287
uint8_t uint8
Definition: my_inttypes.h:58
Quick_ranges min_max_ranges
Definition: opt_range.h:902
int get_type() const
Definition: opt_range.h:528
QUICK_INDEX_MERGE_SELECT(THD *thd, TABLE *table)
Definition: opt_range.cc:1862
bool row_in_ranges()
Definition: opt_range.cc:11082
Definition: opt_range.h:1021
List< Item_sum > * max_functions
Definition: opt_range.h:906
virtual bool is_agg_loose_index_scan() const
Definition: opt_range.h:530
virtual bool is_loose_index_scan() const
Definition: opt_range.h:984
key_part_map keypart_map
Definition: my_base.h:1117
int next_max()
Definition: opt_range.cc:13509
void update_min_result(bool reset)
Definition: opt_range.cc:13875
bool is_index_scan
Definition: opt_range.h:913
bool has_aggregate_function
Definition: opt_range.h:1082
uint16 key
Definition: opt_range.h:65
void dbug_dump(int indent, bool verbose)
Definition: opt_range.cc:15531
Definition: opt_range.h:617
virtual void get_fields_used(MY_BITMAP *used_fields)
Get the fields used by the range access method.
Definition: opt_range.h:539
uchar * min_search_key
Definition: opt_range.h:1075
void update_max_result(bool reset)
Definition: opt_range.cc:13907
Definition: opt_range.h:789
Definition: my_base.h:1114
MEM_ROOT alloc
Definition: opt_range.h:1087
static const char * key
Definition: suite_stubs.c:14
uint quick_range_seq_next(range_seq_t rseq, KEY_MULTI_RANGE *range)
Definition: opt_range.cc:10886
virtual bool is_loose_index_scan() const
Definition: opt_range.h:802
virtual int get_type() const =0
QUICK_SKIP_SCAN_SELECT(TABLE *table, JOIN *join, KEY *index_info, uint index, KEY_PART_INFO *range_part, SEL_ROOT *index_range_tree, uint eq_prefix_len, uint eq_prefix_parts, uint used_key_parts, const Cost_estimate *read_cost_arg, ha_rows records, MEM_ROOT *parent_alloc, bool has_aggregate_function)
Construct new quick select for queries that can do skip scans.
Definition: opt_range.cc:14426
MEM_ROOT alloc
Definition: opt_range.h:652
void trace_quick_description(Opt_trace_context *trace)
Definition: opt_range.cc:1772
const QUICK_SELECT_I * m_me
Definition: opt_range.h:773
uchar * tmp_record
Definition: opt_range.h:888
A per-session context which is always available at any point of execution, because in practice it&#39;s ...
Definition: opt_trace_context.h:86
virtual int get_next()=0
uint16 field_index
Definition: field.h:857
virtual void need_sorted_output()=0
uchar * min_key
Definition: opt_range.h:80
void add_info_string(String *str)
Definition: opt_range.cc:11388
virtual int init()=0
virtual void get_fields_used(MY_BITMAP *used_fields)
Get the fields used by the range access method.
Definition: opt_range.h:745
uchar * record
Definition: opt_range.h:406
int get_next()
Definition: opt_range.cc:11151
void range_end()
Definition: opt_range.cc:1834
void range_optimizer_free()
Global destruction of the null_element. Call on server stop.
Definition: opt_range.cc:1499
uchar * max_search_key
Definition: opt_range.h:1076
List< QUICK_RANGE_SELECT > quick_selects
Definition: opt_range.h:644
void make_max_endpoint(key_range *kr, uint prefix_length, key_part_map keypart_map)
Initalizes a key_range object for communication with storage engine.
Definition: opt_range.h:153
int get_next()
Definition: opt_range.cc:10937
uint16 min_length
Definition: opt_range.h:81
std::shared_ptr< MEM_ROOT > alloc
Definition: opt_range.h:510
Definition: key.h:111
uint eq_prefix_key_parts
Definition: opt_range.h:1046
void need_sorted_output()
Definition: opt_range.h:951
int get_type() const
Definition: opt_range.h:714
virtual bool is_valid()
Simple sanity check that the quick select has been set up correctly.
Definition: opt_range.h:395
int reset(void)
Definition: opt_range.h:992
bool in_ror_merged_scan
Definition: opt_range.h:461
List_iterator< Item_sum > * min_functions_it
Definition: opt_range.h:907
Field * field
Definition: opt_range.h:74
bool free_file
Definition: opt_range.h:484
handler * file
Definition: table.h:1296
Definition: opt_range.h:333
void set_handler(handler *file_arg)
Definition: opt_range.h:537
Definition: sql_list.h:581
bool have_min
Definition: opt_range.h:893
Field * field
Definition: key.h:57
bool doing_pk_scan
Definition: opt_range.h:650
Definition: opt_range.h:230
THD * thd
Definition: opt_range.h:758
virtual void dbug_dump(int indent, bool verbose)=0
KEY_PART_INFO * key_part_info
Definition: opt_range.h:501
THD * thd
Definition: opt_range.h:653
TABLE * table() const
Definition: sql_opt_exec_shared.h:480
void rewind(void)
Definition: sql_list.h:571
uint8 null_bit
Definition: opt_range.h:68
virtual bool is_valid()
Simple sanity check that the quick select has been set up correctly.
Definition: opt_range.h:732
key_part_map max_keypart_map
Definition: opt_range.h:91
bool push_quick_back(QUICK_RANGE_SELECT *quick_sel_range)
Definition: opt_range.cc:1883
bool reverse_sort_possible() const
Whether the range access method is capable of returning records in reverse order. ...
Definition: opt_range.h:799
virtual int get_next()
Definition: opt_range.cc:11035
bool scans_inited
Definition: opt_range.h:848
KEY * index_info
Definition: opt_range.h:1024
~QUICK_ROR_UNION_SELECT()
Definition: opt_range.cc:2264
Definition: opt_range.h:338
bool reverse_sort_possible() const
Whether the range access method is capable of returning records in reverse order. ...
Definition: opt_range.h:712
QUICK_RANGE_SEQ_CTX qr_traversal_ctx
Definition: opt_range.h:491
const uint eq_prefix_len
Definition: opt_range.h:1045
void add_info_string(String *str)
Definition: opt_range.cc:11367
void add_info_string(String *str)
Definition: opt_range.cc:11382
Quick_ranges::const_iterator last
Definition: opt_range.h:447
void dbug_dump(int indent, bool verbose)
Definition: opt_range.cc:15560
virtual bool is_agg_loose_index_scan() const
Definition: opt_range.h:803
Field::imagetype image_type
Definition: opt_range.h:75
key_part_map min_keypart_map
Definition: opt_range.h:91
bool unique_key_range()
Definition: opt_range.h:713
~QUICK_GROUP_MIN_MAX_SELECT()
Definition: opt_range.cc:13120
void add_keys_and_lengths(String *key_names, String *used_lengths)
Append comma-separated list of keys this quick select uses to key_names; append comma-separated list ...
Definition: opt_range.cc:14930
uint16 store_length
Definition: opt_range.h:67
int reset(void)
Definition: opt_range.cc:2124
virtual int reset(void)=0
int get_next()
Definition: opt_range.cc:10608
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:77
void add_keys_and_lengths(String *key_names, String *used_lengths)
Definition: opt_range.cc:11435
static int flags[50]
Definition: hp_test1.cc:39
friend bool get_quick_keys(PARAM *param, QUICK_RANGE_SELECT *quick, KEY_PART *key, SEL_ARG *key_tree, uchar *min_key, uint min_key_flag, uchar *max_key, uint max_key_flag, uint *desc_flag)
Generate key values for range select from given sel_arg tree.
Definition: opt_range.cc:10245
Implements a priority queue using a vector-based max-heap.
Definition: priority_queue.h:92
bool is_keys_used(const MY_BITMAP *fields)
Definition: opt_range.cc:10422
Definition: sql_opt_exec_shared.h:58
Definition: opt_range.h:336
Definition: my_base.h:82
Definition: opt_range.h:332
virtual int init_ror_merged_scan(bool reuse_handler)
Definition: opt_range.h:359
bool have_agg_distinct
Definition: opt_range.h:895
friend range_seq_t quick_range_seq_init(void *init_param, uint n_ranges, uint flags)
Definition: opt_range.cc:10843
Definition: my_base.h:1075
bool clustered_pk_range()
Definition: opt_range.h:656
List_iterator< QUICK_RANGE > rev_it
Definition: opt_range.h:997
Used to store optimizer cost estimates.
Definition: handler.h:3262
bool seen_first_key
Definition: opt_range.h:1070
uchar * distinct_prefix
Definition: opt_range.h:1060
Definition: my_base.h:79
bool set_range(SEL_ARG *sel_range)
Setup fileds that hold the range condition on key part C.
Definition: opt_range.cc:14601
List< QUICK_RANGE > rev_ranges
Definition: opt_range.h:996
Unique * unique
Definition: opt_range.h:618
Definition: my_base.h:1087
A graph of (possible multiple) key ranges, represented as a red-black binary tree.
Definition: opt_range.cc:286
uint rowid_length
Definition: opt_range.h:845
bool reverse_sort_possible() const
Whether the range access method is capable of returning records in reverse order. ...
Definition: opt_range.h:629
uint m_used_key_parts
Definition: opt_range.h:998
int init()
Do post-constructor initialization.
Definition: opt_range.cc:14510
void make_max_endpoint(key_range *kr)
Initalizes a key_range object for communication with storage engine.
Definition: opt_range.h:169
KEY_PART * key_parts
Definition: opt_range.h:500
uchar * max_range_key
Definition: opt_range.h:1074
my_off_t ha_rows
Definition: my_base.h:1130
bool unique_key_range()
Definition: opt_range.h:957
bool unique_key_range()
Definition: opt_range.cc:10366
bool reverse_sort_possible() const
Whether the range access method is capable of returning records in reverse order. ...
Definition: opt_range.h:956
List_iterator< Item_sum > * max_functions_it
Definition: opt_range.h:908
virtual bool clustered_pk_range()
Definition: opt_range.h:319
void add_keys_and_lengths(String *key_names, String *used_lengths)
Definition: opt_range.cc:11404
#define STRING_WITH_LEN(X)
Definition: m_string.h:315
This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical rea...
handler * file
Definition: opt_range.h:459
Definition: my_base.h:81
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:777
virtual void add_keys_and_lengths(String *key_names, String *used_lengths)=0
int get_next()
Definition: opt_range.cc:13339
uint used_key_parts
Definition: opt_range.h:254
~QUICK_ROR_INTERSECT_SELECT()
Definition: opt_range.cc:2153
bool reverse_sorted() const
Whether the range access method returns records in reverse order.
Definition: opt_range.h:798
uchar * min_range_key
Definition: opt_range.h:1073