My Project
abstract_query_plan.h
00001 /*
00002    Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
00003 
00004    This program is free software; you can redistribute it and/or modify
00005    it under the terms of the GNU General Public License as published by
00006    the Free Software Foundation; version 2 of the License.
00007 
00008    This program is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011    GNU General Public License for more details.
00012 
00013    You should have received a copy of the GNU General Public License
00014    along with this program; if not, write to the Free Software
00015    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
00016 */
00017 
00018 #ifndef ABSTRACT_QUERY_PLAN_H_INCLUDED
00019 #define ABSTRACT_QUERY_PLAN_H_INCLUDED
00020 
00021 struct TABLE;
00022 struct st_join_table;
00023 typedef st_join_table JOIN_TAB;
00024 class JOIN;
00025 class Item;
00026 class Item_field;
00027 class Item_equal_iterator;
00028 
00029 #include "sql_list.h"
00030 
00051 namespace AQP
00052 {
00053   class Table_access;
00054 
00060   class Join_plan : public Sql_alloc
00061   {
00062     friend class Equal_set_iterator;
00063     friend class Table_access;
00064   public:
00065 
00066     explicit Join_plan(const JOIN* join);
00067 
00068     ~Join_plan();
00069 
00070     const Table_access* get_table_access(uint access_no) const;
00071 
00072     uint get_access_count() const;
00073 
00074   private:
00079     const JOIN_TAB* const m_join_tabs;
00080 
00082     const uint m_access_count;
00083     Table_access* m_table_accesses;
00084 
00085     const JOIN_TAB* get_join_tab(uint join_tab_no) const;
00086 
00087     // No copying.
00088     Join_plan(const Join_plan&);
00089     Join_plan& operator=(const Join_plan&);
00090   }; 
00091   // class Join_plan
00092 
00093 
00100   class Equal_set_iterator : public Sql_alloc
00101   {
00102   public:
00103     explicit Equal_set_iterator(Item_equal& item_equal)
00104     : m_iterator(item_equal) {}
00105 
00106     const Item_field* next()
00107     { return m_iterator++; }
00108 
00109   private:
00113     Item_equal_iterator m_iterator;
00114 
00115     // No copying.
00116     Equal_set_iterator(const Equal_set_iterator&);
00117     Equal_set_iterator& operator=(const Equal_set_iterator&);
00118   }; 
00119   // class Equal_set_iterator
00120 
00122   enum enum_access_type
00123   {
00125     AT_VOID,
00127     AT_FIXED,
00129     AT_PRIMARY_KEY,
00131     AT_UNIQUE_KEY,
00133     AT_ORDERED_INDEX_SCAN,
00135     AT_MULTI_PRIMARY_KEY,
00137     AT_MULTI_UNIQUE_KEY,
00142     AT_MULTI_MIXED,
00144     AT_TABLE_SCAN,
00146     AT_UNDECIDED,
00151     AT_OTHER
00152   };
00153 
00155   enum enum_join_type
00156   {
00157     JT_OUTER_JOIN,
00158     JT_INNER_JOIN,
00159     JT_SEMI_JOIN
00160   };
00161 
00168   class Table_access : public Sql_alloc
00169   {
00170     friend class Join_plan;
00171     friend inline bool equal(const Table_access*, const Table_access*);
00172   public:
00173 
00174     const Join_plan* get_join_plan() const;
00175 
00176     enum_access_type get_access_type() const;
00177 
00178     const char* get_other_access_reason() const;
00179 
00180     enum_join_type get_join_type(const Table_access* parent) const;
00181 
00182     uint get_no_of_key_fields() const;
00183 
00184     const Item* get_key_field(uint field_no) const;
00185 
00186     const KEY_PART_INFO* get_key_part_info(uint field_no) const;
00187 
00188     uint get_access_no() const;
00189 
00190     int get_index_no() const;
00191 
00192     TABLE* get_table() const;
00193 
00194     double get_fanout() const;
00195 
00196     Item_equal* get_item_equal(const Item_field* field_item) const;
00197 
00198     void dbug_print() const;
00199 
00200     bool uses_join_cache() const;
00201 
00202     bool filesort_before_join() const;
00203 
00204   private:
00205 
00207     const Join_plan* m_join_plan;
00208 
00210     uint m_tab_no;
00211 
00213     mutable enum_access_type m_access_type;
00214 
00218     mutable const char* m_other_access_reason;
00219 
00221     mutable int m_index_no;
00222 
00223     explicit Table_access();
00224 
00225     const JOIN_TAB* get_join_tab() const;
00226 
00227     void compute_type_and_index() const;
00228 
00230     Table_access(const Table_access&);
00231     Table_access& operator=(const Table_access&);
00232   }; 
00233   // class Table_access
00234 
00240   inline const Table_access* Join_plan::get_table_access(uint access_no) const
00241   {
00242     DBUG_ASSERT(access_no < m_access_count);
00243     return m_table_accesses + access_no;
00244   }
00245 
00249   inline uint Join_plan::get_access_count() const
00250   { 
00251     return m_access_count;
00252   }
00253 
00255   inline const Join_plan* Table_access::get_join_plan() const
00256   {
00257     return m_join_plan;
00258   }
00259 
00261   inline enum_access_type Table_access::get_access_type() const
00262   {
00263     if (m_access_type == AT_VOID)
00264       compute_type_and_index();
00265     return m_access_type;
00266   }
00267 
00274   inline const char* Table_access::get_other_access_reason() const
00275   {
00276     if (m_access_type == AT_VOID)
00277       compute_type_and_index();
00278     return m_other_access_reason;
00279   }
00280 
00285   inline int Table_access::get_index_no() const
00286   {
00287     if (m_access_type == AT_VOID)
00288       compute_type_and_index();
00289         
00290     return m_index_no;
00291   }
00292 
00297   inline uint Table_access::get_access_no() const
00298   { 
00299     return m_tab_no;
00300   }
00301 
00302 }; 
00303 // namespace AQP
00304 
00305 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines