~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_lex.cc

  • Committer: Monty Taylor
  • Date: 2009-09-30 07:01:32 UTC
  • mto: This revision was merged to the branch mainline in revision 1184.
  • Revision ID: mordred@inaugust.com-20090930070132-b1ol1xu1rpajdddy
Small namespace cleanup.

Show diffs side-by-side

added added

removed removed

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