~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_lex.cc

  • Committer: Mark Atwood
  • Date: 2012-01-03 02:42:00 UTC
  • mfrom: (2482.1.2 drizzle-build)
  • Revision ID: me@mark.atwood.name-20120103024200-2kjnoze027o3dnwy
mergeĀ lp:~brianaker/drizzle/icc-warnings

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
15
15
 
16
16
 
17
17
/* A lexical scanner on a temporary buffer with a yacc interface */
18
18
 
19
 
#define MYSQL_LEX 1
20
 
#include "mysql_priv.h"
21
 
#include "item_create.h"
22
 
#include <m_ctype.h>
23
 
#include <hash.h>
24
 
 
25
 
static int lex_one_token(void *arg, void *yythd);
26
 
 
27
 
/*
28
 
  We are using pointer to this variable for distinguishing between assignment
29
 
  to NEW row field (when parsing trigger definition) and structured variable.
30
 
*/
31
 
 
32
 
sys_var *trg_new_row_fake_var= (sys_var*) 0x01;
 
19
#include <config.h>
 
20
 
 
21
#define DRIZZLE_LEX 1
 
22
 
 
23
#include <drizzled/sql_reserved_words.h>
 
24
 
 
25
#include <drizzled/configmake.h>
 
26
#include <drizzled/item/num.h>
 
27
#include <drizzled/error.h>
 
28
#include <drizzled/session.h>
 
29
#include <drizzled/sql_base.h>
 
30
#include <drizzled/lookup_symbol.h>
 
31
#include <drizzled/index_hint.h>
 
32
#include <drizzled/select_result.h>
 
33
#include <drizzled/item/subselect.h>
 
34
#include <drizzled/statement.h>
 
35
#include <drizzled/sql_lex.h>
 
36
#include <drizzled/plugin.h>
 
37
#include <drizzled/lex_input_stream.h>
 
38
 
 
39
#include <cstdio>
 
40
#include <ctype.h>
 
41
 
 
42
#include <drizzled/message/alter_table.pb.h>
 
43
 
 
44
union ParserType;
 
45
 
 
46
using namespace std;
 
47
 
 
48
/* Stay outside of the namespace because otherwise bison goes nuts */
 
49
int base_sql_lex(ParserType *arg, drizzled::Session *yysession);
 
50
 
 
51
namespace drizzled {
 
52
 
 
53
static int lex_one_token(ParserType *arg, drizzled::Session *yysession);
33
54
 
34
55
/**
35
 
  LEX_STRING constant for null-string to be used in parser and other places.
36
 
*/
37
 
const LEX_STRING null_lex_str= {NULL, 0};
38
 
 
39
 
/* Longest standard keyword name */
40
 
 
41
 
#define TOCK_NAME_LENGTH 24
42
 
 
43
 
/*
44
 
  The following data is based on the latin1 character set, and is only
45
 
  used when comparing keywords
46
 
*/
47
 
 
48
 
static uchar to_upper_lex[]=
49
 
{
50
 
    0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
51
 
   16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
52
 
   32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
53
 
   48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
54
 
   64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
55
 
   80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
56
 
   96, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
57
 
   80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,123,124,125,126,127,
58
 
  128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
59
 
  144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
60
 
  160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
61
 
  176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
62
 
  192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
63
 
  208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
64
 
  192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
65
 
  208,209,210,211,212,213,214,247,216,217,218,219,220,221,222,255
66
 
};
67
 
 
68
 
/* 
69
 
  Names of the index hints (for error messages). Keep in sync with 
70
 
  index_hint_type 
71
 
*/
72
 
 
73
 
const char * index_hint_type_name[] =
74
 
{
75
 
  "IGNORE INDEX", 
76
 
  "USE INDEX", 
77
 
  "FORCE INDEX"
78
 
};
79
 
 
80
 
inline int lex_casecmp(const char *s, const char *t, uint len)
81
 
{
82
 
  while (len-- != 0 &&
83
 
         to_upper_lex[(uchar) *s++] == to_upper_lex[(uchar) *t++]) ;
84
 
  return (int) len+1;
85
 
}
86
 
 
87
 
#include <lex_hash.h>
88
 
 
89
 
 
90
 
void lex_init(void)
91
 
{
92
 
  uint i;
93
 
  for (i=0 ; i < array_elements(symbols) ; i++)
94
 
    symbols[i].length=(uchar) strlen(symbols[i].name);
95
 
  for (i=0 ; i < array_elements(sql_functions) ; i++)
96
 
    sql_functions[i].length=(uchar) strlen(sql_functions[i].name);
97
 
 
98
 
  return;
99
 
}
100
 
 
101
 
 
102
 
void lex_free(void)
103
 
{                                       // Call this when daemon ends
104
 
  return;
105
 
}
106
 
 
107
 
 
108
 
void
109
 
st_parsing_options::reset()
110
 
{
111
 
  allows_variable= true;
112
 
  allows_select_into= true;
113
 
  allows_select_procedure= true;
114
 
  allows_derived= true;
115
 
}
116
 
 
117
 
Lex_input_stream::Lex_input_stream(THD *thd,
 
56
  save order by and tables in own lists.
 
57
*/
 
58
static void add_to_list(Session *session, SQL_LIST &list, Item *item, bool asc)
 
59
{
 
60
  Order* order = new (session->mem) Order;
 
61
  order->item_ptr= item;
 
62
  order->item= &order->item_ptr;
 
63
  order->asc = asc;
 
64
  order->free_me=0;
 
65
  order->used=0;
 
66
  order->counter_used= 0;
 
67
  list.link_in_list((unsigned char*) order, (unsigned char**) &order->next);
 
68
}
 
69
 
 
70
Lex_input_stream::Lex_input_stream(Session *session,
118
71
                                   const char* buffer,
119
 
                                   unsigned int length)
120
 
: m_thd(thd),
 
72
                                   unsigned int length) :
 
73
  m_session(session),
121
74
  yylineno(1),
122
75
  yytoklen(0),
123
76
  yylval(NULL),
137
90
  m_body_utf8(NULL),
138
91
  m_cpp_utf8_processed_ptr(NULL),
139
92
  next_state(MY_LEX_START),
140
 
  found_semicolon(NULL),
141
93
  ignore_space(1),
142
 
  stmt_prepare_mode(false),
143
 
  in_comment(NO_COMMENT),
144
 
  m_underscore_cs(NULL)
 
94
  in_comment(NO_COMMENT)
145
95
{
146
 
  m_cpp_buf= (char*) thd->alloc(length + 1);
 
96
  m_cpp_buf= (char*) session->mem.alloc(length + 1);
147
97
  m_cpp_ptr= m_cpp_buf;
148
98
}
149
99
 
150
 
Lex_input_stream::~Lex_input_stream()
151
 
{}
152
 
 
153
 
/**
154
 
  The operation is called from the parser in order to
155
 
  1) designate the intention to have utf8 body;
156
 
  1) Indicate to the lexer that we will need a utf8 representation of this
157
 
     statement;
158
 
  2) Determine the beginning of the body.
159
 
 
160
 
  @param thd        Thread context.
161
 
  @param begin_ptr  Pointer to the start of the body in the pre-processed
162
 
                    buffer.
163
 
*/
164
 
 
165
 
void Lex_input_stream::body_utf8_start(THD *thd, const char *begin_ptr)
166
 
{
167
 
  assert(begin_ptr);
168
 
  assert(m_cpp_buf <= begin_ptr && begin_ptr <= m_cpp_buf + m_buf_length);
169
 
 
170
 
  uint body_utf8_length=
171
 
    (m_buf_length / thd->variables.character_set_client->mbminlen) *
172
 
    my_charset_utf8_bin.mbmaxlen;
173
 
 
174
 
  m_body_utf8= (char *) thd->alloc(body_utf8_length + 1);
175
 
  m_body_utf8_ptr= m_body_utf8;
176
 
  *m_body_utf8_ptr= 0;
177
 
 
178
 
  m_cpp_utf8_processed_ptr= begin_ptr;
179
 
}
180
 
 
181
100
/**
182
101
  @brief The operation appends unprocessed part of pre-processed buffer till
183
102
  the given pointer (ptr) and sets m_cpp_utf8_processed_ptr to end_ptr.
198
117
                  m_cpp_utf8_processed_ptr will be set in the end of the
199
118
                  operation.
200
119
*/
201
 
 
202
 
void Lex_input_stream::body_utf8_append(const char *ptr,
203
 
                                        const char *end_ptr)
 
120
void Lex_input_stream::body_utf8_append(const char *ptr, const char *end_ptr)
204
121
{
205
122
  assert(m_cpp_buf <= ptr && ptr <= m_cpp_buf + m_buf_length);
206
123
  assert(m_cpp_buf <= end_ptr && end_ptr <= m_cpp_buf + m_buf_length);
227
144
  @param ptr  Pointer in the pre-processed buffer, which specifies the end
228
145
              of the chunk, which should be appended to the utf8 body.
229
146
*/
230
 
 
231
147
void Lex_input_stream::body_utf8_append(const char *ptr)
232
148
{
233
149
  body_utf8_append(ptr, ptr);
237
153
  The operation converts the specified text literal to the utf8 and appends
238
154
  the result to the utf8-body.
239
155
 
240
 
  @param thd      Thread context.
 
156
  @param session      Thread context.
241
157
  @param txt      Text literal.
242
158
  @param txt_cs   Character set of the text literal.
243
159
  @param end_ptr  Pointer in the pre-processed buffer, to which
244
160
                  m_cpp_utf8_processed_ptr will be set in the end of the
245
161
                  operation.
246
162
*/
247
 
 
248
 
void Lex_input_stream::body_utf8_append_literal(THD *thd,
249
 
                                                const LEX_STRING *txt,
250
 
                                                CHARSET_INFO *txt_cs,
251
 
                                                const char *end_ptr)
 
163
void Lex_input_stream::body_utf8_append_literal(str_ref txt, const char *end_ptr)
252
164
{
253
165
  if (!m_cpp_utf8_processed_ptr)
254
166
    return;
255
167
 
256
 
  LEX_STRING utf_txt;
257
 
 
258
 
  if (!my_charset_same(txt_cs, &my_charset_utf8_general_ci))
259
 
  {
260
 
    thd->convert_string(&utf_txt,
261
 
                        &my_charset_utf8_general_ci,
262
 
                        txt->str, txt->length,
263
 
                        txt_cs);
264
 
  }
265
 
  else
266
 
  {
267
 
    utf_txt.str= txt->str;
268
 
    utf_txt.length= txt->length;
269
 
  }
270
 
 
271
168
  /* NOTE: utf_txt.length is in bytes, not in symbols. */
272
169
 
273
 
  memcpy(m_body_utf8_ptr, utf_txt.str, utf_txt.length);
274
 
  m_body_utf8_ptr += utf_txt.length;
 
170
  memcpy(m_body_utf8_ptr, txt.data(), txt.size());
 
171
  m_body_utf8_ptr += txt.size();
275
172
  *m_body_utf8_ptr= 0;
276
173
 
277
174
  m_cpp_utf8_processed_ptr= end_ptr;
278
175
}
279
176
 
280
 
 
281
177
/*
282
178
  This is called before every query that is to be parsed.
283
179
  Because of this, it's critical to not do too much things here.
284
180
  (We already do too much here)
285
181
*/
286
 
 
287
 
void lex_start(THD *thd)
288
 
{
289
 
  LEX *lex= thd->lex;
290
 
 
291
 
  lex->thd= lex->unit.thd= thd;
292
 
 
293
 
  lex->context_stack.empty();
 
182
void LEX::start(Session *arg)
 
183
{
 
184
  lex_start(arg);
 
185
}
 
186
 
 
187
void lex_start(Session *session)
 
188
{
 
189
  LEX *lex= &session->lex();
 
190
 
 
191
  lex->session= lex->unit.session= session;
 
192
 
 
193
  lex->context_stack.clear();
294
194
  lex->unit.init_query();
295
195
  lex->unit.init_select();
296
196
  /* 'parent_lex' is used in init_query() so it must be before it. */
297
197
  lex->select_lex.parent_lex= lex;
298
198
  lex->select_lex.init_query();
299
 
  lex->value_list.empty();
300
 
  lex->update_list.empty();
301
 
  lex->param_list.empty();
302
 
  lex->view_list.empty();
303
 
  lex->auxiliary_table_list.empty();
 
199
  lex->value_list.clear();
 
200
  lex->update_list.clear();
 
201
  lex->auxiliary_table_list.clear();
304
202
  lex->unit.next= lex->unit.master=
305
203
    lex->unit.link_next= lex->unit.return_to= 0;
306
204
  lex->unit.prev= lex->unit.link_prev= 0;
309
207
  lex->select_lex.master= &lex->unit;
310
208
  lex->select_lex.prev= &lex->unit.slave;
311
209
  lex->select_lex.link_next= lex->select_lex.slave= lex->select_lex.next= 0;
312
 
  lex->select_lex.link_prev= (st_select_lex_node**)&(lex->all_selects_list);
 
210
  lex->select_lex.link_prev= (Select_Lex_Node**)&(lex->all_selects_list);
313
211
  lex->select_lex.options= 0;
314
212
  lex->select_lex.init_order();
315
 
  lex->select_lex.group_list.empty();
 
213
  lex->select_lex.group_list.clear();
316
214
  lex->describe= 0;
317
 
  lex->subqueries= false;
318
215
  lex->derived_tables= 0;
319
216
  lex->lock_option= TL_READ;
320
217
  lex->leaf_tables_insert= 0;
321
 
  lex->parsing_options.reset();
322
 
  lex->empty_field_list_on_rset= 0;
 
218
  lex->var_list.clear();
323
219
  lex->select_lex.select_number= 1;
324
220
  lex->length=0;
325
221
  lex->select_lex.in_sum_expr=0;
326
 
  lex->select_lex.ftfunc_list_alloc.empty();
327
 
  lex->select_lex.ftfunc_list= &lex->select_lex.ftfunc_list_alloc;
328
 
  lex->select_lex.group_list.empty();
329
 
  lex->select_lex.order_list.empty();
 
222
  lex->select_lex.group_list.clear();
 
223
  lex->select_lex.order_list.clear();
330
224
  lex->sql_command= SQLCOM_END;
331
225
  lex->duplicates= DUP_ERROR;
332
226
  lex->ignore= 0;
333
 
  lex->proc_list.first= 0;
334
227
  lex->escape_used= false;
335
228
  lex->query_tables= 0;
336
229
  lex->reset_query_tables_list(false);
337
230
  lex->expr_allows_subselect= true;
338
231
  lex->use_only_table_context= false;
339
232
 
340
 
  lex->name.str= 0;
341
 
  lex->name.length= 0;
 
233
  lex->name.assign(NULL, 0);
342
234
  lex->nest_level=0 ;
343
235
  lex->allow_sum_func= 0;
344
236
  lex->in_sum_func= NULL;
345
 
  /*
346
 
    ok, there must be a better solution for this, long-term
347
 
    I tried "bzero" in the sql_yacc.yy code, but that for
348
 
    some reason made the values zero, even if they were set
349
 
  */
350
 
  lex->server_options.server_name= 0;
351
 
  lex->server_options.server_name_length= 0;
352
 
  lex->server_options.host= 0;
353
 
  lex->server_options.db= 0;
354
 
  lex->server_options.username= 0;
355
 
  lex->server_options.password= 0;
356
 
  lex->server_options.scheme= 0;
357
 
  lex->server_options.socket= 0;
358
 
  lex->server_options.owner= 0;
359
 
  lex->server_options.port= -1;
 
237
  lex->type= 0;
360
238
 
361
239
  lex->is_lex_started= true;
362
 
  return;
 
240
  lex->statement= NULL;
 
241
 
 
242
  lex->is_cross= false;
 
243
  lex->reset();
363
244
}
364
245
 
365
 
void lex_end(LEX *lex)
 
246
void LEX::end()
366
247
{
367
 
  if (lex->yacc_yyss)
 
248
  if (yacc_yyss)
368
249
  {
369
 
    my_free(lex->yacc_yyss, MYF(0));
370
 
    my_free(lex->yacc_yyvs, MYF(0));
371
 
    lex->yacc_yyss= 0;
372
 
    lex->yacc_yyvs= 0;
 
250
    free(yacc_yyss);
 
251
    free(yacc_yyvs);
 
252
    yacc_yyss= 0;
 
253
    yacc_yyvs= 0;
373
254
  }
374
255
 
375
 
  /* release used plugins */
376
 
  plugin_unlock_list(0, (plugin_ref*)lex->plugins.buffer, 
377
 
                     lex->plugins.elements);
378
 
  reset_dynamic(&lex->plugins);
379
 
 
380
 
  return;
 
256
  safe_delete(result);
 
257
  safe_delete(_create_table);
 
258
  safe_delete(_alter_table);
 
259
  _create_table= NULL;
 
260
  _alter_table= NULL;
 
261
  _create_field= NULL;
 
262
 
 
263
  result= 0;
 
264
  setCacheable(true);
 
265
 
 
266
  safe_delete(statement);
381
267
}
382
268
 
383
 
 
384
 
static int find_keyword(Lex_input_stream *lip, uint len, bool function)
 
269
static int find_keyword(Lex_input_stream *lip, uint32_t len, bool function)
385
270
{
 
271
  /* Plenty of memory for the largest lex symbol we have */
 
272
  char tok_upper[64];
386
273
  const char *tok= lip->get_tok_start();
 
274
  uint32_t tok_pos= 0;
 
275
  for (;tok_pos<len && tok_pos<63;tok_pos++)
 
276
    tok_upper[tok_pos]= system_charset_info->toupper(tok[tok_pos]);
 
277
  tok_upper[tok_pos]=0;
387
278
 
388
 
  SYMBOL *symbol= get_hash_symbol(tok, len, function);
 
279
  const SYMBOL *symbol= lookup_symbol(tok_upper, len, function);
389
280
  if (symbol)
390
281
  {
391
282
    lip->yylval->symbol.symbol=symbol;
394
285
 
395
286
    return symbol->tok;
396
287
  }
 
288
 
397
289
  return 0;
398
290
}
399
291
 
400
 
/*
401
 
  Check if name is a keyword
402
 
 
403
 
  SYNOPSIS
404
 
    is_keyword()
405
 
    name      checked name (must not be empty)
406
 
    len       length of checked name
407
 
 
408
 
  RETURN VALUES
409
 
    0         name is a keyword
410
 
    1         name isn't a keyword
411
 
*/
412
 
 
413
 
bool is_keyword(const char *name, uint len)
414
 
{
415
 
  assert(len != 0);
416
 
  return get_hash_symbol(name,len,0)!=0;
417
 
}
418
 
 
419
 
bool is_lex_native_function(const LEX_STRING *name)
420
 
{
421
 
  assert(name != NULL);
422
 
  return (get_hash_symbol(name->str, name->length, 1) != 0);
423
 
}
424
 
 
425
292
/* make a copy of token before ptr and set yytoklen */
426
 
 
427
 
static LEX_STRING get_token(Lex_input_stream *lip, uint skip, uint length)
 
293
static lex_string_t get_token(Lex_input_stream *lip, uint32_t skip, uint32_t length)
428
294
{
429
 
  LEX_STRING tmp;
430
295
  lip->yyUnget();                       // ptr points now after last token char
431
 
  tmp.length=lip->yytoklen=length;
432
 
  tmp.str= lip->m_thd->strmake(lip->get_tok_start() + skip, tmp.length);
433
 
 
 
296
  lip->yytoklen= length;
 
297
  lex_string_t tmp;
 
298
  tmp.assign(lip->m_session->mem.strdup(lip->get_tok_start() + skip, length), length);
434
299
  lip->m_cpp_text_start= lip->get_cpp_tok_start() + skip;
435
 
  lip->m_cpp_text_end= lip->m_cpp_text_start + tmp.length;
436
 
 
 
300
  lip->m_cpp_text_end= lip->m_cpp_text_start + tmp.size();
437
301
  return tmp;
438
302
}
439
303
 
440
 
/* 
441
 
 todo: 
442
 
   There are no dangerous charsets in mysql for function 
443
 
   get_quoted_token yet. But it should be fixed in the 
 
304
/*
 
305
 todo:
 
306
   There are no dangerous charsets in mysql for function
 
307
   get_quoted_token yet. But it should be fixed in the
444
308
   future to operate multichar strings (like ucs2)
445
309
*/
446
 
 
447
 
static LEX_STRING get_quoted_token(Lex_input_stream *lip,
448
 
                                   uint skip,
449
 
                                   uint length, char quote)
 
310
static lex_string_t get_quoted_token(Lex_input_stream *lip,
 
311
                                   uint32_t skip,
 
312
                                   uint32_t length, char quote)
450
313
{
451
 
  LEX_STRING tmp;
452
 
  const char *from, *end;
453
 
  char *to;
454
314
  lip->yyUnget();                       // ptr points now after last token char
455
 
  tmp.length= lip->yytoklen=length;
456
 
  tmp.str=(char*) lip->m_thd->alloc(tmp.length+1);
457
 
  from= lip->get_tok_start() + skip;
458
 
  to= tmp.str;
459
 
  end= to+length;
 
315
  lip->yytoklen= length;
 
316
  lex_string_t tmp;
 
317
  tmp.assign((char*)lip->m_session->mem.alloc(length + 1), length);
 
318
  const char* from= lip->get_tok_start() + skip;
 
319
  char* to= (char*)tmp.data();
 
320
  const char* end= to+length;
460
321
 
461
322
  lip->m_cpp_text_start= lip->get_cpp_tok_start() + skip;
462
323
  lip->m_cpp_text_end= lip->m_cpp_text_start + length;
478
339
  Return an unescaped text literal without quotes
479
340
  Fix sometimes to do only one scan of the string
480
341
*/
481
 
 
482
342
static char *get_text(Lex_input_stream *lip, int pre_skip, int post_skip)
483
343
{
484
 
  register uchar c,sep;
485
 
  uint found_escape=0;
486
 
  CHARSET_INFO *cs= lip->m_thd->charset();
 
344
  bool found_escape= false;
 
345
  const charset_info_st* const cs= lip->m_session->charset();
487
346
 
488
347
  lip->tok_bitmap= 0;
489
 
  sep= lip->yyGetLast();                        // String should end with this
490
 
  while (! lip->eof())
 
348
  unsigned char sep= lip->yyGetLast();                        // String should end with this
 
349
  while (not lip->eof())
491
350
  {
492
 
    c= lip->yyGet();
 
351
    unsigned char c= lip->yyGet();
493
352
    lip->tok_bitmap|= c;
494
 
#ifdef USE_MB
495
353
    {
496
 
      int l;
497
 
      if (use_mb(cs) &&
498
 
          (l = my_ismbchar(cs,
499
 
                           lip->get_ptr() -1,
500
 
                           lip->get_end_of_query()))) {
501
 
        lip->skip_binary(l-1);
502
 
        continue;
 
354
      if (use_mb(cs))
 
355
      {
 
356
        int l= my_ismbchar(cs, lip->get_ptr() -1, lip->get_end_of_query());
 
357
        if (l != 0)
 
358
        {
 
359
          lip->skip_binary(l-1);
 
360
          continue;
 
361
        }
503
362
      }
504
363
    }
505
 
#endif
506
364
    if (c == '\\')
507
365
    {                                   // Escaped character
508
 
      found_escape=1;
 
366
      found_escape= true;
509
367
      if (lip->eof())
510
 
        return 0;
 
368
        return 0;
511
369
      lip->yySkip();
512
370
    }
513
371
    else if (c == sep)
514
372
    {
515
373
      if (c == lip->yyGet())            // Check if two separators in a row
516
374
      {
517
 
        found_escape=1;                 // duplicate. Remember for delete
518
 
        continue;
 
375
        found_escape= true;                 // duplicate. Remember for delete
 
376
        continue;
519
377
      }
520
378
      else
521
379
        lip->yyUnget();
522
380
 
523
381
      /* Found end. Unescape and return string */
524
 
      const char *str, *end;
525
 
      char *start;
526
 
 
527
 
      str= lip->get_tok_start();
528
 
      end= lip->get_ptr();
 
382
      const char* str= lip->get_tok_start();
 
383
      const char* end= lip->get_ptr();
529
384
      /* Extract the text from the token */
530
 
      str += pre_skip;
531
 
      end -= post_skip;
 
385
      str+= pre_skip;
 
386
      end-= post_skip;
532
387
      assert(end >= str);
533
388
 
534
 
      if (!(start= (char*) lip->m_thd->alloc((uint) (end-str)+1)))
535
 
        return (char*) "";              // Sql_alloc has set error flag
 
389
      char* start= (char*) lip->m_session->mem.alloc((uint32_t) (end-str)+1);
536
390
 
537
391
      lip->m_cpp_text_start= lip->get_cpp_tok_start() + pre_skip;
538
392
      lip->m_cpp_text_end= lip->get_cpp_ptr() - post_skip;
539
393
 
540
 
      if (!found_escape)
 
394
      if (! found_escape)
541
395
      {
542
 
        lip->yytoklen=(uint) (end-str);
543
 
        memcpy(start,str,lip->yytoklen);
544
 
        start[lip->yytoklen]=0;
 
396
        lip->yytoklen= (uint32_t) (end-str);
 
397
        memcpy(start, str, lip->yytoklen);
 
398
        start[lip->yytoklen]= 0;
545
399
      }
546
400
      else
547
401
      {
548
402
        char *to;
549
403
 
550
 
        for (to=start ; str != end ; str++)
551
 
        {
552
 
#ifdef USE_MB
553
 
          int l;
554
 
          if (use_mb(cs) &&
555
 
              (l = my_ismbchar(cs, str, end))) {
556
 
              while (l--)
557
 
                  *to++ = *str++;
558
 
              str--;
559
 
              continue;
560
 
          }
561
 
#endif
562
 
          if (!(lip->m_thd->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES) &&
563
 
              *str == '\\' && str+1 != end)
564
 
          {
565
 
            switch(*++str) {
566
 
            case 'n':
567
 
              *to++='\n';
568
 
              break;
569
 
            case 't':
570
 
              *to++= '\t';
571
 
              break;
572
 
            case 'r':
573
 
              *to++ = '\r';
574
 
              break;
575
 
            case 'b':
576
 
              *to++ = '\b';
577
 
              break;
578
 
            case '0':
579
 
              *to++= 0;                 // Ascii null
580
 
              break;
581
 
            case 'Z':                   // ^Z must be escaped on Win32
582
 
              *to++='\032';
583
 
              break;
584
 
            case '_':
585
 
            case '%':
586
 
              *to++= '\\';              // remember prefix for wildcard
587
 
              /* Fall through */
588
 
            default:
 
404
        for (to= start; str != end; str++)
 
405
        {
 
406
          if (use_mb(cs))
 
407
          {
 
408
            int l= my_ismbchar(cs, str, end);
 
409
            if (l != 0)
 
410
            {
 
411
              while (l--)
 
412
                *to++= *str++;
 
413
              str--;
 
414
              continue;
 
415
            }
 
416
          }
 
417
          if (*str == '\\' && (str + 1) != end)
 
418
          {
 
419
            switch (*++str) {
 
420
            case 'n':
 
421
              *to++= '\n';
 
422
              break;
 
423
            case 't':
 
424
              *to++= '\t';
 
425
              break;
 
426
            case 'r':
 
427
              *to++= '\r';
 
428
              break;
 
429
            case 'b':
 
430
              *to++= '\b';
 
431
              break;
 
432
            case '0':
 
433
              *to++= 0;                 // Ascii null
 
434
              break;
 
435
            case 'Z':                   // ^Z must be escaped on Win32
 
436
              *to++= '\032';
 
437
              break;
 
438
            case '_':
 
439
            case '%':
 
440
              *to++= '\\';              // remember prefix for wildcard
 
441
              /* Fall through */
 
442
            default:
589
443
              *to++= *str;
590
 
              break;
591
 
            }
592
 
          }
593
 
          else if (*str == sep)
594
 
            *to++= *str++;              // Two ' or "
595
 
          else
596
 
            *to++ = *str;
597
 
        }
598
 
        *to=0;
599
 
        lip->yytoklen=(uint) (to-start);
 
444
              break;
 
445
            }
 
446
          }
 
447
          else if (*str == sep)
 
448
            *to++= *str++;              // Two ' or "
 
449
          else
 
450
            *to++ = *str;
 
451
        }
 
452
        *to= 0;
 
453
        lip->yytoklen= (uint32_t) (to - start);
600
454
      }
601
455
      return start;
602
456
    }
606
460
 
607
461
 
608
462
/*
609
 
** Calc type of integer; long integer, longlong integer or real.
 
463
** Calc type of integer; long integer, int64_t integer or real.
610
464
** Returns smallest type that match the string.
611
 
** When using unsigned long long values the result is converted to a real
 
465
** When using uint64_t values the result is converted to a real
612
466
** because else they will be unexpected sign changes because all calculation
613
 
** is done with longlong or double.
 
467
** is done with int64_t or double.
614
468
*/
615
469
 
616
 
static const char *long_str="2147483647";
617
 
static const uint long_len=10;
618
 
static const char *signed_long_str="-2147483648";
619
 
static const char *longlong_str="9223372036854775807";
620
 
static const uint longlong_len=19;
621
 
static const char *signed_longlong_str="-9223372036854775808";
622
 
static const uint signed_longlong_len=19;
623
 
static const char *unsigned_longlong_str="18446744073709551615";
624
 
static const uint unsigned_longlong_len=20;
 
470
static const char *long_str= "2147483647";
 
471
static const uint32_t long_len= 10;
 
472
static const char *signed_long_str= "-2147483648";
 
473
static const char *int64_t_str= "9223372036854775807";
 
474
static const uint32_t int64_t_len= 19;
 
475
static const char *signed_int64_t_str= "-9223372036854775808";
 
476
static const uint32_t signed_int64_t_len= 19;
 
477
static const char *unsigned_int64_t_str= "18446744073709551615";
 
478
static const uint32_t unsigned_int64_t_len= 20;
625
479
 
626
 
static inline uint int_token(const char *str,uint length)
 
480
static inline uint32_t int_token(const char *str,uint32_t length)
627
481
{
628
482
  if (length < long_len)                        // quick normal case
629
483
    return NUM;
645
499
  if (length < long_len)
646
500
    return NUM;
647
501
 
648
 
  uint smaller,bigger;
 
502
  uint32_t smaller,bigger;
649
503
  const char *cmp;
650
504
  if (neg)
651
505
  {
655
509
      smaller=NUM;                              // If <= signed_long_str
656
510
      bigger=LONG_NUM;                          // If >= signed_long_str
657
511
    }
658
 
    else if (length < signed_longlong_len)
 
512
    else if (length < signed_int64_t_len)
659
513
      return LONG_NUM;
660
 
    else if (length > signed_longlong_len)
 
514
    else if (length > signed_int64_t_len)
661
515
      return DECIMAL_NUM;
662
516
    else
663
517
    {
664
 
      cmp=signed_longlong_str+1;
665
 
      smaller=LONG_NUM;                         // If <= signed_longlong_str
 
518
      cmp=signed_int64_t_str+1;
 
519
      smaller=LONG_NUM;                         // If <= signed_int64_t_str
666
520
      bigger=DECIMAL_NUM;
667
521
    }
668
522
  }
674
528
      smaller=NUM;
675
529
      bigger=LONG_NUM;
676
530
    }
677
 
    else if (length < longlong_len)
 
531
    else if (length < int64_t_len)
678
532
      return LONG_NUM;
679
 
    else if (length > longlong_len)
 
533
    else if (length > int64_t_len)
680
534
    {
681
 
      if (length > unsigned_longlong_len)
 
535
      if (length > unsigned_int64_t_len)
682
536
        return DECIMAL_NUM;
683
 
      cmp=unsigned_longlong_str;
 
537
      cmp=unsigned_int64_t_str;
684
538
      smaller=ULONGLONG_NUM;
685
539
      bigger=DECIMAL_NUM;
686
540
    }
687
541
    else
688
542
    {
689
 
      cmp=longlong_str;
 
543
      cmp=int64_t_str;
690
544
      smaller=LONG_NUM;
691
545
      bigger= ULONGLONG_NUM;
692
546
    }
693
547
  }
694
548
  while (*cmp && *cmp++ == *str++) ;
695
 
  return ((uchar) str[-1] <= (uchar) cmp[-1]) ? smaller : bigger;
 
549
  return ((unsigned char) str[-1] <= (unsigned char) cmp[-1]) ? smaller : bigger;
696
550
}
697
551
 
698
 
 
 
552
} /* namespace drizzled */
699
553
/*
700
 
  MYSQLlex remember the following states from the following MYSQLlex()
 
554
  base_sql_lex remember the following states from the following sql_baselex()
701
555
 
702
556
  - MY_LEX_EOQ                  Found end of query
703
557
  - MY_LEX_OPERATOR_OR_IDENT    Last state was an ident, text or number
704
558
                                (which can't be followed by a signed number)
705
559
*/
706
 
 
707
 
int MYSQLlex(void *arg, void *yythd)
 
560
int base_sql_lex(union ParserType *yylval, drizzled::Session *session)
708
561
{
709
 
  THD *thd= (THD *)yythd;
710
 
  Lex_input_stream *lip= thd->m_lip;
711
 
  YYSTYPE *yylval=(YYSTYPE*) arg;
 
562
  drizzled::Lex_input_stream *lip= session->m_lip;
712
563
  int token;
713
564
 
714
565
  if (lip->lookahead_token != END_OF_INPUT)
724
575
    return token;
725
576
  }
726
577
 
727
 
  token= lex_one_token(arg, yythd);
 
578
  token= drizzled::lex_one_token(yylval, session);
728
579
 
729
580
  switch(token) {
730
581
  case WITH:
731
582
    /*
732
 
      Parsing 'WITH' 'ROLLUP' or 'WITH' 'CUBE' requires 2 look ups,
 
583
      Parsing 'WITH' 'ROLLUP' requires 2 look ups,
733
584
      which makes the grammar LALR(2).
734
585
      Replace by a single 'WITH_ROLLUP' or 'WITH_CUBE' token,
735
586
      to transform the grammar into a LALR(1) grammar,
736
587
      which sql_yacc.yy can process.
737
588
    */
738
 
    token= lex_one_token(arg, yythd);
739
 
    switch(token) {
740
 
    case CUBE_SYM:
741
 
      return WITH_CUBE_SYM;
742
 
    case ROLLUP_SYM:
 
589
    token= drizzled::lex_one_token(yylval, session);
 
590
    if (token == ROLLUP_SYM)
 
591
    {
743
592
      return WITH_ROLLUP_SYM;
744
 
    default:
 
593
    }
 
594
    else
 
595
    {
745
596
      /*
746
597
        Save the token following 'WITH'
747
598
      */
750
601
      lip->lookahead_token= token;
751
602
      return WITH;
752
603
    }
753
 
    break;
754
604
  default:
755
605
    break;
756
606
  }
758
608
  return token;
759
609
}
760
610
 
761
 
int lex_one_token(void *arg, void *yythd)
762
 
{
763
 
  register unsigned char c= 0; /* Just set to shutup GCC */
 
611
namespace drizzled
 
612
{
 
613
 
 
614
int lex_one_token(ParserType *yylval, drizzled::Session *session)
 
615
{
 
616
  unsigned char c= 0; /* Just set to shutup GCC */
764
617
  bool comment_closed;
765
618
  int   tokval, result_state;
766
619
  unsigned int length;
767
620
  enum my_lex_states state;
768
 
  THD *thd= (THD *)yythd;
769
 
  Lex_input_stream *lip= thd->m_lip;
770
 
  LEX *lex= thd->lex;
771
 
  YYSTYPE *yylval=(YYSTYPE*) arg;
772
 
  CHARSET_INFO *cs= thd->charset();
773
 
  uchar *state_map= cs->state_map;
774
 
  uchar *ident_map= cs->ident_map;
 
621
  Lex_input_stream *lip= session->m_lip;
 
622
  LEX *lex= &session->lex();
 
623
  const charset_info_st * const cs= session->charset();
 
624
  unsigned char *state_map= cs->state_map;
 
625
  unsigned char *ident_map= cs->ident_map;
775
626
 
776
627
  lip->yylval=yylval;                   // The global state
777
628
 
786
637
      // Skip starting whitespace
787
638
      while(state_map[c= lip->yyPeek()] == MY_LEX_SKIP)
788
639
      {
789
 
        if (c == '\n')
790
 
          lip->yylineno++;
 
640
        if (c == '\n')
 
641
          lip->yylineno++;
791
642
 
792
643
        lip->yySkip();
793
644
      }
800
651
    case MY_LEX_ESCAPE:
801
652
      if (lip->yyGet() == 'N')
802
653
      {                                 // Allow \N as shortcut for NULL
803
 
        yylval->lex_str.str=(char*) "\\N";
804
 
        yylval->lex_str.length=2;
805
 
        return NULL_SYM;
 
654
        yylval->lex_str.assign("\\N", 2);
 
655
        return NULL_SYM;
806
656
      }
807
657
    case MY_LEX_CHAR:                   // Unknown or single char token
808
658
    case MY_LEX_SKIP:                   // This should not happen
809
659
      if (c == '-' && lip->yyPeek() == '-' &&
810
 
          (my_isspace(cs,lip->yyPeekn(1)) ||
811
 
           my_iscntrl(cs,lip->yyPeekn(1))))
 
660
          (cs->isspace(lip->yyPeekn(1)) ||
 
661
           cs->iscntrl(lip->yyPeekn(1))))
812
662
      {
813
663
        state=MY_LEX_COMMENT;
814
664
        break;
815
665
      }
816
666
 
817
667
      if (c != ')')
818
 
        lip->next_state= MY_LEX_START;  // Allow signed numbers
 
668
        lip->next_state= MY_LEX_START;  // Allow signed numbers
819
669
 
820
670
      if (c == ',')
821
671
      {
830
680
        */
831
681
        lip->restart_token();
832
682
      }
833
 
      else
834
 
      {
835
 
        /*
836
 
          Check for a placeholder: it should not precede a possible identifier
837
 
          because of binlogging: when a placeholder is replaced with
838
 
          its value in a query for the binlog, the query must stay
839
 
          grammatically correct.
840
 
        */
841
 
        if (c == '?' && lip->stmt_prepare_mode && !ident_map[(uint8_t)(lip->yyPeek())])
842
 
        return(PARAM_MARKER);
843
 
      }
844
683
 
845
684
      return((int) c);
846
685
 
847
 
    case MY_LEX_IDENT_OR_NCHAR:
848
 
      if (lip->yyPeek() != '\'')
849
 
      {
850
 
        state= MY_LEX_IDENT;
851
 
        break;
852
 
      }
853
 
      /* Found N'string' */
854
 
      lip->yySkip();                         // Skip '
855
 
      if (!(yylval->lex_str.str = get_text(lip, 2, 1)))
856
 
      {
857
 
        state= MY_LEX_CHAR;             // Read char by char
858
 
        break;
859
 
      }
860
 
      yylval->lex_str.length= lip->yytoklen;
861
 
      lex->text_string_is_7bit= (lip->tok_bitmap & 0x80) ? 0 : 1;
862
 
      return(NCHAR_STRING);
863
 
 
864
686
    case MY_LEX_IDENT_OR_HEX:
865
687
      if (lip->yyPeek() == '\'')
866
688
      {                                 // Found x'hex-number'
867
 
        state= MY_LEX_HEX_NUMBER;
868
 
        break;
 
689
        state= MY_LEX_HEX_NUMBER;
 
690
        break;
869
691
      }
870
692
    case MY_LEX_IDENT_OR_BIN:
871
693
      if (lip->yyPeek() == '\'')
875
697
      }
876
698
    case MY_LEX_IDENT:
877
699
      const char *start;
878
 
#if defined(USE_MB) && defined(USE_MB_IDENT)
879
700
      if (use_mb(cs))
880
701
      {
881
 
        result_state= IDENT_QUOTED;
 
702
        result_state= IDENT_QUOTED;
882
703
        if (my_mbcharlen(cs, lip->yyGetLast()) > 1)
883
704
        {
884
705
          int l = my_ismbchar(cs,
894
715
        {
895
716
          if (my_mbcharlen(cs, c) > 1)
896
717
          {
897
 
            int l;
898
 
            if ((l = my_ismbchar(cs,
899
 
                                 lip->get_ptr() -1,
900
 
                                 lip->get_end_of_query())) == 0)
 
718
            int l= my_ismbchar(cs, lip->get_ptr() -1, lip->get_end_of_query());
 
719
            if (l == 0)
901
720
              break;
902
721
            lip->skip_binary(l-1);
903
722
          }
904
723
        }
905
724
      }
906
725
      else
907
 
#endif
908
726
      {
909
727
        for (result_state= c; ident_map[c= lip->yyGet()]; result_state|= c) {};
910
728
        /* If there were non-ASCII characters, mark that we must convert */
921
739
        for (; state_map[c] == MY_LEX_SKIP ; c= lip->yyGet()) {};
922
740
      }
923
741
      if (start == lip->get_ptr() && c == '.' && ident_map[(uint8_t)lip->yyPeek()])
924
 
        lip->next_state=MY_LEX_IDENT_SEP;
 
742
              lip->next_state=MY_LEX_IDENT_SEP;
925
743
      else
926
744
      {                                 // '(' must follow directly if function
927
745
        lip->yyUnget();
928
 
        if ((tokval = find_keyword(lip, length, c == '(')))
929
 
        {
930
 
          lip->next_state= MY_LEX_START;        // Allow signed numbers
931
 
          return(tokval);               // Was keyword
932
 
        }
 
746
        if ((tokval = find_keyword(lip, length, c == '(')))
 
747
        {
 
748
          lip->next_state= MY_LEX_START;        // Allow signed numbers
 
749
          return(tokval);               // Was keyword
 
750
        }
933
751
        lip->yySkip();                  // next state does a unget
934
752
      }
935
 
      yylval->lex_str=get_token(lip, 0, length);
936
 
 
937
 
      /*
938
 
         Note: "SELECT _bla AS 'alias'"
939
 
         _bla should be considered as a IDENT if charset haven't been found.
940
 
         So we don't use MYF(MY_WME) with get_charset_by_csname to avoid
941
 
         producing an error.
942
 
      */
943
 
 
944
 
      if (yylval->lex_str.str[0] == '_')
945
 
      {
946
 
        CHARSET_INFO *cs= get_charset_by_csname(yylval->lex_str.str + 1,
947
 
                                                MY_CS_PRIMARY, MYF(0));
948
 
        if (cs)
949
 
        {
950
 
          yylval->charset= cs;
951
 
          lip->m_underscore_cs= cs;
952
 
 
953
 
          lip->body_utf8_append(lip->m_cpp_text_start,
954
 
                                lip->get_cpp_tok_start() + length);
955
 
          return(UNDERSCORE_CHARSET);
956
 
        }
957
 
      }
 
753
      yylval->lex_str= get_token(lip, 0, length);
958
754
 
959
755
      lip->body_utf8_append(lip->m_cpp_text_start);
960
756
 
961
 
      lip->body_utf8_append_literal(thd, &yylval->lex_str, cs,
962
 
                                    lip->m_cpp_text_end);
 
757
      lip->body_utf8_append_literal(yylval->lex_str, lip->m_cpp_text_end);
963
758
 
964
759
      return(result_state);                     // IDENT or IDENT_QUOTED
965
760
 
966
761
    case MY_LEX_IDENT_SEP:              // Found ident and now '.'
967
 
      yylval->lex_str.str= (char*) lip->get_ptr();
968
 
      yylval->lex_str.length= 1;
 
762
      yylval->lex_str.assign(lip->get_ptr(), 1);
969
763
      c= lip->yyGet();                  // should be '.'
970
764
      lip->next_state= MY_LEX_IDENT_START;// Next is an ident (not a keyword)
971
765
      if (!ident_map[(uint8_t)lip->yyPeek()])            // Probably ` or "
972
 
        lip->next_state= MY_LEX_START;
 
766
        lip->next_state= MY_LEX_START;
973
767
      return((int) c);
974
768
 
975
769
    case MY_LEX_NUMBER_IDENT:           // number or ident which num-start
978
772
        c= lip->yyGet();
979
773
        if (c == 'x')
980
774
        {
981
 
          while (my_isxdigit(cs,(c = lip->yyGet()))) ;
 
775
          while (cs->isxdigit((c = lip->yyGet()))) ;
982
776
          if ((lip->yyLength() >= 3) && !ident_map[c])
983
777
          {
984
778
            /* skip '0x' */
985
 
            yylval->lex_str=get_token(lip, 2, lip->yyLength()-2);
 
779
            yylval->lex_str= get_token(lip, 2, lip->yyLength()-2);
986
780
            return (HEX_NUM);
987
781
          }
988
782
          lip->yyUnget();
1005
799
        lip->yyUnget();
1006
800
      }
1007
801
 
1008
 
      while (my_isdigit(cs, (c = lip->yyGet()))) ;
 
802
      while (cs->isdigit((c = lip->yyGet()))) ;
1009
803
      if (!ident_map[c])
1010
804
      {                                 // Can't be identifier
1011
 
        state=MY_LEX_INT_OR_REAL;
1012
 
        break;
 
805
        state=MY_LEX_INT_OR_REAL;
 
806
        break;
1013
807
      }
1014
808
      if (c == 'e' || c == 'E')
1015
809
      {
1016
 
        // The following test is written this way to allow numbers of type 1e1
1017
 
        if (my_isdigit(cs,lip->yyPeek()) ||
 
810
        // The following test is written this way to allow numbers of type 1e1
 
811
        if (cs->isdigit(lip->yyPeek()) ||
1018
812
            (c=(lip->yyGet())) == '+' || c == '-')
1019
 
        {                               // Allow 1E+10
1020
 
          if (my_isdigit(cs,lip->yyPeek()))     // Number must have digit after sign
1021
 
          {
 
813
        {                               // Allow 1E+10
 
814
          if (cs->isdigit(lip->yyPeek()))     // Number must have digit after sign
 
815
          {
1022
816
            lip->yySkip();
1023
 
            while (my_isdigit(cs,lip->yyGet())) ;
1024
 
            yylval->lex_str=get_token(lip, 0, lip->yyLength());
1025
 
            return(FLOAT_NUM);
1026
 
          }
1027
 
        }
 
817
            while (cs->isdigit(lip->yyGet())) ;
 
818
            yylval->lex_str= get_token(lip, 0, lip->yyLength());
 
819
            return(FLOAT_NUM);
 
820
          }
 
821
        }
1028
822
        lip->yyUnget();
1029
823
      }
1030
824
      // fall through
1031
825
    case MY_LEX_IDENT_START:                    // We come here after '.'
1032
826
      result_state= IDENT;
1033
 
#if defined(USE_MB) && defined(USE_MB_IDENT)
1034
827
      if (use_mb(cs))
1035
828
      {
1036
 
        result_state= IDENT_QUOTED;
 
829
        result_state= IDENT_QUOTED;
1037
830
        while (ident_map[c=lip->yyGet()])
1038
831
        {
1039
832
          if (my_mbcharlen(cs, c) > 1)
1040
833
          {
1041
 
            int l;
1042
 
            if ((l = my_ismbchar(cs,
1043
 
                                 lip->get_ptr() -1,
1044
 
                                 lip->get_end_of_query())) == 0)
 
834
            int l= my_ismbchar(cs, lip->get_ptr() -1, lip->get_end_of_query());
 
835
            if (l == 0)
1045
836
              break;
1046
837
            lip->skip_binary(l-1);
1047
838
          }
1048
839
        }
1049
840
      }
1050
841
      else
1051
 
#endif
1052
842
      {
1053
843
        for (result_state=0; ident_map[c= lip->yyGet()]; result_state|= c) {};
1054
844
        /* If there were non-ASCII characters, mark that we must convert */
1055
845
        result_state= result_state & 0x80 ? IDENT_QUOTED : IDENT;
1056
846
      }
1057
847
      if (c == '.' && ident_map[(uint8_t)lip->yyPeek()])
1058
 
        lip->next_state=MY_LEX_IDENT_SEP;// Next is '.'
 
848
        lip->next_state=MY_LEX_IDENT_SEP;// Next is '.'
1059
849
 
1060
850
      yylval->lex_str= get_token(lip, 0, lip->yyLength());
1061
851
 
1062
852
      lip->body_utf8_append(lip->m_cpp_text_start);
1063
 
 
1064
 
      lip->body_utf8_append_literal(thd, &yylval->lex_str, cs,
1065
 
                                    lip->m_cpp_text_end);
 
853
      lip->body_utf8_append_literal(yylval->lex_str, lip->m_cpp_text_end);
1066
854
 
1067
855
      return(result_state);
1068
856
 
1069
857
    case MY_LEX_USER_VARIABLE_DELIMITER:        // Found quote char
1070
858
    {
1071
 
      uint double_quotes= 0;
 
859
      uint32_t double_quotes= 0;
1072
860
      char quote_char= c;                       // Used char
1073
861
      while ((c=lip->yyGet()))
1074
862
      {
1075
 
        int var_length;
1076
 
        if ((var_length= my_mbcharlen(cs, c)) == 1)
1077
 
        {
1078
 
          if (c == quote_char)
1079
 
          {
1080
 
            if (lip->yyPeek() != quote_char)
1081
 
              break;
1082
 
            c=lip->yyGet();
1083
 
            double_quotes++;
1084
 
            continue;
1085
 
          }
1086
 
        }
1087
 
#ifdef USE_MB
1088
 
        else if (var_length < 1)
1089
 
          break;                                // Error
 
863
        int var_length;
 
864
        if ((var_length= my_mbcharlen(cs, c)) == 1)
 
865
        {
 
866
          if (c == quote_char)
 
867
          {
 
868
                  if (lip->yyPeek() != quote_char)
 
869
              break;
 
870
                  c=lip->yyGet();
 
871
            double_quotes++;
 
872
            continue;
 
873
          }
 
874
        }
 
875
        else if (var_length < 1)
 
876
          break;                                // Error
1090
877
        lip->skip_binary(var_length-1);
1091
 
#endif
1092
878
      }
1093
 
      if (double_quotes)
1094
 
        yylval->lex_str=get_quoted_token(lip, 1,
1095
 
                                         lip->yyLength() - double_quotes -1,
1096
 
                                         quote_char);
1097
 
      else
1098
 
        yylval->lex_str=get_token(lip, 1, lip->yyLength() -1);
 
879
      yylval->lex_str= double_quotes
 
880
        ? get_quoted_token(lip, 1, lip->yyLength() - double_quotes - 1, quote_char)
 
881
        : get_token(lip, 1, lip->yyLength() - 1);
1099
882
      if (c == quote_char)
1100
883
        lip->yySkip();                  // Skip end `
1101
884
      lip->next_state= MY_LEX_START;
1102
 
 
1103
885
      lip->body_utf8_append(lip->m_cpp_text_start);
1104
 
 
1105
 
      lip->body_utf8_append_literal(thd, &yylval->lex_str, cs,
1106
 
                                    lip->m_cpp_text_end);
1107
 
 
1108
 
      return(IDENT_QUOTED);
 
886
      lip->body_utf8_append_literal(yylval->lex_str, lip->m_cpp_text_end);
 
887
      return IDENT_QUOTED;
1109
888
    }
1110
889
    case MY_LEX_INT_OR_REAL:            // Complete int or incomplete real
1111
890
      if (c != '.')
1112
891
      {                                 // Found complete integer number.
1113
892
        yylval->lex_str=get_token(lip, 0, lip->yyLength());
1114
 
        return int_token(yylval->lex_str.str,yylval->lex_str.length);
 
893
        return int_token(yylval->lex_str.data(), yylval->lex_str.size());
1115
894
      }
1116
895
      // fall through
1117
896
    case MY_LEX_REAL:                   // Incomplete real number
1118
 
      while (my_isdigit(cs,c = lip->yyGet())) ;
 
897
      while (cs->isdigit(c = lip->yyGet())) ;
1119
898
 
1120
899
      if (c == 'e' || c == 'E')
1121
900
      {
1122
901
        c = lip->yyGet();
1123
 
        if (c == '-' || c == '+')
1124
 
          c = lip->yyGet();                     // Skip sign
1125
 
        if (!my_isdigit(cs,c))
1126
 
        {                               // No digit after sign
1127
 
          state= MY_LEX_CHAR;
1128
 
          break;
1129
 
        }
1130
 
        while (my_isdigit(cs,lip->yyGet())) ;
 
902
        if (c == '-' || c == '+')
 
903
                c = lip->yyGet();                     // Skip sign
 
904
        if (!cs->isdigit(c))
 
905
        {                               // No digit after sign
 
906
          state= MY_LEX_CHAR;
 
907
          break;
 
908
        }
 
909
        while (cs->isdigit(lip->yyGet())) ;
1131
910
        yylval->lex_str=get_token(lip, 0, lip->yyLength());
1132
 
        return(FLOAT_NUM);
 
911
        return(FLOAT_NUM);
1133
912
      }
1134
913
      yylval->lex_str=get_token(lip, 0, lip->yyLength());
1135
914
      return(DECIMAL_NUM);
1136
915
 
1137
916
    case MY_LEX_HEX_NUMBER:             // Found x'hexstring'
1138
917
      lip->yySkip();                    // Accept opening '
1139
 
      while (my_isxdigit(cs, (c= lip->yyGet()))) ;
 
918
      while (cs->isxdigit((c= lip->yyGet()))) ;
1140
919
      if (c != '\'')
1141
920
        return(ABORT_SYM);              // Illegal hex constant
1142
921
      lip->yySkip();                    // Accept closing '
1143
922
      length= lip->yyLength();          // Length of hexnum+3
1144
 
      if ((length % 2) == 0)
1145
 
        return(ABORT_SYM);              // odd number of hex digits
 
923
      if (length % 2 == 0)
 
924
        return ABORT_SYM;               // odd number of hex digits
1146
925
      yylval->lex_str=get_token(lip,
1147
926
                                2,          // skip x'
1148
927
                                length-3);  // don't count x' and last '
1166
945
        lip->yySkip();
1167
946
      if ((tokval = find_keyword(lip, lip->yyLength() + 1, 0)))
1168
947
      {
1169
 
        lip->next_state= MY_LEX_START;  // Allow signed numbers
1170
 
        return(tokval);
 
948
        lip->next_state= MY_LEX_START;  // Allow signed numbers
 
949
        return(tokval);
1171
950
      }
1172
951
      state = MY_LEX_CHAR;              // Something fishy found
1173
952
      break;
1182
961
      }
1183
962
      if ((tokval = find_keyword(lip, lip->yyLength() + 1, 0)))
1184
963
      {
1185
 
        lip->next_state= MY_LEX_START;  // Found long op
1186
 
        return(tokval);
 
964
        lip->next_state= MY_LEX_START;  // Found long op
 
965
        return(tokval);
1187
966
      }
1188
967
      state = MY_LEX_CHAR;              // Something fishy found
1189
968
      break;
1191
970
    case MY_LEX_BOOL:
1192
971
      if (c != lip->yyPeek())
1193
972
      {
1194
 
        state=MY_LEX_CHAR;
1195
 
        break;
 
973
        state=MY_LEX_CHAR;
 
974
        break;
1196
975
      }
1197
976
      lip->yySkip();
1198
977
      tokval = find_keyword(lip,2,0);   // Is a bool operator
1207
986
      }
1208
987
      /* " used for strings */
1209
988
    case MY_LEX_STRING:                 // Incomplete text string
1210
 
      if (!(yylval->lex_str.str = get_text(lip, 1, 1)))
 
989
      if (!(yylval->lex_str.str_ = get_text(lip, 1, 1)))
1211
990
      {
1212
 
        state= MY_LEX_CHAR;             // Read char by char
1213
 
        break;
 
991
        state= MY_LEX_CHAR;             // Read char by char
 
992
        break;
1214
993
      }
1215
 
      yylval->lex_str.length=lip->yytoklen;
 
994
      yylval->lex_str.assign(yylval->lex_str.data(), lip->yytoklen);
1216
995
 
1217
996
      lip->body_utf8_append(lip->m_cpp_text_start);
1218
 
 
1219
 
      lip->body_utf8_append_literal(thd, &yylval->lex_str,
1220
 
        lip->m_underscore_cs ? lip->m_underscore_cs : cs,
1221
 
        lip->m_cpp_text_end);
1222
 
 
1223
 
      lip->m_underscore_cs= NULL;
 
997
      lip->body_utf8_append_literal(yylval->lex_str, lip->m_cpp_text_end);
1224
998
 
1225
999
      lex->text_string_is_7bit= (lip->tok_bitmap & 0x80) ? 0 : 1;
1226
1000
      return(TEXT_STRING);
1231
1005
      lip->yyUnget();                   // Safety against eof
1232
1006
      state = MY_LEX_START;             // Try again
1233
1007
      break;
 
1008
 
1234
1009
    case MY_LEX_LONG_COMMENT:           /* Long C comment? */
1235
1010
      if (lip->yyPeek() != '*')
1236
1011
      {
1237
 
        state=MY_LEX_CHAR;              // Probable division
1238
 
        break;
 
1012
        state=MY_LEX_CHAR;              // Probable division
 
1013
        break;
1239
1014
      }
1240
1015
      lex->select_lex.options|= OPTION_FOUND_COMMENT;
1241
1016
      /* Reject '/' '*', since we might need to turn off the echo */
1252
1027
 
1253
1028
        /*
1254
1029
          The special comment format is very strict:
1255
 
          '/' '*' '!', followed by exactly
1256
 
          1 digit (major), 2 digits (minor), then 2 digits (dot).
1257
 
          32302 -> 3.23.02
1258
 
          50032 -> 5.0.32
1259
 
          50114 -> 5.1.14
 
1030
          '/' '*' '!', followed by digits ended by a non-digit.
 
1031
          There must be at least 5 digits for it to count
1260
1032
        */
1261
 
        char version_str[6];
1262
 
        version_str[0]= lip->yyPeekn(0);
1263
 
        version_str[1]= lip->yyPeekn(1);
1264
 
        version_str[2]= lip->yyPeekn(2);
1265
 
        version_str[3]= lip->yyPeekn(3);
1266
 
        version_str[4]= lip->yyPeekn(4);
1267
 
        version_str[5]= 0;
1268
 
        if (  my_isdigit(cs, version_str[0])
1269
 
           && my_isdigit(cs, version_str[1])
1270
 
           && my_isdigit(cs, version_str[2])
1271
 
           && my_isdigit(cs, version_str[3])
1272
 
           && my_isdigit(cs, version_str[4])
1273
 
           )
1274
 
        {
1275
 
          ulong version;
1276
 
          version=strtol(version_str, NULL, 10);
 
1033
        const int MAX_VERSION_SIZE= 16;
 
1034
        char version_str[MAX_VERSION_SIZE];
 
1035
 
 
1036
        int pos= 0;
 
1037
        do
 
1038
        {
 
1039
          version_str[pos]= lip->yyPeekn(pos);
 
1040
          pos++;
 
1041
        } while ((pos < MAX_VERSION_SIZE-1) && isdigit(version_str[pos-1]));
 
1042
        version_str[pos]= 0;
 
1043
 
 
1044
        /* To keep some semblance of compatibility, we impose a 5 digit floor */
 
1045
        if (pos > 4)
 
1046
        {
 
1047
          uint64_t version;
 
1048
          version=strtoll(version_str, NULL, 10);
1277
1049
 
1278
1050
          /* Accept 'M' 'm' 'm' 'd' 'd' */
1279
 
          lip->yySkipn(5);
 
1051
          lip->yySkipn(pos-1);
1280
1052
 
1281
 
          if (version <= MYSQL_VERSION_ID)
 
1053
          if (version <= DRIZZLE_VERSION_ID)
1282
1054
          {
1283
1055
            /* Expand the content of the special comment as real code */
1284
1056
            lip->set_echo(true);
1331
1103
      lip->in_comment= NO_COMMENT;
1332
1104
      lip->set_echo(true);
1333
1105
      break;
 
1106
 
1334
1107
    case MY_LEX_END_LONG_COMMENT:
1335
1108
      if ((lip->in_comment != NO_COMMENT) && lip->yyPeek() == '/')
1336
1109
      {
1345
1118
        state=MY_LEX_START;
1346
1119
      }
1347
1120
      else
1348
 
        state=MY_LEX_CHAR;              // Return '*'
 
1121
        state=MY_LEX_CHAR;              // Return '*'
1349
1122
      break;
 
1123
 
1350
1124
    case MY_LEX_SET_VAR:                // Check if ':='
1351
1125
      if (lip->yyPeek() != '=')
1352
1126
      {
1353
 
        state=MY_LEX_CHAR;              // Return ':'
1354
 
        break;
 
1127
        state=MY_LEX_CHAR;              // Return ':'
 
1128
        break;
1355
1129
      }
1356
1130
      lip->yySkip();
1357
1131
      return (SET_VAR);
 
1132
 
1358
1133
    case MY_LEX_SEMICOLON:                      // optional line terminator
1359
1134
      if (lip->yyPeek())
1360
1135
      {
1361
 
        if ((thd->client_capabilities & CLIENT_MULTI_STATEMENTS) && 
1362
 
            !lip->stmt_prepare_mode)
1363
 
        {
1364
 
          lip->found_semicolon= lip->get_ptr();
1365
 
          thd->server_status|= SERVER_MORE_RESULTS_EXISTS;
1366
 
          lip->next_state= MY_LEX_END;
1367
 
          lip->set_echo(true);
1368
 
          return (END_OF_INPUT);
1369
 
        }
1370
1136
        state= MY_LEX_CHAR;             // Return ';'
1371
 
        break;
 
1137
        break;
1372
1138
      }
1373
1139
      lip->next_state=MY_LEX_END;       // Mark for next loop
1374
1140
      return(END_OF_INPUT);
 
1141
 
1375
1142
    case MY_LEX_EOL:
1376
1143
      if (lip->eof())
1377
1144
      {
1387
1154
      }
1388
1155
      state=MY_LEX_CHAR;
1389
1156
      break;
 
1157
 
1390
1158
    case MY_LEX_END:
1391
1159
      lip->next_state=MY_LEX_END;
1392
 
      return(0);                        // We found end of input last time
1393
 
      
 
1160
      return false;                     // We found end of input last time
 
1161
 
1394
1162
      /* Actually real shouldn't start with . but allow them anyhow */
 
1163
 
1395
1164
    case MY_LEX_REAL_OR_POINT:
1396
 
      if (my_isdigit(cs,lip->yyPeek()))
1397
 
        state = MY_LEX_REAL;            // Real
 
1165
      if (cs->isdigit(lip->yyPeek()))
 
1166
        state= MY_LEX_REAL;             // Real
1398
1167
      else
1399
1168
      {
1400
 
        state= MY_LEX_IDENT_SEP;        // return '.'
 
1169
        state= MY_LEX_IDENT_SEP;        // return '.'
1401
1170
        lip->yyUnget();                 // Put back '.'
1402
1171
      }
1403
1172
      break;
 
1173
 
1404
1174
    case MY_LEX_USER_END:               // end '@' of user@hostname
1405
1175
      switch (state_map[(uint8_t)lip->yyPeek()]) {
1406
1176
      case MY_LEX_STRING:
1407
1177
      case MY_LEX_USER_VARIABLE_DELIMITER:
1408
1178
      case MY_LEX_STRING_OR_DELIMITER:
1409
 
        break;
 
1179
        break;
1410
1180
      case MY_LEX_USER_END:
1411
 
        lip->next_state=MY_LEX_SYSTEM_VAR;
1412
 
        break;
 
1181
        lip->next_state=MY_LEX_SYSTEM_VAR;
 
1182
        break;
1413
1183
      default:
1414
 
        lip->next_state=MY_LEX_HOSTNAME;
1415
 
        break;
 
1184
        lip->next_state=MY_LEX_HOSTNAME;
 
1185
        break;
1416
1186
      }
1417
 
      yylval->lex_str.str=(char*) lip->get_ptr();
1418
 
      yylval->lex_str.length=1;
1419
 
      return((int) '@');
 
1187
      yylval->lex_str.assign(lip->get_ptr(), 1);
 
1188
      return '@';
 
1189
 
1420
1190
    case MY_LEX_HOSTNAME:               // end '@' of user@hostname
1421
1191
      for (c=lip->yyGet() ;
1422
 
           my_isalnum(cs,c) || c == '.' || c == '_' ||  c == '$';
 
1192
           cs->isalnum(c) || c == '.' || c == '_' ||  c == '$';
1423
1193
           c= lip->yyGet()) ;
1424
1194
      yylval->lex_str=get_token(lip, 0, lip->yyLength());
1425
1195
      return(LEX_HOSTNAME);
 
1196
 
1426
1197
    case MY_LEX_SYSTEM_VAR:
1427
 
      yylval->lex_str.str=(char*) lip->get_ptr();
1428
 
      yylval->lex_str.length=1;
 
1198
      yylval->lex_str.assign(lip->get_ptr(), 1);
1429
1199
      lip->yySkip();                                    // Skip '@'
1430
1200
      lip->next_state= (state_map[(uint8_t)lip->yyPeek()] ==
1431
1201
                        MY_LEX_USER_VARIABLE_DELIMITER ?
1432
1202
                        MY_LEX_OPERATOR_OR_IDENT :
1433
1203
                        MY_LEX_IDENT_OR_KEYWORD);
1434
1204
      return((int) '@');
 
1205
 
1435
1206
    case MY_LEX_IDENT_OR_KEYWORD:
1436
1207
      /*
1437
 
        We come here when we have found two '@' in a row.
1438
 
        We should now be able to handle:
1439
 
        [(global | local | session) .]variable_name
 
1208
        We come here when we have found two '@' in a row.
 
1209
        We should now be able to handle:
 
1210
        [(global | local | session) .]variable_name
1440
1211
      */
1441
1212
 
1442
1213
      for (result_state= 0; ident_map[c= lip->yyGet()]; result_state|= c) {};
1444
1215
      result_state= result_state & 0x80 ? IDENT_QUOTED : IDENT;
1445
1216
 
1446
1217
      if (c == '.')
1447
 
        lip->next_state=MY_LEX_IDENT_SEP;
 
1218
        lip->next_state=MY_LEX_IDENT_SEP;
 
1219
 
1448
1220
      length= lip->yyLength();
1449
1221
      if (length == 0)
1450
1222
        return(ABORT_SYM);              // Names must be nonempty.
 
1223
 
1451
1224
      if ((tokval= find_keyword(lip, length,0)))
1452
1225
      {
1453
1226
        lip->yyUnget();                         // Put back 'c'
1454
 
        return(tokval);                         // Was keyword
 
1227
        return(tokval);                         // Was keyword
1455
1228
      }
1456
1229
      yylval->lex_str=get_token(lip, 0, length);
1457
1230
 
1458
1231
      lip->body_utf8_append(lip->m_cpp_text_start);
1459
 
 
1460
 
      lip->body_utf8_append_literal(thd, &yylval->lex_str, cs,
1461
 
                                    lip->m_cpp_text_end);
1462
 
 
1463
 
      return(result_state);
 
1232
      lip->body_utf8_append_literal(yylval->lex_str, lip->m_cpp_text_end);
 
1233
 
 
1234
      return result_state;
1464
1235
    }
1465
1236
  }
1466
1237
}
1467
1238
 
1468
 
 
1469
 
/**
1470
 
  Construct a copy of this object to be used for mysql_alter_table
1471
 
  and mysql_create_table.
1472
 
 
1473
 
  Historically, these two functions modify their Alter_info
1474
 
  arguments. This behaviour breaks re-execution of prepared
1475
 
  statements and stored procedures and is compensated by always
1476
 
  supplying a copy of Alter_info to these functions.
1477
 
 
1478
 
  @return You need to use check the error in THD for out
1479
 
  of memory condition after calling this function.
1480
 
*/
1481
 
 
1482
 
Alter_info::Alter_info(const Alter_info &rhs, MEM_ROOT *mem_root)
1483
 
  :drop_list(rhs.drop_list, mem_root),
1484
 
  alter_list(rhs.alter_list, mem_root),
1485
 
  key_list(rhs.key_list, mem_root),
1486
 
  create_list(rhs.create_list, mem_root),
1487
 
  flags(rhs.flags),
1488
 
  keys_onoff(rhs.keys_onoff),
1489
 
  tablespace_op(rhs.tablespace_op),
1490
 
  no_parts(rhs.no_parts),
1491
 
  build_method(rhs.build_method),
1492
 
  datetime_field(rhs.datetime_field),
1493
 
  error_if_not_empty(rhs.error_if_not_empty)
1494
 
{
1495
 
  /*
1496
 
    Make deep copies of used objects.
1497
 
    This is not a fully deep copy - clone() implementations
1498
 
    of Alter_drop, Alter_column, Key, foreign_key, Key_part_spec
1499
 
    do not copy string constants. At the same length the only
1500
 
    reason we make a copy currently is that ALTER/CREATE TABLE
1501
 
    code changes input Alter_info definitions, but string
1502
 
    constants never change.
1503
 
  */
1504
 
  list_copy_and_replace_each_value(drop_list, mem_root);
1505
 
  list_copy_and_replace_each_value(alter_list, mem_root);
1506
 
  list_copy_and_replace_each_value(key_list, mem_root);
1507
 
  list_copy_and_replace_each_value(create_list, mem_root);
1508
 
}
1509
 
 
1510
 
 
1511
 
void trim_whitespace(CHARSET_INFO *cs, LEX_STRING *str)
1512
 
{
1513
 
  /*
1514
 
    TODO:
1515
 
    This code assumes that there are no multi-bytes characters
1516
 
    that can be considered white-space.
1517
 
  */
1518
 
 
1519
 
  while ((str->length > 0) && (my_isspace(cs, str->str[0])))
1520
 
  {
1521
 
    str->length --;
1522
 
    str->str ++;
1523
 
  }
1524
 
 
1525
 
  /*
1526
 
    FIXME:
1527
 
    Also, parsing backward is not safe with multi bytes characters
1528
 
  */
1529
 
  while ((str->length > 0) && (my_isspace(cs, str->str[str->length-1])))
1530
 
  {
1531
 
    str->length --;
1532
 
  }
1533
 
}
1534
 
 
1535
 
 
1536
1239
/*
1537
 
  st_select_lex structures initialisations
 
1240
  Select_Lex structures initialisations
1538
1241
*/
1539
 
 
1540
 
void st_select_lex_node::init_query()
 
1242
void Select_Lex_Node::init_query()
1541
1243
{
1542
1244
  options= 0;
1543
1245
  linkage= UNSPECIFIED_TYPE;
1544
1246
  no_error= no_table_names_allowed= 0;
1545
 
  uncacheable= 0;
1546
 
}
1547
 
 
1548
 
void st_select_lex_node::init_select()
1549
 
{
1550
 
}
1551
 
 
1552
 
void st_select_lex_unit::init_query()
1553
 
{
1554
 
  st_select_lex_node::init_query();
 
1247
  uncacheable.reset();
 
1248
}
 
1249
 
 
1250
void Select_Lex_Node::init_select()
 
1251
{
 
1252
}
 
1253
 
 
1254
void Select_Lex_Unit::init_query()
 
1255
{
 
1256
  Select_Lex_Node::init_query();
1555
1257
  linkage= GLOBAL_OPTIONS_TYPE;
1556
1258
  global_parameters= first_select();
1557
1259
  select_limit_cnt= HA_POS_ERROR;
1563
1265
  table= 0;
1564
1266
  fake_select_lex= 0;
1565
1267
  cleaned= 0;
1566
 
  item_list.empty();
 
1268
  item_list.clear();
1567
1269
  describe= 0;
1568
1270
  found_rows_for_union= 0;
1569
1271
}
1570
1272
 
1571
 
void st_select_lex::init_query()
 
1273
void Select_Lex::init_query()
1572
1274
{
1573
 
  st_select_lex_node::init_query();
1574
 
  table_list.empty();
1575
 
  top_join_list.empty();
 
1275
  Select_Lex_Node::init_query();
 
1276
  table_list.clear();
 
1277
  top_join_list.clear();
1576
1278
  join_list= &top_join_list;
1577
1279
  embedding= leaf_tables= 0;
1578
 
  item_list.empty();
 
1280
  item_list.clear();
1579
1281
  join= 0;
1580
 
  having= prep_having= where= prep_where= 0;
 
1282
  having= where= 0;
1581
1283
  olap= UNSPECIFIED_OLAP_TYPE;
1582
1284
  having_fix_field= 0;
1583
1285
  context.select_lex= this;
1594
1296
  parent_lex->push_context(&context);
1595
1297
  cond_count= between_count= with_wild= 0;
1596
1298
  max_equal_elems= 0;
1597
 
  conds_processed_with_permanent_arena= 0;
1598
1299
  ref_pointer_array= 0;
1599
1300
  select_n_where_fields= 0;
1600
1301
  select_n_having_items= 0;
1601
1302
  subquery_in_having= explicit_limit= 0;
1602
1303
  is_item_list_lookup= 0;
1603
 
  first_execution= 1;
1604
 
  first_cond_optimization= 1;
1605
1304
  parsing_place= NO_MATTER;
1606
 
  exclude_from_table_unique_test= no_wrap_view_item= false;
 
1305
  exclude_from_table_unique_test= false;
1607
1306
  nest_level= 0;
1608
1307
  link_next= 0;
1609
1308
}
1610
1309
 
1611
 
void st_select_lex::init_select()
 
1310
void Select_Lex::init_select()
1612
1311
{
1613
 
  st_select_lex_node::init_select();
1614
 
  sj_nests.empty();
1615
 
  group_list.empty();
1616
 
  type= db= 0;
 
1312
  sj_nests.clear();
 
1313
  group_list.clear();
 
1314
  db= 0;
1617
1315
  having= 0;
1618
 
  table_join_options= 0;
1619
1316
  in_sum_expr= with_wild= 0;
1620
1317
  options= 0;
1621
1318
  braces= 0;
1622
 
  interval_list.empty();
1623
 
  ftfunc_list_alloc.empty();
 
1319
  interval_list.clear();
1624
1320
  inner_sum_func_list= 0;
1625
 
  ftfunc_list= &ftfunc_list_alloc;
1626
1321
  linkage= UNSPECIFIED_TYPE;
1627
1322
  order_list.elements= 0;
1628
1323
  order_list.first= 0;
1629
 
  order_list.next= (uchar**) &order_list.first;
 
1324
  order_list.next= (unsigned char**) &order_list.first;
1630
1325
  /* Set limit and offset to default values */
1631
1326
  select_limit= 0;      /* denotes the default limit = HA_POS_ERROR */
1632
1327
  offset_limit= 0;      /* denotes the default offset = 0 */
1633
1328
  with_sum_func= 0;
 
1329
  is_cross= false;
1634
1330
  is_correlated= 0;
1635
1331
  cur_pos_in_select_list= UNDEF_POS;
1636
 
  non_agg_fields.empty();
 
1332
  non_agg_fields.clear();
1637
1333
  cond_value= having_value= Item::COND_UNDEF;
1638
 
  inner_refs_list.empty();
1639
 
  full_group_by_flag= 0;
 
1334
  inner_refs_list.clear();
 
1335
  full_group_by_flag.reset();
1640
1336
}
1641
1337
 
1642
1338
/*
1643
 
  st_select_lex structures linking
 
1339
  Select_Lex structures linking
1644
1340
*/
1645
1341
 
1646
1342
/* include on level down */
1647
 
void st_select_lex_node::include_down(st_select_lex_node *upper)
 
1343
void Select_Lex_Node::include_down(Select_Lex_Node *upper)
1648
1344
{
1649
1345
  if ((next= upper->slave))
1650
1346
    next->prev= &next;
1658
1354
  include on level down (but do not link)
1659
1355
 
1660
1356
  SYNOPSYS
1661
 
    st_select_lex_node::include_standalone()
 
1357
    Select_Lex_Node::include_standalone()
1662
1358
    upper - reference on node underr which this node should be included
1663
1359
    ref - references on reference on this node
1664
1360
*/
1665
 
void st_select_lex_node::include_standalone(st_select_lex_node *upper,
1666
 
                                            st_select_lex_node **ref)
 
1361
void Select_Lex_Node::include_standalone(Select_Lex_Node *upper,
 
1362
                                            Select_Lex_Node **ref)
1667
1363
{
1668
1364
  next= 0;
1669
1365
  prev= ref;
1672
1368
}
1673
1369
 
1674
1370
/* include neighbour (on same level) */
1675
 
void st_select_lex_node::include_neighbour(st_select_lex_node *before)
 
1371
void Select_Lex_Node::include_neighbour(Select_Lex_Node *before)
1676
1372
{
1677
1373
  if ((next= before->next))
1678
1374
    next->prev= &next;
1682
1378
  slave= 0;
1683
1379
}
1684
1380
 
1685
 
/* including in global SELECT_LEX list */
1686
 
void st_select_lex_node::include_global(st_select_lex_node **plink)
 
1381
/* including in global Select_Lex list */
 
1382
void Select_Lex_Node::include_global(Select_Lex_Node **plink)
1687
1383
{
1688
1384
  if ((link_next= *plink))
1689
1385
    link_next->link_prev= &link_next;
1692
1388
}
1693
1389
 
1694
1390
//excluding from global list (internal function)
1695
 
void st_select_lex_node::fast_exclude()
 
1391
void Select_Lex_Node::fast_exclude()
1696
1392
{
1697
1393
  if (link_prev)
1698
1394
  {
1702
1398
  // Remove slave structure
1703
1399
  for (; slave; slave= slave->next)
1704
1400
    slave->fast_exclude();
1705
 
  
 
1401
 
1706
1402
}
1707
1403
 
1708
1404
/*
1709
1405
  excluding select_lex structure (except first (first select can't be
1710
1406
  deleted, because it is most upper select))
1711
1407
*/
1712
 
void st_select_lex_node::exclude()
 
1408
void Select_Lex_Node::exclude()
1713
1409
{
1714
1410
  //exclude from global list
1715
1411
  fast_exclude();
1716
1412
  //exclude from other structures
1717
1413
  if ((*prev= next))
1718
1414
    next->prev= prev;
1719
 
  /* 
1720
 
     We do not need following statements, because prev pointer of first 
 
1415
  /*
 
1416
     We do not need following statements, because prev pointer of first
1721
1417
     list element point to master->slave
1722
1418
     if (master->slave == this)
1723
1419
       master->slave= next;
1729
1425
  Exclude level of current unit from tree of SELECTs
1730
1426
 
1731
1427
  SYNOPSYS
1732
 
    st_select_lex_unit::exclude_level()
 
1428
    Select_Lex_Unit::exclude_level()
1733
1429
 
1734
1430
  NOTE: units which belong to current will be brought up on level of
1735
 
  currernt unit 
 
1431
  currernt unit
1736
1432
*/
1737
 
void st_select_lex_unit::exclude_level()
 
1433
void Select_Lex_Unit::exclude_level()
1738
1434
{
1739
 
  SELECT_LEX_UNIT *units= 0, **units_last= &units;
1740
 
  for (SELECT_LEX *sl= first_select(); sl; sl= sl->next_select())
 
1435
  Select_Lex_Unit *units= 0, **units_last= &units;
 
1436
  for (Select_Lex *sl= first_select(); sl; sl= sl->next_select())
1741
1437
  {
1742
1438
    // unlink current level from global SELECTs list
1743
1439
    if (sl->link_prev && (*sl->link_prev= sl->link_next))
1744
1440
      sl->link_next->link_prev= sl->link_prev;
1745
1441
 
1746
1442
    // bring up underlay levels
1747
 
    SELECT_LEX_UNIT **last= 0;
1748
 
    for (SELECT_LEX_UNIT *u= sl->first_inner_unit(); u; u= u->next_unit())
 
1443
    Select_Lex_Unit **last= 0;
 
1444
    for (Select_Lex_Unit *u= sl->first_inner_unit(); u; u= u->next_unit())
1749
1445
    {
1750
1446
      u->master= master;
1751
 
      last= (SELECT_LEX_UNIT**)&(u->next);
 
1447
      last= (Select_Lex_Unit**)&(u->next);
1752
1448
    }
1753
1449
    if (last)
1754
1450
    {
1760
1456
  {
1761
1457
    // include brought up levels in place of current
1762
1458
    (*prev)= units;
1763
 
    (*units_last)= (SELECT_LEX_UNIT*)next;
 
1459
    (*units_last)= (Select_Lex_Unit*)next;
1764
1460
    if (next)
1765
 
      next->prev= (SELECT_LEX_NODE**)units_last;
 
1461
      next->prev= (Select_Lex_Node**)units_last;
1766
1462
    units->prev= prev;
1767
1463
  }
1768
1464
  else
1774
1470
  }
1775
1471
}
1776
1472
 
1777
 
 
1778
1473
/*
1779
1474
  Exclude subtree of current unit from tree of SELECTs
1780
 
 
1781
 
  SYNOPSYS
1782
 
    st_select_lex_unit::exclude_tree()
1783
1475
*/
1784
 
void st_select_lex_unit::exclude_tree()
 
1476
void Select_Lex_Unit::exclude_tree()
1785
1477
{
1786
 
  for (SELECT_LEX *sl= first_select(); sl; sl= sl->next_select())
 
1478
  for (Select_Lex *sl= first_select(); sl; sl= sl->next_select())
1787
1479
  {
1788
1480
    // unlink current level from global SELECTs list
1789
1481
    if (sl->link_prev && (*sl->link_prev= sl->link_next))
1790
1482
      sl->link_next->link_prev= sl->link_prev;
1791
1483
 
1792
1484
    // unlink underlay levels
1793
 
    for (SELECT_LEX_UNIT *u= sl->first_inner_unit(); u; u= u->next_unit())
 
1485
    for (Select_Lex_Unit *u= sl->first_inner_unit(); u; u= u->next_unit())
1794
1486
    {
1795
1487
      u->exclude_level();
1796
1488
    }
1801
1493
    next->prev= prev;
1802
1494
}
1803
1495
 
1804
 
 
1805
 
/*
1806
 
  st_select_lex_node::mark_as_dependent mark all st_select_lex struct from 
1807
 
  this to 'last' as dependent
1808
 
 
1809
 
  SYNOPSIS
1810
 
    last - pointer to last st_select_lex struct, before wich all 
1811
 
           st_select_lex have to be marked as dependent
1812
 
 
1813
 
  NOTE
1814
 
    'last' should be reachable from this st_select_lex_node
1815
 
*/
1816
 
 
1817
 
void st_select_lex::mark_as_dependent(st_select_lex *last)
 
1496
/**
 
1497
 * Mark all Select_Lex struct from this to 'last' as dependent
 
1498
 *
 
1499
 * @param Pointer to last Select_Lex struct, before wich all
 
1500
 *        Select_Lex have to be marked as dependent
 
1501
 * @note 'last' should be reachable from this Select_Lex_Node
 
1502
 */
 
1503
void Select_Lex::mark_as_dependent(Select_Lex *last)
1818
1504
{
1819
1505
  /*
1820
1506
    Mark all selects from resolved to 1 before select where was
1821
1507
    found table as depended (of select where was found table)
1822
1508
  */
1823
 
  for (SELECT_LEX *s= this;
 
1509
  for (Select_Lex *s= this;
1824
1510
       s && s != last;
1825
1511
       s= s->outer_select())
1826
1512
  {
1827
 
    if (!(s->uncacheable & UNCACHEABLE_DEPENDENT))
 
1513
    if (! (s->uncacheable.test(UNCACHEABLE_DEPENDENT)))
1828
1514
    {
1829
1515
      // Select is dependent of outer select
1830
 
      s->uncacheable= (s->uncacheable & ~UNCACHEABLE_UNITED) |
1831
 
                       UNCACHEABLE_DEPENDENT;
1832
 
      SELECT_LEX_UNIT *munit= s->master_unit();
1833
 
      munit->uncacheable= (munit->uncacheable & ~UNCACHEABLE_UNITED) |
1834
 
                       UNCACHEABLE_DEPENDENT;
1835
 
      for (SELECT_LEX *sl= munit->first_select(); sl ; sl= sl->next_select())
 
1516
      s->uncacheable.set(UNCACHEABLE_DEPENDENT);
 
1517
      s->uncacheable.set(UNCACHEABLE_UNITED);
 
1518
      Select_Lex_Unit *munit= s->master_unit();
 
1519
      munit->uncacheable.set(UNCACHEABLE_UNITED);
 
1520
      munit->uncacheable.set(UNCACHEABLE_DEPENDENT);
 
1521
      for (Select_Lex *sl= munit->first_select(); sl ; sl= sl->next_select())
1836
1522
      {
1837
1523
        if (sl != s &&
1838
 
            !(sl->uncacheable & (UNCACHEABLE_DEPENDENT | UNCACHEABLE_UNITED)))
1839
 
          sl->uncacheable|= UNCACHEABLE_UNITED;
 
1524
            ! (sl->uncacheable.test(UNCACHEABLE_DEPENDENT) && sl->uncacheable.test(UNCACHEABLE_UNITED)))
 
1525
          sl->uncacheable.set(UNCACHEABLE_UNITED);
1840
1526
      }
1841
1527
    }
1842
1528
    s->is_correlated= true;
1846
1532
  }
1847
1533
}
1848
1534
 
1849
 
bool st_select_lex_node::set_braces(bool value __attribute__((__unused__)))
1850
 
{ return 1; }
1851
 
bool st_select_lex_node::inc_in_sum_expr()           { return 1; }
1852
 
uint st_select_lex_node::get_in_sum_expr()           { return 0; }
1853
 
TABLE_LIST* st_select_lex_node::get_table_list()     { return 0; }
1854
 
List<Item>* st_select_lex_node::get_item_list()      { return 0; }
1855
 
TABLE_LIST *st_select_lex_node::add_table_to_list (THD *thd __attribute__((__unused__)),
1856
 
                                                   Table_ident *table __attribute__((__unused__)),
1857
 
                                                  LEX_STRING *alias __attribute__((__unused__)),
1858
 
                                                  ulong table_join_options __attribute__((__unused__)),
1859
 
                                                  thr_lock_type flags __attribute__((__unused__)),
1860
 
                                                  List<Index_hint> *hints __attribute__((__unused__)),
1861
 
                                                  LEX_STRING *option __attribute__((__unused__)))
1862
 
{
1863
 
  return 0;
1864
 
}
1865
 
ulong st_select_lex_node::get_table_join_options()
1866
 
{
1867
 
  return 0;
1868
 
}
 
1535
bool Select_Lex_Node::set_braces(bool)
 
1536
{ return true; }
 
1537
 
 
1538
bool Select_Lex_Node::inc_in_sum_expr()
 
1539
{ return true; }
 
1540
 
 
1541
uint32_t Select_Lex_Node::get_in_sum_expr()
 
1542
{ return 0; }
 
1543
 
 
1544
TableList* Select_Lex_Node::get_table_list()
 
1545
{ return NULL; }
 
1546
 
 
1547
List<Item>* Select_Lex_Node::get_item_list()
 
1548
{ return NULL; }
 
1549
 
 
1550
TableList *Select_Lex_Node::add_table_to_list(Session *,
 
1551
                                              Table_ident *,
 
1552
                                              lex_string_t *,
 
1553
                                              const bitset<NUM_OF_TABLE_OPTIONS>&,
 
1554
                                              thr_lock_type,
 
1555
                                              List<Index_hint> *,
 
1556
                                              lex_string_t *)
 
1557
{
 
1558
  return 0;
 
1559
}
 
1560
 
1869
1561
 
1870
1562
/*
1871
1563
  prohibit using LIMIT clause
1872
1564
*/
1873
 
bool st_select_lex::test_limit()
 
1565
bool Select_Lex::test_limit()
1874
1566
{
1875
1567
  if (select_limit != 0)
1876
1568
  {
1877
1569
    my_error(ER_NOT_SUPPORTED_YET, MYF(0),
1878
1570
             "LIMIT & IN/ALL/ANY/SOME subquery");
1879
 
    return(1);
 
1571
    return true;
1880
1572
  }
1881
 
  return(0);
1882
 
}
1883
 
 
1884
 
 
1885
 
st_select_lex_unit* st_select_lex_unit::master_unit()
1886
 
{
1887
 
    return this;
1888
 
}
1889
 
 
1890
 
 
1891
 
st_select_lex* st_select_lex_unit::outer_select()
1892
 
{
1893
 
  return (st_select_lex*) master;
1894
 
}
1895
 
 
1896
 
 
1897
 
bool st_select_lex::add_order_to_list(THD *thd, Item *item, bool asc)
1898
 
{
1899
 
  return add_to_list(thd, order_list, item, asc);
1900
 
}
1901
 
 
1902
 
 
1903
 
bool st_select_lex::add_item_to_list(THD *thd __attribute__((__unused__)),
1904
 
                                     Item *item)
1905
 
{
1906
 
  return(item_list.push_back(item));
1907
 
}
1908
 
 
1909
 
 
1910
 
bool st_select_lex::add_group_to_list(THD *thd, Item *item, bool asc)
1911
 
{
1912
 
  return add_to_list(thd, group_list, item, asc);
1913
 
}
1914
 
 
1915
 
 
1916
 
st_select_lex_unit* st_select_lex::master_unit()
1917
 
{
1918
 
  return (st_select_lex_unit*) master;
1919
 
}
1920
 
 
1921
 
 
1922
 
st_select_lex* st_select_lex::outer_select()
1923
 
{
1924
 
  return (st_select_lex*) master->get_master();
1925
 
}
1926
 
 
1927
 
 
1928
 
bool st_select_lex::set_braces(bool value)
 
1573
  return false;
 
1574
}
 
1575
 
 
1576
Select_Lex_Unit* Select_Lex_Unit::master_unit()
 
1577
{
 
1578
  return this;
 
1579
}
 
1580
 
 
1581
Select_Lex* Select_Lex_Unit::outer_select()
 
1582
{
 
1583
  return (Select_Lex*) master;
 
1584
}
 
1585
 
 
1586
void Select_Lex::add_order_to_list(Session *session, Item *item, bool asc)
 
1587
{
 
1588
  add_to_list(session, order_list, item, asc);
 
1589
}
 
1590
 
 
1591
void Select_Lex::add_item_to_list(Session *, Item *item)
 
1592
{
 
1593
        item_list.push_back(item);
 
1594
}
 
1595
 
 
1596
void Select_Lex::add_group_to_list(Session *session, Item *item, bool asc)
 
1597
{
 
1598
  add_to_list(session, group_list, item, asc);
 
1599
}
 
1600
 
 
1601
Select_Lex_Unit* Select_Lex::master_unit()
 
1602
{
 
1603
  return (Select_Lex_Unit*) master;
 
1604
}
 
1605
 
 
1606
Select_Lex* Select_Lex::outer_select()
 
1607
{
 
1608
  return (Select_Lex*) master->get_master();
 
1609
}
 
1610
 
 
1611
bool Select_Lex::set_braces(bool value)
1929
1612
{
1930
1613
  braces= value;
1931
 
  return 0; 
 
1614
  return false;
1932
1615
}
1933
1616
 
1934
 
 
1935
 
bool st_select_lex::inc_in_sum_expr()
 
1617
bool Select_Lex::inc_in_sum_expr()
1936
1618
{
1937
1619
  in_sum_expr++;
1938
 
  return 0;
 
1620
  return false;
1939
1621
}
1940
1622
 
1941
 
 
1942
 
uint st_select_lex::get_in_sum_expr()
 
1623
uint32_t Select_Lex::get_in_sum_expr()
1943
1624
{
1944
1625
  return in_sum_expr;
1945
1626
}
1946
1627
 
1947
 
 
1948
 
TABLE_LIST* st_select_lex::get_table_list()
 
1628
TableList* Select_Lex::get_table_list()
1949
1629
{
1950
 
  return (TABLE_LIST*) table_list.first;
 
1630
  return (TableList*) table_list.first;
1951
1631
}
1952
1632
 
1953
 
List<Item>* st_select_lex::get_item_list()
 
1633
List<Item>* Select_Lex::get_item_list()
1954
1634
{
1955
1635
  return &item_list;
1956
1636
}
1957
1637
 
1958
 
ulong st_select_lex::get_table_join_options()
1959
 
{
1960
 
  return table_join_options;
1961
 
}
1962
 
 
1963
 
 
1964
 
bool st_select_lex::setup_ref_array(THD *thd, uint order_group_num)
1965
 
{
1966
 
  if (ref_pointer_array)
1967
 
    return 0;
1968
 
 
1969
 
  /*
1970
 
    We have to create array in prepared statement memory if it is
1971
 
    prepared statement
1972
 
  */
1973
 
  Query_arena *arena= thd->stmt_arena;
1974
 
  return (ref_pointer_array=
1975
 
          (Item **)arena->alloc(sizeof(Item*) * (n_child_sum_items +
1976
 
                                                 item_list.elements +
1977
 
                                                 select_n_having_items +
1978
 
                                                 select_n_where_fields +
1979
 
                                                 order_group_num)*5)) == 0;
1980
 
}
1981
 
 
1982
 
 
1983
 
void st_select_lex_unit::print(String *str, enum_query_type query_type)
 
1638
void Select_Lex::setup_ref_array(Session *session, uint32_t order_group_num)
 
1639
{
 
1640
  if (not ref_pointer_array)
 
1641
    ref_pointer_array= new (session->mem) Item*[5 * (n_child_sum_items + item_list.size() + select_n_having_items + select_n_where_fields + order_group_num)];
 
1642
}
 
1643
 
 
1644
void Select_Lex_Unit::print(String *str)
1984
1645
{
1985
1646
  bool union_all= !union_distinct;
1986
 
  for (SELECT_LEX *sl= first_select(); sl; sl= sl->next_select())
 
1647
  for (Select_Lex *sl= first_select(); sl; sl= sl->next_select())
1987
1648
  {
1988
1649
    if (sl != first_select())
1989
1650
    {
1995
1656
    }
1996
1657
    if (sl->braces)
1997
1658
      str->append('(');
1998
 
    sl->print(thd, str, query_type);
 
1659
    sl->print(session, str);
1999
1660
    if (sl->braces)
2000
1661
      str->append(')');
2001
1662
  }
2006
1667
      str->append(STRING_WITH_LEN(" order by "));
2007
1668
      fake_select_lex->print_order(
2008
1669
        str,
2009
 
        (ORDER *) fake_select_lex->order_list.first,
2010
 
        query_type);
 
1670
        (Order *) fake_select_lex->order_list.first);
2011
1671
    }
2012
 
    fake_select_lex->print_limit(thd, str, query_type);
 
1672
    fake_select_lex->print_limit(session, str);
2013
1673
  }
2014
1674
}
2015
1675
 
2016
 
 
2017
 
void st_select_lex::print_order(String *str,
2018
 
                                ORDER *order,
2019
 
                                enum_query_type query_type)
 
1676
void Select_Lex::print_order(String *str,
 
1677
                             Order *order)
2020
1678
{
2021
1679
  for (; order; order= order->next)
2022
1680
  {
2023
1681
    if (order->counter_used)
2024
1682
    {
2025
1683
      char buffer[20];
2026
 
      uint length= snprintf(buffer, 20, "%d", order->counter);
 
1684
      uint32_t length= snprintf(buffer, 20, "%d", order->counter);
2027
1685
      str->append(buffer, length);
2028
1686
    }
2029
1687
    else
2030
 
      (*order->item)->print(str, query_type);
 
1688
      (*order->item)->print(str);
2031
1689
    if (!order->asc)
2032
1690
      str->append(STRING_WITH_LEN(" desc"));
2033
1691
    if (order->next)
2034
1692
      str->append(',');
2035
1693
  }
2036
1694
}
2037
 
 
2038
1695
 
2039
 
void st_select_lex::print_limit(THD *thd __attribute__((__unused__)),
2040
 
                                String *str,
2041
 
                                enum_query_type query_type)
 
1696
void Select_Lex::print_limit(Session *, String *str)
2042
1697
{
2043
 
  SELECT_LEX_UNIT *unit= master_unit();
 
1698
  Select_Lex_Unit *unit= master_unit();
2044
1699
  Item_subselect *item= unit->item;
2045
1700
 
2046
1701
  if (item && unit->global_parameters == this)
2059
1714
                    ((Item_in_subselect*)item)->exec_method ==
2060
1715
                    Item_in_subselect::MATERIALIZATION) ?
2061
1716
                   true :
2062
 
                   (select_limit->val_int() == 1LL) &&
 
1717
                   (select_limit->val_int() == 1L) &&
2063
1718
                   offset_limit == 0));
2064
1719
      return;
2065
1720
    }
2069
1724
    str->append(STRING_WITH_LEN(" limit "));
2070
1725
    if (offset_limit)
2071
1726
    {
2072
 
      offset_limit->print(str, query_type);
 
1727
      offset_limit->print(str);
2073
1728
      str->append(',');
2074
1729
    }
2075
 
    select_limit->print(str, query_type);
 
1730
    select_limit->print(str);
2076
1731
  }
2077
1732
}
2078
1733
 
2079
 
/**
2080
 
  @brief Restore the LEX and THD in case of a parse error.
2081
 
 
2082
 
  This is a clean up call that is invoked by the Bison generated
2083
 
  parser before returning an error from MYSQLparse. If your
2084
 
  semantic actions manipulate with the global thread state (which
2085
 
  is a very bad practice and should not normally be employed) and
2086
 
  need a clean-up in case of error, and you can not use %destructor
2087
 
  rule in the grammar file itself, this function should be used
2088
 
  to implement the clean up.
2089
 
*/
2090
 
 
2091
 
void st_lex::cleanup_lex_after_parse_error(THD *thd __attribute__((__unused__)))
 
1734
LEX::~LEX()
2092
1735
{
 
1736
  delete _create_table;
 
1737
  delete _alter_table;
2093
1738
}
2094
1739
 
2095
1740
/*
2109
1754
    this method to reset state of already initialized Query_tables_list
2110
1755
    so it can be used for processing of new statement.
2111
1756
*/
2112
 
 
2113
1757
void Query_tables_list::reset_query_tables_list(bool init)
2114
1758
{
2115
1759
  if (!init && query_tables)
2116
1760
  {
2117
 
    TABLE_LIST *table= query_tables;
 
1761
    TableList *table= query_tables;
2118
1762
    for (;;)
2119
1763
    {
2120
1764
      if (query_tables_last == &table->next_global ||
2125
1769
  query_tables= 0;
2126
1770
  query_tables_last= &query_tables;
2127
1771
  query_tables_own_last= 0;
2128
 
  if (init)
2129
 
  {
2130
 
    /*
2131
 
      We delay real initialization of hash (and therefore related
2132
 
      memory allocation) until first insertion into this hash.
2133
 
    */
2134
 
    hash_clear(&sroutines);
2135
 
  }
2136
 
  else if (sroutines.records)
2137
 
  {
2138
 
    /* Non-zero sroutines.records means that hash was initialized. */
2139
 
    my_hash_reset(&sroutines);
2140
 
  }
2141
 
  sroutines_list.empty();
2142
 
  sroutines_list_own_last= sroutines_list.next;
2143
 
  sroutines_list_own_elements= 0;
2144
 
  binlog_stmt_flags= 0;
2145
 
}
2146
 
 
2147
 
 
2148
 
/*
2149
 
  Destroy Query_tables_list object with freeing all resources used by it.
2150
 
 
2151
 
  SYNOPSIS
2152
 
    destroy_query_tables_list()
2153
 
*/
2154
 
 
2155
 
void Query_tables_list::destroy_query_tables_list()
2156
 
{
2157
 
  hash_free(&sroutines);
2158
 
}
2159
 
 
 
1772
}
2160
1773
 
2161
1774
/*
2162
1775
  Initialize LEX object.
2163
1776
 
2164
1777
  SYNOPSIS
2165
 
    st_lex::st_lex()
 
1778
    LEX::LEX()
2166
1779
 
2167
1780
  NOTE
2168
1781
    LEX object initialized with this constructor can be used as part of
2169
 
    THD object for which one can safely call open_tables(), lock_tables()
 
1782
    Session object for which one can safely call open_tables(), lock_tables()
2170
1783
    and close_thread_tables() functions. But it is not yet ready for
2171
1784
    statement parsing. On should use lex_start() function to prepare LEX
2172
1785
    for this.
2173
1786
*/
2174
 
 
2175
 
st_lex::st_lex()
2176
 
  :result(0), yacc_yyss(0), yacc_yyvs(0),
2177
 
   sql_command(SQLCOM_END), option_type(OPT_DEFAULT), is_lex_started(0)
 
1787
LEX::LEX() :
 
1788
    result(0),
 
1789
    yacc_yyss(0),
 
1790
    yacc_yyvs(0),
 
1791
    session(NULL),
 
1792
    charset(NULL),
 
1793
    var_list(),
 
1794
    sql_command(SQLCOM_END),
 
1795
    statement(NULL),
 
1796
    option_type(OPT_DEFAULT),
 
1797
    is_lex_started(0),
 
1798
    cacheable(true),
 
1799
    sum_expr_used(false),
 
1800
    _create_table(NULL),
 
1801
    _alter_table(NULL),
 
1802
    _create_field(NULL),
 
1803
    _exists(false)
2178
1804
{
2179
 
 
2180
 
  my_init_dynamic_array2(&plugins, sizeof(plugin_ref),
2181
 
                         plugins_static_buffer,
2182
 
                         INITIAL_LEX_PLUGIN_LIST_SIZE, 
2183
 
                         INITIAL_LEX_PLUGIN_LIST_SIZE);
2184
1805
  reset_query_tables_list(true);
2185
1806
}
2186
1807
 
2187
 
 
2188
 
/*
2189
 
  Check whether the merging algorithm can be used on this VIEW
2190
 
 
2191
 
  SYNOPSIS
2192
 
    st_lex::can_be_merged()
2193
 
 
2194
 
  DESCRIPTION
2195
 
    We can apply merge algorithm if it is single SELECT view  with
2196
 
    subqueries only in WHERE clause (we do not count SELECTs of underlying
2197
 
    views, and second level subqueries) and we have not grpouping, ordering,
2198
 
    HAVING clause, aggregate functions, DISTINCT clause, LIMIT clause and
2199
 
    several underlying tables.
2200
 
 
2201
 
  RETURN
2202
 
    false - only temporary table algorithm can be used
2203
 
    true  - merge algorithm can be used
2204
 
*/
2205
 
 
2206
 
bool st_lex::can_be_merged()
2207
 
{
2208
 
  // TODO: do not forget implement case when select_lex.table_list.elements==0
2209
 
 
2210
 
  /* find non VIEW subqueries/unions */
2211
 
  bool selects_allow_merge= select_lex.next_select() == 0;
2212
 
  if (selects_allow_merge)
2213
 
  {
2214
 
    for (SELECT_LEX_UNIT *tmp_unit= select_lex.first_inner_unit();
2215
 
         tmp_unit;
2216
 
         tmp_unit= tmp_unit->next_unit())
2217
 
    {
2218
 
      if (tmp_unit->first_select()->parent_lex == this &&
2219
 
          (tmp_unit->item == 0 ||
2220
 
           (tmp_unit->item->place() != IN_WHERE &&
2221
 
            tmp_unit->item->place() != IN_ON)))
2222
 
      {
2223
 
        selects_allow_merge= 0;
2224
 
        break;
2225
 
      }
2226
 
    }
2227
 
  }
2228
 
 
2229
 
  return (selects_allow_merge &&
2230
 
          select_lex.group_list.elements == 0 &&
2231
 
          select_lex.having == 0 &&
2232
 
          select_lex.with_sum_func == 0 &&
2233
 
          select_lex.table_list.elements >= 1 &&
2234
 
          !(select_lex.options & SELECT_DISTINCT) &&
2235
 
          select_lex.select_limit == 0);
2236
 
}
2237
 
 
2238
 
 
2239
 
/*
2240
 
  check if command can use VIEW with MERGE algorithm (for top VIEWs)
2241
 
 
2242
 
  SYNOPSIS
2243
 
    st_lex::can_use_merged()
2244
 
 
2245
 
  DESCRIPTION
2246
 
    Only listed here commands can use merge algorithm in top level
2247
 
    SELECT_LEX (for subqueries will be used merge algorithm if
2248
 
    st_lex::can_not_use_merged() is not true).
2249
 
 
2250
 
  RETURN
2251
 
    false - command can't use merged VIEWs
2252
 
    true  - VIEWs with MERGE algorithms can be used
2253
 
*/
2254
 
 
2255
 
bool st_lex::can_use_merged()
2256
 
{
2257
 
  switch (sql_command)
2258
 
  {
2259
 
  case SQLCOM_SELECT:
2260
 
  case SQLCOM_CREATE_TABLE:
2261
 
  case SQLCOM_UPDATE:
2262
 
  case SQLCOM_UPDATE_MULTI:
2263
 
  case SQLCOM_DELETE:
2264
 
  case SQLCOM_DELETE_MULTI:
2265
 
  case SQLCOM_INSERT:
2266
 
  case SQLCOM_INSERT_SELECT:
2267
 
  case SQLCOM_REPLACE:
2268
 
  case SQLCOM_REPLACE_SELECT:
2269
 
  case SQLCOM_LOAD:
2270
 
    return true;
2271
 
  default:
2272
 
    return false;
2273
 
  }
2274
 
}
2275
 
 
2276
 
/*
2277
 
  Check if command can't use merged views in any part of command
2278
 
 
2279
 
  SYNOPSIS
2280
 
    st_lex::can_not_use_merged()
2281
 
 
2282
 
  DESCRIPTION
2283
 
    Temporary table algorithm will be used on all SELECT levels for queries
2284
 
    listed here (see also st_lex::can_use_merged()).
2285
 
 
2286
 
  RETURN
2287
 
    false - command can't use merged VIEWs
2288
 
    true  - VIEWs with MERGE algorithms can be used
2289
 
*/
2290
 
 
2291
 
bool st_lex::can_not_use_merged()
2292
 
{
2293
 
  switch (sql_command)
2294
 
  {
2295
 
  /*
2296
 
    SQLCOM_SHOW_FIELDS is necessary to make 
2297
 
    information schema tables working correctly with views.
2298
 
    see get_schema_tables_result function
2299
 
  */
2300
 
  case SQLCOM_SHOW_FIELDS:
2301
 
    return true;
2302
 
  default:
2303
 
    return false;
2304
 
  }
2305
 
}
2306
 
 
2307
 
/*
2308
 
  Detect that we need only table structure of derived table/view
2309
 
 
2310
 
  SYNOPSIS
2311
 
    only_view_structure()
2312
 
 
2313
 
  RETURN
2314
 
    true yes, we need only structure
2315
 
    false no, we need data
2316
 
*/
2317
 
 
2318
 
bool st_lex::only_view_structure()
2319
 
{
2320
 
  switch (sql_command) {
2321
 
  case SQLCOM_SHOW_CREATE:
2322
 
  case SQLCOM_SHOW_TABLES:
2323
 
  case SQLCOM_SHOW_FIELDS:
2324
 
    return true;
2325
 
  default:
2326
 
    return false;
2327
 
  }
2328
 
}
2329
 
 
2330
 
 
2331
 
/*
2332
 
  Should Items_ident be printed correctly
2333
 
 
2334
 
  SYNOPSIS
2335
 
    need_correct_ident()
2336
 
 
2337
 
  RETURN
2338
 
    true yes, we need only structure
2339
 
    false no, we need data
2340
 
*/
2341
 
 
2342
 
 
2343
 
bool st_lex::need_correct_ident()
2344
 
{
2345
 
  switch(sql_command)
2346
 
  {
2347
 
  case SQLCOM_SHOW_CREATE:
2348
 
  case SQLCOM_SHOW_TABLES:
2349
 
    return true;
2350
 
  default:
2351
 
    return false;
2352
 
  }
2353
 
}
2354
 
 
2355
 
/*
2356
 
  Get effective type of CHECK OPTION for given view
2357
 
 
2358
 
  SYNOPSIS
2359
 
    get_effective_with_check()
2360
 
    view    given view
2361
 
 
2362
 
  NOTE
2363
 
    It have not sense to set CHECK OPTION for SELECT satement or subqueries,
2364
 
    so we do not.
2365
 
 
2366
 
  RETURN
2367
 
    VIEW_CHECK_NONE      no need CHECK OPTION
2368
 
    VIEW_CHECK_LOCAL     CHECK OPTION LOCAL
2369
 
    VIEW_CHECK_CASCADED  CHECK OPTION CASCADED
2370
 
*/
2371
 
 
2372
 
uint8 st_lex::get_effective_with_check(TABLE_LIST *view __attribute__((__unused__)))
2373
 
{
2374
 
  return 0;
2375
 
}
2376
 
 
2377
 
 
2378
 
/**
2379
 
  This method should be called only during parsing.
2380
 
  It is aware of compound statements (stored routine bodies)
2381
 
  and will initialize the destination with the default
2382
 
  database of the stored routine, rather than the default
2383
 
  database of the connection it is parsed in.
2384
 
  E.g. if one has no current database selected, or current database 
2385
 
  set to 'bar' and then issues:
2386
 
 
2387
 
  CREATE PROCEDURE foo.p1() BEGIN SELECT * FROM t1 END//
2388
 
 
2389
 
  t1 is meant to refer to foo.t1, not to bar.t1.
2390
 
 
2391
 
  This method is needed to support this rule.
2392
 
 
2393
 
  @return true in case of error (parsing should be aborted, false in
2394
 
  case of success
2395
 
*/
2396
 
 
2397
 
bool
2398
 
st_lex::copy_db_to(char **p_db, size_t *p_db_length) const
2399
 
{
2400
 
  return thd->copy_db_to(p_db, p_db_length);
2401
 
}
2402
 
 
2403
1808
/*
2404
1809
  initialize limit counters
2405
1810
 
2406
1811
  SYNOPSIS
2407
 
    st_select_lex_unit::set_limit()
2408
 
    values      - SELECT_LEX with initial values for counters
 
1812
    Select_Lex_Unit::set_limit()
 
1813
    values      - Select_Lex with initial values for counters
2409
1814
*/
2410
 
 
2411
 
void st_select_lex_unit::set_limit(st_select_lex *sl)
 
1815
void Select_Lex_Unit::set_limit(Select_Lex *sl)
2412
1816
{
2413
1817
  ha_rows select_limit_val;
2414
 
  ulonglong val;
 
1818
  uint64_t val;
2415
1819
 
2416
1820
  val= sl->select_limit ? sl->select_limit->val_uint() : HA_POS_ERROR;
2417
1821
  select_limit_val= (ha_rows)val;
2418
 
#ifndef BIG_TABLES
2419
 
  /* 
2420
 
    Check for overflow : ha_rows can be smaller then ulonglong if
 
1822
  /*
 
1823
    Check for overflow : ha_rows can be smaller then uint64_t if
2421
1824
    BIG_TABLES is off.
2422
1825
    */
2423
 
  if (val != (ulonglong)select_limit_val)
 
1826
  if (val != (uint64_t)select_limit_val)
2424
1827
    select_limit_val= HA_POS_ERROR;
2425
 
#endif
2426
1828
  offset_limit_cnt= (ha_rows)(sl->offset_limit ? sl->offset_limit->val_uint() :
2427
 
                                                 0ULL);
 
1829
                                                 0UL);
2428
1830
  select_limit_cnt= select_limit_val + offset_limit_cnt;
2429
1831
  if (select_limit_cnt < select_limit_val)
2430
1832
    select_limit_cnt= HA_POS_ERROR;             // no limit
2431
1833
}
2432
1834
 
2433
 
 
2434
1835
/*
2435
1836
  Unlink the first table from the global table list and the first table from
2436
1837
  outer select (lex->select_lex) local list
2449
1850
      In this case link_to_local is set.
2450
1851
 
2451
1852
*/
2452
 
TABLE_LIST *st_lex::unlink_first_table(bool *link_to_local)
 
1853
TableList *LEX::unlink_first_table(bool *link_to_local)
2453
1854
{
2454
 
  TABLE_LIST *first;
 
1855
  TableList *first;
2455
1856
  if ((first= query_tables))
2456
1857
  {
2457
1858
    /*
2468
1869
    */
2469
1870
    if ((*link_to_local= test(select_lex.table_list.first)))
2470
1871
    {
2471
 
      select_lex.context.table_list= 
 
1872
      select_lex.context.table_list=
2472
1873
        select_lex.context.first_name_resolution_table= first->next_local;
2473
 
      select_lex.table_list.first= (uchar*) (first->next_local);
 
1874
      select_lex.table_list.first= (unsigned char*) (first->next_local);
2474
1875
      select_lex.table_list.elements--; //safety
2475
1876
      first->next_local= 0;
2476
1877
      /*
2483
1884
  return first;
2484
1885
}
2485
1886
 
2486
 
 
2487
1887
/*
2488
1888
  Bring first local table of first most outer select to first place in global
2489
1889
  table list
2490
1890
 
2491
1891
  SYNOPSYS
2492
 
     st_lex::first_lists_tables_same()
 
1892
     LEX::first_lists_tables_same()
2493
1893
 
2494
1894
  NOTES
2495
1895
    In many cases (for example, usual INSERT/DELETE/...) the first table of
2496
 
    main SELECT_LEX have special meaning => check that it is the first table
 
1896
    main Select_Lex have special meaning => check that it is the first table
2497
1897
    in global list and re-link to be first in the global list if it is
2498
1898
    necessary.  We need such re-linking only for queries with sub-queries in
2499
1899
    the select list, as only in this case tables of sub-queries will go to
2500
1900
    the global list first.
2501
1901
*/
2502
 
 
2503
 
void st_lex::first_lists_tables_same()
 
1902
void LEX::first_lists_tables_same()
2504
1903
{
2505
 
  TABLE_LIST *first_table= (TABLE_LIST*) select_lex.table_list.first;
 
1904
  TableList *first_table= (TableList*) select_lex.table_list.first;
2506
1905
  if (query_tables != first_table && first_table != 0)
2507
1906
  {
2508
 
    TABLE_LIST *next;
 
1907
    TableList *next;
2509
1908
    if (query_tables_last == &first_table->next_global)
2510
1909
      query_tables_last= first_table->prev_global;
2511
1910
 
2524
1923
  }
2525
1924
}
2526
1925
 
2527
 
 
2528
1926
/*
2529
1927
  Link table back that was unlinked with unlink_first_table()
2530
1928
 
2535
1933
  RETURN
2536
1934
    global list
2537
1935
*/
2538
 
 
2539
 
void st_lex::link_first_table_back(TABLE_LIST *first,
2540
 
                                   bool link_to_local)
 
1936
void LEX::link_first_table_back(TableList *first, bool link_to_local)
2541
1937
{
2542
1938
  if (first)
2543
1939
  {
2549
1945
 
2550
1946
    if (link_to_local)
2551
1947
    {
2552
 
      first->next_local= (TABLE_LIST*) select_lex.table_list.first;
 
1948
      first->next_local= (TableList*) select_lex.table_list.first;
2553
1949
      select_lex.context.table_list= first;
2554
 
      select_lex.table_list.first= (uchar*) first;
 
1950
      select_lex.table_list.first= (unsigned char*) first;
2555
1951
      select_lex.table_list.elements++; //safety
2556
1952
    }
2557
1953
  }
2558
1954
}
2559
1955
 
2560
 
 
2561
 
 
2562
1956
/*
2563
1957
  cleanup lex for case when we open table by table for processing
2564
1958
 
2565
1959
  SYNOPSIS
2566
 
    st_lex::cleanup_after_one_table_open()
 
1960
    LEX::cleanup_after_one_table_open()
2567
1961
 
2568
1962
  NOTE
2569
1963
    This method is mostly responsible for cleaning up of selects lists and
2570
1964
    derived tables state. To rollback changes in Query_tables_list one has
2571
1965
    to call Query_tables_list::reset_query_tables_list(false).
2572
1966
*/
2573
 
 
2574
 
void st_lex::cleanup_after_one_table_open()
 
1967
void LEX::cleanup_after_one_table_open()
2575
1968
{
2576
1969
  /*
2577
 
    thd->lex->derived_tables & additional units may be set if we open
2578
 
    a view. It is necessary to clear thd->lex->derived_tables flag
2579
 
    to prevent processing of derived tables during next open_and_lock_tables
 
1970
    session->lex().derived_tables & additional units may be set if we open
 
1971
    a view. It is necessary to clear session->lex().derived_tables flag
 
1972
    to prevent processing of derived tables during next openTablesLock
2580
1973
    if next table is a real table and cleanup & remove underlying units
2581
 
    NOTE: all units will be connected to thd->lex->select_lex, because we
 
1974
    NOTE: all units will be connected to session->lex().select_lex, because we
2582
1975
    have not UNION on most upper level.
2583
1976
    */
2584
1977
  if (all_selects_list != &select_lex)
2585
1978
  {
2586
1979
    derived_tables= 0;
2587
1980
    /* cleunup underlying units (units of VIEW) */
2588
 
    for (SELECT_LEX_UNIT *un= select_lex.first_inner_unit();
 
1981
    for (Select_Lex_Unit *un= select_lex.first_inner_unit();
2589
1982
         un;
2590
1983
         un= un->next_unit())
2591
1984
      un->cleanup();
2596
1989
  }
2597
1990
}
2598
1991
 
2599
 
 
2600
 
/*
2601
 
  Save current state of Query_tables_list for this LEX, and prepare it
2602
 
  for processing of new statemnt.
2603
 
 
2604
 
  SYNOPSIS
2605
 
    reset_n_backup_query_tables_list()
2606
 
      backup  Pointer to Query_tables_list instance to be used for backup
2607
 
*/
2608
 
 
2609
 
void st_lex::reset_n_backup_query_tables_list(Query_tables_list *backup __attribute__((__unused__)))
2610
 
{
2611
 
}
2612
 
 
2613
 
 
2614
 
/*
2615
 
  Restore state of Query_tables_list for this LEX from backup.
2616
 
 
2617
 
  SYNOPSIS
2618
 
    restore_backup_query_tables_list()
2619
 
      backup  Pointer to Query_tables_list instance used for backup
2620
 
*/
2621
 
 
2622
 
void st_lex::restore_backup_query_tables_list(Query_tables_list *backup __attribute__((__unused__)))
2623
 
{
2624
 
}
2625
 
 
2626
 
 
2627
 
/*
2628
 
  Checks for usage of routines and/or tables in a parsed statement
2629
 
 
2630
 
  SYNOPSIS
2631
 
    st_lex:table_or_sp_used()
2632
 
 
2633
 
  RETURN
2634
 
    false  No routines and tables used
2635
 
    true   Either or both routines and tables are used.
2636
 
*/
2637
 
 
2638
 
bool st_lex::table_or_sp_used()
2639
 
{
2640
 
  if (sroutines.records || query_tables)
2641
 
    return(true);
2642
 
 
2643
 
  return(false);
2644
 
}
2645
 
 
2646
 
 
2647
 
/*
2648
 
  Do end-of-prepare fixup for list of tables and their merge-VIEWed tables
2649
 
 
2650
 
  SYNOPSIS
2651
 
    fix_prepare_info_in_table_list()
2652
 
      thd  Thread handle
2653
 
      tbl  List of tables to process
2654
 
 
2655
 
  DESCRIPTION
2656
 
    Perform end-end-of prepare fixup for list of tables, if any of the tables
2657
 
    is a merge-algorithm VIEW, recursively fix up its underlying tables as
2658
 
    well.
2659
 
 
2660
 
*/
2661
 
 
2662
 
static void fix_prepare_info_in_table_list(THD *thd, TABLE_LIST *tbl)
2663
 
{
2664
 
  for (; tbl; tbl= tbl->next_local)
2665
 
  {
2666
 
    if (tbl->on_expr)
2667
 
    {
2668
 
      tbl->prep_on_expr= tbl->on_expr;
2669
 
      tbl->on_expr= tbl->on_expr->copy_andor_structure(thd);
2670
 
    }
2671
 
    fix_prepare_info_in_table_list(thd, tbl->merge_underlying_list);
2672
 
  }
2673
 
}
2674
 
 
2675
 
 
2676
 
/*
2677
 
  Save WHERE/HAVING/ON clauses and replace them with disposable copies
2678
 
 
2679
 
  SYNOPSIS
2680
 
    st_select_lex::fix_prepare_information
2681
 
      thd          thread handler
2682
 
      conds        in/out pointer to WHERE condition to be met at execution
2683
 
      having_conds in/out pointer to HAVING condition to be met at execution
2684
 
  
2685
 
  DESCRIPTION
2686
 
    The passed WHERE and HAVING are to be saved for the future executions.
2687
 
    This function saves it, and returns a copy which can be thrashed during
2688
 
    this execution of the statement. By saving/thrashing here we mean only
2689
 
    AND/OR trees.
2690
 
    The function also calls fix_prepare_info_in_table_list that saves all
2691
 
    ON expressions.    
2692
 
*/
2693
 
 
2694
 
void st_select_lex::fix_prepare_information(THD *thd, Item **conds, 
2695
 
                                            Item **having_conds)
2696
 
{
2697
 
  if (thd->stmt_arena->is_conventional() == false && first_execution)
2698
 
  {
2699
 
    first_execution= 0;
2700
 
    if (*conds)
2701
 
    {
2702
 
      prep_where= *conds;
2703
 
      *conds= where= prep_where->copy_andor_structure(thd);
2704
 
    }
2705
 
    if (*having_conds)
2706
 
    {
2707
 
      prep_having= *having_conds;
2708
 
      *having_conds= having= prep_having->copy_andor_structure(thd);
2709
 
    }
2710
 
    fix_prepare_info_in_table_list(thd, (TABLE_LIST *)table_list.first);
2711
 
  }
2712
 
}
2713
 
 
2714
 
 
2715
 
/*
2716
 
  There are st_select_lex::add_table_to_list &
2717
 
  st_select_lex::set_lock_for_tables are in sql_parse.cc
2718
 
 
2719
 
  st_select_lex::print is in sql_select.cc
2720
 
 
2721
 
  st_select_lex_unit::prepare, st_select_lex_unit::exec,
2722
 
  st_select_lex_unit::cleanup, st_select_lex_unit::reinit_exec_mechanism,
2723
 
  st_select_lex_unit::change_result
 
1992
/*
 
1993
  There are Select_Lex::add_table_to_list &
 
1994
  Select_Lex::set_lock_for_tables are in sql_parse.cc
 
1995
 
 
1996
  Select_Lex::print is in sql_select.cc
 
1997
 
 
1998
  Select_Lex_Unit::prepare, Select_Lex_Unit::exec,
 
1999
  Select_Lex_Unit::cleanup, Select_Lex_Unit::reinit_exec_mechanism,
 
2000
  Select_Lex_Unit::change_result
2724
2001
  are in sql_union.cc
2725
2002
*/
2726
2003
 
2734
2011
 
2735
2012
  DESCRIPTION
2736
2013
    Used in filling up the tagged hints list.
2737
 
    This list is filled by first setting the kind of the hint as a 
 
2014
    This list is filled by first setting the kind of the hint as a
2738
2015
    context variable and then adding hints of the current kind.
2739
2016
    Then the context variable index_hint_type can be reset to the
2740
2017
    next hint type.
2741
2018
*/
2742
 
void st_select_lex::set_index_hint_type(enum index_hint_type type_arg,
2743
 
                                        index_clause_map clause)
2744
 
 
2019
void Select_Lex::set_index_hint_type(index_hint_type type_arg, index_clause_map clause)
 
2020
{
2745
2021
  current_index_hint_type= type_arg;
2746
2022
  current_index_hint_clause= clause;
2747
2023
}
2748
2024
 
2749
 
 
2750
2025
/*
2751
2026
  Makes an array to store index usage hints (ADD/FORCE/IGNORE INDEX).
2752
2027
 
2753
2028
  SYNOPSIS
2754
2029
    alloc_index_hints()
2755
 
      thd         current thread.
 
2030
      session         current thread.
2756
2031
*/
2757
 
 
2758
 
void st_select_lex::alloc_index_hints (THD *thd)
2759
 
2760
 
  index_hints= new (thd->mem_root) List<Index_hint>(); 
 
2032
void Select_Lex::alloc_index_hints (Session *session)
 
2033
{
 
2034
  index_hints= new (session->mem_root) List<Index_hint>();
2761
2035
}
2762
2036
 
2763
 
 
2764
 
 
2765
2037
/*
2766
 
  adds an element to the array storing index usage hints 
 
2038
  adds an element to the array storing index usage hints
2767
2039
  (ADD/FORCE/IGNORE INDEX).
2768
2040
 
2769
2041
  SYNOPSIS
2770
2042
    add_index_hint()
2771
 
      thd         current thread.
 
2043
      session         current thread.
2772
2044
      str         name of the index.
2773
2045
      length      number of characters in str.
2774
2046
 
2775
2047
  RETURN VALUE
2776
2048
    0 on success, non-zero otherwise
2777
2049
*/
2778
 
bool st_select_lex::add_index_hint (THD *thd, char *str, uint length)
2779
 
{
2780
 
  return index_hints->push_front (new (thd->mem_root) 
2781
 
                                 Index_hint(current_index_hint_type,
2782
 
                                            current_index_hint_clause,
2783
 
                                            str, length));
2784
 
}
 
2050
void Select_Lex::add_index_hint(Session *session, const char *str)
 
2051
{
 
2052
  index_hints->push_front(new (session->mem_root) Index_hint(current_index_hint_type, current_index_hint_clause, str));
 
2053
}
 
2054
 
 
2055
message::AlterTable *LEX::alter_table()
 
2056
{
 
2057
  if (not _alter_table)
 
2058
    _alter_table= new message::AlterTable;
 
2059
 
 
2060
  return _alter_table;
 
2061
}
 
2062
 
 
2063
} /* namespace drizzled */