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