MySQL  8.0.27
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, 2021, Oracle and/or its affiliates.
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 and the two window iterators are also composite iterators,
38  but are defined in their own files.
39  */
40 
41 #include <assert.h>
42 #include <stdint.h>
43 #include <stdio.h>
44 #include <memory>
45 #include <string>
46 #include <utility>
47 #include <vector>
48 
49 #include "my_alloc.h"
50 #include "my_base.h"
51 #include "my_inttypes.h"
52 #include "my_table_map.h"
53 #include "sql/join_type.h"
54 #include "sql/mem_root_array.h"
55 #include "sql/pack_rows.h"
56 #include "sql/row_iterator.h"
57 #include "sql/table.h"
58 #include "sql_string.h"
59 
60 class Cached_item;
61 class FollowTailIterator;
62 class Item;
63 class JOIN;
64 class KEY;
65 class Query_expression;
66 class SJ_TMP_TABLE;
67 class THD;
68 class Table_function;
69 class Temp_table_param;
70 
71 /**
72  An iterator that takes in a stream of rows and passes through only those that
73  meet some criteria (i.e., a condition evaluates to true). This is typically
74  used for WHERE/HAVING.
75  */
76 class FilterIterator final : public RowIterator {
77  public:
79  Item *condition)
80  : RowIterator(thd), m_source(move(source)), m_condition(condition) {}
81 
82  bool Init() override { return m_source->Init(); }
83 
84  int Read() override;
85 
86  void SetNullRowFlag(bool is_null_row) override {
87  m_source->SetNullRowFlag(is_null_row);
88  }
89 
90  void StartPSIBatchMode() override { m_source->StartPSIBatchMode(); }
91  void EndPSIBatchModeIfStarted() override {
92  m_source->EndPSIBatchModeIfStarted();
93  }
94  void UnlockRow() override { m_source->UnlockRow(); }
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  */
105 class LimitOffsetIterator final : public RowIterator {
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 reject_multiple_rows True if a derived table transformed from a
117  scalar subquery needs a run-time cardinality check
118  @param skipped_rows If not nullptr, is incremented for each row skipped by
119  offset or limit.
120  */
122  ha_rows limit, ha_rows offset, bool count_all_rows,
123  bool reject_multiple_rows, ha_rows *skipped_rows)
124  : RowIterator(thd),
125  m_source(move(source)),
126  m_limit(limit),
127  m_offset(offset),
128  m_count_all_rows(count_all_rows),
129  m_reject_multiple_rows(reject_multiple_rows),
130  m_skipped_rows(skipped_rows) {
131  if (count_all_rows) {
132  assert(m_skipped_rows != nullptr);
133  }
134  }
135 
136  bool Init() override;
137 
138  int Read() override;
139 
140  void SetNullRowFlag(bool is_null_row) override {
141  m_source->SetNullRowFlag(is_null_row);
142  }
143 
144  void StartPSIBatchMode() override { m_source->StartPSIBatchMode(); }
145  void EndPSIBatchModeIfStarted() override {
146  m_source->EndPSIBatchModeIfStarted();
147  }
148  void UnlockRow() override { m_source->UnlockRow(); }
149 
150  private:
152 
153  // Note: The number of seen rows starts off at m_limit if we have OFFSET,
154  // which means we don't need separate LIMIT and OFFSET tests on the
155  // fast path of Read().
157 
158  /**
159  Whether we have OFFSET rows that we still need to skip.
160  */
162 
164  const bool m_count_all_rows;
167 };
168 
169 /**
170  Handles aggregation (typically used for GROUP BY) for the case where the rows
171  are already properly grouped coming in, ie., all rows that are supposed to be
172  part of the same group are adjacent in the input stream. (This could be
173  because they were sorted earlier, because we are scanning an index that
174  already gives us the rows in a group-compatible order, or because there is no
175  grouping.)
176 
177  AggregateIterator needs to be able to save and restore rows; it doesn't know
178  when a group ends until it's seen the first row that is part of the _next_
179  group. When that happens, it needs to tuck away that next row, and then
180  restore the previous row so that the output row gets the correct grouped
181  values. A simple example, doing SELECT a, SUM(b) FROM t1 GROUP BY a:
182 
183  t1.a t1.b SUM(b)
184  1 1 <-- first row, save it 1
185  1 2 3
186  1 3 6
187  2 1 <-- group changed, save row
188  [1 1] <-- restore first row, output 6
189  reset aggregate --> 0
190  [2 1] <-- restore new row, process it 1
191  2 10 11
192  <-- EOF, output 11
193 
194  To save and restore rows like this, it uses the infrastructure from
195  pack_rows.h to pack and unpack all relevant rows into record[0] of every input
196  table. (Currently, there can only be one input table, but this may very well
197  change in the future.) It would be nice to have a more abstract concept of
198  sending a row around and taking copies of it if needed, as opposed to it
199  implicitly staying in the table's buffer. (This would also solve some
200  issues in EQRefIterator and when synthesizing NULL rows for outer joins.)
201  However, that's a large refactoring.
202  */
203 class AggregateIterator final : public RowIterator {
204  public:
206  JOIN *join, pack_rows::TableCollection tables, bool rollup);
207 
208  bool Init() override;
209  int Read() override;
210  void SetNullRowFlag(bool is_null_row) override {
211  m_source->SetNullRowFlag(is_null_row);
212  }
213 
214  void StartPSIBatchMode() override { m_source->StartPSIBatchMode(); }
215  void EndPSIBatchModeIfStarted() override {
216  m_source->EndPSIBatchModeIfStarted();
217  }
218  void UnlockRow() override {
219  // Most likely, HAVING failed. Ideally, we'd like to backtrack and
220  // unlock all rows that went into this aggregate, but we can't do that,
221  // and we also can't unlock the _current_ row, since that belongs to a
222  // different group. Thus, do nothing.
223  }
224 
225  private:
226  enum {
232 
234 
235  /**
236  The join we are part of. It would be nicer not to rely on this,
237  but we need a large number of members from there, like which
238  aggregate functions we have, the THD, temporary table parameters
239  and so on.
240  */
241  JOIN *m_join = nullptr;
242 
243  /// Whether we have seen the last input row.
245 
246  /**
247  Used to save NULL information in the specific case where we have
248  zero input rows.
249  */
251 
252  /// Whether this is a rollup query.
253  const bool m_rollup;
254 
255  /**
256  For rollup: The index of the first group item that did _not_ change when we
257  last switched groups. E.g., if we have group fields A,B,C,D and then switch
258  to group A,B,E,D, this value will become 1 (which means that we need
259  to output rollup rows for 2 -- A,B,E,NULL -- and then 1 -- A,B,NULL,NULL).
260  m_current_rollup_position will count down from the end until it becomes
261  less than this value.
262 
263  If we do not have rollup, this value is perennially zero.
264  */
266 
267  /**
268  If we are in state OUTPUTTING_ROLLUP_ROWS, where we are in the iteration.
269  This value will start at the index of the last group expression and then
270  count backwards down to and including m_last_unchanged_group_item_idx.
271  It is used to communicate to the rollup group items whether to turn
272  themselves into NULLs, and the sum items which of their sums to output.
273  */
275 
276  /**
277  The list of tables we are reading from; they are the ones for which we need
278  to save and restore rows.
279  */
281 
282  /// Packed version of the first row in the group we are currently processing.
284 
285  /**
286  If applicable, packed version of the first row in the _next_ group. This is
287  used only in the LAST_ROW_STARTED_NEW_GROUP state; we just saw a row that
288  didn't belong to the current group, so we saved it here and went to output
289  a group. On the next Read() call, we need to process this deferred row
290  first of all.
291 
292  Even when not in use, this string contains a buffer that is large enough to
293  pack a full row into, sans blobs. (If blobs are present,
294  StoreFromTableBuffers() will automatically allocate more space if needed.)
295  */
297 
298  /**
299  The slice we're setting when returning rows. See the comment in the
300  constructor.
301  */
302  int m_output_slice = -1;
303 
304  void SetRollupLevel(int level);
305 };
306 
307 /**
308  A simple nested loop join, taking in two iterators (left/outer and
309  right/inner) and joining them together. This may, of course, scan the inner
310  iterator many times. It is currently the only form of join we have.
311 
312  The iterator works as a state machine, where the state records whether we need
313  to read a new outer row or not, and whether we've seen any rows from the inner
314  iterator at all (if not, an outer join need to synthesize a new NULL row).
315 
316  The iterator takes care of activating performance schema batch mode on the
317  right iterator if needed; this is typically only used if it is the innermost
318  table in the entire join (where the gains from turning on batch mode is the
319  largest, and the accuracy loss from turning it off are the least critical).
320  */
321 class NestedLoopIterator final : public RowIterator {
322  public:
326  JoinType join_type, bool pfs_batch_mode)
327  : RowIterator(thd),
328  m_source_outer(move(source_outer)),
329  m_source_inner(move(source_inner)),
331  m_pfs_batch_mode(pfs_batch_mode) {
332  assert(m_source_outer != nullptr);
333  assert(m_source_inner != nullptr);
334 
335  // Batch mode makes no sense for anti- or semijoins, since they should only
336  // be reading one row.
338  assert(!pfs_batch_mode);
339  }
340  }
341 
342  bool Init() override;
343 
344  int Read() override;
345 
346  void SetNullRowFlag(bool is_null_row) override {
347  // TODO: write something here about why we can't do this lazily.
348  m_source_outer->SetNullRowFlag(is_null_row);
349  m_source_inner->SetNullRowFlag(is_null_row);
350  }
351 
352  void EndPSIBatchModeIfStarted() override {
353  m_source_outer->EndPSIBatchModeIfStarted();
354  m_source_inner->EndPSIBatchModeIfStarted();
355  }
356 
357  void UnlockRow() override {
358  // Since we don't know which condition that caused the row to be rejected,
359  // we can't know whether we could also unlock the outer row
360  // (it may still be used as parts of other joined rows).
362  m_source_inner->UnlockRow();
363  }
364  }
365 
366  private:
367  enum {
373 
377 
378  /** Whether to use batch mode when scanning the inner iterator. */
379  const bool m_pfs_batch_mode;
380 };
381 
382 /**
383  An iterator that helps invalidating caches. Every time a row passes through it
384  or it changes state in any other way, it increments its “generation” counter.
385  This allows MaterializeIterator to see whether any of its dependencies has
386  changed, and then force a rematerialization -- this is typically used for
387  LATERAL tables, where we're joining in a derived table that depends on
388  something earlier in the join.
389  */
390 class CacheInvalidatorIterator final : public RowIterator {
391  public:
393  unique_ptr_destroy_only<RowIterator> source_iterator,
394  const std::string &name)
395  : RowIterator(thd),
396  m_source_iterator(move(source_iterator)),
397  m_name(name) {}
398 
399  bool Init() override {
400  ++m_generation;
401  return m_source_iterator->Init();
402  }
403 
404  int Read() override {
405  ++m_generation;
406  return m_source_iterator->Read();
407  }
408 
409  void SetNullRowFlag(bool is_null_row) override {
410  ++m_generation;
411  m_source_iterator->SetNullRowFlag(is_null_row);
412  }
413 
414  void UnlockRow() override { m_source_iterator->UnlockRow(); }
415 
416  int64_t generation() const { return m_generation; }
417  std::string name() const { return m_name; }
418 
419  private:
421  int64_t m_generation = 0;
422  std::string m_name;
423 };
424 
425 /**
426  Handles materialization; the first call to Init() will scan the given iterator
427  to the end, store the results in a temporary table (optionally with
428  deduplication), and then Read() will allow you to read that table repeatedly
429  without the cost of executing the given subquery many times (unless you ask
430  for rematerialization).
431 
432  When materializing, MaterializeIterator takes care of evaluating any items
433  that need so, and storing the results in the fields of the outgoing table --
434  which items is governed by the temporary table parameters.
435 
436  Conceptually (although not performance-wise!), the MaterializeIterator is a
437  no-op if you don't ask for deduplication, and in some cases (e.g. when
438  scanning a table only once), we elide it. However, it's not necessarily
439  straightforward to do so by just not inserting the iterator, as the optimizer
440  will have set up everything (e.g., read sets, or what table upstream items
441  will read from) assuming the materialization will happen, so the realistic
442  option is setting up everything as if materialization would happen but not
443  actually write to the table; see StreamingIterator for details.
444 
445  MaterializeIterator conceptually materializes iterators, not JOINs or
446  Query_expressions. However, there are many details that leak out
447  (e.g., setting performance schema batch mode, slices, reusing CTEs,
448  etc.), so we need to send them in anyway.
449  */
450 class MaterializeIterator final : public TableRowIterator {
451  public:
452  struct QueryBlock {
453  /// The iterator to read the actual rows from.
455 
456  /// Used only for optimizer trace.
458 
459  /// The JOIN that this query block represents. Used for performance
460  /// schema batch mode: When materializing a query block that consists of
461  /// a single table, MaterializeIterator needs to set up schema batch mode,
462  /// since there is no nested loop iterator to do it. (This is similar to
463  /// what ExecuteIteratorQuery() needs to do at the top level.)
465 
466  /// If true, unique constraint checking via hash key is disabled
467  /// when materializing this query block (ie., we simply avoid calling
468  /// check_unique_constraint() for each row). Used when materializing
469  /// UNION DISTINCT and UNION ALL parts into the same table.
470  /// We'd like to just use a unique constraint via unique index instead,
471  /// but there might be other indexes on the destination table
472  /// that we'd like to keep, and the implementation doesn't allow
473  /// disabling only one index.
474  ///
475  /// If you use this on a query block, doing_hash_deduplication()
476  /// must be true.
478 
479  /// If set to false, the Field objects in the output row are
480  /// presumed already to be filled out. This is the case iff
481  /// there's a windowing iterator earlier in the chain.
483 
484  /// If copy_items is true, used for copying the Field objects
485  /// into the temporary table row. Otherwise unused.
487 
488  // Whether this query block is a recursive reference back to the
489  // output of the materialization.
491 
492  // If is_recursive_reference is true, contains the FollowTailIterator
493  // in the query block (there can be at most one recursive reference
494  // in a join list, as per the SQL standard, so there should be exactly one).
495  // Used for informing the iterators about various shared state in the
496  // materialization (including coordinating rematerializations).
498  };
499 
500  /**
501  @param thd Thread handler.
502  @param query_blocks_to_materialize List of query blocks to materialize.
503  @param table Handle to table to materialize into.
504  @param table_iterator Iterator used for scanning the temporary table
505  after materialization.
506  @param cte If materializing a CTE, points to it (see m_cte), otherwise
507  nullptr.
508  @param unit The query expression we are materializing (see
509  m_query_expression).
510  @param join
511  When materializing within the same JOIN (e.g., into a temporary table
512  before sorting), as opposed to a derived table or a CTE, we may need
513  to change the slice on the join before returning rows from the result
514  table. If so, join and ref_slice would need to be set, and
515  query_blocks_to_materialize should contain only one member, with the same
516  join.
517  @param ref_slice See join. If we are materializing across JOINs,
518  e.g. derived tables, ref_slice should be left at -1.
519  @param rematerialize true if rematerializing on every Init() call
520  (e.g., because we have a dependency on a value from outside the query
521  block).
522  @param limit_rows
523  Used for when pushing LIMIT down to MaterializeIterator; this is
524  more efficient than having a LimitOffsetIterator above the
525  MaterializeIterator, since we can stop materializing when there are
526  enough rows. (This is especially important for recursive CTEs.)
527  Note that we cannot have a LimitOffsetIterator _below_ the
528  MaterializeIterator, as that would count wrong if we have deduplication,
529  and would not work at all for recursive CTEs.
530  Set to HA_POS_ERROR for no limit.
531  @param reject_multiple_rows true if this is the top level iterator for a
532  materialized derived table transformed from a scalar subquery which needs
533  run-time cardinality check.
534  */
536  Mem_root_array<QueryBlock> query_blocks_to_materialize,
537  TABLE *table,
540  JOIN *join, int ref_slice, bool rematerialize,
541  ha_rows limit_rows, bool reject_multiple_rows);
542 
543  bool Init() override;
544  int Read() override;
545 
546  void SetNullRowFlag(bool is_null_row) override {
547  m_table_iterator->SetNullRowFlag(is_null_row);
548  }
549 
550  void StartPSIBatchMode() override { m_table_iterator->StartPSIBatchMode(); }
551  void EndPSIBatchModeIfStarted() override;
552 
553  // The temporary table is private to us, so there's no need to worry about
554  // locks to other transactions.
555  void UnlockRow() override {}
556 
557  /**
558  Add a cache invalidator that must be checked on every Init().
559  If its generation has increased since last materialize, we need to
560  rematerialize even if m_rematerialize is false.
561  */
562  void AddInvalidator(const CacheInvalidatorIterator *invalidator);
563 
564  // Signal to TimingIterator that num_init_calls() and num_rows() exists.
565  using keeps_own_timing = void;
566  uint64_t num_init_calls() const { return m_num_materializations; }
567  uint64_t num_rows() const { return m_num_materialized_rows; }
568 
569  private:
572 
573  /// If we are materializing a CTE, points to it (otherwise nullptr).
574  /// Used so that we see if some other iterator already materialized the table,
575  /// avoiding duplicate work.
577 
578  /// The query expression we are materializing. For derived tables,
579  /// we materialize the entire query expression; for materialization within
580  /// a query expression (e.g. for sorting or for windowing functions),
581  /// we materialize only parts of it. Used to clear correlated CTEs within
582  /// the unit when we rematerialize, since they depend on values from
583  /// outside the query expression, and those values may have changed
584  /// since last materialization.
586 
587  /// See constructor.
588  JOIN *const m_join;
589 
590  /// The slice to set when accessing temporary table; used if anything upstream
591  /// (e.g. WHERE, HAVING) wants to evaluate values based on its contents.
592  /// See constructor.
593  const int m_ref_slice;
594 
595  /// If true, we need to materialize anew for each Init() (because the contents
596  /// of the table will depend on some outer non-constant value).
597  const bool m_rematerialize;
598 
599  /// See constructor.
601 
602  /// See constructor.
604 
605  struct Invalidator {
608  };
610 
611  // How many times we've actually materialized, and how many rows we
612  // materialized then. Used when we're wrapped in TimingIterator.
615 
616  /// Whether we are deduplicating using a hash field on the temporary
617  /// table. (This condition mirrors check_unique_constraint().)
618  /// If so, we compute a hash value for every row, look up all rows with
619  /// the same hash and manually compare them to the row we are trying to
620  /// insert.
621  ///
622  /// Note that this is _not_ the common way of deduplicating as we go.
623  /// The common method is to have a regular index on the table
624  /// over the right columns, and in that case, ha_write_row() will fail
625  /// with an ignorable error, so that the row is ignored even though
626  /// check_unique_constraint() is not called. However, B-tree indexes
627  /// have limitations, in particular on length, that sometimes require us
628  /// to do this instead. See create_tmp_table() for details.
629  bool doing_hash_deduplication() const { return table()->hash_field; }
630 
631  /// Whether we are deduplicating, whether through a hash field
632  /// or a regular unique index.
633  bool doing_deduplication() const;
634 
635  bool MaterializeRecursive();
636  bool MaterializeQueryBlock(const QueryBlock &query_block,
637  ha_rows *stored_rows);
638 };
639 
640 /**
641  StreamingIterator is a minimal version of MaterializeIterator that does not
642  actually materialize; instead, every Read() just forwards the call to the
643  subquery iterator and does the required copying from one set of fields to
644  another.
645 
646  It is used for when the optimizer would normally set up a materialization,
647  but you don't actually need one, ie. you don't want to read the rows multiple
648  times after writing them, and you don't want to access them by index (only
649  a single table scan). It also takes care of setting the NULL row flag
650  on the temporary table.
651  */
652 class StreamingIterator final : public TableRowIterator {
653  public:
654  /**
655  @param thd Thread handle.
656  @param subquery_iterator The iterator to read rows from.
657  @param temp_table_param Parameters for the temp table.
658  @param table The table we are streaming through. Will never actually
659  be written to, but its fields will be used.
660  @param provide_rowid If true, generate a row ID for each row we stream.
661  This is used if the parent needs row IDs for deduplication, in particular
662  weedout.
663  @param join See MaterializeIterator.
664  @param ref_slice See MaterializeIterator.
665  */
667  unique_ptr_destroy_only<RowIterator> subquery_iterator,
668  Temp_table_param *temp_table_param, TABLE *table,
669  bool provide_rowid, JOIN *join, int ref_slice);
670 
671  bool Init() override;
672 
673  int Read() override;
674 
675  void StartPSIBatchMode() override {
676  m_subquery_iterator->StartPSIBatchMode();
677  }
678  void EndPSIBatchModeIfStarted() override {
679  m_subquery_iterator->EndPSIBatchModeIfStarted();
680  }
681  void UnlockRow() override { m_subquery_iterator->UnlockRow(); }
682 
683  private:
687  JOIN *const m_join;
688  const int m_output_slice;
690 
691  // Whether the iterator should generate and provide a row ID. Only true if the
692  // iterator is part of weedout, where the iterator will create a fake row ID
693  // to uniquely identify the rows it produces.
694  const bool m_provide_rowid;
695 };
696 
697 /**
698  Aggregates unsorted data into a temporary table, using update operations
699  to keep running aggregates. After that, works as a MaterializeIterator
700  in that it allows the temporary table to be scanned.
701  */
703  public:
705  THD *thd, unique_ptr_destroy_only<RowIterator> subquery_iterator,
706  Temp_table_param *temp_table_param, TABLE *table,
708  int ref_slice);
709 
710  bool Init() override;
711  int Read() override;
712  void SetNullRowFlag(bool is_null_row) override {
713  m_table_iterator->SetNullRowFlag(is_null_row);
714  }
715  void EndPSIBatchModeIfStarted() override {
716  m_table_iterator->EndPSIBatchModeIfStarted();
717  m_subquery_iterator->EndPSIBatchModeIfStarted();
718  }
719  void UnlockRow() override {}
720 
721  private:
722  /// The iterator we are reading rows from.
724 
725  /// The iterator used to scan the resulting temporary table.
727 
729  JOIN *const m_join;
730  const int m_ref_slice;
731 
732  // See MaterializeIterator::doing_hash_deduplication().
733  bool using_hash_key() const { return table()->hash_field; }
734 
735  bool move_table_to_disk(int error, bool was_insert);
736 };
737 
738 /**
739  An iterator that wraps a Table_function (e.g. JSON_TABLE) and allows you to
740  iterate over the materialized temporary table. The table is materialized anew
741  for every Init().
742 
743  TODO: Just wrapping it is probably not the optimal thing to do;
744  Table_function is highly oriented around materialization, but never caches.
745  Thus, perhaps we should rewrite Table_function to return a RowIterator
746  instead of going through a temporary table.
747  */
749  public:
751  THD *thd, Table_function *table_function, TABLE *table,
752  unique_ptr_destroy_only<RowIterator> table_iterator);
753 
754  bool Init() override;
755  int Read() override { return m_table_iterator->Read(); }
756  void SetNullRowFlag(bool is_null_row) override {
757  m_table_iterator->SetNullRowFlag(is_null_row);
758  }
759 
760  void StartPSIBatchMode() override { m_table_iterator->StartPSIBatchMode(); }
761  void EndPSIBatchModeIfStarted() override {
762  m_table_iterator->EndPSIBatchModeIfStarted();
763  }
764 
765  // The temporary table is private to us, so there's no need to worry about
766  // locks to other transactions.
767  void UnlockRow() override {}
768 
769  private:
771 
773 };
774 
775 /**
776  Like semijoin materialization, weedout works on the basic idea that a semijoin
777  is just like an inner join as we long as we can get rid of the duplicates
778  somehow. (This is advantageous, because inner joins can be reordered, whereas
779  semijoins generally can't.) However, unlike semijoin materialization, weedout
780  removes duplicates after the join, not before it. Consider something like
781 
782  SELECT * FROM t1 WHERE a IN ( SELECT b FROM t2 );
783 
784  Semijoin materialization solves this by materializing t2, with deduplication,
785  and then joining. Weedout joins t1 to t2 and then leaves only one output row
786  per t1 row. The disadvantage is that this potentially needs to discard more
787  rows; the (potential) advantage is that we deduplicate on t1 instead of t2.
788 
789  Weedout, unlike materialization, works in a streaming fashion; rows are output
790  (or discarded) as they come in, with a temporary table used for recording the
791  row IDs we've seen before. (We need to deduplicate on t1's row IDs, not its
792  contents.) See SJ_TMP_TABLE for details about the table format.
793  */
794 class WeedoutIterator final : public RowIterator {
795  public:
797  SJ_TMP_TABLE *sj, table_map tables_to_get_rowid_for);
798 
799  bool Init() override;
800  int Read() override;
801 
802  void SetNullRowFlag(bool is_null_row) override {
803  m_source->SetNullRowFlag(is_null_row);
804  }
805 
806  void EndPSIBatchModeIfStarted() override {
807  m_source->EndPSIBatchModeIfStarted();
808  }
809  void UnlockRow() override { m_source->UnlockRow(); }
810 
811  private:
815 };
816 
817 /**
818  An iterator that removes consecutive rows that are the same according to
819  a set of items (typically the join key), so-called “loose scan”
820  (not to be confused with “loose index scan”, which is a QUICK_SELECT_I).
821  This is similar in spirit to WeedoutIterator above (removing duplicates
822  allows us to treat the semijoin as a normal join), but is much cheaper
823  if the data is already ordered/grouped correctly, as the removal can
824  happen before the join, and it does not need a temporary table.
825  */
826 class RemoveDuplicatesIterator final : public RowIterator {
827  public:
830  JOIN *join, Item **group_items,
831  int group_items_size);
832 
833  bool Init() override;
834  int Read() override;
835 
836  void SetNullRowFlag(bool is_null_row) override {
837  m_source->SetNullRowFlag(is_null_row);
838  }
839 
840  void StartPSIBatchMode() override { m_source->StartPSIBatchMode(); }
841  void EndPSIBatchModeIfStarted() override {
842  m_source->EndPSIBatchModeIfStarted();
843  }
844  void UnlockRow() override { m_source->UnlockRow(); }
845 
846  private:
850 };
851 
852 /**
853  Much like RemoveDuplicatesIterator, but works on the basis of a given index
854  (or more accurately, its keypart), not an arbitrary list of grouped fields.
855  This is only used in the non-hypergraph optimizer; the hypergraph optimizer
856  can deal with groupings that come from e.g. sorts.
857  */
859  public:
862  const TABLE *table, KEY *key, size_t key_len);
863 
864  bool Init() override;
865  int Read() override;
866 
867  void SetNullRowFlag(bool is_null_row) override {
868  m_source->SetNullRowFlag(is_null_row);
869  }
870 
871  void StartPSIBatchMode() override { m_source->StartPSIBatchMode(); }
872  void EndPSIBatchModeIfStarted() override {
873  m_source->EndPSIBatchModeIfStarted();
874  }
875  void UnlockRow() override { m_source->UnlockRow(); }
876 
877  private:
879  const TABLE *m_table;
881  uchar *m_key_buf; // Owned by the THD's MEM_ROOT.
882  const size_t m_key_len;
884 };
885 
886 /**
887  An iterator that is semantically equivalent to a semijoin NestedLoopIterator
888  immediately followed by a RemoveDuplicatesOnIndexIterator. It is used to
889  implement the “loose scan” strategy in queries with multiple tables on the
890  inside of a semijoin, like
891 
892  ... FROM t1 WHERE ... IN ( SELECT ... FROM t2 JOIN t3 ... )
893 
894  In this case, the query tree without this iterator would ostensibly look like
895 
896  -> Nested loop join
897  -> Table scan on t1
898  -> Remove duplicates on t2_idx
899  -> Nested loop semijoin
900  -> Index scan on t2 using t2_idx
901  -> Filter (e.g. t3.a = t2.a)
902  -> Table scan on t3
903 
904  (t3 will be marked as “first match” on t2 when implementing loose scan,
905  thus the semijoin.)
906 
907  First note that we can't put the duplicate removal directly on t2 in this
908  case, as the first t2 row doesn't necessarily match anything in t3, so it
909  needs to be above. However, this is wasteful, because once we find a matching
910  t2/t3 pair, we should stop scanning t3 until we have a new t2.
911 
912  NestedLoopSemiJoinWithDuplicateRemovalIterator solves the problem by doing
913  exactly this; it gets a row from the outer side, gets exactly one row from the
914  inner side, and then skips over rows from the outer side (_without_ scanning
915  the inner side) until its keypart changes.
916  */
918  : public RowIterator {
919  public:
922  unique_ptr_destroy_only<RowIterator> source_inner, const TABLE *table,
923  KEY *key, size_t key_len);
924 
925  bool Init() override;
926 
927  int Read() override;
928 
929  void SetNullRowFlag(bool is_null_row) override {
930  m_source_outer->SetNullRowFlag(is_null_row);
931  m_source_inner->SetNullRowFlag(is_null_row);
932  }
933 
934  void EndPSIBatchModeIfStarted() override {
935  m_source_outer->EndPSIBatchModeIfStarted();
936  m_source_inner->EndPSIBatchModeIfStarted();
937  }
938 
939  void UnlockRow() override {
940  m_source_outer->UnlockRow();
941  m_source_inner->UnlockRow();
942  }
943 
944  private:
947 
950  uchar *m_key_buf; // Owned by the THD's MEM_ROOT.
951  const size_t m_key_len;
953 };
954 
955 /**
956  MaterializeInformationSchemaTableIterator makes sure a given I_S temporary
957  table is materialized (filled out) before we try to scan it.
958  */
960  public:
963  TABLE_LIST *table_list, Item *condition);
964 
965  bool Init() override;
966  int Read() override { return m_table_iterator->Read(); }
967 
968  void SetNullRowFlag(bool is_null_row) override {
969  m_table_iterator->SetNullRowFlag(is_null_row);
970  }
971 
972  void StartPSIBatchMode() override { m_table_iterator->StartPSIBatchMode(); }
973  void EndPSIBatchModeIfStarted() override {
974  m_table_iterator->EndPSIBatchModeIfStarted();
975  }
976 
977  // The temporary table is private to us, so there's no need to worry about
978  // locks to other transactions.
979  void UnlockRow() override {}
980 
981  private:
982  /// The iterator that reads from the materialized table.
986 };
987 
988 /**
989  Takes in two or more iterators and output rows from them sequentially
990  (first all rows from the first one, the all from the second one, etc.).
991  Used for implementing UNION ALL, typically together with StreamingIterator.
992  */
993 class AppendIterator final : public RowIterator {
994  public:
996  THD *thd,
998 
999  bool Init() override;
1000  int Read() override;
1001 
1002  void StartPSIBatchMode() override;
1003  void EndPSIBatchModeIfStarted() override;
1004 
1005  void SetNullRowFlag(bool is_null_row) override;
1006  void UnlockRow() override;
1007 
1008  private:
1009  std::vector<unique_ptr_destroy_only<RowIterator>> m_sub_iterators;
1012 };
1013 
1014 #endif // SQL_COMPOSITE_ITERATORS_INCLUDED
Handles aggregation (typically used for GROUP BY) for the case where the rows are already properly gr...
Definition: composite_iterators.h:203
void UnlockRow() override
Definition: composite_iterators.h:218
int m_current_rollup_position
If we are in state OUTPUTTING_ROLLUP_ROWS, where we are in the iteration.
Definition: composite_iterators.h:274
void StartPSIBatchMode() override
Start performance schema batch mode, if supported (otherwise ignored).
Definition: composite_iterators.h:214
int Read() override
Read a single row.
Definition: composite_iterators.cc:220
JOIN * m_join
The join we are part of.
Definition: composite_iterators.h:241
bool m_seen_eof
Whether we have seen the last input row.
Definition: composite_iterators.h:244
pack_rows::TableCollection m_tables
The list of tables we are reading from; they are the ones for which we need to save and restore rows.
Definition: composite_iterators.h:280
String m_first_row_this_group
Packed version of the first row in the group we are currently processing.
Definition: composite_iterators.h:283
String m_first_row_next_group
If applicable, packed version of the first row in the next group.
Definition: composite_iterators.h:296
table_map m_save_nullinfo
Used to save NULL information in the specific case where we have zero input rows.
Definition: composite_iterators.h:250
bool Init() override
Initialize or reinitialize the iterator.
Definition: composite_iterators.cc:184
unique_ptr_destroy_only< RowIterator > m_source
Definition: composite_iterators.h:233
int m_output_slice
The slice we're setting when returning rows.
Definition: composite_iterators.h:302
AggregateIterator(THD *thd, unique_ptr_destroy_only< RowIterator > source, JOIN *join, pack_rows::TableCollection tables, bool rollup)
Definition: composite_iterators.cc:171
@ LAST_ROW_STARTED_NEW_GROUP
Definition: composite_iterators.h:228
@ READING_FIRST_ROW
Definition: composite_iterators.h:227
@ OUTPUTTING_ROLLUP_ROWS
Definition: composite_iterators.h:229
@ DONE_OUTPUTTING_ROWS
Definition: composite_iterators.h:230
void EndPSIBatchModeIfStarted() override
Ends performance schema batch mode, if started.
Definition: composite_iterators.h:215
const bool m_rollup
Whether this is a rollup query.
Definition: composite_iterators.h:253
enum AggregateIterator::@33 m_state
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:210
void SetRollupLevel(int level)
Definition: composite_iterators.cc:430
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:265
Takes in two or more iterators and output rows from them sequentially (first all rows from the first ...
Definition: composite_iterators.h:993
size_t m_current_iterator_index
Definition: composite_iterators.h:1010
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:1586
AppendIterator(THD *thd, std::vector< unique_ptr_destroy_only< RowIterator >> &&sub_iterators)
Definition: composite_iterators.cc:1549
bool Init() override
Initialize or reinitialize the iterator.
Definition: composite_iterators.cc:1555
void EndPSIBatchModeIfStarted() override
Ends performance schema batch mode, if started.
Definition: composite_iterators.cc:1596
void UnlockRow() override
Definition: composite_iterators.cc:1604
std::vector< unique_ptr_destroy_only< RowIterator > > m_sub_iterators
Definition: composite_iterators.h:1009
int Read() override
Read a single row.
Definition: composite_iterators.cc:1561
bool m_pfs_batch_mode_enabled
Definition: composite_iterators.h:1011
void StartPSIBatchMode() override
Start performance schema batch mode, if supported (otherwise ignored).
Definition: composite_iterators.cc:1591
An iterator that helps invalidating caches.
Definition: composite_iterators.h:390
bool Init() override
Initialize or reinitialize the iterator.
Definition: composite_iterators.h:399
CacheInvalidatorIterator(THD *thd, unique_ptr_destroy_only< RowIterator > source_iterator, const std::string &name)
Definition: composite_iterators.h:392
std::string m_name
Definition: composite_iterators.h:422
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:409
unique_ptr_destroy_only< RowIterator > m_source_iterator
Definition: composite_iterators.h:420
void UnlockRow() override
Definition: composite_iterators.h:414
int64_t m_generation
Definition: composite_iterators.h:421
int Read() override
Read a single row.
Definition: composite_iterators.h:404
std::string name() const
Definition: composite_iterators.h:417
int64_t generation() const
Definition: composite_iterators.h:416
This is used for segregating rows in groups (e.g.
Definition: item.h:6136
After parsing, a Common Table Expression is accessed through a TABLE_LIST.
Definition: table.h:4237
An iterator that takes in a stream of rows and passes through only those that meet some criteria (i....
Definition: composite_iterators.h:76
void EndPSIBatchModeIfStarted() override
Ends performance schema batch mode, if started.
Definition: composite_iterators.h:91
int Read() override
Read a single row.
Definition: composite_iterators.cc:70
void UnlockRow() override
Definition: composite_iterators.h:94
bool Init() override
Initialize or reinitialize the iterator.
Definition: composite_iterators.h:82
unique_ptr_destroy_only< RowIterator > m_source
Definition: composite_iterators.h:97
FilterIterator(THD *thd, unique_ptr_destroy_only< RowIterator > source, Item *condition)
Definition: composite_iterators.h:78
void StartPSIBatchMode() override
Start performance schema batch mode, if supported (otherwise ignored).
Definition: composite_iterators.h:90
Item * m_condition
Definition: composite_iterators.h:98
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:86
FollowTailIterator is a special version of TableScanIterator that is used as part of WITH RECURSIVE q...
Definition: basic_row_iterators.h:465
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:802
Definition: sql_optimizer.h:125
Definition: key.h:112
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
void UnlockRow() override
Definition: composite_iterators.h:148
LimitOffsetIterator(THD *thd, unique_ptr_destroy_only< RowIterator > source, ha_rows limit, ha_rows offset, bool count_all_rows, bool reject_multiple_rows, ha_rows *skipped_rows)
Definition: composite_iterators.h:121
bool Init() override
Initialize or reinitialize the iterator.
Definition: composite_iterators.cc:95
ha_rows m_seen_rows
Definition: composite_iterators.h:156
const bool m_count_all_rows
Definition: composite_iterators.h:164
ha_rows * m_skipped_rows
Definition: composite_iterators.h:166
void EndPSIBatchModeIfStarted() override
Ends performance schema batch mode, if started.
Definition: composite_iterators.h:145
const ha_rows m_limit
Definition: composite_iterators.h:163
const ha_rows m_offset
Definition: composite_iterators.h:163
bool m_needs_offset
Whether we have OFFSET rows that we still need to skip.
Definition: composite_iterators.h:161
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:140
unique_ptr_destroy_only< RowIterator > m_source
Definition: composite_iterators.h:151
int Read() override
Read a single row.
Definition: composite_iterators.cc:109
const bool m_reject_multiple_rows
Definition: composite_iterators.h:165
void StartPSIBatchMode() override
Start performance schema batch mode, if supported (otherwise ignored).
Definition: composite_iterators.h:144
MaterializeInformationSchemaTableIterator makes sure a given I_S temporary table is materialized (fil...
Definition: composite_iterators.h:959
Item * m_condition
Definition: composite_iterators.h:985
TABLE_LIST * m_table_list
Definition: composite_iterators.h:984
void UnlockRow() override
Definition: composite_iterators.h:979
MaterializeInformationSchemaTableIterator(THD *thd, unique_ptr_destroy_only< RowIterator > table_iterator, TABLE_LIST *table_list, Item *condition)
Definition: composite_iterators.cc:1524
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:968
void EndPSIBatchModeIfStarted() override
Ends performance schema batch mode, if started.
Definition: composite_iterators.h:973
int Read() override
Read a single row.
Definition: composite_iterators.h:966
void StartPSIBatchMode() override
Start performance schema batch mode, if supported (otherwise ignored).
Definition: composite_iterators.h:972
unique_ptr_destroy_only< RowIterator > m_table_iterator
The iterator that reads from the materialized table.
Definition: composite_iterators.h:983
bool Init() override
Initialize or reinitialize the iterator.
Definition: composite_iterators.cc:1532
Handles materialization; the first call to Init() will scan the given iterator to the end,...
Definition: composite_iterators.h:450
Query_expression * m_query_expression
The query expression we are materializing.
Definition: composite_iterators.h:585
void StartPSIBatchMode() override
Start performance schema batch mode, if supported (otherwise ignored).
Definition: composite_iterators.h:550
Common_table_expr * m_cte
If we are materializing a CTE, points to it (otherwise nullptr).
Definition: composite_iterators.h:576
uint64_t m_num_materialized_rows
Definition: composite_iterators.h:614
uint64_t num_init_calls() const
Definition: composite_iterators.h:566
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:546
const ha_rows m_limit_rows
See constructor.
Definition: composite_iterators.h:603
bool doing_hash_deduplication() const
Whether we are deduplicating using a hash field on the temporary table.
Definition: composite_iterators.h:629
void keeps_own_timing
Definition: composite_iterators.h:565
bool doing_deduplication() const
Whether we are deduplicating, whether through a hash field or a regular unique index.
Definition: composite_iterators.cc:925
Mem_root_array< QueryBlock > m_query_blocks_to_materialize
Definition: composite_iterators.h:570
void AddInvalidator(const CacheInvalidatorIterator *invalidator)
Add a cache invalidator that must be checked on every Init().
Definition: composite_iterators.cc:942
uint64_t num_rows() const
Definition: composite_iterators.h:567
unique_ptr_destroy_only< RowIterator > m_table_iterator
Definition: composite_iterators.h:571
void EndPSIBatchModeIfStarted() override
Ends performance schema batch mode, if started.
Definition: composite_iterators.cc:918
bool MaterializeRecursive()
Recursive materialization happens much like regular materialization, but some steps are repeated mult...
Definition: composite_iterators.cc:710
JOIN *const m_join
See constructor.
Definition: composite_iterators.h:588
Mem_root_array< Invalidator > m_invalidators
Definition: composite_iterators.h:609
void UnlockRow() override
Definition: composite_iterators.h:555
int Read() override
Read a single row.
Definition: composite_iterators.cc:903
MaterializeIterator(THD *thd, Mem_root_array< QueryBlock > query_blocks_to_materialize, TABLE *table, unique_ptr_destroy_only< RowIterator > table_iterator, Common_table_expr *cte, Query_expression *unit, JOIN *join, int ref_slice, bool rematerialize, ha_rows limit_rows, bool reject_multiple_rows)
Definition: composite_iterators.cc:530
bool MaterializeQueryBlock(const QueryBlock &query_block, ha_rows *stored_rows)
Definition: composite_iterators.cc:822
const bool m_reject_multiple_rows
See constructor.
Definition: composite_iterators.h:600
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:597
const int m_ref_slice
The slice to set when accessing temporary table; used if anything upstream (e.g.
Definition: composite_iterators.h:593
uint64_t m_num_materializations
Definition: composite_iterators.h:613
bool Init() override
Initialize or reinitialize the iterator.
Definition: composite_iterators.cc:555
An iterator that wraps a Table_function (e.g.
Definition: composite_iterators.h:748
Table_function * m_table_function
Definition: composite_iterators.h:772
unique_ptr_destroy_only< RowIterator > m_table_iterator
Definition: composite_iterators.h:770
void StartPSIBatchMode() override
Start performance schema batch mode, if supported (otherwise ignored).
Definition: composite_iterators.h:760
void UnlockRow() override
Definition: composite_iterators.h:767
int Read() override
Read a single row.
Definition: composite_iterators.h:755
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:756
void EndPSIBatchModeIfStarted() override
Ends performance schema batch mode, if started.
Definition: composite_iterators.h:761
MaterializedTableFunctionIterator(THD *thd, Table_function *table_function, TABLE *table, unique_ptr_destroy_only< RowIterator > table_iterator)
Definition: composite_iterators.cc:1281
bool Init() override
Initialize or reinitialize the iterator.
Definition: composite_iterators.cc:1288
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:418
A simple nested loop join, taking in two iterators (left/outer and right/inner) and joining them toge...
Definition: composite_iterators.h:321
bool Init() override
Initialize or reinitialize the iterator.
Definition: composite_iterators.cc:442
int Read() override
Read a single row.
Definition: composite_iterators.cc:453
enum NestedLoopIterator::@34 m_state
void UnlockRow() override
Definition: composite_iterators.h:357
const bool m_pfs_batch_mode
Whether to use batch mode when scanning the inner iterator.
Definition: composite_iterators.h:379
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:323
unique_ptr_destroy_only< RowIterator > const m_source_inner
Definition: composite_iterators.h:375
void EndPSIBatchModeIfStarted() override
Ends performance schema batch mode, if started.
Definition: composite_iterators.h:352
const JoinType m_join_type
Definition: composite_iterators.h:376
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:346
@ END_OF_ROWS
Definition: composite_iterators.h:371
@ READING_INNER_ROWS
Definition: composite_iterators.h:370
@ NEEDS_OUTER_ROW
Definition: composite_iterators.h:368
@ READING_FIRST_INNER_ROW
Definition: composite_iterators.h:369
unique_ptr_destroy_only< RowIterator > const m_source_outer
Definition: composite_iterators.h:374
An iterator that is semantically equivalent to a semijoin NestedLoopIterator immediately followed by ...
Definition: composite_iterators.h:918
int Read() override
Read a single row.
Definition: composite_iterators.cc:1468
void UnlockRow() override
Definition: composite_iterators.h:939
KEY * m_key
Definition: composite_iterators.h:949
unique_ptr_destroy_only< RowIterator > const m_source_outer
Definition: composite_iterators.h:945
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:929
const size_t m_key_len
Definition: composite_iterators.h:951
bool m_deduplicate_against_previous_row
Definition: composite_iterators.h:952
uchar * m_key_buf
Definition: composite_iterators.h:950
unique_ptr_destroy_only< RowIterator > const m_source_inner
Definition: composite_iterators.h:946
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:1445
void EndPSIBatchModeIfStarted() override
Ends performance schema batch mode, if started.
Definition: composite_iterators.h:934
const TABLE * m_table_outer
Definition: composite_iterators.h:948
bool Init() override
Initialize or reinitialize the iterator.
Definition: composite_iterators.cc:1460
This class represents a query expression (one query block or several query blocks combined with UNION...
Definition: sql_lex.h:629
An iterator that removes consecutive rows that are the same according to a set of items (typically th...
Definition: composite_iterators.h:826
void StartPSIBatchMode() override
Start performance schema batch mode, if supported (otherwise ignored).
Definition: composite_iterators.h:840
void EndPSIBatchModeIfStarted() override
Ends performance schema batch mode, if started.
Definition: composite_iterators.h:841
void UnlockRow() override
Definition: composite_iterators.h:844
int Read() override
Read a single row.
Definition: composite_iterators.cc:1379
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:836
bool m_first_row
Definition: composite_iterators.h:849
bool Init() override
Initialize or reinitialize the iterator.
Definition: composite_iterators.cc:1374
Bounds_checked_array< Cached_item * > m_caches
Definition: composite_iterators.h:848
RemoveDuplicatesIterator(THD *thd, unique_ptr_destroy_only< RowIterator > source, JOIN *join, Item **group_items, int group_items_size)
Definition: composite_iterators.cc:1362
unique_ptr_destroy_only< RowIterator > m_source
Definition: composite_iterators.h:847
Much like RemoveDuplicatesIterator, but works on the basis of a given index (or more accurately,...
Definition: composite_iterators.h:858
bool Init() override
Initialize or reinitialize the iterator.
Definition: composite_iterators.cc:1416
void UnlockRow() override
Definition: composite_iterators.h:875
uchar * m_key_buf
Definition: composite_iterators.h:881
bool m_first_row
Definition: composite_iterators.h:883
const TABLE * m_table
Definition: composite_iterators.h:879
void StartPSIBatchMode() override
Start performance schema batch mode, if supported (otherwise ignored).
Definition: composite_iterators.h:871
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:867
const size_t m_key_len
Definition: composite_iterators.h:882
void EndPSIBatchModeIfStarted() override
Ends performance schema batch mode, if started.
Definition: composite_iterators.h:872
RemoveDuplicatesOnIndexIterator(THD *thd, unique_ptr_destroy_only< RowIterator > source, const TABLE *table, KEY *key, size_t key_len)
Definition: composite_iterators.cc:1406
KEY * m_key
Definition: composite_iterators.h:880
int Read() override
Read a single row.
Definition: composite_iterators.cc:1421
unique_ptr_destroy_only< RowIterator > m_source
Definition: composite_iterators.h:878
A context for reading through a single table using a chosen access method: index read,...
Definition: row_iterator.h:60
THD * thd() const
Definition: row_iterator.h:190
Definition: sql_executor.h:101
StreamingIterator is a minimal version of MaterializeIterator that does not actually materialize; ins...
Definition: composite_iterators.h:652
JOIN *const m_join
Definition: composite_iterators.h:687
void UnlockRow() override
Definition: composite_iterators.h:681
void StartPSIBatchMode() override
Start performance schema batch mode, if supported (otherwise ignored).
Definition: composite_iterators.h:675
int Read() override
Read a single row.
Definition: composite_iterators.cc:995
StreamingIterator(THD *thd, unique_ptr_destroy_only< RowIterator > subquery_iterator, Temp_table_param *temp_table_param, TABLE *table, bool provide_rowid, JOIN *join, int ref_slice)
Definition: composite_iterators.cc:953
Temp_table_param * m_temp_table_param
Definition: composite_iterators.h:685
const bool m_provide_rowid
Definition: composite_iterators.h:694
const int m_output_slice
Definition: composite_iterators.h:688
void EndPSIBatchModeIfStarted() override
Ends performance schema batch mode, if started.
Definition: composite_iterators.h:678
bool Init() override
Initialize or reinitialize the iterator.
Definition: composite_iterators.cc:982
int m_input_slice
Definition: composite_iterators.h:689
unique_ptr_destroy_only< RowIterator > m_subquery_iterator
Definition: composite_iterators.h:684
ha_rows m_row_number
Definition: composite_iterators.h:686
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:165
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:821
Definition: row_iterator.h:196
TABLE * table() const
Definition: row_iterator.h:208
Class representing a table function.
Definition: table_function.h:52
Object containing parameters used when creating and using temporary tables.
Definition: temp_table_param.h:98
Aggregates unsorted data into a temporary table, using update operations to keep running aggregates.
Definition: composite_iterators.h:702
void UnlockRow() override
Definition: composite_iterators.h:719
int Read() override
Read a single row.
Definition: composite_iterators.cc:1267
void EndPSIBatchModeIfStarted() override
Ends performance schema batch mode, if started.
Definition: composite_iterators.h:715
bool using_hash_key() const
Definition: composite_iterators.h:733
bool Init() override
Initialize or reinitialize the iterator.
Definition: composite_iterators.cc:1060
unique_ptr_destroy_only< RowIterator > m_table_iterator
The iterator used to scan the resulting temporary table.
Definition: composite_iterators.h:726
unique_ptr_destroy_only< RowIterator > m_subquery_iterator
The iterator we are reading rows from.
Definition: composite_iterators.h:723
Temp_table_param * m_temp_table_param
Definition: composite_iterators.h:728
JOIN *const m_join
Definition: composite_iterators.h:729
bool move_table_to_disk(int error, bool was_insert)
Move the in-memory temporary table to disk.
Definition: composite_iterators.cc:1033
const int m_ref_slice
Definition: composite_iterators.h:730
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:712
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, JOIN *join, int ref_slice)
Definition: composite_iterators.cc:1048
Like semijoin materialization, weedout works on the basic idea that a semijoin is just like an inner ...
Definition: composite_iterators.h:794
unique_ptr_destroy_only< RowIterator > m_source
Definition: composite_iterators.h:812
void EndPSIBatchModeIfStarted() override
Ends performance schema batch mode, if started.
Definition: composite_iterators.h:806
WeedoutIterator(THD *thd, unique_ptr_destroy_only< RowIterator > source, SJ_TMP_TABLE *sj, table_map tables_to_get_rowid_for)
Definition: composite_iterators.cc:1301
int Read() override
Read a single row.
Definition: composite_iterators.cc:1331
const table_map m_tables_to_get_rowid_for
Definition: composite_iterators.h:814
SJ_TMP_TABLE * m_sj
Definition: composite_iterators.h:813
void UnlockRow() override
Definition: composite_iterators.h:809
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:802
bool Init() override
Initialize or reinitialize the iterator.
Definition: composite_iterators.cc:1314
A structure that contains a list of tables for the hash join operation, and some pre-computed propert...
Definition: pack_rows.h:83
JoinType
Definition: join_type.h:27
This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical rea...
std::unique_ptr< T, Destroy_only< T > > unique_ptr_destroy_only
std::unique_ptr, but only destroying.
Definition: my_alloc.h:464
This file includes constants used by all storage engines.
my_off_t ha_rows
Definition: my_base.h:1138
Some integer typedefs for easier portability.
unsigned char uchar
Definition: my_inttypes.h:51
uint64_t table_map
Definition: my_table_map.h:29
std::string join(Container cont, const std::string &delim)
join elements of an container into a string separated by a delimiter.
Definition: string.h:144
std::vector< T, ut::allocator< T > > vector
Specialization of vector which uses allocator.
Definition: ut0new.h:2162
Generic routines for packing rows (possibly from multiple tables at the same time) into strings,...
required string key
Definition: replication_asynchronous_connection_failover.proto:59
repeated Source source
Definition: replication_asynchronous_connection_failover.proto:41
join_type
Definition: sql_opt_exec_shared.h:178
Our own string classes, used pervasively throughout the executor.
Definition: composite_iterators.h:605
int64_t generation_at_last_materialize
Definition: composite_iterators.h:607
const CacheInvalidatorIterator * iterator
Definition: composite_iterators.h:606
Definition: composite_iterators.h:452
int select_number
Used only for optimizer trace.
Definition: composite_iterators.h:457
bool is_recursive_reference
Definition: composite_iterators.h:490
unique_ptr_destroy_only< RowIterator > subquery_iterator
The iterator to read the actual rows from.
Definition: composite_iterators.h:454
bool copy_items
If set to false, the Field objects in the output row are presumed already to be filled out.
Definition: composite_iterators.h:482
JOIN * join
The JOIN that this query block represents.
Definition: composite_iterators.h:464
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:477
Temp_table_param * temp_table_param
If copy_items is true, used for copying the Field objects into the temporary table row.
Definition: composite_iterators.h:486
FollowTailIterator * recursive_reader
Definition: composite_iterators.h:497
Definition: table.h:2694
Definition: table.h:1394
Field * hash_field
Field used by unique constraint.
Definition: table.h:1497