MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
opt_trace_context.h
Go to the documentation of this file.
1 /* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation; version 2 of the License.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software
14  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15 
16 #ifndef OPT_TRACE_CONTEXT_INCLUDED
17 #define OPT_TRACE_CONTEXT_INCLUDED
18 
19 #include "my_config.h" // OPTIMIZER_TRACE
20 #include "sql_array.h" // Dynamic_array
21 
29 #ifdef OPTIMIZER_TRACE
30 
31 class Opt_trace_stmt; // implementation detail local to opt_trace.cc
32 
33 
81 {
82 public:
83 
84  Opt_trace_context() : pimpl(NULL), I_S_disabled(0) {}
86 
121  bool start(bool support_I_S,
122  bool support_dbug_or_missing_priv,
123  bool end_marker, bool one_line,
124  long offset, long limit, ulong max_mem_size,
125  ulonglong features);
126 
135  void end();
136 
138  bool is_started() const
139  { return unlikely(pimpl != NULL) && pimpl->current_stmt_in_gen != NULL; }
140 
146  bool support_I_S() const;
147 
155  void set_query(const char* query, size_t length,
156  const CHARSET_INFO *charset);
157 
163  void reset();
164 
166  bool get_end_marker() const { return pimpl->end_marker; }
168  bool get_one_line() const { return pimpl->one_line; }
169 
176  static const char *flag_names[];
177 
179  enum {
180  FLAG_DEFAULT= 0,
181  FLAG_ENABLED= 1 << 0,
182  FLAG_ONE_LINE= 1 << 1
183  };
184 
196  static const char *feature_names[];
197 
199  enum feature_value {
200  GREEDY_SEARCH= 1 << 0,
201  RANGE_OPTIMIZER= 1 << 1,
202  DYNAMIC_RANGE= 1 << 2,
203  REPEATED_SUBSELECT= 1 << 3,
204  /*
205  If you add here, update feature_value of empty implementation
206  and default_features!
207  */
214  MISC= 1 << 7
215  };
216 
224  void missing_privilege();
225 
227  static const feature_value default_features;
228 
233  bool feature_enabled (feature_value f) const
234  { return unlikely(pimpl != NULL) && (pimpl->features & f); }
235 
241  Opt_trace_stmt *get_current_stmt_in_gen()
242  { return pimpl->current_stmt_in_gen; }
243 
250  const Opt_trace_stmt *get_next_stmt_for_I_S(long *got_so_far) const;
251 
253  void disable_I_S_for_this_and_children()
254  {
255  ++I_S_disabled;
256  if (unlikely(pimpl != NULL))
257  pimpl->disable_I_S_for_this_and_children();
258  }
259 
264  void restore_I_S()
265  {
266  --I_S_disabled;
267  DBUG_ASSERT(I_S_disabled >= 0);
268  if (unlikely(pimpl != NULL))
269  pimpl->restore_I_S();
270  }
271 
272 private:
273 
283  class Opt_trace_context_impl
284  {
285  public:
286  Opt_trace_context_impl() : current_stmt_in_gen(NULL),
287  features(feature_value(0)), offset(0), limit(0), since_offset_0(0)
288  {}
289 
290  void disable_I_S_for_this_and_children();
291  void restore_I_S();
292 
321  Opt_trace_stmt *current_stmt_in_gen;
322 
332  Dynamic_array<Opt_trace_stmt *> stack_of_current_stmts;
333 
343  Dynamic_array<Opt_trace_stmt *> all_stmts_for_I_S;
348  Dynamic_array<Opt_trace_stmt *> all_stmts_to_del;
349 
350  bool end_marker;
351  bool one_line;
352  feature_value features;
353  long offset;
354  long limit;
355  size_t max_mem_size;
356 
361  long since_offset_0;
362  };
363 
364  Opt_trace_context_impl *pimpl;
365 
371  int I_S_disabled;
372 
380  void purge_stmts(bool purge_all);
381 
392  size_t allowed_mem_size_for_current_stmt() const;
393 
397  Opt_trace_context& operator=(const Opt_trace_context&);
398 };
399 
400 #else /* OPTIMIZER_TRACE */
401 
404 {
405 public:
408  GREEDY_SEARCH= 1 << 0,
409  RANGE_OPTIMIZER= 1 << 1,
410  DYNAMIC_RANGE= 1 << 2,
411  REPEATED_SUBSELECT= 1 << 3,
412  MISC= 1 << 7
413  };
414  enum {
415  FLAG_DEFAULT= 0,
416  FLAG_ENABLED= 1 << 0,
417  FLAG_ONE_LINE= 1 << 1
418  };
419  static bool is_started() { return false; }
420 };
421 
422 #endif /* OPTIMIZER_TRACE */
423 
424 #endif /* OPT_TRACE_CONTEXT_INCLUDED */