1
/* Copyright (C) 2009 Sun Microsystems
1
/* Copyright (C) 2009 Sun Microsystems, Inc.
3
3
This program is free software; you can redistribute it and/or modify
4
4
it under the terms of the GNU General Public License as published by
13
13
along with this program; if not, write to the Free Software
14
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
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"
27
#include "drizzled/strfunc.h"
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>
29
28
using namespace std;
37
bool TableList::set_insert_values(memory::Root *)
32
void TableList::set_insert_values()
41
36
table->insert_values.resize(table->getShare()->rec_buff_length);
47
bool TableList::is_leaf_for_name_resolution()
40
bool TableList::is_leaf_for_name_resolution() const
49
return (is_natural_join || is_join_columns_complete || !nested_join);
42
return is_natural_join || is_join_columns_complete || not nested_join;
52
45
TableList *TableList::find_underlying_table(Table *table_to_find)
76
69
TableList *TableList::last_leaf_for_name_resolution()
78
71
TableList *cur_table_ref= this;
79
nested_join_st *cur_nested_join;
72
NestedJoin *cur_nested_join;
81
74
if (is_leaf_for_name_resolution())
87
80
cur_nested_join= cur_table_ref->nested_join)
89
cur_table_ref= cur_nested_join->join_list.head();
82
cur_table_ref= &cur_nested_join->join_list.front();
91
84
If the current nested is a RIGHT JOIN, the operands in
92
85
'join_list' are in reverse order, thus the last operand is in the
114
107
TableList *TableList::first_leaf_for_name_resolution()
116
109
TableList *cur_table_ref= NULL;
117
nested_join_st *cur_nested_join;
110
NestedJoin *cur_nested_join;
119
112
if (is_leaf_for_name_resolution())
125
118
cur_nested_join= cur_table_ref->nested_join)
127
List_iterator_fast<TableList> it(cur_nested_join->join_list);
120
List<TableList>::iterator it(cur_nested_join->join_list.begin());
128
121
cur_table_ref= it++;
130
123
If the current nested join is a RIGHT JOIN, the operands in
161
154
key_map index_join[INDEX_HINT_FORCE + 1];
162
155
key_map index_order[INDEX_HINT_FORCE + 1];
163
156
key_map index_group[INDEX_HINT_FORCE + 1];
166
157
bool have_empty_use_join= false, have_empty_use_order= false,
167
158
have_empty_use_group= false;
168
List_iterator <Index_hint> iter(*index_hints);
159
List_iterator <Index_hint> iter(index_hints->begin());
170
161
/* initialize temporary variables used to collect hints of each kind */
171
for (type= INDEX_HINT_IGNORE; type <= INDEX_HINT_FORCE; type++)
162
for (int type= INDEX_HINT_IGNORE; type <= INDEX_HINT_FORCE; type++)
173
164
index_join[type].reset();
174
165
index_order[type].reset();
178
169
/* iterate over the hints list */
179
while ((hint= iter++))
170
while (Index_hint* hint= iter++)
183
172
/* process empty USE INDEX () */
184
if (hint->type == INDEX_HINT_USE && !hint->key_name.str)
173
if (hint->type == INDEX_HINT_USE && !hint->key_name)
186
175
if (hint->clause & INDEX_HINT_MASK_JOIN)
205
194
Check if an index with the given name exists and get his offset in
206
195
the keys bitmask for the table
208
if (not tbl->getShare()->doesKeyNameExist(hint->key_name.str, hint->key_name.length, pos))
197
uint32_t pos= tbl->getShare()->doesKeyNameExist(hint->key_name);
198
if (pos == UINT32_MAX)
210
my_error(ER_KEY_DOES_NOT_EXITS, MYF(0), hint->key_name.str, alias);
200
my_error(ER_KEY_DOES_NOT_EXITS, MYF(0), hint->key_name, alias);
213
203
/* add to the appropriate clause mask */
227
217
index_order[INDEX_HINT_USE].any() || have_empty_use_order ||
228
218
index_group[INDEX_HINT_USE].any() || have_empty_use_group))
230
my_error(ER_WRONG_USAGE, MYF(0), index_hint_type_name[INDEX_HINT_USE],
231
index_hint_type_name[INDEX_HINT_FORCE]);
220
my_error(ER_WRONG_USAGE, MYF(0), index_hint_type_name[INDEX_HINT_USE], index_hint_type_name[INDEX_HINT_FORCE]);
265
void TableList::print(Session *session, String *str, enum_query_type query_type)
254
void TableList::print(Session *session, String *str)
269
258
str->append('(');
270
print_join(session, str, &nested_join->join_list, query_type);
259
print_join(session, str, &nested_join->join_list);
271
260
str->append(')');
278
267
// A derived table
279
268
str->append('(');
280
derived->print(str, query_type);
281
270
str->append(')');
282
271
cmp_name= ""; // Force printing of alias
286
275
// A normal table
288
str->append_identifier(db, db_length);
291
str->append_identifier(table_name, table_name_length);
276
str->append_identifier(str_ref(schema));
278
str->append_identifier(str_ref(table_name));
292
279
cmp_name= table_name;
294
if (my_strcasecmp(table_alias_charset, cmp_name, alias))
281
if (table_alias_charset->strcasecmp(cmp_name, alias) && alias && alias[0])
297
if (alias && alias[0])
301
string t_alias(alias);
302
transform(t_alias.begin(), t_alias.end(),
303
t_alias.begin(), ::tolower);
305
str->append_identifier(t_alias.c_str(), t_alias.length());
284
str->append_identifier(boost::to_lower_copy(string(alias)));
312
List_iterator<Index_hint> it(*index_hints);
289
List<Index_hint>::iterator it(index_hints->begin());
290
while (Index_hint* hint= it++)
317
str->append (STRING_WITH_LEN(" "));
318
hint->print (session, str);
292
str->append(STRING_WITH_LEN(" "));