~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table_list.cc

mergeĀ lp:~hingo/drizzle/drizzle-auth_ldap-fix-and-docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2009 Sun Microsystems
 
1
/* Copyright (C) 2009 Sun Microsystems, Inc.
2
2
 
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 */
15
15
 
16
 
#include "config.h"
 
16
#include <config.h>
17
17
 
18
18
#include <string>
19
19
 
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>
28
27
 
29
28
using namespace std;
30
29
 
31
 
namespace drizzled
32
 
{
33
 
 
34
 
class Item;
35
 
class Item_field;
36
 
 
37
 
bool TableList::set_insert_values(memory::Root *)
 
30
namespace drizzled {
 
31
 
 
32
void TableList::set_insert_values()
38
33
{
39
34
  if (table)
40
35
  {
41
36
    table->insert_values.resize(table->getShare()->rec_buff_length);
42
37
  }
43
 
 
44
 
  return false;
45
38
}
46
39
 
47
 
bool TableList::is_leaf_for_name_resolution()
 
40
bool TableList::is_leaf_for_name_resolution() const
48
41
{
49
 
  return (is_natural_join || is_join_columns_complete || !nested_join);
 
42
  return is_natural_join || is_join_columns_complete || not nested_join;
50
43
}
51
44
 
52
45
TableList *TableList::find_underlying_table(Table *table_to_find)
76
69
TableList *TableList::last_leaf_for_name_resolution()
77
70
{
78
71
  TableList *cur_table_ref= this;
79
 
  nested_join_st *cur_nested_join;
 
72
  NestedJoin *cur_nested_join;
80
73
 
81
74
  if (is_leaf_for_name_resolution())
82
75
    return this;
86
79
       cur_nested_join;
87
80
       cur_nested_join= cur_table_ref->nested_join)
88
81
  {
89
 
    cur_table_ref= cur_nested_join->join_list.head();
 
82
    cur_table_ref= &cur_nested_join->join_list.front();
90
83
    /*
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
94
87
    */
95
88
    if ((cur_table_ref->outer_join & JOIN_TYPE_RIGHT))
96
89
    {
97
 
      List_iterator_fast<TableList> it(cur_nested_join->join_list);
 
90
      List<TableList>::iterator it(cur_nested_join->join_list.begin());
98
91
      TableList *next;
99
92
      cur_table_ref= it++;
100
93
      while ((next= it++))
114
107
TableList *TableList::first_leaf_for_name_resolution()
115
108
{
116
109
  TableList *cur_table_ref= NULL;
117
 
  nested_join_st *cur_nested_join;
 
110
  NestedJoin *cur_nested_join;
118
111
 
119
112
  if (is_leaf_for_name_resolution())
120
113
    return this;
124
117
       cur_nested_join;
125
118
       cur_nested_join= cur_table_ref->nested_join)
126
119
  {
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++;
129
122
    /*
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];
164
 
    Index_hint *hint;
165
 
    int type;
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());
169
160
 
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++)
172
163
    {
173
164
      index_join[type].reset();
174
165
      index_order[type].reset();
176
167
    }
177
168
 
178
169
    /* iterate over the hints list */
179
 
    while ((hint= iter++))
 
170
    while (Index_hint* hint= iter++)
180
171
    {
181
 
      uint32_t pos= 0;
182
 
 
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)
185
174
      {
186
175
        if (hint->clause & INDEX_HINT_MASK_JOIN)
187
176
        {
205
194
        Check if an index with the given name exists and get his offset in
206
195
        the keys bitmask for the table
207
196
      */
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)
209
199
      {
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);
211
201
        return 1;
212
202
      }
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))
229
219
    {
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]);
232
221
      return 1;
233
222
    }
234
223
 
262
251
  return 0;
263
252
}
264
253
 
265
 
void TableList::print(Session *session, String *str, enum_query_type query_type)
 
254
void TableList::print(Session *session, String *str)
266
255
{
267
256
  if (nested_join)
268
257
  {
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(')');
272
261
  }
273
262
  else
277
266
    {
278
267
      // A derived table
279
268
      str->append('(');
280
 
      derived->print(str, query_type);
 
269
      derived->print(str);
281
270
      str->append(')');
282
271
      cmp_name= "";                               // Force printing of alias
283
272
    }
284
273
    else
285
274
    {
286
275
      // A normal table
287
 
      {
288
 
        str->append_identifier(db, db_length);
289
 
        str->append('.');
290
 
      }
291
 
      str->append_identifier(table_name, table_name_length);
 
276
      str->append_identifier(str_ref(schema));
 
277
      str->append('.');
 
278
      str->append_identifier(str_ref(table_name));
292
279
      cmp_name= table_name;
293
280
    }
294
 
    if (my_strcasecmp(table_alias_charset, cmp_name, alias))
 
281
    if (table_alias_charset->strcasecmp(cmp_name, alias) && alias && alias[0])
295
282
    {
296
 
 
297
 
      if (alias && alias[0])
298
 
      {
299
 
        str->append(' ');
300
 
 
301
 
        string t_alias(alias);
302
 
        transform(t_alias.begin(), t_alias.end(),
303
 
                  t_alias.begin(), ::tolower);
304
 
 
305
 
        str->append_identifier(t_alias.c_str(), t_alias.length());
306
 
      }
307
 
 
 
283
      str->append(' ');
 
284
      str->append_identifier(boost::to_lower_copy(string(alias)));
308
285
    }
309
286
 
310
287
    if (index_hints)
311
288
    {
312
 
      List_iterator<Index_hint> it(*index_hints);
313
 
      Index_hint *hint;
314
 
 
315
 
      while ((hint= it++))
 
289
      List<Index_hint>::iterator it(index_hints->begin());
 
290
      while (Index_hint* hint= it++)
316
291
      {
317
 
        str->append (STRING_WITH_LEN(" "));
318
 
        hint->print (session, str);
 
292
        str->append(STRING_WITH_LEN(" "));
 
293
        hint->print(*str);
319
294
      }
320
295
    }
321
296
  }