MySQL  8.0.21
Source Code Documentation
composite_iterators.h
Go to the documentation of this file.
1 #ifndef SQL_COMPOSITE_ITERATORS_INCLUDED
2 #define SQL_COMPOSITE_ITERATORS_INCLUDED
3 
4 /* Copyright (c) 2018, 2020, 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 /**
27  @file composite_iterators.h
28 
29  A composite row iterator is one that takes in one or more existing iterators
30  and processes their rows in some interesting way. They are usually not bound
31  to a single table or similar, but are the inner (non-leaf) nodes of the
32  iterator execution tree. They consistently own their source iterator, although
33  not its memory (since we never allocate row iterators on the heap--usually on
34  a MEM_ROOT>). This means that in the end, you'll end up with a single root
35  iterator which then owns everything else recursively.
36 
37  SortingIterator is also a composite iterator, but is defined in its own file.
38  */
39 
40 #include <stdio.h>
41 
42 #include <algorithm>
43 #include <memory>
44 #include <string>
45 #include <vector>
46 
47 #include "my_alloc.h"
48 #include "my_base.h"
49 #include "my_dbug.h"
50 #include "my_table_map.h"
51 #include "prealloced_array.h"
52 #include "sql/item.h"
53 #include "sql/row_iterator.h"
54 #include "sql/table.h"
55 
56 class FollowTailIterator;
57 template <class T>
58 class List;
59 class JOIN;
60 class SELECT_LEX;
61 class SJ_TMP_TABLE;
62 class THD;
63 class Temp_table_param;
64 class Window;
65 
66 /**
67  An iterator that takes in a stream of rows and passes through only those that
68  meet some criteria (i.e., a condition evaluates to true). This is typically
69  used for WHERE/HAVING.
70  */
72  public:
74  Item *condition)
75  : RowIterator(thd), m_source(move(source)), m_condition(condition) {}
76 
77  bool Init() override { return m_source->Init(); }
78 
79  int Read() override;
80 
81  void SetNullRowFlag(bool is_null_row) override {
82  m_source->SetNullRowFlag(is_null_row);
83  }
84 
85  void StartPSIBatchMode() override { m_source->StartPSIBatchMode(); }
86  void EndPSIBatchModeIfStarted() override {
87  m_source->EndPSIBatchModeIfStarted();
88  }
89  void UnlockRow() override { m_source->UnlockRow(); }
90 
91  std::vector<Child> children() const override;
92 
93  std::vector<std::string> DebugString() const override {
94  return {"Filter: " + ItemToString(m_condition)};
95  }
96 
97  private:
100 };
101 
102 /**
103  Handles LIMIT and/or OFFSET; Init() eats the first "offset" rows, and Read()
104  stops as soon as it's seen "limit" rows (including any skipped by offset).
105  */
107  public:
108  /**
109  @param thd Thread context
110  @param source Row source
111  @param limit Maximum number of rows to read, including the ones skipped by
112  offset. Can be HA_POS_ERROR for no limit.
113  @param offset Number of initial rows to skip. Can be 0 for no offset.
114  @param count_all_rows If true, the query will run to completion to get
115  more accurate numbers for skipped_rows, so you will not get any
116  performance benefits of early end.
117  @param skipped_rows If not nullptr, is incremented for each row skipped by
118  offset or limit.
119  */
121  ha_rows limit, ha_rows offset, bool count_all_rows,
122  ha_rows *skipped_rows)
123  : RowIterator(thd),
124  m_source(move(source)),
125  m_limit(limit),
126  m_offset(offset),
127  m_count_all_rows(count_all_rows),
128  m_skipped_rows(skipped_rows) {
129  if (count_all_rows) {
130  DBUG_ASSERT(m_skipped_rows != nullptr);
131  }
132  }
133 
134  bool Init() override;
135 
136  int Read() override;
137 
138  void SetNullRowFlag(bool is_null_row) override {
139  m_source->SetNullRowFlag(is_null_row);
140  }
141 
142  void StartPSIBatchMode() override { m_source->StartPSIBatchMode(); }
143  void EndPSIBatchModeIfStarted() override {
144  m_source->EndPSIBatchModeIfStarted();
145  }
146  void UnlockRow() override { m_source->UnlockRow(); }
147 
148  std::vector<Child> children() const override {
149  return std::vector<Child>{{m_source.get(), ""}};
150  }
151 
152  std::vector<std::string> DebugString() const override {
153  char buf[256];
154  if (m_offset == 0) {
155  snprintf(buf, sizeof(buf), "Limit: %llu row(s)", m_limit);
156  } else if (m_limit == HA_POS_ERROR) {
157  snprintf(buf, sizeof(buf), "Offset: %llu row(s)", m_offset);
158  } else {
159  snprintf(buf, sizeof(buf), "Limit/Offset: %llu/%llu row(s)",
160  m_limit - m_offset, m_offset);
161  }
162  if (m_count_all_rows) {
163  return {std::string(buf) + " (no early end due to SQL_CALC_FOUND_ROWS)"};
164  } else {
165  return {std::string(buf)};
166  }
167  }
168 
169  private:
171 
172  // Note: The number of seen rows starts off at m_limit if we have OFFSET,
173  // which means we don't need separate LIMIT and OFFSET tests on the
174  // fast path of Read().
176 
177  /**
178  Whether we have OFFSET rows that we still need to skip.
179  */
181 
182  const ha_rows m_limit, m_offset;
183  const bool m_count_all_rows;
185 };
186 
187 /**
188  Handles aggregation (typically used for GROUP BY) for the case where the rows
189  are already properly grouped coming in, ie., all rows that are supposed to be
190  part of the same group are adjacent in the input stream. (This could be
191  because they were sorted earlier, because we are scanning an index that
192  already gives us the rows in a group-compatible order, or because there is no
193  grouping.)
194 
195  AggregateIterator is special in that it's one of the very few row iterators
196  that actually change the shape of the rows; some columns are dropped as part
197  of aggregation, others (the aggregates) are added. For this reason (and also
198  because we need to make copies of the group expressions -- see Read()), it
199  conceptually always outputs to a temporary table. If we _are_ outputting to a
200  temporary table, that's not a problem -- we take over responsibility for
201  copying the group expressions from MaterializeIterator, which would otherwise
202  do it.
203 
204  However, if we are outputting directly to the user, we need somewhere to store
205  the output. This is solved by abusing the slice system; since we only need to
206  buffer a single row, we can set up just enough items in the
207  REF_SLICE_ORDERED_GROUP_BY slice, so that it can hold a single row. This row
208  is then used for our output, and we then switch to it just before the end of
209  Read() so that anyone reading from the buffers will get that output.
210  The caller knows the context about where our output goes, and thus also picks
211  the appropriate output slice for us.
212 
213  This isn't very pretty. What should be done is probably a more abstract
214  concept of sending a row around and taking copies of it if needed, as opposed
215  to it implicitly staying in the table's buffer. (This would also solve some
216  issues in EQRefIterator and when synthesizing NULL rows for outer joins.)
217  However, that's a large refactoring.
218  */
220  public:
222  JOIN *join, Temp_table_param *temp_table_param,
223  int output_slice, bool rollup);
224 
225  bool Init() override;
226  int Read() override;
227  void SetNullRowFlag(bool is_null_row) override {
228  m_source->SetNullRowFlag(is_null_row);
229  }
230 
231  void StartPSIBatchMode() override { m_source->StartPSIBatchMode(); }
232  void EndPSIBatchModeIfStarted() override {
233  m_source->EndPSIBatchModeIfStarted();
234  }
235  void UnlockRow() override {
236  // Most likely, HAVING failed. Ideally, we'd like to backtrack and
237  // unlock all rows that went into this aggregate, but we can't do that,
238  // and we also can't unlock the _current_ row, since that belongs to a
239  // different group. Thus, do nothing.
240  }
241 
242  std::vector<Child> children() const override {
243  return std::vector<Child>{{m_source.get(), ""}};
244  }
245 
246  std::vector<std::string> DebugString() const override;
247 
248  private:
249  enum {
254  DONE_OUTPUTTING_ROWS
255  } m_state;
256 
258 
259  /**
260  The join we are part of. It would be nicer not to rely on this,
261  but we need a large number of members from there, like which
262  aggregate functions we have, the THD, temporary table parameters
263  and so on.
264  */
265  JOIN *m_join = nullptr;
266 
267  /// The slice of the fields we are reading from (see the class comment).
269 
270  /// The slice of the fields we are outputting to. See the class comment.
272 
273  /// Whether we have seen the last input row.
275 
276  /**
277  Used to save NULL information in the specific case where we have
278  zero input rows.
279  */
281 
282  /// The parameters for the temporary table we are materializing into, if any.
284 
285  /// Whether this is a rollup query.
286  const bool m_rollup;
287 
288  /**
289  For rollup: The index of the first group item that did _not_ change when we
290  last switched groups. E.g., if we have group fields A,B,C,D and then switch
291  to group A,B,E,D, this value will become 1 (which means that we need
292  to output rollup rows for 2 -- A,B,E,NULL -- and then 1 -- A,B,NULL,NULL).
293  m_current_rollup_position will count down from the end until it becomes
294  less than this value.
295 
296  If we do not have rollup, this value is perennially zero.
297  */
299 
300  /**
301  If we are in state OUTPUTTING_ROLLUP_ROWS, where we are in the iteration.
302  This value will start at the index of the last group expression and then
303  count backwards down to and including m_last_unchanged_group_item_idx.
304  It is used to communicate to the rollup group items whether to turn
305  themselves into NULLs, and the sum items which of their sums to output.
306  */
308 
309  void copy_sum_funcs();
310  void SetRollupLevel(int level);
311 };
312 
313 /**
314  Similar to AggregateIterator, but asusmes that the actual aggregates are
315  already have been filled out (typically by QUICK_RANGE_MIN_MAX), and all the
316  iterator needs to do is copy over the non-aggregated fields.
317  */
319  public:
322  JOIN *join, Temp_table_param *temp_table_param,
323  int output_slice)
324  : RowIterator(thd),
325  m_source(move(source)),
326  m_join(join),
327  m_temp_table_param(temp_table_param),
328  m_output_slice(output_slice) {}
329 
330  bool Init() override;
331  int Read() override;
332  void SetNullRowFlag(bool is_null_row) override {
333  m_source->SetNullRowFlag(is_null_row);
334  }
335 
336  void StartPSIBatchMode() override { m_source->StartPSIBatchMode(); }
337  void EndPSIBatchModeIfStarted() override {
338  m_source->EndPSIBatchModeIfStarted();
339  }
340  void UnlockRow() override {
341  // See AggregateIterator::UnlockRow().
342  }
343 
344  std::vector<Child> children() const override {
345  return std::vector<Child>{{m_source.get(), ""}};
346  }
347 
348  std::vector<std::string> DebugString() const override;
349 
350  private:
352 
353  /**
354  The join we are part of. It would be nicer not to rely on this,
355  but we need a large number of members from there, like which
356  aggregate functions we have, the THD, temporary table parameters
357  and so on.
358  */
359  JOIN *m_join = nullptr;
360 
361  /// The parameters for the temporary table we are materializing into, if any.
363 
364  /// The slice of the fields we are outputting to.
366 };
367 
368 /**
369  A simple nested loop join, taking in two iterators (left/outer and
370  right/inner) and joining them together. This may, of course, scan the inner
371  iterator many times. It is currently the only form of join we have.
372 
373  The iterator works as a state machine, where the state records whether we need
374  to read a new outer row or not, and whether we've seen any rows from the inner
375  iterator at all (if not, an outer join need to synthesize a new NULL row).
376 
377  The iterator takes care of activating performance schema batch mode on the
378  right iterator if needed; this is typically only used if it is the innermost
379  table in the entire join (where the gains from turning on batch mode is the
380  largest, and the accuracy loss from turning it off are the least critical).
381  */
383  public:
387  JoinType join_type, bool pfs_batch_mode)
388  : RowIterator(thd),
389  m_source_outer(move(source_outer)),
390  m_source_inner(move(source_inner)),
391  m_join_type(join_type),
392  m_pfs_batch_mode(pfs_batch_mode) {
393  DBUG_ASSERT(m_source_outer != nullptr);
394  DBUG_ASSERT(m_source_inner != nullptr);
395 
396  // Batch mode makes no sense for anti- or semijoins, since they should only
397  // be reading one row.
398  if (join_type == JoinType::ANTI || join_type == JoinType::SEMI) {
399  DBUG_ASSERT(!pfs_batch_mode);
400  }
401  }
402 
403  bool Init() override;
404 
405  int Read() override;
406 
407  void SetNullRowFlag(bool is_null_row) override {
408  // TODO: write something here about why we can't do this lazily.
409  m_source_outer->SetNullRowFlag(is_null_row);
410  m_source_inner->SetNullRowFlag(is_null_row);
411  }
412 
413  void EndPSIBatchModeIfStarted() override {
414  m_source_outer->EndPSIBatchModeIfStarted();
415  m_source_inner->EndPSIBatchModeIfStarted();
416  }
417 
418  void UnlockRow() override {
419  // Since we don't know which condition that caused the row to be rejected,
420  // we can't know whether we could also unlock the outer row
421  // (it may still be used as parts of other joined rows).
422  if (m_state == READING_FIRST_INNER_ROW || m_state == READING_INNER_ROWS) {
423  m_source_inner->UnlockRow();
424  }
425  }
426 
427  std::vector<std::string> DebugString() const override;
428 
429  std::vector<Child> children() const override {
430  return std::vector<Child>{{m_source_outer.get(), ""},
431  {m_source_inner.get(), ""}};
432  }
433 
434  private:
435  enum {
439  END_OF_ROWS
440  } m_state;
441 
445 
446  /** Whether to use batch mode when scanning the inner iterator. */
447  const bool m_pfs_batch_mode;
448 };
449 
450 /**
451  An iterator that helps invalidating caches. Every time a row passes through it
452  or it changes state in any other way, it increments its “generation” counter.
453  This allows MaterializeIterator to see whether any of its dependencies has
454  changed, and then force a rematerialization -- this is typically used for
455  LATERAL tables, where we're joining in a derived table that depends on
456  something earlier in the join.
457  */
459  public:
461  unique_ptr_destroy_only<RowIterator> source_iterator,
462  const std::string &name)
463  : RowIterator(thd),
464  m_source_iterator(move(source_iterator)),
465  m_name(name) {}
466 
467  bool Init() override {
468  ++m_generation;
469  return m_source_iterator->Init();
470  }
471 
472  int Read() override {
473  ++m_generation;
474  return m_source_iterator->Read();
475  }
476 
477  void SetNullRowFlag(bool is_null_row) override {
478  ++m_generation;
479  m_source_iterator->SetNullRowFlag(is_null_row);
480  }
481 
482  void UnlockRow() override { m_source_iterator->UnlockRow(); }
483  std::vector<std::string> DebugString() const override;
484  std::vector<Child> children() const override {
485  return {Child{m_source_iterator.get(), ""}};
486  }
487 
488  int64_t generation() const { return m_generation; }
489  std::string name() const { return m_name; }
490 
491  private:
493  int64_t m_generation = 0;
494  std::string m_name;
495 };
496 
497 /**
498  Handles materialization; the first call to Init() will scan the given iterator
499  to the end, store the results in a temporary table (optionally with
500  deduplication), and then Read() will allow you to read that table repeatedly
501  without the cost of executing the given subquery many times (unless you ask
502  for rematerialization).
503 
504  When materializing, MaterializeIterator takes care of evaluating any items
505  that need so, and storing the results in the fields of the outgoing table --
506  which items is governed by the temporary table parameters.
507 
508  Conceptually (although not performance-wise!), the MaterializeIterator is a
509  no-op if you don't ask for deduplication, and in some cases (e.g. when
510  scanning a table only once), we elide it. However, it's not necessarily
511  straightforward to do so by just not inserting the iterator, as the optimizer
512  will have set up everything (e.g., read sets, or what table upstream items
513  will read from) assuming the materialization will happen, so the realistic
514  option is setting up everything as if materialization would happen but not
515  actually write to the table; see StreamingIterator for details.
516 
517  MaterializeIterator conceptually materializes iterators, not JOINs or
518  SELECT_LEX_UNITs. However, there are many details that leak out
519  (e.g., setting performance schema batch mode, slices, reusing CTEs,
520  etc.), so we need to send them in anyway.
521  */
523  public:
524  struct QueryBlock {
525  /// The iterator to read the actual rows from.
527 
528  /// Used only for optimizer trace.
530 
531  /// The JOIN that this query block represents. Used for performance
532  /// schema batch mode: When materializing a query block that consists of
533  /// a single table, MaterializeIterator needs to set up schema batch mode,
534  /// since there is no nested loop iterator to do it. (This is similar to
535  /// what ExecuteIteratorQuery() needs to do at the top level.)
537 
538  /// If true, unique constraint checking via hash key is disabled
539  /// when materializing this query block (ie., we simply avoid calling
540  /// check_unique_constraint() for each row). Used when materializing
541  /// UNION DISTINCT and UNION ALL parts into the same table.
542  /// We'd like to just use a unique constraint via unique index instead,
543  /// but there might be other indexes on the destination table
544  /// that we'd like to keep, and the implementation doesn't allow
545  /// disabling only one index.
546  ///
547  /// If you use this on a query block, doing_hash_deduplication()
548  /// must be true.
549  bool disable_deduplication_by_hash_field = false;
550 
551  /// If set to false, the Field objects in the output row are
552  /// presumed already to be filled out. This is the case iff
553  /// there's an AggregateIterator earlier in the chain.
555 
556  /// If copy_fields_and_items is true, used for copying the Field objects
557  /// into the temporary table row. Otherwise unused.
559 
560  // Whether this query block is a recursive reference back to the
561  // output of the materialization.
562  bool is_recursive_reference = false;
563 
564  // If is_recursive_reference is true, contains the FollowTailIterator
565  // in the query block (there can be at most one recursive reference
566  // in a join list, as per the SQL standard, so there should be exactly one).
567  // Used for informing the iterators about various shared state in the
568  // materialization (including coordinating rematerializations).
569  FollowTailIterator *recursive_reader = nullptr;
570  };
571 
572  /**
573  @param thd Thread handler.
574  @param query_blocks_to_materialize List of query blocks to materialize.
575  @param table Handle to table to materialize into.
576  @param table_iterator Iterator used for scanning the temporary table
577  after materialization.
578  @param cte If materializing a CTE, points to it (see m_cte), otherwise
579  nullptr.
580  @param unit The query expression we are materializing (see m_unit).
581  @param join
582  When materializing within the same JOIN (e.g., into a temporary table
583  before sorting), as opposed to a derived table or a CTE, we may need
584  to change the slice on the join before returning rows from the result
585  table. If so, join and ref_slice would need to be set, and
586  query_blocks_to_materialize should contain only one member, with the same
587  join.
588  @param ref_slice See join. If we are materializing across JOINs,
589  e.g. derived tables, ref_slice should be left at -1.
590  @param rematerialize true if rematerializing on every Init() call
591  (e.g., because we have a dependency on a value from outside the query
592  block).
593  @param limit_rows
594  Used for when pushing LIMIT down to MaterializeIterator; this is
595  more efficient than having a LimitOffsetIterator above the
596  MaterializeIterator, since we can stop materializing when there are
597  enough rows. (This is especially important for recursive CTEs.)
598  Note that we cannot have a LimitOffsetIterator _below_ the
599  MaterializeIterator, as that would count wrong if we have deduplication,
600  and would not work at all for recursive CTEs.
601  Set to HA_POS_ERROR for no limit.
602  */
604  Mem_root_array<QueryBlock> query_blocks_to_materialize,
605  TABLE *table,
608  int ref_slice, bool rematerialize, ha_rows limit_rows);
609 
610  /**
611  A convenience form for materializing a single table only.
612 
613  @param thd Thread handler.
614  @param subquery_iterator The iterator to read the actual rows from.
615  @param temp_table_param If copy_fields_and_items is true, used for copying
616  the Field objects into the temporary table row. Otherwise unused.
617  @param table Handle to table to materialize into.
618  @param table_iterator Iterator used for scanning the temporary table
619  after materialization.
620  @param cte If materializing a CTE, points to it (see m_cte), otherwise
621  nullptr.
622  @param select_number Used only for optimizer trace.
623  @param unit The query expression we are materializing (see m_unit).
624  @param join
625  When materializing within the same JOIN (e.g., into a temporary table
626  before sorting), as opposed to a derived table or a CTE, we may need
627  to change the slice on the join before returning rows from the result
628  table. If so, join and ref_slice would need to be set, and
629  query_blocks_to_materialize should contain only one member, with the same
630  join.
631  @param ref_slice See join. If we are materializing across JOINs,
632  e.g. derived tables, ref_slice should be left at -1.
633  @param copy_fields_and_items If set to false, the Field objects in the
634  output row are presumed already to be filled out. This is the case iff
635  there's an AggregateIterator earlier in the chain.
636  @param rematerialize true if rematerializing on every Init() call
637  (e.g., because we have a dependency on a value from outside the query
638  block).
639  @param limit_rows See limit_rows on the other constructor.
640  */
642  unique_ptr_destroy_only<RowIterator> subquery_iterator,
643  Temp_table_param *temp_table_param, TABLE *table,
645  Common_table_expr *cte, int select_number,
646  SELECT_LEX_UNIT *unit, JOIN *join, int ref_slice,
647  bool copy_fields_and_items, bool rematerialize,
648  ha_rows limit_rows);
649 
650  bool Init() override;
651  int Read() override;
652  std::vector<std::string> DebugString() const override;
653 
654  std::vector<Child> children() const override;
655 
656  void SetNullRowFlag(bool is_null_row) override {
657  m_table_iterator->SetNullRowFlag(is_null_row);
658  }
659 
660  void StartPSIBatchMode() override { m_table_iterator->StartPSIBatchMode(); }
661  void EndPSIBatchModeIfStarted() override;
662 
663  // The temporary table is private to us, so there's no need to worry about
664  // locks to other transactions.
665  void UnlockRow() override {}
666 
667  /**
668  Add a cache invalidator that must be checked on every Init().
669  If its generation has increased since last materialize, we need to
670  rematerialize even if m_rematerialize is false.
671  */
672  void AddInvalidator(const CacheInvalidatorIterator *invalidator);
673 
674  private:
677 
678  /// If we are materializing a CTE, points to it (otherwise nullptr).
679  /// Used so that we see if some other iterator already materialized the table,
680  /// avoiding duplicate work.
682 
683  /// The query expression we are materializing. For derived tables,
684  /// we materialize the entire query expression; for materialization within
685  /// a query expression (e.g. for sorting or for windowing functions),
686  /// we materialize only parts of it. Used to clear correlated CTEs within
687  /// the unit when we rematerialize, since they depend on values from
688  /// outside the query expression, and those values may have changed
689  /// since last materialization.
691 
692  /// See constructor.
693  JOIN *const m_join;
694 
695  /// The slice to set when accessing temporary table; used if anything upstream
696  /// (e.g. WHERE, HAVING) wants to evaluate values based on its contents.
697  /// See constructor.
698  const int m_ref_slice;
699 
700  /// If true, we need to materialize anew for each Init() (because the contents
701  /// of the table will depend on some outer non-constant value).
702  const bool m_rematerialize;
703 
704  /// See constructor.
706 
707  struct Invalidator {
710  };
712 
713  /// Whether we are deduplicating using a hash field on the temporary
714  /// table. (This condition mirrors check_unique_constraint().)
715  /// If so, we compute a hash value for every row, look up all rows with
716  /// the same hash and manually compare them to the row we are trying to
717  /// insert.
718  ///
719  /// Note that this is _not_ the common way of deduplicating as we go.
720  /// The common method is to have a regular index on the table
721  /// over the right columns, and in that case, ha_write_row() will fail
722  /// with an ignorable error, so that the row is ignored even though
723  /// check_unique_constraint() is not called. However, B-tree indexes
724  /// have limitations, in particular on length, that sometimes require us
725  /// to do this instead. See create_tmp_table() for details.
726  bool doing_hash_deduplication() const { return table()->hash_field; }
727 
728  /// Whether we are deduplicating, whether through a hash field
729  /// or a regular unique index.
730  bool doing_deduplication() const;
731 
732  bool MaterializeRecursive();
733  bool MaterializeQueryBlock(const QueryBlock &query_block,
734  ha_rows *stored_rows);
735 };
736 
737 /**
738  StreamingIterator is a minimal version of MaterializeIterator that does not
739  actually materialize; instead, every Read() just forwards the call to the
740  subquery iterator and does the required copying from one set of fields to
741  another.
742 
743  It is used for when the optimizer would normally set up a materialization,
744  but you don't actually need one, ie. you don't want to read the rows multiple
745  times after writing them, and you don't want to access them by index (only
746  a single table scan). If you don't need the copy functionality (ie., you
747  have an AggregateIterator, which does this job already), you still need a
748  StreamingIterator, to set the NULL row flag on the temporary table.
749  */
751  public:
753  unique_ptr_destroy_only<RowIterator> subquery_iterator,
754  Temp_table_param *temp_table_param, TABLE *table,
755  bool copy_fields_and_items);
756 
757  bool Init() override;
758 
759  int Read() override;
760 
761  std::vector<std::string> DebugString() const override {
762  return {"Stream results"};
763  }
764 
765  std::vector<Child> children() const override {
766  return std::vector<Child>{{m_subquery_iterator.get(), ""}};
767  }
768 
769  void StartPSIBatchMode() override {
770  m_subquery_iterator->StartPSIBatchMode();
771  }
772  void EndPSIBatchModeIfStarted() override {
773  m_subquery_iterator->EndPSIBatchModeIfStarted();
774  }
775  void UnlockRow() override { m_subquery_iterator->UnlockRow(); }
776 
777  private:
782 
783  // Whether the iterator should generate and provide a row ID. Only true if the
784  // iterator is part of weedout, where the iterator will create a fake row ID
785  // to uniquely identify the rows it produces.
786  bool m_provide_rowid{false};
787 };
788 
789 /**
790  Aggregates unsorted data into a temporary table, using update operations
791  to keep running aggregates. After that, works as a MaterializeIterator
792  in that it allows the temporary table to be scanned.
793  */
795  public:
797  THD *thd, unique_ptr_destroy_only<RowIterator> subquery_iterator,
798  Temp_table_param *temp_table_param, TABLE *table,
800  SELECT_LEX *select_lex, JOIN *join, int ref_slice);
801 
802  bool Init() override;
803  int Read() override;
804  void SetNullRowFlag(bool is_null_row) override {
805  m_table_iterator->SetNullRowFlag(is_null_row);
806  }
807  void EndPSIBatchModeIfStarted() override {
808  m_table_iterator->EndPSIBatchModeIfStarted();
809  m_subquery_iterator->EndPSIBatchModeIfStarted();
810  }
811  void UnlockRow() override {}
812  std::vector<std::string> DebugString() const override;
813 
814  std::vector<Child> children() const override;
815 
816  private:
817  /// The iterator we are reading rows from.
819 
820  /// The iterator used to scan the resulting temporary table.
822 
825  JOIN *const m_join;
826  const int m_ref_slice;
827 
828  // See MaterializeIterator::doing_hash_deduplication().
829  bool using_hash_key() const { return table()->hash_field; }
830 };
831 
832 /**
833  An iterator that wraps a Table_function (e.g. JSON_TABLE) and allows you to
834  iterate over the materialized temporary table. The table is materialized anew
835  for every Init().
836 
837  TODO: Just wrapping it is probably not the optimal thing to do;
838  Table_function is highly oriented around materialization, but never caches.
839  Thus, perhaps we should rewrite Table_function to return a RowIterator
840  instead of going through a temporary table.
841  */
843  public:
845  THD *thd, Table_function *table_function, TABLE *table,
846  unique_ptr_destroy_only<RowIterator> table_iterator);
847 
848  bool Init() override;
849  int Read() override { return m_table_iterator->Read(); }
850  std::vector<std::string> DebugString() const override {
851  return {{"Materialize table function"}};
852  }
853  void SetNullRowFlag(bool is_null_row) override {
854  m_table_iterator->SetNullRowFlag(is_null_row);
855  }
856 
857  void StartPSIBatchMode() override { m_table_iterator->StartPSIBatchMode(); }
858  void EndPSIBatchModeIfStarted() override {
859  m_table_iterator->EndPSIBatchModeIfStarted();
860  }
861 
862  // The temporary table is private to us, so there's no need to worry about
863  // locks to other transactions.
864  void UnlockRow() override {}
865 
866  private:
868 
870 };
871 
872 /**
873  Like semijoin materialization, weedout works on the basic idea that a semijoin
874  is just like an inner join as we long as we can get rid of the duplicates
875  somehow. (This is advantageous, because inner joins can be reordered, whereas
876  semijoins generally can't.) However, unlike semijoin materialization, weedout
877  removes duplicates after the join, not before it. Consider something like
878 
879  SELECT * FROM t1 WHERE a IN ( SELECT b FROM t2 );
880 
881  Semijoin materialization solves this by materializing t2, with deduplication,
882  and then joining. Weedout joins t1 to t2 and then leaves only one output row
883  per t1 row. The disadvantage is that this potentially needs to discard more
884  rows; the (potential) advantage is that we deduplicate on t1 instead of t2.
885 
886  Weedout, unlike materialization, works in a streaming fashion; rows are output
887  (or discarded) as they come in, with a temporary table used for recording the
888  row IDs we've seen before. (We need to deduplicate on t1's row IDs, not its
889  contents.) See SJ_TMP_TABLE for details about the table format.
890  */
892  public:
894  SJ_TMP_TABLE *sj);
895 
896  bool Init() override;
897  int Read() override;
898  std::vector<std::string> DebugString() const override;
899 
900  std::vector<Child> children() const override {
901  return std::vector<Child>{{m_source.get(), ""}};
902  }
903 
904  void SetNullRowFlag(bool is_null_row) override {
905  m_source->SetNullRowFlag(is_null_row);
906  }
907 
908  void EndPSIBatchModeIfStarted() override {
909  m_source->EndPSIBatchModeIfStarted();
910  }
911  void UnlockRow() override { m_source->UnlockRow(); }
912 
913  private:
916 
917  // The cached value of QEP_TAB::rowid_status for each of the tables in the
918  // weedout. Index 0 corresponds to the first table in m_sj.
919  // See QEP_TAB::rowid_status for why we need to cache this value.
921 };
922 
923 /**
924  An iterator that removes consecutive rows that are the same according to
925  a given index (or more accurately, its keypart), so-called “loose scan”
926  (not to be confused with “loose index scan”, which is a QUICK_SELECT_I).
927  This is similar in spirit to WeedoutIterator above (removing duplicates
928  allows us to treat the semijoin as a normal join), but is much cheaper
929  if the data is already ordered/grouped correctly, as the removal can
930  happen before the join, and it does not need a temporary table.
931  */
933  public:
936  const TABLE *table, KEY *key, size_t key_len);
937 
938  bool Init() override;
939  int Read() override;
940  std::vector<std::string> DebugString() const override;
941 
942  std::vector<Child> children() const override {
943  return std::vector<Child>{{m_source.get(), ""}};
944  }
945 
946  void SetNullRowFlag(bool is_null_row) override {
947  m_source->SetNullRowFlag(is_null_row);
948  }
949 
950  void StartPSIBatchMode() override { m_source->StartPSIBatchMode(); }
951  void EndPSIBatchModeIfStarted() override {
952  m_source->EndPSIBatchModeIfStarted();
953  }
954  void UnlockRow() override { m_source->UnlockRow(); }
955 
956  private:
958  const TABLE *m_table;
960  uchar *m_key_buf; // Owned by the THD's MEM_ROOT.
961  const size_t m_key_len;
963 };
964 
965 /**
966  An iterator that is semantically equivalent to a semijoin NestedLoopIterator
967  immediately followed by a RemoveDuplicatesIterator. It is used to implement
968  the “loose scan” strategy in queries with multiple tables on the inside of a
969  semijoin, like
970 
971  ... FROM t1 WHERE ... IN ( SELECT ... FROM t2 JOIN t3 ... )
972 
973  In this case, the query tree without this iterator would ostensibly look like
974 
975  -> Nested loop join
976  -> Table scan on t1
977  -> Remove duplicates on t2_idx
978  -> Nested loop semijoin
979  -> Index scan on t2 using t2_idx
980  -> Filter (e.g. t3.a = t2.a)
981  -> Table scan on t3
982 
983  (t3 will be marked as “first match” on t2 when implementing loose scan,
984  thus the semijoin.)
985 
986  First note that we can't put the duplicate removal directly on t2 in this
987  case, as the first t2 row doesn't necessarily match anything in t3, so it
988  needs to be above. However, this is wasteful, because once we find a matching
989  t2/t3 pair, we should stop scanning t3 until we have a new t2.
990 
991  NestedLoopSemiJoinWithDuplicateRemovalIterator solves the problem by doing
992  exactly this; it gets a row from the outer side, gets exactly one row from the
993  inner side, and then skips over rows from the outer side (_without_ scanning
994  the inner side) until its keypart changes.
995  */
997  : public RowIterator {
998  public:
1001  unique_ptr_destroy_only<RowIterator> source_inner, const TABLE *table,
1002  KEY *key, size_t key_len);
1003 
1004  bool Init() override;
1005 
1006  int Read() override;
1007 
1008  void SetNullRowFlag(bool is_null_row) override {
1009  m_source_outer->SetNullRowFlag(is_null_row);
1010  m_source_inner->SetNullRowFlag(is_null_row);
1011  }
1012 
1013  void EndPSIBatchModeIfStarted() override {
1014  m_source_outer->EndPSIBatchModeIfStarted();
1015  m_source_inner->EndPSIBatchModeIfStarted();
1016  }
1017 
1018  void UnlockRow() override {
1019  m_source_outer->UnlockRow();
1020  m_source_inner->UnlockRow();
1021  }
1022 
1023  std::vector<std::string> DebugString() const override;
1024 
1025  std::vector<Child> children() const override {
1026  return std::vector<Child>{{m_source_outer.get(), ""},
1027  {m_source_inner.get(), ""}};
1028  }
1029 
1030  private:
1033 
1036  uchar *m_key_buf; // Owned by the THD's MEM_ROOT.
1037  const size_t m_key_len;
1039 };
1040 
1041 /**
1042  WindowingIterator is similar to AggregateIterator, but deals with windowed
1043  aggregates (i.e., OVER expressions). It deals specifically with aggregates
1044  that don't need to buffer rows.
1045 
1046  WindowingIterator always outputs to a temporary table. Similarly to
1047  AggregateIterator, needs to do some of MaterializeIterator's work in
1048  copying fields and Items into the destination fields (see AggregateIterator
1049  for more information).
1050  */
1052  public:
1054  Temp_table_param *temp_table_param, // Includes the window.
1055  JOIN *join, int output_slice);
1056 
1057  bool Init() override;
1058 
1059  int Read() override;
1060 
1061  void SetNullRowFlag(bool is_null_row) override {
1062  m_source->SetNullRowFlag(is_null_row);
1063  }
1064 
1065  void StartPSIBatchMode() override { m_source->StartPSIBatchMode(); }
1066  void EndPSIBatchModeIfStarted() override {
1067  m_source->EndPSIBatchModeIfStarted();
1068  }
1069 
1070  void UnlockRow() override {
1071  // There's nothing we can do here.
1072  }
1073 
1074  std::vector<std::string> DebugString() const override;
1075 
1076  std::vector<Child> children() const override {
1077  return std::vector<Child>{{m_source.get(), ""}};
1078  }
1079 
1080  private:
1081  /// The iterator we are reading from.
1083 
1084  /// Parameters for the temporary table we are outputting to.
1086 
1087  /// The window function itself.
1089 
1090  /// The join we are a part of.
1092 
1093  /// The slice we will be using when reading rows.
1095 
1096  /// The slice we will be using when outputting rows.
1098 };
1099 
1100 /**
1101  BufferingWindowingIterator is like WindowingIterator, but deals with window
1102  functions that need to buffer rows.
1103  */
1105  public:
1108  Temp_table_param *temp_table_param, // Includes the window.
1109  JOIN *join, int output_slice);
1110 
1111  bool Init() override;
1112 
1113  int Read() override;
1114 
1115  void SetNullRowFlag(bool is_null_row) override {
1116  m_source->SetNullRowFlag(is_null_row);
1117  }
1118 
1119  void StartPSIBatchMode() override { m_source->StartPSIBatchMode(); }
1120  void EndPSIBatchModeIfStarted() override {
1121  m_source->EndPSIBatchModeIfStarted();
1122  }
1123 
1124  void UnlockRow() override {
1125  // There's nothing we can do here.
1126  }
1127 
1128  std::vector<std::string> DebugString() const override;
1129 
1130  std::vector<Child> children() const override {
1131  return std::vector<Child>{{m_source.get(), ""}};
1132  }
1133 
1134  private:
1135  int ReadBufferedRow(bool new_partition_or_eof);
1136 
1137  /// The iterator we are reading from.
1139 
1140  /// Parameters for the temporary table we are outputting to.
1142 
1143  /// The window function itself.
1145 
1146  /// The join we are a part of.
1148 
1149  /// The slice we will be using when reading rows.
1151 
1152  /// The slice we will be using when outputting rows.
1154 
1155  /// If true, we may have more buffered rows to process that need to be
1156  /// checked for before reading more rows from the source.
1158 
1159  /// Whether the last input row started a new partition, and was tucked away
1160  /// to finalize the previous partition; if so, we need to bring it back
1161  /// for processing before we read more rows.
1163 
1164  /// Whether we have seen the last input row.
1165  bool m_eof;
1166 };
1167 
1168 /**
1169  MaterializeInformationSchemaTableIterator makes sure a given I_S temporary
1170  table is materialized (filled out) before we try to scan it.
1171  */
1173  public:
1175  THD *thd, QEP_TAB *qep_tab,
1176  unique_ptr_destroy_only<RowIterator> table_iterator);
1177 
1178  bool Init() override;
1179  int Read() override { return m_table_iterator->Read(); }
1180  std::vector<std::string> DebugString() const override;
1181 
1182  std::vector<Child> children() const override {
1183  // We don't list the table iterator as an explicit child; we mark it in
1184  // our DebugString() instead. (Anything else would look confusingly much
1185  // like a join.)
1186  return {};
1187  }
1188 
1189  void SetNullRowFlag(bool is_null_row) override {
1190  m_table_iterator->SetNullRowFlag(is_null_row);
1191  }
1192 
1193  void StartPSIBatchMode() override { m_table_iterator->StartPSIBatchMode(); }
1194  void EndPSIBatchModeIfStarted() override {
1195  m_table_iterator->EndPSIBatchModeIfStarted();
1196  }
1197 
1198  // The temporary table is private to us, so there's no need to worry about
1199  // locks to other transactions.
1200  void UnlockRow() override {}
1201 
1202  private:
1203  /// The iterator that reads from the materialized table.
1206 };
1207 
1208 /**
1209  Takes in two or more iterators and output rows from them sequentially
1210  (first all rows from the first one, the all from the second one, etc.).
1211  Used for implementing UNION ALL, typically together with StreamingIterator.
1212  */
1214  public:
1216  THD *thd,
1218 
1219  bool Init() override;
1220  int Read() override;
1221 
1222  std::vector<std::string> DebugString() const override { return {"Append"}; }
1223  std::vector<Child> children() const override;
1224 
1225  void StartPSIBatchMode() override;
1226  void EndPSIBatchModeIfStarted() override;
1227 
1228  void SetNullRowFlag(bool is_null_row) override;
1229  void UnlockRow() override;
1230 
1231  private:
1232  std::vector<unique_ptr_destroy_only<RowIterator>> m_sub_iterators;
1233  size_t m_current_iterator_index = 0;
1234  bool m_pfs_batch_mode_enabled = false;
1235 };
1236 
1237 #endif // SQL_COMPOSITE_ITERATORS_INCLUDED
A simple nested loop join, taking in two iterators (left/outer and right/inner) and joining them toge...
Definition: composite_iterators.h:382
After parsing, a Common Table Expression is accessed through a TABLE_LIST.
Definition: table.h:3955
unique_ptr_destroy_only< RowIterator > m_source_iterator
Definition: composite_iterators.h:492
unsigned char uchar
Definition: my_inttypes.h:51
Definition: sql_optimizer.h:119
int Read() override
Read a single row.
Definition: composite_iterators.h:1179
bool m_seen_eof
Whether we have seen the last input row.
Definition: composite_iterators.h:274
Temp_table_param * m_temp_table_param
Definition: composite_iterators.h:823
Definition: row_iterator.h:263
An iterator that helps invalidating caches.
Definition: composite_iterators.h:458
unique_ptr_destroy_only< RowIterator > const m_source_inner
Definition: composite_iterators.h:1032
void UnlockRow() override
Definition: composite_iterators.h:864
Temp_table_param * m_temp_table_param
Definition: composite_iterators.h:779
void SetNullRowFlag(bool is_null_row) override
Mark the current row buffer as containing a NULL row or not, so that if you read from it and the flag...
Definition: composite_iterators.h:853
std::string m_name
Definition: composite_iterators.h:494
void EndPSIBatchModeIfStarted() override
Ends performance schema batch mode, if started.
Definition: composite_iterators.h:1194
std::vector< Child > children() const override
List of zero or more iterators which are direct children of this one.
Definition: composite_iterators.h:429
void SetNullRowFlag(bool is_null_row) override
Mark the current row buffer as containing a NULL row or not, so that if you read from it and the flag...
Definition: composite_iterators.h:227
void UnlockRow() override
Definition: composite_iterators.h:418
ha_rows m_seen_rows
Definition: composite_iterators.h:175
Common_table_expr * m_cte
If we are materializing a CTE, points to it (otherwise nullptr).
Definition: composite_iterators.h:681
std::vector< T, ut_allocator< T > > vector
Specialization of vector which uses ut_allocator.
Definition: ut0new.h:1307
bool m_deduplicate_against_previous_row
Definition: composite_iterators.h:1038
void SetNullRowFlag(bool is_null_row) override
Mark the current row buffer as containing a NULL row or not, so that if you read from it and the flag...
Definition: composite_iterators.h:407
std::vector< Child > children() const override
List of zero or more iterators which are direct children of this one.
Definition: composite_iterators.h:942
An iterator that wraps a Table_function (e.g.
Definition: composite_iterators.h:842
void UnlockRow() override
Definition: composite_iterators.h:954
JoinType
Definition: row_iterator.h:290
Prealloced_array< rowid_statuses, 4 > m_rowid_status
Definition: composite_iterators.h:920
void UnlockRow() override
Definition: composite_iterators.h:482
const bool m_pfs_batch_mode
Whether to use batch mode when scanning the inner iterator.
Definition: composite_iterators.h:447
Definition: composite_iterators.h:252
void StartPSIBatchMode() override
Start performance schema batch mode, if supported (otherwise ignored).
Definition: composite_iterators.h:857
Field * hash_field
Field used by unique constraint.
Definition: table.h:1401
std::vector< std::string > DebugString() const override
Returns a short string (used for EXPLAIN FORMAT=tree) with user-readable information for this iterato...
Definition: composite_iterators.h:93
A context for reading through a single table using a chosen access method: index read, scan, etc, use of cache, etc.
Definition: row_iterator.h:61
KEY * m_key
Definition: composite_iterators.h:959
int Read() override
Read a single row.
Definition: composite_iterators.h:472
bool Init() override
Initialize or reinitialize the iterator.
Definition: composite_iterators.h:467
table_map m_save_nullinfo
Used to save NULL information in the specific case where we have zero input rows. ...
Definition: composite_iterators.h:280
SELECT_LEX_UNIT * m_unit
The query expression we are materializing.
Definition: composite_iterators.h:690
This class represents a query block, aka a query specification, which is a query consisting of a SELE...
Definition: sql_lex.h:1001
Definition: composite_iterators.h:707
void UnlockRow() override
Definition: composite_iterators.h:235
const int m_ref_slice
Definition: composite_iterators.h:826
Represents the (explicit) window of a SQL 2003 section 7.11 <window clause>, or the implicit (inlined...
Definition: window.h:94
int m_input_slice
The slice of the fields we are reading from (see the class comment).
Definition: composite_iterators.h:268
void EndPSIBatchModeIfStarted() override
Ends performance schema batch mode, if started.
Definition: composite_iterators.h:1066
Temp_table_param * m_temp_table_param
Parameters for the temporary table we are outputting to.
Definition: composite_iterators.h:1085
string ItemToString(const Item *item)
Definition: item.cc:10009
int Read() override
Read a single row.
Definition: composite_iterators.h:849
std::vector< Child > children() const override
List of zero or more iterators which are direct children of this one.
Definition: composite_iterators.h:1130
Similar to AggregateIterator, but asusmes that the actual aggregates are already have been filled out...
Definition: composite_iterators.h:318
void EndPSIBatchModeIfStarted() override
Ends performance schema batch mode, if started.
Definition: composite_iterators.h:951
void EndPSIBatchModeIfStarted() override
Ends performance schema batch mode, if started.
Definition: composite_iterators.h:908
const JoinType m_join_type
Definition: composite_iterators.h:444
bool m_last_input_row_started_new_partition
Whether the last input row started a new partition, and was tucked away to finalize the previous part...
Definition: composite_iterators.h:1162
void SetNullRowFlag(bool is_null_row) override
Mark the current row buffer as containing a NULL row or not, so that if you read from it and the flag...
Definition: composite_iterators.h:138
void UnlockRow() override
Definition: composite_iterators.h:911
std::vector< Child > children() const override
List of zero or more iterators which are direct children of this one.
Definition: composite_iterators.h:1182
std::string join(Container cont, const std::string &delim)
join elements of an container into a string seperated by a delimiter.
Definition: string.h:144
void UnlockRow() override
Definition: composite_iterators.h:1200
void EndPSIBatchModeIfStarted() override
Ends performance schema batch mode, if started.
Definition: composite_iterators.h:86
unique_ptr_destroy_only< RowIterator > m_table_iterator
Definition: composite_iterators.h:676
PrecomputedAggregateIterator(THD *thd, unique_ptr_destroy_only< RowIterator > source, JOIN *join, Temp_table_param *temp_table_param, int output_slice)
Definition: composite_iterators.h:320
std::vector< Child > children() const override
List of zero or more iterators which are direct children of this one.
Definition: composite_iterators.h:484
JOIN *const m_join
See constructor.
Definition: composite_iterators.h:693
MaterializeInformationSchemaTableIterator makes sure a given I_S temporary table is materialized (fil...
Definition: composite_iterators.h:1172
const int m_ref_slice
The slice to set when accessing temporary table; used if anything upstream (e.g.
Definition: composite_iterators.h:698
unique_ptr_destroy_only< RowIterator > const m_source
The iterator we are reading from.
Definition: composite_iterators.h:1082
std::vector< std::string > DebugString() const override
Returns a short string (used for EXPLAIN FORMAT=tree) with user-readable information for this iterato...
Definition: composite_iterators.h:1222
Definition: composite_iterators.h:436
void StartPSIBatchMode() override
Start performance schema batch mode, if supported (otherwise ignored).
Definition: composite_iterators.h:1065
Handles aggregation (typically used for GROUP BY) for the case where the rows are already properly gr...
Definition: composite_iterators.h:219
Mem_root_array< QueryBlock > m_query_blocks_to_materialize
Definition: composite_iterators.h:675
unique_ptr_destroy_only< RowIterator > m_subquery_iterator
Definition: composite_iterators.h:778
int m_current_rollup_position
If we are in state OUTPUTTING_ROLLUP_ROWS, where we are in the iteration.
Definition: composite_iterators.h:307
bool m_possibly_buffered_rows
If true, we may have more buffered rows to process that need to be checked for before reading more ro...
Definition: composite_iterators.h:1157
Definition: table.h:1313
void SetNullRowFlag(bool is_null_row) override
Mark the current row buffer as containing a NULL row or not, so that if you read from it and the flag...
Definition: composite_iterators.h:477
unique_ptr_destroy_only< RowIterator > subquery_iterator
The iterator to read the actual rows from.
Definition: composite_iterators.h:526
int select_number
Used only for optimizer trace.
Definition: composite_iterators.h:529
unique_ptr_destroy_only< RowIterator > m_source
Definition: composite_iterators.h:170
void SetNullRowFlag(bool is_null_row) override
Mark the current row buffer as containing a NULL row or not, so that if you read from it and the flag...
Definition: composite_iterators.h:332
void StartPSIBatchMode() override
Start performance schema batch mode, if supported (otherwise ignored).
Definition: composite_iterators.h:1193
An iterator that is semantically equivalent to a semijoin NestedLoopIterator immediately followed by ...
Definition: composite_iterators.h:996
Item * m_condition
Definition: composite_iterators.h:99
This file includes constants used by all storage engines.
CacheInvalidatorIterator(THD *thd, unique_ptr_destroy_only< RowIterator > source_iterator, const std::string &name)
Definition: composite_iterators.h:460
#define DBUG_ASSERT(A)
Definition: my_dbug.h:199
void EndPSIBatchModeIfStarted() override
Ends performance schema batch mode, if started.
Definition: composite_iterators.h:413
JOIN * m_join
The join we are a part of.
Definition: composite_iterators.h:1147
KEY * m_key
Definition: composite_iterators.h:1035
Table_function * m_table_function
Definition: composite_iterators.h:869
FilterIterator(THD *thd, unique_ptr_destroy_only< RowIterator > source, Item *condition)
Definition: composite_iterators.h:73
StreamingIterator is a minimal version of MaterializeIterator that does not actually materialize; ins...
Definition: composite_iterators.h:750
Definition: composite_iterators.h:251
std::vector< std::string > DebugString() const override
Returns a short string (used for EXPLAIN FORMAT=tree) with user-readable information for this iterato...
Definition: composite_iterators.h:850
int Read() override
Read a single row.
Definition: composite_iterators.cc:77
ha_rows m_row_number
Definition: composite_iterators.h:781
bool copy_fields_and_items
If set to false, the Field objects in the output row are presumed already to be filled out...
Definition: composite_iterators.h:554
void SetNullRowFlag(bool is_null_row) override
Mark the current row buffer as containing a NULL row or not, so that if you read from it and the flag...
Definition: composite_iterators.h:1008
void EndPSIBatchModeIfStarted() override
Ends performance schema batch mode, if started.
Definition: composite_iterators.h:143
int m_output_slice
The slice we will be using when outputting rows.
Definition: composite_iterators.h:1097
const CacheInvalidatorIterator * iterator
Definition: composite_iterators.h:708
const size_t m_key_len
Definition: composite_iterators.h:961
bool Init() override
Initialize or reinitialize the iterator.
Definition: composite_iterators.h:77
Definition: aggregate_check.h:523
unique_ptr_destroy_only< RowIterator > const m_source_outer
Definition: composite_iterators.h:1031
SELECT_LEX * m_select_lex
Definition: composite_iterators.h:824
Temp_table_param * m_temp_table_param
The parameters for the temporary table we are materializing into, if any.
Definition: composite_iterators.h:283
const TABLE * m_table
Definition: composite_iterators.h:958
void EndPSIBatchModeIfStarted() override
Ends performance schema batch mode, if started.
Definition: composite_iterators.h:858
JOIN *const m_join
Definition: composite_iterators.h:825
void EndPSIBatchModeIfStarted() override
Ends performance schema batch mode, if started.
Definition: composite_iterators.h:337
JOIN * join
The JOIN that this query block represents.
Definition: composite_iterators.h:536
unique_ptr_destroy_only< RowIterator > m_table_iterator
The iterator that reads from the materialized table.
Definition: composite_iterators.h:1204
std::vector< Child > children() const override
List of zero or more iterators which are direct children of this one.
Definition: composite_iterators.h:344
int m_output_slice
The slice we will be using when outputting rows.
Definition: composite_iterators.h:1153
NestedLoopIterator(THD *thd, unique_ptr_destroy_only< RowIterator > source_outer, unique_ptr_destroy_only< RowIterator > source_inner, JoinType join_type, bool pfs_batch_mode)
Definition: composite_iterators.h:384
Definition: item.h:741
#define final(a, b, c)
Definition: hash.c:109
case opt name
Definition: sslopt-case.h:32
bool doing_hash_deduplication() const
Whether we are deduplicating using a hash field on the temporary table.
Definition: composite_iterators.h:726
Mem_root_array< Invalidator > m_invalidators
Definition: composite_iterators.h:711
FollowTailIterator is a special version of TableScanIterator that is used as part of WITH RECURSIVE q...
Definition: basic_row_iterators.h:490
An iterator that takes in a stream of rows and passes through only those that meet some criteria (i...
Definition: composite_iterators.h:71
std::vector< Child > children() const override
List of zero or more iterators which are direct children of this one.
Definition: composite_iterators.h:242
std::vector< Child > children() const override
List of zero or more iterators which are direct children of this one.
Definition: composite_iterators.h:900
Temp_table_param * m_temp_table_param
The parameters for the temporary table we are materializing into, if any.
Definition: composite_iterators.h:362
Aggregates unsorted data into a temporary table, using update operations to keep running aggregates...
Definition: composite_iterators.h:794
const bool m_count_all_rows
Definition: composite_iterators.h:183
Window * m_window
The window function itself.
Definition: composite_iterators.h:1144
This class represents a query expression (one query block or several query blocks combined with UNION...
Definition: sql_lex.h:590
THD * thd() const
Definition: row_iterator.h:254
void EndPSIBatchModeIfStarted() override
Ends performance schema batch mode, if started.
Definition: composite_iterators.h:772
const ha_rows m_offset
Definition: composite_iterators.h:182
void UnlockRow() override
Definition: composite_iterators.h:1070
std::vector< unique_ptr_destroy_only< RowIterator > > m_sub_iterators
Definition: composite_iterators.h:1232
void StartPSIBatchMode() override
Start performance schema batch mode, if supported (otherwise ignored).
Definition: composite_iterators.h:142
void SetNullRowFlag(bool is_null_row) override
Mark the current row buffer as containing a NULL row or not, so that if you read from it and the flag...
Definition: composite_iterators.h:1115
void StartPSIBatchMode() override
Start performance schema batch mode, if supported (otherwise ignored).
Definition: composite_iterators.h:769
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:389
Definition: composite_iterators.h:253
Handles materialization; the first call to Init() will scan the given iterator to the end...
Definition: composite_iterators.h:522
void EndPSIBatchModeIfStarted() override
Ends performance schema batch mode, if started.
Definition: composite_iterators.h:1120
JOIN * m_join
The join we are a part of.
Definition: composite_iterators.h:1091
void SetNullRowFlag(bool is_null_row) override
Mark the current row buffer as containing a NULL row or not, so that if you read from it and the flag...
Definition: composite_iterators.h:946
void UnlockRow() override
Definition: composite_iterators.h:775
Definition: sql_executor.h:279
static const char * key
Definition: suite_stubs.c:14
std::unique_ptr< T, Destroy_only< T > > unique_ptr_destroy_only
std::unique_ptr, but only destroying.
Definition: my_alloc.h:408
void SetNullRowFlag(bool is_null_row) override
Mark the current row buffer as containing a NULL row or not, so that if you read from it and the flag...
Definition: composite_iterators.h:804
void StartPSIBatchMode() override
Start performance schema batch mode, if supported (otherwise ignored).
Definition: composite_iterators.h:1119
An iterator that removes consecutive rows that are the same according to a given index (or more accur...
Definition: composite_iterators.h:932
std::vector< Child > children() const override
List of zero or more iterators which are direct children of this one.
Definition: composite_iterators.h:1025
void SetNullRowFlag(bool is_null_row) override
Mark the current row buffer as containing a NULL row or not, so that if you read from it and the flag...
Definition: composite_iterators.h:656
void StartPSIBatchMode() override
Start performance schema batch mode, if supported (otherwise ignored).
Definition: composite_iterators.h:231
unique_ptr_destroy_only< RowIterator > const m_source
The iterator we are reading from.
Definition: composite_iterators.h:1138
Class representing a table function.
Definition: table_function.h:52
int64_t generation() const
Definition: composite_iterators.h:488
int m_last_unchanged_group_item_idx
For rollup: The index of the first group item that did not change when we last switched groups...
Definition: composite_iterators.h:298
const size_t m_key_len
Definition: composite_iterators.h:1037
const ha_rows m_limit_rows
See constructor.
Definition: composite_iterators.h:705
Definition: row_iterator.h:129
unique_ptr_destroy_only< RowIterator > m_subquery_iterator
The iterator we are reading rows from.
Definition: composite_iterators.h:818
int m_input_slice
The slice we will be using when reading rows.
Definition: composite_iterators.h:1150
void StartPSIBatchMode() override
Start performance schema batch mode, if supported (otherwise ignored).
Definition: composite_iterators.h:950
unique_ptr_destroy_only< RowIterator > m_table_iterator
The iterator used to scan the resulting temporary table.
Definition: composite_iterators.h:821
Definition: sql_executor.h:99
void StartPSIBatchMode() override
Start performance schema batch mode, if supported (otherwise ignored).
Definition: composite_iterators.h:660
std::vector< Child > children() const override
List of zero or more iterators which are direct children of this one.
Definition: composite_iterators.h:1076
bool m_eof
Whether we have seen the last input row.
Definition: composite_iterators.h:1165
Window * m_window
The window function itself.
Definition: composite_iterators.h:1088
void EndPSIBatchModeIfStarted() override
Ends performance schema batch mode, if started.
Definition: composite_iterators.h:807
void UnlockRow() override
Definition: composite_iterators.h:89
Definition: composite_iterators.h:250
WindowingIterator is similar to AggregateIterator, but deals with windowed aggregates (i...
Definition: composite_iterators.h:1051
Definition: key.h:111
void UnlockRow() override
Definition: composite_iterators.h:1124
bool m_first_row
Definition: composite_iterators.h:962
const TABLE * m_table_outer
Definition: composite_iterators.h:1034
Definition: composite_iterators.h:438
std::vector< std::string > DebugString() const override
Returns a short string (used for EXPLAIN FORMAT=tree) with user-readable information for this iterato...
Definition: composite_iterators.h:152
std::vector< Child > children() const override
List of zero or more iterators which are direct children of this one.
Definition: composite_iterators.cc:165
#define HA_POS_ERROR
Definition: my_base.h:1137
void UnlockRow() override
Definition: composite_iterators.h:146
void SetNullRowFlag(bool is_null_row) override
Mark the current row buffer as containing a NULL row or not, so that if you read from it and the flag...
Definition: composite_iterators.h:1061
Temp_table_param * temp_table_param
If copy_fields_and_items is true, used for copying the Field objects into the temporary table row...
Definition: composite_iterators.h:558
Definition: composite_iterators.h:524
QEP_TAB * m_qep_tab
Definition: composite_iterators.h:1205
int m_output_slice
The slice of the fields we are outputting to.
Definition: composite_iterators.h:365
unique_ptr_destroy_only< RowIterator > const m_source_inner
Definition: composite_iterators.h:443
void UnlockRow() override
Definition: composite_iterators.h:811
void SetNullRowFlag(bool is_null_row) override
Mark the current row buffer as containing a NULL row or not, so that if you read from it and the flag...
Definition: composite_iterators.h:81
uint64_t table_map
Definition: my_table_map.h:30
bool using_hash_key() const
Definition: composite_iterators.h:829
void SetNullRowFlag(bool is_null_row) override
Mark the current row buffer as containing a NULL row or not, so that if you read from it and the flag...
Definition: composite_iterators.h:1189
unique_ptr_destroy_only< RowIterator > m_source
Definition: composite_iterators.h:351
unique_ptr_destroy_only< RowIterator > m_table_iterator
Definition: composite_iterators.h:867
Definition: composite_iterators.h:437
unique_ptr_destroy_only< RowIterator > m_source
Definition: composite_iterators.h:957
const bool m_copy_fields_and_items
Definition: composite_iterators.h:780
bool m_needs_offset
Whether we have OFFSET rows that we still need to skip.
Definition: composite_iterators.h:180
std::vector< Child > children() const override
List of zero or more iterators which are direct children of this one.
Definition: composite_iterators.h:148
const bool m_rematerialize
If true, we need to materialize anew for each Init() (because the contents of the table will depend o...
Definition: composite_iterators.h:702
int m_input_slice
The slice we will be using when reading rows.
Definition: composite_iterators.h:1094
BufferingWindowingIterator is like WindowingIterator, but deals with window functions that need to bu...
Definition: composite_iterators.h:1104
int m_output_slice
The slice of the fields we are outputting to. See the class comment.
Definition: composite_iterators.h:271
LimitOffsetIterator(THD *thd, unique_ptr_destroy_only< RowIterator > source, ha_rows limit, ha_rows offset, bool count_all_rows, ha_rows *skipped_rows)
Definition: composite_iterators.h:120
Takes in two or more iterators and output rows from them sequentially (first all rows from the first ...
Definition: composite_iterators.h:1213
void StartPSIBatchMode() override
Start performance schema batch mode, if supported (otherwise ignored).
Definition: composite_iterators.h:85
void EndPSIBatchModeIfStarted() override
Ends performance schema batch mode, if started.
Definition: composite_iterators.h:1013
unique_ptr_destroy_only< RowIterator > m_source
Definition: composite_iterators.h:914
Handles LIMIT and/or OFFSET; Init() eats the first "offset" rows, and Read() stops as soon as it&#39;s se...
Definition: composite_iterators.h:106
uchar * m_key_buf
Definition: composite_iterators.h:1036
void SetNullRowFlag(bool is_null_row) override
Mark the current row buffer as containing a NULL row or not, so that if you read from it and the flag...
Definition: composite_iterators.h:904
void UnlockRow() override
Definition: composite_iterators.h:665
void EndPSIBatchModeIfStarted() override
Ends performance schema batch mode, if started.
Definition: composite_iterators.h:232
join_type
Definition: sql_opt_exec_shared.h:176
Like semijoin materialization, weedout works on the basic idea that a semijoin is just like an inner ...
Definition: composite_iterators.h:891
std::vector< Child > children() const override
List of zero or more iterators which are direct children of this one.
Definition: composite_iterators.h:765
void UnlockRow() override
Definition: composite_iterators.h:1018
void StartPSIBatchMode() override
Start performance schema batch mode, if supported (otherwise ignored).
Definition: composite_iterators.h:336
SJ_TMP_TABLE * m_sj
Definition: composite_iterators.h:915
ha_rows * m_skipped_rows
Definition: composite_iterators.h:184
my_off_t ha_rows
Definition: my_base.h:1135
void UnlockRow() override
Definition: composite_iterators.h:340
Object containing parameters used when creating and using temporary tables.
Definition: temp_table_param.h:74
std::vector< std::string > DebugString() const override
Returns a short string (used for EXPLAIN FORMAT=tree) with user-readable information for this iterato...
Definition: composite_iterators.h:761
unique_ptr_destroy_only< RowIterator > m_source
Definition: composite_iterators.h:98
const bool m_rollup
Whether this is a rollup query.
Definition: composite_iterators.h:286
int64_t generation_at_last_materialize
Definition: composite_iterators.h:709
This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical rea...
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:799
unique_ptr_destroy_only< RowIterator > const m_source_outer
Definition: composite_iterators.h:442
unique_ptr_destroy_only< RowIterator > m_source
Definition: composite_iterators.h:257
Temp_table_param * m_temp_table_param
Parameters for the temporary table we are outputting to.
Definition: composite_iterators.h:1141
uchar * m_key_buf
Definition: composite_iterators.h:960
std::string name() const
Definition: composite_iterators.h:489