20 #include <drizzled/error.h>
21 #include <drizzled/table_list.h>
22 #include <drizzled/item.h>
23 #include <drizzled/item/field.h>
24 #include <drizzled/nested_join.h>
25 #include <drizzled/sql_lex.h>
26 #include <drizzled/sql_select.h>
32 void TableList::set_insert_values()
36 table->insert_values.resize(table->getShare()->rec_buff_length);
40 bool TableList::is_leaf_for_name_resolution()
const
42 return is_natural_join || is_join_columns_complete || not nested_join;
48 if (table == table_to_find)
54 bool TableList::isCartesian()
const
59 bool TableList::placeholder()
61 return derived || (create && !table->getDBStat()) || !table;
69 TableList *TableList::last_leaf_for_name_resolution()
74 if (is_leaf_for_name_resolution())
78 for (cur_nested_join= nested_join;
82 cur_table_ref= &cur_nested_join->join_list.front();
88 if ((cur_table_ref->
outer_join & JOIN_TYPE_RIGHT))
112 if (is_leaf_for_name_resolution())
116 for (cur_nested_join= nested_join;
128 if (!(cur_table_ref->outer_join & JOIN_TYPE_RIGHT))
134 if (cur_table_ref->is_leaf_for_name_resolution())
137 return cur_table_ref;
142 return (select_lex ? select_lex->master_unit()->item : 0);
145 bool TableList::process_index_hints(
Table *tbl)
148 tbl->keys_in_use_for_query= tbl->keys_in_use_for_group_by=
149 tbl->keys_in_use_for_order_by= tbl->getShare()->keys_in_use;
154 key_map index_join[INDEX_HINT_FORCE + 1];
155 key_map index_order[INDEX_HINT_FORCE + 1];
156 key_map index_group[INDEX_HINT_FORCE + 1];
157 bool have_empty_use_join=
false, have_empty_use_order=
false,
158 have_empty_use_group=
false;
162 for (
int type= INDEX_HINT_IGNORE; type <= INDEX_HINT_FORCE; type++)
164 index_join[type].reset();
165 index_order[type].reset();
166 index_group[type].reset();
173 if (hint->type == INDEX_HINT_USE && !hint->key_name)
175 if (hint->clause & INDEX_HINT_MASK_JOIN)
177 index_join[hint->type].reset();
178 have_empty_use_join=
true;
180 if (hint->clause & INDEX_HINT_MASK_ORDER)
182 index_order[hint->type].reset();
183 have_empty_use_order=
true;
185 if (hint->clause & INDEX_HINT_MASK_GROUP)
187 index_group[hint->type].reset();
188 have_empty_use_group=
true;
197 uint32_t pos= tbl->getShare()->doesKeyNameExist(hint->key_name);
198 if (pos == UINT32_MAX)
200 my_error(ER_KEY_DOES_NOT_EXITS, MYF(0), hint->key_name, alias);
204 if (hint->clause & INDEX_HINT_MASK_JOIN)
205 index_join[hint->type].set(pos);
206 if (hint->clause & INDEX_HINT_MASK_ORDER)
207 index_order[hint->type].set(pos);
208 if (hint->clause & INDEX_HINT_MASK_GROUP)
209 index_group[hint->type].set(pos);
213 if ((index_join[INDEX_HINT_FORCE].any() ||
214 index_order[INDEX_HINT_FORCE].any() ||
215 index_group[INDEX_HINT_FORCE].any()) &&
216 (index_join[INDEX_HINT_USE].any() || have_empty_use_join ||
217 index_order[INDEX_HINT_USE].any() || have_empty_use_order ||
218 index_group[INDEX_HINT_USE].any() || have_empty_use_group))
220 my_error(ER_WRONG_USAGE, MYF(0), index_hint_type_name[INDEX_HINT_USE], index_hint_type_name[INDEX_HINT_FORCE]);
225 if (index_join[INDEX_HINT_FORCE].any() ||
226 index_order[INDEX_HINT_FORCE].any() ||
227 index_group[INDEX_HINT_FORCE].any())
229 tbl->force_index=
true;
230 index_join[INDEX_HINT_USE]|= index_join[INDEX_HINT_FORCE];
231 index_order[INDEX_HINT_USE]|= index_order[INDEX_HINT_FORCE];
232 index_group[INDEX_HINT_USE]|= index_group[INDEX_HINT_FORCE];
236 if (index_join[INDEX_HINT_USE].any() || have_empty_use_join)
237 tbl->keys_in_use_for_query&= index_join[INDEX_HINT_USE];
238 if (index_order[INDEX_HINT_USE].any() || have_empty_use_order)
239 tbl->keys_in_use_for_order_by&= index_order[INDEX_HINT_USE];
240 if (index_group[INDEX_HINT_USE].any() || have_empty_use_group)
241 tbl->keys_in_use_for_group_by&= index_group[INDEX_HINT_USE];
244 key_map_subtract(tbl->keys_in_use_for_query, index_join[INDEX_HINT_IGNORE]);
245 key_map_subtract(tbl->keys_in_use_for_order_by, index_order[INDEX_HINT_IGNORE]);
246 key_map_subtract(tbl->keys_in_use_for_group_by, index_group[INDEX_HINT_IGNORE]);
250 tbl->covering_keys&= tbl->keys_in_use_for_query;
259 print_join(session, str, &nested_join->join_list);
264 const char *cmp_name;
276 str->append_identifier(
str_ref(schema));
278 str->append_identifier(
str_ref(table_name));
279 cmp_name= table_name;
281 if (table_alias_charset->strcasecmp(cmp_name, alias) && alias && alias[0])
284 str->append_identifier(boost::to_lower_copy(
string(alias)));
292 str->append(STRING_WITH_LEN(
" "));
bool is_leaf_for_name_resolution() const
NestedJoin * nested_join
if the element is a nested join
void print_join(Session *session, String *str, List< TableList > *tables)
uint32_t outer_join
Which join type.