My Project
opt_trace_context.h
Go to the documentation of this file.
00001 /* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
00002 
00003    This program is free software; you can redistribute it and/or modify
00004    it under the terms of the GNU General Public License as published by
00005    the Free Software Foundation; version 2 of the License.
00006 
00007    This program is distributed in the hope that it will be useful,
00008    but WITHOUT ANY WARRANTY; without even the implied warranty of
00009    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010    GNU General Public License for more details.
00011 
00012    You should have received a copy of the GNU General Public License
00013    along with this program; if not, write to the Free Software
00014    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA  */
00015 
00016 #ifndef OPT_TRACE_CONTEXT_INCLUDED
00017 #define OPT_TRACE_CONTEXT_INCLUDED
00018 
00019 #include "my_config.h"  // OPTIMIZER_TRACE
00020 #include "sql_array.h"  // Dynamic_array
00021 
00029 #ifdef OPTIMIZER_TRACE
00030 
00031 class Opt_trace_stmt;           // implementation detail local to opt_trace.cc
00032 
00033 
00080 class Opt_trace_context
00081 {
00082 public:
00083 
00084   Opt_trace_context() : pimpl(NULL), I_S_disabled(0) {}
00085   ~Opt_trace_context();
00086 
00121   bool start(bool support_I_S,
00122              bool support_dbug_or_missing_priv,
00123              bool end_marker, bool one_line,
00124              long offset, long limit, ulong max_mem_size,
00125              ulonglong features);
00126 
00135   void end();
00136 
00138   bool is_started() const
00139   { return unlikely(pimpl != NULL) && pimpl->current_stmt_in_gen != NULL; }
00140 
00146   bool support_I_S() const;
00147 
00155   void set_query(const char* query, size_t length,
00156                  const CHARSET_INFO *charset);
00157 
00163   void reset();
00164 
00166   bool get_end_marker() const { return pimpl->end_marker; }
00168   bool get_one_line() const { return pimpl->one_line; }
00169 
00176   static const char *flag_names[];
00177 
00179   enum {
00180     FLAG_DEFAULT=    0,
00181     FLAG_ENABLED=    1 << 0,
00182     FLAG_ONE_LINE=   1 << 1
00183   };
00184 
00196   static const char *feature_names[];
00197 
00199   enum feature_value {
00200     GREEDY_SEARCH=      1 << 0,
00201     RANGE_OPTIMIZER=    1 << 1,
00202     DYNAMIC_RANGE=      1 << 2,
00203     REPEATED_SUBSELECT= 1 << 3,
00204     /*
00205       If you add here, update feature_value of empty implementation
00206       and default_features!
00207     */
00214     MISC=               1 << 7
00215   };
00216 
00224   void missing_privilege();
00225 
00227   static const feature_value default_features;
00228 
00233   bool feature_enabled (feature_value f) const
00234   { return unlikely(pimpl != NULL) && (pimpl->features & f); }
00235 
00241   Opt_trace_stmt *get_current_stmt_in_gen()
00242   { return pimpl->current_stmt_in_gen; }
00243 
00250   const Opt_trace_stmt *get_next_stmt_for_I_S(long *got_so_far) const;
00251 
00253   void disable_I_S_for_this_and_children()
00254   {
00255     ++I_S_disabled;
00256     if (unlikely(pimpl != NULL))
00257       pimpl->disable_I_S_for_this_and_children();
00258   }
00259 
00264   void restore_I_S()
00265   {
00266     --I_S_disabled;
00267     DBUG_ASSERT(I_S_disabled >= 0);
00268     if (unlikely(pimpl != NULL))
00269       pimpl->restore_I_S();
00270   }
00271 
00272 private:
00273 
00283   class Opt_trace_context_impl
00284   {
00285   public:
00286     Opt_trace_context_impl() : current_stmt_in_gen(NULL),
00287       features(feature_value(0)), offset(0), limit(0), since_offset_0(0)
00288     {}
00289 
00290     void disable_I_S_for_this_and_children();
00291     void restore_I_S();
00292 
00321     Opt_trace_stmt *current_stmt_in_gen;
00322 
00332     Dynamic_array<Opt_trace_stmt *> stack_of_current_stmts;
00333 
00343     Dynamic_array<Opt_trace_stmt *> all_stmts_for_I_S;
00348     Dynamic_array<Opt_trace_stmt *> all_stmts_to_del;
00349 
00350     bool end_marker;        
00351     bool one_line;
00352     feature_value features;
00353     long offset;
00354     long limit;
00355     size_t max_mem_size;
00356 
00361     long since_offset_0;
00362   };
00363 
00364   Opt_trace_context_impl *pimpl;     
00365 
00371   int I_S_disabled;
00372 
00380   void purge_stmts(bool purge_all);
00381 
00392   size_t allowed_mem_size_for_current_stmt() const;
00393 
00395   Opt_trace_context(const Opt_trace_context&);
00397   Opt_trace_context& operator=(const Opt_trace_context&);
00398 };
00399 
00400 #else /* OPTIMIZER_TRACE */
00401 
00403 class Opt_trace_context
00404 {
00405 public:
00407   enum feature_value {
00408     GREEDY_SEARCH=      1 << 0,
00409     RANGE_OPTIMIZER=    1 << 1,
00410     DYNAMIC_RANGE=      1 << 2,
00411     REPEATED_SUBSELECT= 1 << 3,
00412     MISC=               1 << 7
00413   };
00414   enum {
00415     FLAG_DEFAULT=    0,
00416     FLAG_ENABLED=    1 << 0,
00417     FLAG_ONE_LINE=   1 << 1
00418   };
00419   static bool is_started() { return false; }
00420 };
00421 
00422 #endif /* OPTIMIZER_TRACE */
00423 
00424 #endif /* OPT_TRACE_CONTEXT_INCLUDED */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines