~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_lex.cc

  • Committer: Brian Aker
  • Date: 2008-10-06 06:47:29 UTC
  • Revision ID: brian@tangent.org-20081006064729-2i9mhjkzyvow9xsm
RemoveĀ uint.

Show diffs side-by-side

added added

removed removed

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