00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*- 00002 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab: 00003 * 00004 * Copyright (C) 2008 Sun Microsystems, Inc. 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; version 2 of the License. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00018 */ 00019 00020 #pragma once 00021 00022 #include <drizzled/item.h> 00023 #include <drizzled/lex_string.h> 00024 #include <drizzled/sql_list.h> 00025 00026 #include <bitset> 00027 00028 namespace drizzled { 00029 00030 class NestedJoin 00031 { 00032 public: 00033 /* 00034 This constructor serves for creation of NestedJoin instances 00035 */ 00036 NestedJoin() 00037 : 00038 join_list(), 00039 used_tables(), 00040 not_null_tables(), 00041 first_nested(NULL), 00042 counter_(0), 00043 nj_map(), 00044 sj_depends_on(), 00045 sj_corr_tables(), 00046 sj_outer_expr_list() 00047 { } 00048 00049 /* list of elements in the nested join */ 00050 List<TableList> join_list; 00051 00052 /* bitmap of tables in the nested join */ 00053 table_map used_tables; 00054 00055 /* tables that rejects nulls */ 00056 table_map not_null_tables; 00057 00058 /* the first nested table in the plan */ 00059 JoinTable *first_nested; 00060 00061 /* 00062 Used to count tables in the nested join in 2 isolated places: 00063 1. In make_outerjoin_info(). 00064 2. check_interleaving_with_nj/restore_prev_nj_state (these are called 00065 by the join optimizer. 00066 Before each use the counters are zeroed by reset_nj_counters. 00067 */ 00068 00069 uint32_t counter_; 00070 00071 /* Bit used to identify this nested join*/ 00072 std::bitset<64> nj_map; 00073 00074 /* 00075 True if this join nest node is completely covered by the query execution 00076 plan. This means two things. 00077 00078 1. All tables on its @c join_list are covered by the plan. 00079 00080 2. All child join nest nodes are fully covered. 00081 */ 00082 00083 bool is_fully_covered() const { return join_list.size() == counter_; } 00084 00085 /* To get the table_map sj_depends_on */ 00086 table_map getSjDependsOn() const 00087 { 00088 return sj_depends_on; 00089 } 00090 00091 /* To set the table_map sj_depends_on */ 00092 void setSjDependsOn(const table_map &in_sj_depends_on) 00093 { 00094 sj_depends_on= in_sj_depends_on; 00095 } 00096 00097 /* To get the table_map sj_corr_tables */ 00098 table_map getSjCorrTables() const 00099 { 00100 return sj_corr_tables; 00101 } 00102 00103 /* To set the table_map sj_corr_tables */ 00104 void setSjCorrTables(const table_map &in_sj_corr_tables) 00105 { 00106 sj_corr_tables= in_sj_corr_tables; 00107 } 00108 00109 /* To get the List sj_outer_expr_list */ 00110 const List<Item>& getSjOuterExprList() const 00111 { 00112 return sj_outer_expr_list; 00113 } 00114 00115 /* To set the List sj_outer_expr_list */ 00116 void setSjOuterExprList(const List<Item> &in_sj_outer_expr_list) 00117 { 00118 sj_outer_expr_list= in_sj_outer_expr_list; 00119 } 00120 00121 private: 00122 /* 00123 (Valid only for semi-join nests) Bitmap of tables outside the semi-join 00124 that are used within the semi-join's ON condition. 00125 */ 00126 table_map sj_depends_on; 00127 00128 /* Outer non-trivially correlated tables */ 00129 table_map sj_corr_tables; 00130 00131 List<Item> sj_outer_expr_list; 00132 00133 }; 00134 00135 } /* namespace drizzled */ 00136