MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
abstract_query_plan.h
1 /*
2  Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #ifndef ABSTRACT_QUERY_PLAN_H_INCLUDED
19 #define ABSTRACT_QUERY_PLAN_H_INCLUDED
20 
21 struct TABLE;
22 struct st_join_table;
23 typedef st_join_table JOIN_TAB;
24 class JOIN;
25 class Item;
26 class Item_field;
28 
29 #include "sql_list.h"
30 
51 namespace AQP
52 {
53  class Table_access;
54 
60  class Join_plan : public Sql_alloc
61  {
62  friend class Equal_set_iterator;
63  friend class Table_access;
64  public:
65 
66  explicit Join_plan(const JOIN* join);
67 
68  ~Join_plan();
69 
70  const Table_access* get_table_access(uint access_no) const;
71 
72  uint get_access_count() const;
73 
74  private:
79  const JOIN_TAB* const m_join_tabs;
80 
82  const uint m_access_count;
83  Table_access* m_table_accesses;
84 
85  const JOIN_TAB* get_join_tab(uint join_tab_no) const;
86 
87  // No copying.
88  Join_plan(const Join_plan&);
89  Join_plan& operator=(const Join_plan&);
90  };
91  // class Join_plan
92 
93 
101  {
102  public:
103  explicit Equal_set_iterator(Item_equal& item_equal)
104  : m_iterator(item_equal) {}
105 
106  const Item_field* next()
107  { return m_iterator++; }
108 
109  private:
113  Item_equal_iterator m_iterator;
114 
115  // No copying.
117  Equal_set_iterator& operator=(const Equal_set_iterator&);
118  };
119  // class Equal_set_iterator
120 
123  {
152  };
153 
156  {
157  JT_OUTER_JOIN,
158  JT_INNER_JOIN,
159  JT_SEMI_JOIN
160  };
161 
168  class Table_access : public Sql_alloc
169  {
170  friend class Join_plan;
171  friend inline bool equal(const Table_access*, const Table_access*);
172  public:
173 
174  const Join_plan* get_join_plan() const;
175 
177 
178  const char* get_other_access_reason() const;
179 
180  enum_join_type get_join_type(const Table_access* parent) const;
181 
182  uint get_no_of_key_fields() const;
183 
184  const Item* get_key_field(uint field_no) const;
185 
186  const KEY_PART_INFO* get_key_part_info(uint field_no) const;
187 
188  uint get_access_no() const;
189 
190  int get_index_no() const;
191 
192  TABLE* get_table() const;
193 
194  double get_fanout() const;
195 
196  Item_equal* get_item_equal(const Item_field* field_item) const;
197 
198  void dbug_print() const;
199 
200  bool uses_join_cache() const;
201 
202  bool filesort_before_join() const;
203 
204  private:
205 
207  const Join_plan* m_join_plan;
208 
210  uint m_tab_no;
211 
213  mutable enum_access_type m_access_type;
214 
218  mutable const char* m_other_access_reason;
219 
221  mutable int m_index_no;
222 
223  explicit Table_access();
224 
225  const JOIN_TAB* get_join_tab() const;
226 
227  void compute_type_and_index() const;
228 
230  Table_access(const Table_access&);
231  Table_access& operator=(const Table_access&);
232  };
233  // class Table_access
234 
240  inline const Table_access* Join_plan::get_table_access(uint access_no) const
241  {
242  DBUG_ASSERT(access_no < m_access_count);
243  return m_table_accesses + access_no;
244  }
245 
249  inline uint Join_plan::get_access_count() const
250  {
251  return m_access_count;
252  }
253 
256  {
257  return m_join_plan;
258  }
259 
262  {
263  if (m_access_type == AT_VOID)
264  compute_type_and_index();
265  return m_access_type;
266  }
267 
274  inline const char* Table_access::get_other_access_reason() const
275  {
276  if (m_access_type == AT_VOID)
277  compute_type_and_index();
278  return m_other_access_reason;
279  }
280 
285  inline int Table_access::get_index_no() const
286  {
287  if (m_access_type == AT_VOID)
288  compute_type_and_index();
289 
290  return m_index_no;
291  }
292 
297  inline uint Table_access::get_access_no() const
298  {
299  return m_tab_no;
300  }
301 
302 };
303 // namespace AQP
304 
305 #endif