MySQL  8.0.19
Source Code Documentation
sql_join_buffer.h
Go to the documentation of this file.
1 #ifndef SQL_JOIN_CACHE_INCLUDED
2 #define SQL_JOIN_CACHE_INCLUDED
3 
4 /* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License, version 2.0,
8  as published by the Free Software Foundation.
9 
10  This program is also distributed with certain software (including
11  but not limited to OpenSSL) that is licensed under separate terms,
12  as designated in a particular file or component or in included license
13  documentation. The authors of MySQL hereby grant you an additional
14  permission to link the program and your derivative works with the
15  separately licensed software that they have included with MySQL.
16 
17  This program is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  GNU General Public License, version 2.0, for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with this program; if not, write to the Free Software
24  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
25 
26 #include <string.h>
27 #include <sys/types.h>
28 
29 #include "my_byteorder.h"
30 #include "my_dbug.h"
31 #include "my_inttypes.h"
33 #include "sql/handler.h"
34 #include "sql/sql_executor.h" // QEP_operation
35 
36 class Field;
37 class Item;
38 class JOIN;
39 
40 /**
41  @file sql/sql_join_buffer.h
42  Join buffer classes.
43 */
44 
45 /*
46  Categories of data fields of variable length written into join cache buffers.
47  The value of any of these fields is written into cache together with the
48  prepended length of the value.
49 */
50 #define CACHE_BLOB 1 /* blob field */
51 #define CACHE_STRIPPED 2 /* field stripped of trailing spaces */
52 #define CACHE_VARSTR1 3 /* short string value (length takes 1 byte) */
53 #define CACHE_VARSTR2 4 /* long string value (length takes 2 bytes) */
54 
55 /*
56  The CACHE_FIELD structure used to describe fields of records that
57  are written into a join cache buffer from record buffers and backward.
58 */
59 struct CACHE_FIELD {
60  uchar *str; /**< buffer from/to where the field is to be copied */
61  uint length; /**< maximal number of bytes to be copied from/to str */
62  /*
63  Field object for the moved field
64  (0 - for a flag field, see JOIN_CACHE::create_flag_fields).
65  */
67  uint type; /**< category of the of the copied field (CACHE_BLOB et al.) */
68  /*
69  The number of the record offset value for the field in the sequence
70  of offsets placed after the last field of the record. These
71  offset values are used to access fields referred to from other caches.
72  If the value is 0 then no offset for the field is saved in the
73  trailing sequence of offsets.
74  */
76  /// Used to chain rowid copy objects belonging to one join_tab
78  /* The remaining structure fields are used as containers for temp values */
79  uint blob_length; /**< length of the blob to be copied */
80  uint offset; /**< field offset to be saved in cache buffer */
81 
84  str = buffer;
85  }
86  bool buffer_is_bound() const { return str != NULL; }
87 };
88 
89 /**
90  Filter the base columns of virtual generated columns if using a covering index
91  scan.
92 
93  Adjust table->read_set so that it only contains the columns that are needed in
94  the join operation and afterwards. A copy of the original read_set is stored
95  in "saved_bitmaps".
96 
97  For a virtual generated column, all base columns are added to the read_set
98  of the table. The storage engine will then copy all base column values so
99  that the value of the GC can be calculated inside the executor.
100  But when a virtual GC is fetched using a covering index, the actual GC
101  value is fetched by the storage engine and the base column values are not
102  needed. Join buffering code must not try to copy them (in
103  create_remaining_fields()).
104  So, we eliminate from read_set those columns that are available from the
105  covering index.
106 */
108  const QEP_TAB *qep_tab, MEM_ROOT *mem_root,
110 
111 /**
112  Restore table->read_set to the value stored in "saved_bitmaps".
113 */
115  const QEP_TAB *qep_tab,
117 
118 /**
119  JOIN_CACHE is the base class to support the implementations of both
120  Blocked-Based Nested Loops (BNL) Join Algorithm and Batched Key Access (BKA)
121  Join Algorithm. The first algorithm is supported by the derived class
122  JOIN_CACHE_BNL, while the second algorithm is supported by the derived
123  class JOIN_CACHE_BKA.
124  These two algorithms have a lot in common. Both algorithms first
125  accumulate the records of the left join operand in a join buffer and
126  then search for matching rows of the second operand for all accumulated
127  records.
128  For the first algorithm this strategy saves on logical I/O operations:
129  the entire set of records from the join buffer requires only one look-through
130  the records provided by the second operand.
131  For the second algorithm the accumulation of records allows to optimize
132  fetching rows of the second operand from disk for some engines (MyISAM,
133  InnoDB), or to minimize the number of round-trips between the Server and
134  the engine nodes (NDB Cluster).
135 */
136 
137 class JOIN_CACHE : public QEP_operation {
138  private:
139  /// Size of the offset of a record from the cache.
141  /// Size of the length of a record in the cache.
143  /// Size of the offset of a field within a record in the cache.
145 
146  /**
147  In init() there are several uses of TABLE::tmp_set, so one tmp_set isn't
148  enough; this one is specific of generated column handling.
149  */
151 
152  protected:
153  /// @return the number of bytes used to store an offset value
154  static uint offset_size(ulong len) {
155  if (len <= 0xFFUL) return 1;
156  if (len <= 0xFFFFUL) return 2;
157  if (len <= 0xFFFFFFFFUL) return 4;
158  return 8;
159  }
160 
161  /**
162  Decode an offset.
163  @param ofs_sz size of the encoded offset
164  @param ptr the encoded offset
165  @return the decoded offset value
166  */
167  static ulong get_offset(uint ofs_sz, const uchar *ptr) {
168  switch (ofs_sz) {
169  case 1:
170  return uint(*ptr);
171  case 2:
172  return uint2korr(ptr);
173  case 4:
174  return uint4korr(ptr);
175  case 8:
176  return static_cast<ulong>(uint8korr(ptr));
177  }
178  return 0;
179  }
180 
181  /**
182  Encode an offset.
183  @param ofs_sz size of the encoded offset
184  @param ptr the encoded offset
185  @param ofs the offset value to encode
186  */
187  static void store_offset(uint ofs_sz, uchar *ptr, ulong ofs) {
188  switch (ofs_sz) {
189  case 1:
190  *ptr = (uchar)ofs;
191  return;
192  case 2:
193  int2store(ptr, (uint16)ofs);
194  return;
195  case 4:
196  int4store(ptr, (uint32)ofs);
197  return;
198  case 8:
199  int8store(ptr, (uint64)ofs);
200  return;
201  }
202  }
203 
204  /**
205  The total maximum length of the fields stored for a record in the cache.
206  For blob fields only the sizes of the blob lengths are taken into account.
207  */
209 
210  /**
211  Representation of the executed multi-way join through which all needed
212  context can be accessed.
213  */
215 
216  /**
217  Cardinality of the range of join tables whose fields can be put into the
218  cache. (A table from the range not necessarily contributes to the cache.)
219  */
221 
222  /**
223  The total number of flag and data fields that can appear in a record
224  written into the cache. Fields with null values are always skipped
225  to save space.
226  */
228 
229  /**
230  The total number of flag fields in a record put into the cache. They are
231  used for table null bitmaps, table null row flags, and an optional match
232  flag. Flag fields go before other fields in a cache record with the match
233  flag field placed always at the very beginning of the record.
234  */
236 
237  /// The total number of blob fields that are written into the cache.
239 
240  /**
241  The total number of fields referenced from field descriptors for other join
242  caches. These fields are used to construct key values to access matching
243  rows with index lookups. Currently the fields can be referenced only from
244  descriptors for bka caches. However they may belong to a cache of any type.
245  */
247 
248  /**
249  The current number of already created data field descriptors.
250  This number can be useful for implementations of the init methods.
251  */
253 
254  /**
255  The current number of already created pointers to the data field
256  descriptors. This number can be useful for implementations of
257  the init methods.
258  */
260  /**
261  Array of the descriptors of fields containing 'fields' elements.
262  These are all fields that are stored for a record in the cache.
263  */
265 
266  /**
267  Array of pointers to the blob descriptors that contains 'blobs' elements.
268  */
270 
271  /**
272  This flag indicates that records written into the join buffer contain
273  a match flag field. The flag must be set by the init method.
274  */
276  /**
277  This flag indicates that any record is prepended with the length of the
278  record which allows us to skip the record or part of it without reading.
279  */
281 
282  /**
283  The maximum number of bytes used for a record representation in
284  the cache excluding the space for blob data.
285  For future derived classes this representation may contains some
286  redundant info such as a key value associated with the record.
287  */
289  /**
290  The value of pack_length incremented by the total size of all
291  pointers of a record in the cache to the blob data.
292  */
294 
295  /// Start of the join buffer.
297  /**
298  Size of the entire memory allocated for the join buffer.
299 
300  Part of this memory may be reserved for an auxiliary buffer.
301  @sa rem_space()
302  */
304 #ifndef DBUG_OFF
305  /// Whether the join buffer is read-only.
306  bool m_read_only = false;
307 #endif
308 
309  /// The number of records put into the join buffer.
311 
312  /**
313  Pointer to the current position in the join buffer.
314  This member is used both when writing to buffer and
315  when reading from it.
316  */
318  /**
319  Pointer to the first free position in the join buffer,
320  right after the last record into it.
321  */
323 
324  /**
325  Pointer to the beginning of first field of the current read/write record
326  from the join buffer. The value is adjusted by the get_record/put_record
327  functions.
328  */
330  /**
331  Pointer to the beginning of first field of the last record
332  from the join buffer.
333  */
335 
336  /**
337  Flag is set if the blob data for the last record in the join buffer
338  is in record buffers rather than in the join cache.
339  */
341 
342  /**
343  Pointer to the position to the current record link.
344  Record links are used only with linked caches. Record links allow to set
345  connections between parts of one join record that are stored in different
346  join buffers.
347  In the simplest case a record link is just a pointer to the beginning of
348  the record stored in the buffer.
349  In a more general case a link could be a reference to an array of pointers
350  to records in the buffer. */
352 
353  /// Cached value of calc_check_only_first_match(join_tab).
355 
356  void calc_record_fields();
357  int alloc_fields(uint external_fields);
358  void create_flag_fields();
359  void create_remaining_fields(bool all_read_fields);
360  void set_constants();
361  bool alloc_buffer();
362 
366 
369  }
370  ulong get_rec_length(const uchar *ptr) {
371  return get_offset(size_of_rec_len, ptr);
372  }
373  ulong get_fld_offset(const uchar *ptr) {
374  return get_offset(size_of_fld_ofs, ptr);
375  }
376 
377  void store_rec_ref(uchar *ptr, const uchar *ref) {
379  }
380 
381  void store_rec_length(uchar *ptr, ulong len) {
382  store_offset(size_of_rec_len, ptr, len);
383  }
384  void store_fld_offset(uchar *ptr, ulong ofs) {
385  store_offset(size_of_fld_ofs, ptr, ofs);
386  }
387 
388  /// Write record fields and their required offsets into the join buffer.
389  uint write_record_data(uchar *link, bool *is_full);
390 
391  /// Reserve some auxiliary space from the end of the join buffer.
392  virtual void reserve_aux_buffer() {}
393 
394  /**
395  @return the minimum size for the auxiliary buffer
396  @retval 0 if no auxiliary buffer is needed
397  */
398  virtual uint aux_buffer_min_size() const { return 0; }
399 
400  /// @return how much space is remaining in the join buffer
401  virtual ulong rem_space() const {
404  return ulong(buff_size - (end_pos - buff));
405  }
406 
407  /**
408  Skip record from the join buffer if it was flagged as matched.
409  @return whether the record was skipped
410  */
411  virtual bool skip_record_if_match();
412 
413  /* Read some flag and data fields of a record from the join buffer */
415 
416  /* Read some flag fields of a record from the join buffer */
417  void read_some_flag_fields();
418 
419  /* Read all flag fields of the record which is at position rec_ptr */
420  void read_all_flag_fields_by_pos(uchar *rec_ptr);
421 
422  /* Read a data record field from the join buffer */
423  uint read_record_field(CACHE_FIELD *copy, bool last_record);
424 
425  /* Read a referenced field from the join buffer */
426  bool read_referenced_field(CACHE_FIELD *copy, uchar *rec_ptr, uint *len);
427 
428  /*
429  True if rec_ptr points to the record whose blob data stay in
430  record buffers
431  */
433  return rec_ptr == last_rec_pos && last_rec_blob_data_is_in_rec_buff;
434  }
435 
436  /**
437  Find matches from the next table for records from the join buffer.
438  @param skip_last whether to ignore any matches for the
439  last partial join record
440  @return nested loop state
441  */
442  virtual enum_nested_loop_state join_matching_records(bool skip_last) = 0;
443 
444  /* Add null complements for unmatched outer records from buffer */
445  virtual enum_nested_loop_state join_null_complements(bool skip_last);
446 
447  /* Restore the fields of the last record from the join buffer */
448  virtual void restore_last_record();
449 
450  /*Set match flag for a record in join buffer if it has not been set yet */
451  bool set_match_flag_if_none(QEP_TAB *first_inner, uchar *rec_ptr);
452 
454 
455  /**
456  Check matching to a partial join record from the join buffer.
457 
458  @param rec_ptr pointer to the record from join buffer to check matching to
459  @return whether there is a match
460 
461  @details
462  The function checks whether the current record of 'join_tab' matches
463  the partial join record from join buffer located at 'rec_ptr'. If this is
464  the case and 'join_tab' is the last inner table of a semi-join or an outer
465  join the function turns on the match flag for the 'rec_ptr' record unless
466  it has been already set.
467 
468  @note
469  Setting the match flag on can trigger re-evaluation of pushdown conditions
470  for the record when join_tab is the last inner table of an outer join.
471  */
472  virtual bool check_match(uchar *rec_ptr);
473 
474  /** @returns whether we should check only the first match for this table */
475  bool calc_check_only_first_match(const QEP_TAB *t) const;
476 
477  /**
478  Add a record into the join buffer.
479  @return whether it should be the last record in the buffer
480  */
481  virtual bool put_record_in_cache();
482 
483  public:
484  /* Pointer to the previous join cache if there is any */
486  /* Pointer to the next join cache if there is any */
488 
489  // See if this operation can be replaced with a hash join. In order to be
490  // replaced with hash join, the operation must be a block nested loop,
491  // and the table must have at least one equi-join condition attached. If there
492  // are other conditions that are not equi-join conditions, they will be
493  // attached as filters after the hash join.
494  virtual bool can_be_replaced_with_hash_join() const { return false; }
495 
496  /**
497  Initialize the join cache.
498  @retval 0 on success
499  @retval 1 on failure
500  */
501  virtual int init() = 0;
502 
503  /// Reset the join buffer for reading/writing.
504  virtual void reset_cache(bool for_writing);
505 
506  /// Add a record into join buffer and call join_records() if it's full.
508  if (put_record_in_cache()) return join_records(false);
509  return NESTED_LOOP_OK;
510  }
511 
512  virtual bool get_record();
513 
514  void get_record_by_pos(uchar *rec_ptr);
515 
516  /**
517  Read the match flag of a record.
518  @param rec_ptr record in the join buffer
519  @return the match flag
520  */
521  bool get_match_flag_by_pos(uchar *rec_ptr);
522 
523  /// @return the position of the current record
524  uchar *get_curr_rec() const { return curr_rec_pos; }
525 
526  /** Set the current record link. */
528 
529  /// @return the current record link
532  }
533 
534  /// Join records from the join buffer with records from the next join table.
536  enum_nested_loop_state join_records(bool skip_last);
537 
538  enum_op_type type() { return OT_CACHE; }
539 
540  /**
541  This constructor creates a join cache, linked or not. The cache is to be
542  used to join table 'tab' to the result of joining the previous tables
543  specified by the 'j' parameter. The parameter 'prev' specifies the previous
544  cache object to which this cache is linked, or NULL if this cache is not
545  linked.
546  */
547  JOIN_CACHE(JOIN *j, QEP_TAB *qep_tab_arg, JOIN_CACHE *prev)
548  : QEP_operation(qep_tab_arg),
550  join(j),
551  buff(NULL),
552  prev_cache(prev),
553  next_cache(NULL) {
554  if (prev_cache) prev_cache->next_cache = this;
555  }
556  virtual ~JOIN_CACHE() {}
557  void mem_free() {
558  /*
559  JOIN_CACHE doesn't support unlinking cache chain. This code is needed
560  only by set_join_cache_denial().
561  */
562  /*
563  If there is a previous/next cache linked to this cache through the
564  (next|prev)_cache pointer: remove the link.
565  */
568 
569  my_free(buff);
570  buff = NULL;
571  }
572 
573  /** Bits describing cache's type @sa setup_join_buffering() */
575 
576  virtual enum_join_cache_type cache_type() const = 0;
577 
578  /* true <=> cache reads rows by key */
579  bool is_key_access() const { return cache_type() & ALG_BKA; }
580 
581  friend class JOIN_CACHE_BNL;
582  friend class JOIN_CACHE_BKA;
583 };
584 
586  protected:
587  enum_nested_loop_state join_matching_records(bool skip_last) override;
588 
589  public:
590  JOIN_CACHE_BNL(JOIN *j, QEP_TAB *qep_tab_arg, JOIN_CACHE *prev)
591  : JOIN_CACHE(j, qep_tab_arg, prev), const_cond(NULL) {}
592 
593  int init() override;
594 
595  enum_join_cache_type cache_type() const override { return ALG_BNL; }
596 
597  bool can_be_replaced_with_hash_join() const override;
598 
599  private:
601 };
602 
603 class JOIN_CACHE_BKA : public JOIN_CACHE {
604  protected:
605  /// Size of the MRR buffer at JOIN_CACHE::end_pos.
607  /// Flag to to be passed to the MRR interface.
609 
610  /// MRR buffer associated with this join cache.
612 
613  /**
614  Initialize the MRR buffer.
615 
616  After this point, JOIN_CACHE::write_record_data() must not be
617  invoked on this object.
618  rem_space() and aux_buff_size will ensure that
619  there be at least some space available.
620 
621  @param end end of the buffer
622 
623  @sa DsMrr_impl::dsmrr_init()
624  @sa DsMrr_impl::dsmrr_next()
625  @sa DsMrr_impl::dsmrr_fill_buffer()
626  */
630 #ifndef DBUG_OFF
631  m_read_only = true;
632 #endif
635  }
636 
637  virtual void init_mrr_buff() { init_mrr_buff(buff + buff_size); }
638 
639  /**
640  The number of the cache fields that are used in building keys to access
641  the table join_tab
642  */
644  /**
645  The total number of the fields in the previous caches that are used
646  in building keys t access the table join_tab
647  */
649 
650  /**
651  Whether the key values will be read directly from the join
652  buffer (whether we avoid building key values in the key buffer).
653  */
655  /// The length of an embedded key value.
657 
658  /// @return whether access keys can be read directly from the join buffer
659  bool check_emb_key_usage();
660 
661  /// @return number of bytes to reserve for the MRR buffer for a record
663 
664  /// Reserve space for the MRR buffer for a record.
665  void reserve_aux_buffer() override {
666  if (auto rem = rem_space()) {
667  auto incr = aux_buffer_incr();
668  aux_buff_size += pack_length + incr < rem ? incr : rem;
669  }
670  }
671 
672  /// @return the minimum size for the MRR buffer
673  uint aux_buffer_min_size() const override;
674 
675  enum_nested_loop_state join_matching_records(bool skip_last) override;
676 
677  /// Prepare to search for records that match records from the join buffer.
678  bool init_join_matching_records(RANGE_SEQ_IF *seq_funcs, uint ranges);
679 
680  public:
681  /// The MRR mode initially is set to 'flags'
682  JOIN_CACHE_BKA(JOIN *j, QEP_TAB *qep_tab_arg, uint flags, JOIN_CACHE *prev)
683  : JOIN_CACHE(j, qep_tab_arg, prev), mrr_mode(flags) {}
684 
685  int init() override;
686 
687  void reset_cache(bool for_writing) override {
688  JOIN_CACHE::reset_cache(for_writing);
689  aux_buff_size = 0;
690  }
691 
692  /// @return how much space is remaining in the join buffer
693  ulong rem_space() const override {
694  const auto space = JOIN_CACHE::rem_space();
695  DBUG_ASSERT(space >= aux_buff_size);
696  return space - aux_buff_size;
697  }
698 
699  /// @return false if a key was built successfully over the next record
700  /// from the join buffer, true otherwise.
701  virtual bool get_next_key(key_range *key);
702 
703  /// @return whether the record combination does not match the index condition
704  bool skip_index_tuple(range_seq_t rseq, char *range_info);
705 
706  enum_join_cache_type cache_type() const override { return ALG_BKA; }
707 };
708 
709 #endif /* SQL_JOIN_CACHE_INCLUDED */
int8store
void int8store(char *pT, ulonglong A)
Definition: my_byteorder.h:184
Item
Definition: item.h:665
CACHE_FIELD::referenced_field_no
uint referenced_field_no
Definition: sql_join_buffer.h:75
my_byteorder.h
JOIN_CACHE_BKA::reset_cache
void reset_cache(bool for_writing) override
Reset the join buffer for reading/writing.
Definition: sql_join_buffer.h:687
JOIN_CACHE::read_referenced_field
bool read_referenced_field(CACHE_FIELD *copy, uchar *rec_ptr, uint *len)
Definition: sql_join_buffer.cc:1630
JOIN_CACHE::put_record
virtual enum_nested_loop_state put_record()
Add a record into join buffer and call join_records() if it's full.
Definition: sql_join_buffer.h:507
JOIN_CACHE::get_fld_offset
ulong get_fld_offset(const uchar *ptr)
Definition: sql_join_buffer.h:373
JOIN_CACHE::get_curr_rec_link
uchar * get_curr_rec_link() const
Definition: sql_join_buffer.h:530
JOIN_CACHE_BKA::aux_buffer_incr
uint aux_buffer_incr()
Definition: sql_join_buffer.cc:1026
JOIN_CACHE::pack_length
uint pack_length
The maximum number of bytes used for a record representation in the cache excluding the space for blo...
Definition: sql_join_buffer.h:288
JOIN_CACHE::size_of_rec_len
uint size_of_rec_len
Size of the length of a record in the cache.
Definition: sql_join_buffer.h:142
JOIN_CACHE_BNL::can_be_replaced_with_hash_join
bool can_be_replaced_with_hash_join() const override
Definition: sql_join_buffer.cc:676
CACHE_FIELD::str
uchar * str
buffer from/to where the field is to be copied
Definition: sql_join_buffer.h:60
NULL
#define NULL
Definition: types.h:55
JOIN_CACHE::get_size_of_rec_length
uint get_size_of_rec_length() const
Definition: sql_join_buffer.h:364
JOIN_CACHE::cache_type
virtual enum_join_cache_type cache_type() const =0
JOIN_CACHE::store_rec_ref
void store_rec_ref(uchar *ptr, const uchar *ref)
Definition: sql_join_buffer.h:377
QEP_operation
QEP_operation is an interface class for operations in query execution plan.
Definition: sql_executor.h:208
JOIN_CACHE::ALG_NONE
@ ALG_NONE
Definition: sql_join_buffer.h:574
JOIN_CACHE::mem_free
void mem_free()
Internal state cleanup.
Definition: sql_join_buffer.h:557
JOIN_CACHE::size_of_rec_ofs
uint size_of_rec_ofs
Size of the offset of a record from the cache.
Definition: sql_join_buffer.h:140
JOIN_CACHE::calc_record_fields
void calc_record_fields()
Definition: sql_join_buffer.cc:183
int4store
void int4store(char *pT, uint32 A)
Definition: my_byteorder.h:172
sql_executor.h
string.h
uint64
uint64_t uint64
Definition: my_inttypes.h:68
QEP_operation::OT_CACHE
@ OT_CACHE
Definition: sql_executor.h:211
JOIN_CACHE_BNL::join_matching_records
enum_nested_loop_state join_matching_records(bool skip_last) override
Find matches from the next table for records from the join buffer.
Definition: sql_join_buffer.cc:1906
JOIN_CACHE::check_match
virtual bool check_match(uchar *rec_ptr)
Check matching to a partial join record from the join buffer.
Definition: sql_join_buffer.cc:2109
my_dbug.h
uint4korr
uint32 uint4korr(const char *pT)
Definition: my_byteorder.h:144
JOIN_CACHE::get_record
virtual bool get_record()
Read the next record from the join buffer.
Definition: sql_join_buffer.cc:1409
JOIN_CACHE_BNL::cache_type
enum_join_cache_type cache_type() const override
Definition: sql_join_buffer.h:595
JOIN_CACHE::calc_check_only_first_match
bool calc_check_only_first_match(const QEP_TAB *t) const
Definition: sql_join_buffer.cc:1980
QEP_TAB
Definition: sql_executor.h:417
JOIN_CACHE::get_rec_ref
uchar * get_rec_ref(uchar *ptr)
Definition: sql_join_buffer.h:367
JOIN_CACHE::write_record_data
uint write_record_data(uchar *link, bool *is_full)
Write record fields and their required offsets into the join buffer.
Definition: sql_join_buffer.cc:1170
JOIN_CACHE_BKA::use_emb_key
bool use_emb_key
Whether the key values will be read directly from the join buffer (whether we avoid building key valu...
Definition: sql_join_buffer.h:654
incr
void incr(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1)
Definition: suite_stubs.c:109
JOIN_CACHE::field_descr
CACHE_FIELD * field_descr
Array of the descriptors of fields containing 'fields' elements.
Definition: sql_join_buffer.h:264
JOIN_CACHE::can_be_replaced_with_hash_join
virtual bool can_be_replaced_with_hash_join() const
Definition: sql_join_buffer.h:494
JOIN_CACHE::data_field_count
uint data_field_count
The current number of already created data field descriptors.
Definition: sql_join_buffer.h:252
JOIN_CACHE::flag_fields
uint flag_fields
The total number of flag fields in a record put into the cache.
Definition: sql_join_buffer.h:235
mem_root
static MEM_ROOT mem_root
Definition: client_plugin.cc:109
CACHE_FIELD::offset
uint offset
field offset to be saved in cache buffer
Definition: sql_join_buffer.h:80
JOIN_CACHE::tables
uint tables
Cardinality of the range of join tables whose fields can be put into the cache.
Definition: sql_join_buffer.h:220
JOIN_CACHE::store_fld_offset
void store_fld_offset(uchar *ptr, ulong ofs)
Definition: sql_join_buffer.h:384
JOIN_CACHE::join_null_complements
virtual enum_nested_loop_state join_null_complements(bool skip_last)
Definition: sql_join_buffer.cc:2189
JOIN_CACHE::curr_rec_pos
uchar * curr_rec_pos
Pointer to the beginning of first field of the current read/write record from the join buffer.
Definition: sql_join_buffer.h:329
CACHE_FIELD::buffer_is_bound
bool buffer_is_bound() const
Definition: sql_join_buffer.h:86
JOIN_CACHE_BKA::reserve_aux_buffer
void reserve_aux_buffer() override
Reserve space for the MRR buffer for a record.
Definition: sql_join_buffer.h:665
JOIN_CACHE::set_match_flag_if_none
bool set_match_flag_if_none(QEP_TAB *first_inner, uchar *rec_ptr)
Definition: sql_join_buffer.cc:2015
key
static const char * key
Definition: suite_stubs.c:14
JOIN_CACHE_BNL::const_cond
Item * const_cond
Definition: sql_join_buffer.h:600
JOIN_CACHE_BKA::init
int init() override
Initialize the join cache.
Definition: sql_join_buffer.cc:759
JOIN_CACHE_BKA::aux_buffer_min_size
uint aux_buffer_min_size() const override
Calculate the minimum size for the MRR buffer.
Definition: sql_join_buffer.cc:1051
JOIN_CACHE_BKA::init_mrr_buff
virtual void init_mrr_buff()
Definition: sql_join_buffer.h:637
JOIN_CACHE::get_rec_length
ulong get_rec_length(const uchar *ptr)
Definition: sql_join_buffer.h:370
JOIN_CACHE_BNL::JOIN_CACHE_BNL
JOIN_CACHE_BNL(JOIN *j, QEP_TAB *qep_tab_arg, JOIN_CACHE *prev)
Definition: sql_join_buffer.h:590
handler.h
JOIN_CACHE_BKA::mrr_buff
HANDLER_BUFFER mrr_buff
MRR buffer associated with this join cache.
Definition: sql_join_buffer.h:611
JOIN_CACHE_BKA::check_emb_key_usage
bool check_emb_key_usage()
Definition: sql_join_buffer.cc:929
JOIN_CACHE::JOIN_CACHE
JOIN_CACHE(JOIN *j, QEP_TAB *qep_tab_arg, JOIN_CACHE *prev)
This constructor creates a join cache, linked or not.
Definition: sql_join_buffer.h:547
JOIN_CACHE::get_size_of_fld_offset
uint get_size_of_fld_offset() const
Definition: sql_join_buffer.h:365
JOIN_CACHE::m_read_only
bool m_read_only
Whether the join buffer is read-only.
Definition: sql_join_buffer.h:306
JOIN_CACHE::aux_buffer_min_size
virtual uint aux_buffer_min_size() const
Definition: sql_join_buffer.h:398
JOIN_CACHE_BNL::init
int init() override
Initialize the join cache.
Definition: sql_join_buffer.cc:615
JOIN_CACHE::type
enum_op_type type()
Definition: sql_join_buffer.h:538
JOIN_CACHE::referenced_fields
uint referenced_fields
The total number of fields referenced from field descriptors for other join caches.
Definition: sql_join_buffer.h:246
JOIN_CACHE::next_cache
JOIN_CACHE * next_cache
Definition: sql_join_buffer.h:487
CACHE_FIELD::bind_buffer
void bind_buffer(uchar *buffer)
Definition: sql_join_buffer.h:82
JOIN_CACHE::read_all_flag_fields_by_pos
void read_all_flag_fields_by_pos(uchar *rec_ptr)
Reads all flag fields of a positioned record from the join buffer.
Definition: sql_join_buffer.cc:2493
JOIN_CACHE::create_flag_fields
void create_flag_fields()
Definition: sql_join_buffer.cc:282
JOIN_CACHE::blobs
uint blobs
The total number of blob fields that are written into the cache.
Definition: sql_join_buffer.h:238
JOIN_CACHE::fields
uint fields
The total number of flag and data fields that can appear in a record written into the cache.
Definition: sql_join_buffer.h:227
JOIN
Definition: sql_optimizer.h:174
my_inttypes.h
JOIN_CACHE::alloc_fields
int alloc_fields(uint external_fields)
Definition: sql_join_buffer.cc:236
JOIN_CACHE::restore_last_record
virtual void restore_last_record()
Definition: sql_join_buffer.cc:1706
service_mysql_alloc.h
JOIN_CACHE::create_remaining_fields
void create_remaining_fields(bool all_read_fields)
Definition: sql_join_buffer.cc:347
JOIN_CACHE::get_size_of_rec_offset
uint get_size_of_rec_offset() const
Definition: sql_join_buffer.h:363
JOIN_CACHE::get_match_flag_by_pos
bool get_match_flag_by_pos(uchar *rec_ptr)
Read the match flag of a record.
Definition: sql_join_buffer.cc:1465
JOIN_CACHE::rem_space
virtual ulong rem_space() const
Definition: sql_join_buffer.h:401
JOIN_CACHE::end_pos
uchar * end_pos
Pointer to the first free position in the join buffer, right after the last record into it.
Definition: sql_join_buffer.h:322
JOIN_CACHE_BKA::join_matching_records
enum_nested_loop_state join_matching_records(bool skip_last) override
Find matches from the next table for records from the join buffer.
Definition: sql_join_buffer.cc:2379
JOIN_CACHE::enum_join_cache_type
enum_join_cache_type
Bits describing cache's type.
Definition: sql_join_buffer.h:574
JOIN_CACHE_BKA::skip_index_tuple
bool skip_index_tuple(range_seq_t rseq, char *range_info)
Definition: sql_join_buffer.cc:1097
JOIN_CACHE::offset_size
static uint offset_size(ulong len)
Definition: sql_join_buffer.h:154
MEM_ROOT
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:77
CACHE_FIELD::blob_length
uint blob_length
length of the blob to be copied
Definition: sql_join_buffer.h:79
JOIN_CACHE::put_record_in_cache
virtual bool put_record_in_cache()
Add a record into the join buffer.
Definition: sql_join_buffer.cc:1384
JOIN_CACHE::store_offset
static void store_offset(uint ofs_sz, uchar *ptr, ulong ofs)
Encode an offset.
Definition: sql_join_buffer.h:187
filter_virtual_gcol_base_cols
void filter_virtual_gcol_base_cols(const QEP_TAB *qep_tab, MEM_ROOT *mem_root, memroot_unordered_map< const QEP_TAB *, MY_BITMAP * > *saved_bitmaps)
Filter the base columns of virtual generated columns if using a covering index scan.
Definition: sql_join_buffer.cc:529
JOIN_CACHE::reserve_aux_buffer
virtual void reserve_aux_buffer()
Reserve some auxiliary space from the end of the join buffer.
Definition: sql_join_buffer.h:392
JOIN_CACHE::save_read_set_for_gcol
memroot_unordered_map< const QEP_TAB *, MY_BITMAP * > save_read_set_for_gcol
In init() there are several uses of TABLE::tmp_set, so one tmp_set isn't enough; this one is specific...
Definition: sql_join_buffer.h:150
uint
unsigned int uint
Definition: uca-dump.cc:29
JOIN_CACHE::is_key_access
bool is_key_access() const
Definition: sql_join_buffer.h:579
JOIN_CACHE_BKA::cache_type
enum_join_cache_type cache_type() const override
Definition: sql_join_buffer.h:706
HANDLER_BUFFER
Definition: handler.h:3209
JOIN_CACHE
JOIN_CACHE is the base class to support the implementations of both Blocked-Based Nested Loops (BNL) ...
Definition: sql_join_buffer.h:137
int2store
void int2store(char *pT, uint16 A)
Definition: my_byteorder.h:164
JOIN_CACHE::set_curr_rec_link
void set_curr_rec_link(uchar *link)
Set the current record link.
Definition: sql_join_buffer.h:527
JOIN_CACHE::end_send
enum_nested_loop_state end_send()
Join records from the join buffer with records from the next join table.
Definition: sql_join_buffer.h:535
JOIN_CACHE::last_rec_blob_data_is_in_rec_buff
bool last_rec_blob_data_is_in_rec_buff
Flag is set if the blob data for the last record in the join buffer is in record buffers rather than ...
Definition: sql_join_buffer.h:340
JOIN_CACHE::prev_cache
JOIN_CACHE * prev_cache
Definition: sql_join_buffer.h:485
uchar
unsigned char uchar
Definition: my_inttypes.h:51
JOIN_CACHE::~JOIN_CACHE
virtual ~JOIN_CACHE()
Definition: sql_join_buffer.h:556
JOIN_CACHE::pos
uchar * pos
Pointer to the current position in the join buffer.
Definition: sql_join_buffer.h:317
rules_table_service::end
Cursor end()
A past-the-end Cursor.
Definition: rules_table_service.cc:188
NESTED_LOOP_OK
@ NESTED_LOOP_OK
Record has been successfully handled.
Definition: sql_executor.h:84
JOIN_CACHE_BKA::JOIN_CACHE_BKA
JOIN_CACHE_BKA(JOIN *j, QEP_TAB *qep_tab_arg, uint flags, JOIN_CACHE *prev)
The MRR mode initially is set to 'flags'.
Definition: sql_join_buffer.h:682
uint32
uint32_t uint32
Definition: my_inttypes.h:66
JOIN_CACHE::reset_cache
virtual void reset_cache(bool for_writing)
Reset the join buffer for reading/writing.
Definition: sql_join_buffer.cc:1350
JOIN_CACHE::data_field_ptr_count
uint data_field_ptr_count
The current number of already created pointers to the data field descriptors.
Definition: sql_join_buffer.h:259
enum_nested_loop_state
enum_nested_loop_state
Possible status of a "nested loop" operation (Next_select_func family of functions).
Definition: sql_executor.h:75
CACHE_FIELD::next_copy_rowid
CACHE_FIELD * next_copy_rowid
Used to chain rowid copy objects belonging to one join_tab.
Definition: sql_join_buffer.h:77
JOIN_CACHE::set_constants
void set_constants()
Definition: sql_join_buffer.cc:407
memroot_unordered_map< const QEP_TAB *, MY_BITMAP * >
JOIN_CACHE::curr_rec_link
uchar * curr_rec_link
Pointer to the position to the current record link.
Definition: sql_join_buffer.h:351
range_seq_t
void * range_seq_t
Definition: handler.h:3215
JOIN_CACHE_BKA::init_mrr_buff
void init_mrr_buff(uchar *end)
Initialize the MRR buffer.
Definition: sql_join_buffer.h:627
JOIN_CACHE::ALG_BKA
@ ALG_BKA
Definition: sql_join_buffer.h:574
JOIN_CACHE::records
uint records
The number of records put into the join buffer.
Definition: sql_join_buffer.h:310
QEP_operation::enum_op_type
enum_op_type
Definition: sql_executor.h:211
uint8korr
ulonglong uint8korr(const char *pT)
Definition: my_byteorder.h:156
JOIN_CACHE::skip_record_if_match
virtual bool skip_record_if_match()
Skip record from the join buffer if it was flagged as matched.
Definition: sql_join_buffer.cc:1677
DBUG_ASSERT
#define DBUG_ASSERT(A)
Definition: my_dbug.h:197
RANGE_SEQ_IF
Definition: handler.h:3217
JOIN_CACHE::read_some_flag_fields
void read_some_flag_fields()
Read some flag fields of a record from the join buffer.
Definition: sql_join_buffer.cc:1527
JOIN_CACHE::last_rec_pos
uchar * last_rec_pos
Pointer to the beginning of first field of the last record from the join buffer.
Definition: sql_join_buffer.h:334
JOIN_CACHE::with_match_flag
bool with_match_flag
This flag indicates that records written into the join buffer contain a match flag field.
Definition: sql_join_buffer.h:275
JOIN_CACHE::get_record_by_pos
void get_record_by_pos(uchar *rec_ptr)
Read a positioned record from the join buffer.
Definition: sql_join_buffer.cc:1442
HANDLER_BUFFER::buffer
uchar * buffer
Definition: handler.h:3210
CACHE_FIELD::length
uint length
maximal number of bytes to be copied from/to str
Definition: sql_join_buffer.h:61
uint2korr
uint16 uint2korr(const char *pT)
Definition: my_byteorder.h:132
JOIN_CACHE::buff_size
ulong buff_size
Size of the entire memory allocated for the join buffer.
Definition: sql_join_buffer.h:303
my_free
void my_free(void *ptr)
Frees the memory pointed by the ptr.
Definition: my_memory.cc:81
JOIN_CACHE::read_record_field
uint read_record_field(CACHE_FIELD *copy, bool last_record)
Definition: sql_join_buffer.cc:1557
JOIN_CACHE::check_only_first_match
bool check_only_first_match
Cached value of calc_check_only_first_match(join_tab).
Definition: sql_join_buffer.h:354
JOIN_CACHE_BKA::get_next_key
virtual bool get_next_key(key_range *key)
Definition: sql_join_buffer.cc:2537
JOIN_CACHE::join_matching_records
virtual enum_nested_loop_state join_matching_records(bool skip_last)=0
Find matches from the next table for records from the join buffer.
JOIN_CACHE_BKA::local_key_arg_fields
uint local_key_arg_fields
The number of the cache fields that are used in building keys to access the table join_tab.
Definition: sql_join_buffer.h:643
JOIN_CACHE::length
uint length
The total maximum length of the fields stored for a record in the cache.
Definition: sql_join_buffer.h:208
ulong
unsigned long ulong
Definition: my_inttypes.h:48
restore_virtual_gcol_base_cols
void restore_virtual_gcol_base_cols(const QEP_TAB *qep_tab, memroot_unordered_map< const QEP_TAB *, MY_BITMAP * > *saved_bitmaps)
Restore table->read_set to the value stored in "saved_bitmaps".
Definition: sql_join_buffer.cc:578
JOIN_CACHE::size_of_fld_ofs
uint size_of_fld_ofs
Size of the offset of a field within a record in the cache.
Definition: sql_join_buffer.h:144
JOIN_CACHE_BKA::aux_buff_size
ulong aux_buff_size
Size of the MRR buffer at JOIN_CACHE::end_pos.
Definition: sql_join_buffer.h:606
uint16
uint16_t uint16
Definition: my_inttypes.h:64
JOIN_CACHE_BKA::mrr_mode
uint mrr_mode
Flag to to be passed to the MRR interface.
Definition: sql_join_buffer.h:608
JOIN_CACHE::blob_ptr
CACHE_FIELD ** blob_ptr
Array of pointers to the blob descriptors that contains 'blobs' elements.
Definition: sql_join_buffer.h:269
JOIN_CACHE::generate_full_extensions
enum_nested_loop_state generate_full_extensions(uchar *rec_ptr)
Definition: sql_join_buffer.cc:2059
CACHE_FIELD
Definition: sql_join_buffer.h:59
JOIN_CACHE::ALG_BNL
@ ALG_BNL
Definition: sql_join_buffer.h:574
JOIN_CACHE::join
JOIN * join
Representation of the executed multi-way join through which all needed context can be accessed.
Definition: sql_join_buffer.h:214
CACHE_FIELD::type
uint type
category of the of the copied field (CACHE_BLOB et al.)
Definition: sql_join_buffer.h:67
Field
Definition: field.h:695
JOIN_CACHE::blob_data_is_in_rec_buff
bool blob_data_is_in_rec_buff(uchar *rec_ptr)
Definition: sql_join_buffer.h:432
JOIN_CACHE_BKA::emb_key_length
uint emb_key_length
The length of an embedded key value.
Definition: sql_join_buffer.h:656
JOIN_CACHE::join_records
enum_nested_loop_state join_records(bool skip_last)
Definition: sql_join_buffer.cc:1745
HANDLER_BUFFER::buffer_end
uchar * buffer_end
Definition: handler.h:3211
JOIN_CACHE::store_rec_length
void store_rec_length(uchar *ptr, ulong len)
Definition: sql_join_buffer.h:381
THR_MALLOC
thread_local MEM_ROOT ** THR_MALLOC
Definition: mysqld.cc:1331
JOIN_CACHE_BKA::external_key_arg_fields
uint external_key_arg_fields
The total number of the fields in the previous caches that are used in building keys t access the tab...
Definition: sql_join_buffer.h:648
JOIN_CACHE::get_curr_rec
uchar * get_curr_rec() const
Definition: sql_join_buffer.h:524
key_range
Definition: my_base.h:1116
final
#define final(a, b, c)
Definition: hash.c:109
JOIN_CACHE::read_some_record_fields
int read_some_record_fields()
Read some flag and data fields of a record from the join buffer.
Definition: sql_join_buffer.cc:1496
JOIN_CACHE::alloc_buffer
bool alloc_buffer()
Allocate memory for a join buffer.
Definition: sql_join_buffer.cc:456
buffer
char buffer[STRING_BUFFER]
Definition: test_sql_9_sessions.cc:57
JOIN_CACHE::with_length
bool with_length
This flag indicates that any record is prepended with the length of the record which allows us to ski...
Definition: sql_join_buffer.h:280
JOIN_CACHE_BNL
Definition: sql_join_buffer.h:585
JOIN_CACHE_BKA
Definition: sql_join_buffer.h:603
JOIN_CACHE::buff
uchar * buff
Start of the join buffer.
Definition: sql_join_buffer.h:296
JOIN_CACHE::init
virtual int init()=0
Initialize the join cache.
JOIN_CACHE_BKA::init_join_matching_records
bool init_join_matching_records(RANGE_SEQ_IF *seq_funcs, uint ranges)
Prepare to search for records that match records from the join buffer.
Definition: sql_join_buffer.cc:2462
JOIN_CACHE::pack_length_with_blob_ptrs
uint pack_length_with_blob_ptrs
The value of pack_length incremented by the total size of all pointers of a record in the cache to th...
Definition: sql_join_buffer.h:293
JOIN_CACHE::get_offset
static ulong get_offset(uint ofs_sz, const uchar *ptr)
Decode an offset.
Definition: sql_join_buffer.h:167
flags
static int flags[50]
Definition: hp_test1.cc:39
CACHE_FIELD::field
Field * field
Definition: sql_join_buffer.h:66
JOIN_CACHE_BKA::rem_space
ulong rem_space() const override
Definition: sql_join_buffer.h:693