~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_lex.cc

  • Committer: Monty Taylor
  • Date: 2008-12-24 01:49:53 UTC
  • mto: This revision was merged to the branch mainline in revision 751.
  • Revision ID: mordred@inaugust.com-20081224014953-rc9p7a162p74y889
Fixed connect.test.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
#define DRIZZLE_LEX 1
20
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>
21
25
 
22
 
static int lex_one_token(void *arg, void *yythd);
 
26
static int lex_one_token(void *arg, void *yysession);
23
27
 
24
28
/*
25
29
  We are using pointer to this variable for distinguishing between assignment
33
37
*/
34
38
const LEX_STRING null_lex_str= {NULL, 0};
35
39
 
36
 
/* Longest standard keyword name */
37
 
 
38
 
#define TOCK_NAME_LENGTH 24
39
40
 
40
41
/*
41
42
  The following data is based on the latin1 character set, and is only
42
43
  used when comparing keywords
43
44
*/
44
45
 
45
 
static uchar to_upper_lex[]=
 
46
static unsigned char to_upper_lex[]=
46
47
{
47
48
    0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
48
49
   16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
62
63
  208,209,210,211,212,213,214,247,216,217,218,219,220,221,222,255
63
64
};
64
65
 
65
 
/* 
66
 
  Names of the index hints (for error messages). Keep in sync with 
67
 
  index_hint_type 
 
66
/*
 
67
  Names of the index hints (for error messages). Keep in sync with
 
68
  index_hint_type
68
69
*/
69
70
 
70
71
const char * index_hint_type_name[] =
71
72
{
72
 
  "IGNORE INDEX", 
73
 
  "USE INDEX", 
 
73
  "IGNORE INDEX",
 
74
  "USE INDEX",
74
75
  "FORCE INDEX"
75
76
};
76
77
 
77
 
inline int lex_casecmp(const char *s, const char *t, uint len)
 
78
int lex_casecmp(const char *s, const char *t, uint32_t len)
78
79
{
79
80
  while (len-- != 0 &&
80
 
         to_upper_lex[(uchar) *s++] == to_upper_lex[(uchar) *t++]) ;
 
81
         to_upper_lex[(unsigned char) *s++] == to_upper_lex[(unsigned char) *t++]) ;
81
82
  return (int) len+1;
82
83
}
83
84
 
84
 
#include <lex_hash.h>
 
85
/* EVIL EVIL - this is included here so that it will have to_upper_lex */
 
86
#include <drizzled/lex_hash.h>
85
87
 
86
88
 
87
89
void lex_init(void)
88
90
{
89
 
  uint i;
 
91
  uint32_t i;
90
92
  for (i=0 ; i < array_elements(symbols) ; i++)
91
 
    symbols[i].length=(uchar) strlen(symbols[i].name);
 
93
    symbols[i].length=(unsigned char) strlen(symbols[i].name);
92
94
  for (i=0 ; i < array_elements(sql_functions) ; i++)
93
 
    sql_functions[i].length=(uchar) strlen(sql_functions[i].name);
 
95
    sql_functions[i].length=(unsigned char) strlen(sql_functions[i].name);
94
96
 
95
97
  return;
96
98
}
105
107
void
106
108
st_parsing_options::reset()
107
109
{
108
 
  allows_variable= true;
109
 
  allows_select_into= true;
110
110
  allows_select_procedure= true;
111
 
  allows_derived= true;
112
111
}
113
112
 
114
 
Lex_input_stream::Lex_input_stream(THD *thd,
 
113
Lex_input_stream::Lex_input_stream(Session *session,
115
114
                                   const char* buffer,
116
115
                                   unsigned int length)
117
 
: m_thd(thd),
 
116
: m_session(session),
118
117
  yylineno(1),
119
118
  yytoklen(0),
120
119
  yylval(NULL),
139
138
  in_comment(NO_COMMENT),
140
139
  m_underscore_cs(NULL)
141
140
{
142
 
  m_cpp_buf= (char*) thd->alloc(length + 1);
 
141
  m_cpp_buf= (char*) session->alloc(length + 1);
143
142
  m_cpp_ptr= m_cpp_buf;
144
143
}
145
144
 
153
152
     statement;
154
153
  2) Determine the beginning of the body.
155
154
 
156
 
  @param thd        Thread context.
 
155
  @param session        Thread context.
157
156
  @param begin_ptr  Pointer to the start of the body in the pre-processed
158
157
                    buffer.
159
158
*/
160
159
 
161
 
void Lex_input_stream::body_utf8_start(THD *thd, const char *begin_ptr)
 
160
void Lex_input_stream::body_utf8_start(Session *session, const char *begin_ptr)
162
161
{
163
162
  assert(begin_ptr);
164
163
  assert(m_cpp_buf <= begin_ptr && begin_ptr <= m_cpp_buf + m_buf_length);
165
164
 
166
 
  uint body_utf8_length=
167
 
    (m_buf_length / thd->variables.character_set_client->mbminlen) *
 
165
  uint32_t body_utf8_length=
 
166
    (m_buf_length / session->variables.character_set_client->mbminlen) *
168
167
    my_charset_utf8_bin.mbmaxlen;
169
168
 
170
 
  m_body_utf8= (char *) thd->alloc(body_utf8_length + 1);
 
169
  m_body_utf8= (char *) session->alloc(body_utf8_length + 1);
171
170
  m_body_utf8_ptr= m_body_utf8;
172
171
  *m_body_utf8_ptr= 0;
173
172
 
233
232
  The operation converts the specified text literal to the utf8 and appends
234
233
  the result to the utf8-body.
235
234
 
236
 
  @param thd      Thread context.
 
235
  @param session      Thread context.
237
236
  @param txt      Text literal.
238
237
  @param txt_cs   Character set of the text literal.
239
238
  @param end_ptr  Pointer in the pre-processed buffer, to which
241
240
                  operation.
242
241
*/
243
242
 
244
 
void Lex_input_stream::body_utf8_append_literal(THD *thd,
 
243
void Lex_input_stream::body_utf8_append_literal(Session *session,
245
244
                                                const LEX_STRING *txt,
246
245
                                                const CHARSET_INFO * const txt_cs,
247
246
                                                const char *end_ptr)
253
252
 
254
253
  if (!my_charset_same(txt_cs, &my_charset_utf8_general_ci))
255
254
  {
256
 
    thd->convert_string(&utf_txt,
 
255
    session->convert_string(&utf_txt,
257
256
                        &my_charset_utf8_general_ci,
258
257
                        txt->str, txt->length,
259
258
                        txt_cs);
280
279
  (We already do too much here)
281
280
*/
282
281
 
283
 
void lex_start(THD *thd)
 
282
void lex_start(Session *session)
284
283
{
285
 
  LEX *lex= thd->lex;
 
284
  LEX *lex= session->lex;
286
285
 
287
 
  lex->thd= lex->unit.thd= thd;
 
286
  lex->session= lex->unit.session= session;
288
287
 
289
288
  lex->context_stack.empty();
290
289
  lex->unit.init_query();
314
313
  lex->lock_option= TL_READ;
315
314
  lex->leaf_tables_insert= 0;
316
315
  lex->parsing_options.reset();
317
 
  lex->empty_field_list_on_rset= 0;
318
316
  lex->select_lex.select_number= 1;
319
317
  lex->length=0;
320
318
  lex->select_lex.in_sum_expr=0;
331
329
  lex->reset_query_tables_list(false);
332
330
  lex->expr_allows_subselect= true;
333
331
  lex->use_only_table_context= false;
 
332
  lex->parse_vcol_expr= false;
334
333
 
335
334
  lex->name.str= 0;
336
335
  lex->name.length= 0;
337
336
  lex->nest_level=0 ;
338
337
  lex->allow_sum_func= 0;
339
338
  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;
354
339
 
355
340
  lex->is_lex_started= true;
356
 
  return;
357
341
}
358
342
 
359
343
void lex_end(LEX *lex)
360
344
{
361
345
  if (lex->yacc_yyss)
362
346
  {
363
 
    my_free(lex->yacc_yyss, MYF(0));
364
 
    my_free(lex->yacc_yyvs, MYF(0));
 
347
    free(lex->yacc_yyss);
 
348
    free(lex->yacc_yyvs);
365
349
    lex->yacc_yyss= 0;
366
350
    lex->yacc_yyvs= 0;
367
351
  }
368
352
 
369
 
  /* release used plugins */
370
 
  plugin_unlock_list(0, (plugin_ref*)lex->plugins.buffer, 
371
 
                     lex->plugins.elements);
372
 
  reset_dynamic(&lex->plugins);
373
 
 
374
 
  return;
 
353
  delete lex->result;
 
354
  lex->result= 0;
375
355
}
376
356
 
377
357
 
378
 
static int find_keyword(Lex_input_stream *lip, uint len, bool function)
 
358
static int find_keyword(Lex_input_stream *lip, uint32_t len, bool function)
379
359
{
380
360
  const char *tok= lip->get_tok_start();
381
361
 
388
368
 
389
369
    return symbol->tok;
390
370
  }
 
371
 
391
372
  return 0;
392
373
}
393
374
 
404
385
    1         name isn't a keyword
405
386
*/
406
387
 
407
 
bool is_keyword(const char *name, uint len)
 
388
bool is_keyword(const char *name, uint32_t len)
408
389
{
409
390
  assert(len != 0);
410
391
  return get_hash_symbol(name,len,0)!=0;
418
399
 
419
400
/* make a copy of token before ptr and set yytoklen */
420
401
 
421
 
static LEX_STRING get_token(Lex_input_stream *lip, uint skip, uint length)
 
402
static LEX_STRING get_token(Lex_input_stream *lip, uint32_t skip, uint32_t length)
422
403
{
423
404
  LEX_STRING tmp;
424
405
  lip->yyUnget();                       // ptr points now after last token char
425
406
  tmp.length=lip->yytoklen=length;
426
 
  tmp.str= lip->m_thd->strmake(lip->get_tok_start() + skip, tmp.length);
 
407
  tmp.str= lip->m_session->strmake(lip->get_tok_start() + skip, tmp.length);
427
408
 
428
409
  lip->m_cpp_text_start= lip->get_cpp_tok_start() + skip;
429
410
  lip->m_cpp_text_end= lip->m_cpp_text_start + tmp.length;
431
412
  return tmp;
432
413
}
433
414
 
434
 
/* 
435
 
 todo: 
436
 
   There are no dangerous charsets in mysql for function 
437
 
   get_quoted_token yet. But it should be fixed in the 
 
415
/*
 
416
 todo:
 
417
   There are no dangerous charsets in mysql for function
 
418
   get_quoted_token yet. But it should be fixed in the
438
419
   future to operate multichar strings (like ucs2)
439
420
*/
440
421
 
441
422
static LEX_STRING get_quoted_token(Lex_input_stream *lip,
442
 
                                   uint skip,
443
 
                                   uint length, char quote)
 
423
                                   uint32_t skip,
 
424
                                   uint32_t length, char quote)
444
425
{
445
426
  LEX_STRING tmp;
446
427
  const char *from, *end;
447
428
  char *to;
448
429
  lip->yyUnget();                       // ptr points now after last token char
449
430
  tmp.length= lip->yytoklen=length;
450
 
  tmp.str=(char*) lip->m_thd->alloc(tmp.length+1);
 
431
  tmp.str=(char*) lip->m_session->alloc(tmp.length+1);
451
432
  from= lip->get_tok_start() + skip;
452
433
  to= tmp.str;
453
434
  end= to+length;
475
456
 
476
457
static char *get_text(Lex_input_stream *lip, int pre_skip, int post_skip)
477
458
{
478
 
  register uchar c,sep;
479
 
  uint found_escape=0;
480
 
  const CHARSET_INFO * const cs= lip->m_thd->charset();
 
459
  register unsigned char c,sep;
 
460
  uint32_t found_escape=0;
 
461
  const CHARSET_INFO * const cs= lip->m_session->charset();
481
462
 
482
463
  lip->tok_bitmap= 0;
483
464
  sep= lip->yyGetLast();                        // String should end with this
525
506
      end -= post_skip;
526
507
      assert(end >= str);
527
508
 
528
 
      if (!(start= (char*) lip->m_thd->alloc((uint) (end-str)+1)))
 
509
      if (!(start= (char*) lip->m_session->alloc((uint) (end-str)+1)))
529
510
        return (char*) "";              // Sql_alloc has set error flag
530
511
 
531
512
      lip->m_cpp_text_start= lip->get_cpp_tok_start() + pre_skip;
553
534
              continue;
554
535
          }
555
536
#endif
556
 
          if (!(lip->m_thd->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES) &&
557
 
              *str == '\\' && str+1 != end)
 
537
          if (*str == '\\' && str+1 != end)
558
538
          {
559
539
            switch(*++str) {
560
540
            case 'n':
602
582
/*
603
583
** Calc type of integer; long integer, int64_t integer or real.
604
584
** Returns smallest type that match the string.
605
 
** When using unsigned long long values the result is converted to a real
 
585
** When using uint64_t values the result is converted to a real
606
586
** because else they will be unexpected sign changes because all calculation
607
587
** is done with int64_t or double.
608
588
*/
609
589
 
610
590
static const char *long_str="2147483647";
611
 
static const uint long_len=10;
 
591
static const uint32_t long_len=10;
612
592
static const char *signed_long_str="-2147483648";
613
593
static const char *int64_t_str="9223372036854775807";
614
 
static const uint int64_t_len=19;
 
594
static const uint32_t int64_t_len=19;
615
595
static const char *signed_int64_t_str="-9223372036854775808";
616
 
static const uint signed_int64_t_len=19;
 
596
static const uint32_t signed_int64_t_len=19;
617
597
static const char *unsigned_int64_t_str="18446744073709551615";
618
 
static const uint unsigned_int64_t_len=20;
 
598
static const uint32_t unsigned_int64_t_len=20;
619
599
 
620
 
static inline uint int_token(const char *str,uint length)
 
600
static inline uint32_t int_token(const char *str,uint32_t length)
621
601
{
622
602
  if (length < long_len)                        // quick normal case
623
603
    return NUM;
639
619
  if (length < long_len)
640
620
    return NUM;
641
621
 
642
 
  uint smaller,bigger;
 
622
  uint32_t smaller,bigger;
643
623
  const char *cmp;
644
624
  if (neg)
645
625
  {
686
666
    }
687
667
  }
688
668
  while (*cmp && *cmp++ == *str++) ;
689
 
  return ((uchar) str[-1] <= (uchar) cmp[-1]) ? smaller : bigger;
 
669
  return ((unsigned char) str[-1] <= (unsigned char) cmp[-1]) ? smaller : bigger;
690
670
}
691
671
 
692
672
 
693
673
/*
694
 
  MYSQLlex remember the following states from the following MYSQLlex()
 
674
  DRIZZLElex remember the following states from the following DRIZZLElex()
695
675
 
696
676
  - MY_LEX_EOQ                  Found end of query
697
677
  - MY_LEX_OPERATOR_OR_IDENT    Last state was an ident, text or number
698
678
                                (which can't be followed by a signed number)
699
679
*/
700
680
 
701
 
int MYSQLlex(void *arg, void *yythd)
 
681
int DRIZZLElex(void *arg, void *yysession)
702
682
{
703
 
  THD *thd= (THD *)yythd;
704
 
  Lex_input_stream *lip= thd->m_lip;
 
683
  Session *session= (Session *)yysession;
 
684
  Lex_input_stream *lip= session->m_lip;
705
685
  YYSTYPE *yylval=(YYSTYPE*) arg;
706
686
  int token;
707
687
 
718
698
    return token;
719
699
  }
720
700
 
721
 
  token= lex_one_token(arg, yythd);
 
701
  token= lex_one_token(arg, yysession);
722
702
 
723
703
  switch(token) {
724
704
  case WITH:
725
705
    /*
726
 
      Parsing 'WITH' 'ROLLUP' or 'WITH' 'CUBE' requires 2 look ups,
 
706
      Parsing 'WITH' 'ROLLUP' requires 2 look ups,
727
707
      which makes the grammar LALR(2).
728
708
      Replace by a single 'WITH_ROLLUP' or 'WITH_CUBE' token,
729
709
      to transform the grammar into a LALR(1) grammar,
730
710
      which sql_yacc.yy can process.
731
711
    */
732
 
    token= lex_one_token(arg, yythd);
733
 
    switch(token) {
734
 
    case CUBE_SYM:
735
 
      return WITH_CUBE_SYM;
736
 
    case ROLLUP_SYM:
 
712
    token= lex_one_token(arg, yysession);
 
713
    if (token == ROLLUP_SYM)
 
714
    {
737
715
      return WITH_ROLLUP_SYM;
738
 
    default:
 
716
    }
 
717
    else
 
718
    {
739
719
      /*
740
720
        Save the token following 'WITH'
741
721
      */
752
732
  return token;
753
733
}
754
734
 
755
 
int lex_one_token(void *arg, void *yythd)
 
735
int lex_one_token(void *arg, void *yysession)
756
736
{
757
737
  register unsigned char c= 0; /* Just set to shutup GCC */
758
738
  bool comment_closed;
759
739
  int   tokval, result_state;
760
740
  unsigned int length;
761
741
  enum my_lex_states state;
762
 
  THD *thd= (THD *)yythd;
763
 
  Lex_input_stream *lip= thd->m_lip;
764
 
  LEX *lex= thd->lex;
 
742
  Session *session= (Session *)yysession;
 
743
  Lex_input_stream *lip= session->m_lip;
 
744
  LEX *lex= session->lex;
765
745
  YYSTYPE *yylval=(YYSTYPE*) arg;
766
 
  const CHARSET_INFO * const cs= thd->charset();
767
 
  uchar *state_map= cs->state_map;
768
 
  uchar *ident_map= cs->ident_map;
 
746
  const CHARSET_INFO * const cs= session->charset();
 
747
  unsigned char *state_map= cs->state_map;
 
748
  unsigned char *ident_map= cs->ident_map;
769
749
 
770
750
  lip->yylval=yylval;                   // The global state
771
751
 
924
904
 
925
905
      lip->body_utf8_append(lip->m_cpp_text_start);
926
906
 
927
 
      lip->body_utf8_append_literal(thd, &yylval->lex_str, cs,
 
907
      lip->body_utf8_append_literal(session, &yylval->lex_str, cs,
928
908
                                    lip->m_cpp_text_end);
929
909
 
930
910
      return(result_state);                     // IDENT or IDENT_QUOTED
1027
1007
 
1028
1008
      lip->body_utf8_append(lip->m_cpp_text_start);
1029
1009
 
1030
 
      lip->body_utf8_append_literal(thd, &yylval->lex_str, cs,
 
1010
      lip->body_utf8_append_literal(session, &yylval->lex_str, cs,
1031
1011
                                    lip->m_cpp_text_end);
1032
1012
 
1033
1013
      return(result_state);
1034
1014
 
1035
1015
    case MY_LEX_USER_VARIABLE_DELIMITER:        // Found quote char
1036
1016
    {
1037
 
      uint double_quotes= 0;
 
1017
      uint32_t double_quotes= 0;
1038
1018
      char quote_char= c;                       // Used char
1039
1019
      while ((c=lip->yyGet()))
1040
1020
      {
1068
1048
 
1069
1049
      lip->body_utf8_append(lip->m_cpp_text_start);
1070
1050
 
1071
 
      lip->body_utf8_append_literal(thd, &yylval->lex_str, cs,
 
1051
      lip->body_utf8_append_literal(session, &yylval->lex_str, cs,
1072
1052
                                    lip->m_cpp_text_end);
1073
1053
 
1074
1054
      return(IDENT_QUOTED);
1182
1162
 
1183
1163
      lip->body_utf8_append(lip->m_cpp_text_start);
1184
1164
 
1185
 
      lip->body_utf8_append_literal(thd, &yylval->lex_str,
 
1165
      lip->body_utf8_append_literal(session, &yylval->lex_str,
1186
1166
        lip->m_underscore_cs ? lip->m_underscore_cs : cs,
1187
1167
        lip->m_cpp_text_end);
1188
1168
 
1324
1304
    case MY_LEX_SEMICOLON:                      // optional line terminator
1325
1305
      if (lip->yyPeek())
1326
1306
      {
1327
 
        if ((thd->client_capabilities & CLIENT_MULTI_STATEMENTS))
 
1307
        if ((session->client_capabilities & CLIENT_MULTI_STATEMENTS))
1328
1308
        {
1329
1309
          lip->found_semicolon= lip->get_ptr();
1330
 
          thd->server_status|= SERVER_MORE_RESULTS_EXISTS;
 
1310
          session->server_status|= SERVER_MORE_RESULTS_EXISTS;
1331
1311
          lip->next_state= MY_LEX_END;
1332
1312
          lip->set_echo(true);
1333
1313
          return (END_OF_INPUT);
1355
1335
    case MY_LEX_END:
1356
1336
      lip->next_state=MY_LEX_END;
1357
1337
      return(0);                        // We found end of input last time
1358
 
      
 
1338
 
1359
1339
      /* Actually real shouldn't start with . but allow them anyhow */
1360
1340
    case MY_LEX_REAL_OR_POINT:
1361
1341
      if (my_isdigit(cs,lip->yyPeek()))
1422
1402
 
1423
1403
      lip->body_utf8_append(lip->m_cpp_text_start);
1424
1404
 
1425
 
      lip->body_utf8_append_literal(thd, &yylval->lex_str, cs,
 
1405
      lip->body_utf8_append_literal(session, &yylval->lex_str, cs,
1426
1406
                                    lip->m_cpp_text_end);
1427
1407
 
1428
1408
      return(result_state);
1440
1420
  statements and stored procedures and is compensated by always
1441
1421
  supplying a copy of Alter_info to these functions.
1442
1422
 
1443
 
  @return You need to use check the error in THD for out
 
1423
  @return You need to use check the error in Session for out
1444
1424
  of memory condition after calling this function.
1445
1425
*/
1446
1426
 
1559
1539
  parent_lex->push_context(&context);
1560
1540
  cond_count= between_count= with_wild= 0;
1561
1541
  max_equal_elems= 0;
1562
 
  conds_processed_with_permanent_arena= 0;
1563
1542
  ref_pointer_array= 0;
1564
1543
  select_n_where_fields= 0;
1565
1544
  select_n_having_items= 0;
1566
1545
  subquery_in_having= explicit_limit= 0;
1567
1546
  is_item_list_lookup= 0;
1568
 
  first_execution= 1;
1569
 
  first_cond_optimization= 1;
1570
1547
  parsing_place= NO_MATTER;
1571
1548
  exclude_from_table_unique_test= false;
1572
1549
  nest_level= 0;
1591
1568
  linkage= UNSPECIFIED_TYPE;
1592
1569
  order_list.elements= 0;
1593
1570
  order_list.first= 0;
1594
 
  order_list.next= (uchar**) &order_list.first;
 
1571
  order_list.next= (unsigned char**) &order_list.first;
1595
1572
  /* Set limit and offset to default values */
1596
1573
  select_limit= 0;      /* denotes the default limit = HA_POS_ERROR */
1597
1574
  offset_limit= 0;      /* denotes the default offset = 0 */
1667
1644
  // Remove slave structure
1668
1645
  for (; slave; slave= slave->next)
1669
1646
    slave->fast_exclude();
1670
 
  
 
1647
 
1671
1648
}
1672
1649
 
1673
1650
/*
1681
1658
  //exclude from other structures
1682
1659
  if ((*prev= next))
1683
1660
    next->prev= prev;
1684
 
  /* 
1685
 
     We do not need following statements, because prev pointer of first 
 
1661
  /*
 
1662
     We do not need following statements, because prev pointer of first
1686
1663
     list element point to master->slave
1687
1664
     if (master->slave == this)
1688
1665
       master->slave= next;
1697
1674
    st_select_lex_unit::exclude_level()
1698
1675
 
1699
1676
  NOTE: units which belong to current will be brought up on level of
1700
 
  currernt unit 
 
1677
  currernt unit
1701
1678
*/
1702
1679
void st_select_lex_unit::exclude_level()
1703
1680
{
1768
1745
 
1769
1746
 
1770
1747
/*
1771
 
  st_select_lex_node::mark_as_dependent mark all st_select_lex struct from 
 
1748
  st_select_lex_node::mark_as_dependent mark all st_select_lex struct from
1772
1749
  this to 'last' as dependent
1773
1750
 
1774
1751
  SYNOPSIS
1775
 
    last - pointer to last st_select_lex struct, before wich all 
 
1752
    last - pointer to last st_select_lex struct, before wich all
1776
1753
           st_select_lex have to be marked as dependent
1777
1754
 
1778
1755
  NOTE
1811
1788
  }
1812
1789
}
1813
1790
 
1814
 
bool st_select_lex_node::set_braces(bool value __attribute__((unused)))
 
1791
bool st_select_lex_node::set_braces(bool)
1815
1792
{ return 1; }
1816
1793
bool st_select_lex_node::inc_in_sum_expr()           { return 1; }
1817
 
uint st_select_lex_node::get_in_sum_expr()           { return 0; }
1818
 
TABLE_LIST* st_select_lex_node::get_table_list()     { return 0; }
 
1794
uint32_t st_select_lex_node::get_in_sum_expr()           { return 0; }
 
1795
TableList* st_select_lex_node::get_table_list()     { return 0; }
1819
1796
List<Item>* st_select_lex_node::get_item_list()      { return 0; }
1820
 
TABLE_LIST *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)))
 
1797
TableList *st_select_lex_node::add_table_to_list (Session *, Table_ident *, LEX_STRING *, uint32_t,
 
1798
                                                  thr_lock_type, List<Index_hint> *, LEX_STRING *)
1827
1799
{
1828
1800
  return 0;
1829
1801
}
1859
1831
}
1860
1832
 
1861
1833
 
1862
 
bool st_select_lex::add_order_to_list(THD *thd, Item *item, bool asc)
 
1834
bool st_select_lex::add_order_to_list(Session *session, Item *item, bool asc)
1863
1835
{
1864
 
  return add_to_list(thd, order_list, item, asc);
 
1836
  return add_to_list(session, order_list, item, asc);
1865
1837
}
1866
1838
 
1867
1839
 
1868
 
bool st_select_lex::add_item_to_list(THD *thd __attribute__((unused)),
1869
 
                                     Item *item)
 
1840
bool st_select_lex::add_item_to_list(Session *, Item *item)
1870
1841
{
1871
1842
  return(item_list.push_back(item));
1872
1843
}
1873
1844
 
1874
1845
 
1875
 
bool st_select_lex::add_group_to_list(THD *thd, Item *item, bool asc)
 
1846
bool st_select_lex::add_group_to_list(Session *session, Item *item, bool asc)
1876
1847
{
1877
 
  return add_to_list(thd, group_list, item, asc);
 
1848
  return add_to_list(session, group_list, item, asc);
1878
1849
}
1879
1850
 
1880
1851
 
1893
1864
bool st_select_lex::set_braces(bool value)
1894
1865
{
1895
1866
  braces= value;
1896
 
  return 0; 
 
1867
  return 0;
1897
1868
}
1898
1869
 
1899
1870
 
1904
1875
}
1905
1876
 
1906
1877
 
1907
 
uint st_select_lex::get_in_sum_expr()
 
1878
uint32_t st_select_lex::get_in_sum_expr()
1908
1879
{
1909
1880
  return in_sum_expr;
1910
1881
}
1911
1882
 
1912
1883
 
1913
 
TABLE_LIST* st_select_lex::get_table_list()
 
1884
TableList* st_select_lex::get_table_list()
1914
1885
{
1915
 
  return (TABLE_LIST*) table_list.first;
 
1886
  return (TableList*) table_list.first;
1916
1887
}
1917
1888
 
1918
1889
List<Item>* st_select_lex::get_item_list()
1926
1897
}
1927
1898
 
1928
1899
 
1929
 
bool st_select_lex::setup_ref_array(THD *thd, uint order_group_num)
 
1900
bool st_select_lex::setup_ref_array(Session *session, uint32_t order_group_num)
1930
1901
{
1931
1902
  if (ref_pointer_array)
1932
1903
    return 0;
1933
1904
 
1934
 
  /*
1935
 
    We have to create array in prepared statement memory if it is
1936
 
    prepared statement
1937
 
  */
1938
 
  Query_arena *arena= thd->stmt_arena;
1939
1905
  return (ref_pointer_array=
1940
 
          (Item **)arena->alloc(sizeof(Item*) * (n_child_sum_items +
 
1906
          (Item **)session->alloc(sizeof(Item*) * (n_child_sum_items +
1941
1907
                                                 item_list.elements +
1942
1908
                                                 select_n_having_items +
1943
1909
                                                 select_n_where_fields +
1960
1926
    }
1961
1927
    if (sl->braces)
1962
1928
      str->append('(');
1963
 
    sl->print(thd, str, query_type);
 
1929
    sl->print(session, str, query_type);
1964
1930
    if (sl->braces)
1965
1931
      str->append(')');
1966
1932
  }
1971
1937
      str->append(STRING_WITH_LEN(" order by "));
1972
1938
      fake_select_lex->print_order(
1973
1939
        str,
1974
 
        (ORDER *) fake_select_lex->order_list.first,
 
1940
        (order_st *) fake_select_lex->order_list.first,
1975
1941
        query_type);
1976
1942
    }
1977
 
    fake_select_lex->print_limit(thd, str, query_type);
 
1943
    fake_select_lex->print_limit(session, str, query_type);
1978
1944
  }
1979
1945
}
1980
1946
 
1981
1947
 
1982
1948
void st_select_lex::print_order(String *str,
1983
 
                                ORDER *order,
 
1949
                                order_st *order,
1984
1950
                                enum_query_type query_type)
1985
1951
{
1986
1952
  for (; order; order= order->next)
1988
1954
    if (order->counter_used)
1989
1955
    {
1990
1956
      char buffer[20];
1991
 
      uint length= snprintf(buffer, 20, "%d", order->counter);
 
1957
      uint32_t length= snprintf(buffer, 20, "%d", order->counter);
1992
1958
      str->append(buffer, length);
1993
1959
    }
1994
1960
    else
1999
1965
      str->append(',');
2000
1966
  }
2001
1967
}
2002
 
 
2003
 
 
2004
 
void st_select_lex::print_limit(THD *thd __attribute__((unused)),
2005
 
                                String *str,
 
1968
 
 
1969
 
 
1970
void st_select_lex::print_limit(Session *, String *str,
2006
1971
                                enum_query_type query_type)
2007
1972
{
2008
1973
  SELECT_LEX_UNIT *unit= master_unit();
2024
1989
                    ((Item_in_subselect*)item)->exec_method ==
2025
1990
                    Item_in_subselect::MATERIALIZATION) ?
2026
1991
                   true :
2027
 
                   (select_limit->val_int() == 1LL) &&
 
1992
                   (select_limit->val_int() == 1L) &&
2028
1993
                   offset_limit == 0));
2029
1994
      return;
2030
1995
    }
2042
2007
}
2043
2008
 
2044
2009
/**
2045
 
  @brief Restore the LEX and THD in case of a parse error.
 
2010
  @brief Restore the LEX and Session in case of a parse error.
2046
2011
 
2047
2012
  This is a clean up call that is invoked by the Bison generated
2048
 
  parser before returning an error from MYSQLparse. If your
 
2013
  parser before returning an error from DRIZZLEparse. If your
2049
2014
  semantic actions manipulate with the global thread state (which
2050
2015
  is a very bad practice and should not normally be employed) and
2051
2016
  need a clean-up in case of error, and you can not use %destructor
2053
2018
  to implement the clean up.
2054
2019
*/
2055
2020
 
2056
 
void st_lex::cleanup_lex_after_parse_error(THD *thd __attribute__((unused)))
 
2021
void LEX::cleanup_lex_after_parse_error(Session *)
2057
2022
{
2058
2023
}
2059
2024
 
2079
2044
{
2080
2045
  if (!init && query_tables)
2081
2046
  {
2082
 
    TABLE_LIST *table= query_tables;
 
2047
    TableList *table= query_tables;
2083
2048
    for (;;)
2084
2049
    {
2085
2050
      if (query_tables_last == &table->next_global ||
2090
2055
  query_tables= 0;
2091
2056
  query_tables_last= &query_tables;
2092
2057
  query_tables_own_last= 0;
2093
 
  if (init)
2094
 
  {
2095
 
    /*
2096
 
      We delay real initialization of hash (and therefore related
2097
 
      memory allocation) until first insertion into this hash.
2098
 
    */
2099
 
    hash_clear(&sroutines);
2100
 
  }
2101
 
  else if (sroutines.records)
2102
 
  {
2103
 
    /* Non-zero sroutines.records means that hash was initialized. */
2104
 
    my_hash_reset(&sroutines);
2105
 
  }
2106
 
  sroutines_list.empty();
2107
 
  sroutines_list_own_last= sroutines_list.next;
2108
 
  sroutines_list_own_elements= 0;
2109
 
  binlog_stmt_flags= 0;
2110
2058
}
2111
2059
 
2112
2060
 
2119
2067
 
2120
2068
void Query_tables_list::destroy_query_tables_list()
2121
2069
{
2122
 
  hash_free(&sroutines);
2123
2070
}
2124
2071
 
2125
2072
 
2127
2074
  Initialize LEX object.
2128
2075
 
2129
2076
  SYNOPSIS
2130
 
    st_lex::st_lex()
 
2077
    LEX::LEX()
2131
2078
 
2132
2079
  NOTE
2133
2080
    LEX object initialized with this constructor can be used as part of
2134
 
    THD object for which one can safely call open_tables(), lock_tables()
 
2081
    Session object for which one can safely call open_tables(), lock_tables()
2135
2082
    and close_thread_tables() functions. But it is not yet ready for
2136
2083
    statement parsing. On should use lex_start() function to prepare LEX
2137
2084
    for this.
2138
2085
*/
2139
2086
 
2140
 
st_lex::st_lex()
 
2087
LEX::LEX()
2141
2088
  :result(0), yacc_yyss(0), yacc_yyvs(0),
2142
2089
   sql_command(SQLCOM_END), option_type(OPT_DEFAULT), is_lex_started(0)
2143
2090
{
2144
2091
 
2145
 
  my_init_dynamic_array2(&plugins, sizeof(plugin_ref),
2146
 
                         plugins_static_buffer,
2147
 
                         INITIAL_LEX_PLUGIN_LIST_SIZE, 
2148
 
                         INITIAL_LEX_PLUGIN_LIST_SIZE);
2149
2092
  reset_query_tables_list(true);
2150
2093
}
2151
2094
 
2152
 
 
2153
 
/*
2154
 
  Check whether the merging algorithm can be used on this VIEW
2155
 
 
2156
 
  SYNOPSIS
2157
 
    st_lex::can_be_merged()
2158
 
 
2159
 
  DESCRIPTION
2160
 
    We can apply merge algorithm if it is single SELECT view  with
2161
 
    subqueries only in WHERE clause (we do not count SELECTs of underlying
2162
 
    views, and second level subqueries) and we have not grpouping, ordering,
2163
 
    HAVING clause, aggregate functions, DISTINCT clause, LIMIT clause and
2164
 
    several underlying tables.
2165
 
 
2166
 
  RETURN
2167
 
    false - only temporary table algorithm can be used
2168
 
    true  - merge algorithm can be used
2169
 
*/
2170
 
 
2171
 
bool st_lex::can_be_merged()
2172
 
{
2173
 
  // TODO: do not forget implement case when select_lex.table_list.elements==0
2174
 
 
2175
 
  /* find non VIEW subqueries/unions */
2176
 
  bool selects_allow_merge= select_lex.next_select() == 0;
2177
 
  if (selects_allow_merge)
2178
 
  {
2179
 
    for (SELECT_LEX_UNIT *tmp_unit= select_lex.first_inner_unit();
2180
 
         tmp_unit;
2181
 
         tmp_unit= tmp_unit->next_unit())
2182
 
    {
2183
 
      if (tmp_unit->first_select()->parent_lex == this &&
2184
 
          (tmp_unit->item == 0 ||
2185
 
           (tmp_unit->item->place() != IN_WHERE &&
2186
 
            tmp_unit->item->place() != IN_ON)))
2187
 
      {
2188
 
        selects_allow_merge= 0;
2189
 
        break;
2190
 
      }
2191
 
    }
2192
 
  }
2193
 
 
2194
 
  return (selects_allow_merge &&
2195
 
          select_lex.group_list.elements == 0 &&
2196
 
          select_lex.having == 0 &&
2197
 
          select_lex.with_sum_func == 0 &&
2198
 
          select_lex.table_list.elements >= 1 &&
2199
 
          !(select_lex.options & SELECT_DISTINCT) &&
2200
 
          select_lex.select_limit == 0);
2201
 
}
2202
 
 
2203
 
 
2204
 
/*
2205
 
  check if command can use VIEW with MERGE algorithm (for top VIEWs)
2206
 
 
2207
 
  SYNOPSIS
2208
 
    st_lex::can_use_merged()
2209
 
 
2210
 
  DESCRIPTION
2211
 
    Only listed here commands can use merge algorithm in top level
2212
 
    SELECT_LEX (for subqueries will be used merge algorithm if
2213
 
    st_lex::can_not_use_merged() is not true).
2214
 
 
2215
 
  RETURN
2216
 
    false - command can't use merged VIEWs
2217
 
    true  - VIEWs with MERGE algorithms can be used
2218
 
*/
2219
 
 
2220
 
bool st_lex::can_use_merged()
2221
 
{
2222
 
  switch (sql_command)
2223
 
  {
2224
 
  case SQLCOM_SELECT:
2225
 
  case SQLCOM_CREATE_TABLE:
2226
 
  case SQLCOM_UPDATE:
2227
 
  case SQLCOM_UPDATE_MULTI:
2228
 
  case SQLCOM_DELETE:
2229
 
  case SQLCOM_DELETE_MULTI:
2230
 
  case SQLCOM_INSERT:
2231
 
  case SQLCOM_INSERT_SELECT:
2232
 
  case SQLCOM_REPLACE:
2233
 
  case SQLCOM_REPLACE_SELECT:
2234
 
  case SQLCOM_LOAD:
2235
 
    return true;
2236
 
  default:
2237
 
    return false;
2238
 
  }
2239
 
}
2240
 
 
2241
 
/*
2242
 
  Check if command can't use merged views in any part of command
2243
 
 
2244
 
  SYNOPSIS
2245
 
    st_lex::can_not_use_merged()
2246
 
 
2247
 
  DESCRIPTION
2248
 
    Temporary table algorithm will be used on all SELECT levels for queries
2249
 
    listed here (see also st_lex::can_use_merged()).
2250
 
 
2251
 
  RETURN
2252
 
    false - command can't use merged VIEWs
2253
 
    true  - VIEWs with MERGE algorithms can be used
2254
 
*/
2255
 
 
2256
 
bool st_lex::can_not_use_merged()
2257
 
{
2258
 
  switch (sql_command)
2259
 
  {
2260
 
  /*
2261
 
    SQLCOM_SHOW_FIELDS is necessary to make 
2262
 
    information schema tables working correctly with views.
2263
 
    see get_schema_tables_result function
2264
 
  */
2265
 
  case SQLCOM_SHOW_FIELDS:
2266
 
    return true;
2267
 
  default:
2268
 
    return false;
2269
 
  }
2270
 
}
2271
 
 
2272
2095
/*
2273
2096
  Detect that we need only table structure of derived table/view
2274
2097
 
2280
2103
    false no, we need data
2281
2104
*/
2282
2105
 
2283
 
bool st_lex::only_view_structure()
 
2106
bool LEX::only_view_structure()
2284
2107
{
2285
2108
  switch (sql_command) {
2286
2109
  case SQLCOM_SHOW_CREATE:
2305
2128
*/
2306
2129
 
2307
2130
 
2308
 
bool st_lex::need_correct_ident()
 
2131
bool LEX::need_correct_ident()
2309
2132
{
2310
2133
  switch(sql_command)
2311
2134
  {
2324
2147
  and will initialize the destination with the default
2325
2148
  database of the stored routine, rather than the default
2326
2149
  database of the connection it is parsed in.
2327
 
  E.g. if one has no current database selected, or current database 
 
2150
  E.g. if one has no current database selected, or current database
2328
2151
  set to 'bar' and then issues:
2329
2152
 
2330
2153
  CREATE PROCEDURE foo.p1() BEGIN SELECT * FROM t1 END//
2338
2161
*/
2339
2162
 
2340
2163
bool
2341
 
st_lex::copy_db_to(char **p_db, size_t *p_db_length) const
 
2164
LEX::copy_db_to(char **p_db, size_t *p_db_length) const
2342
2165
{
2343
 
  return thd->copy_db_to(p_db, p_db_length);
 
2166
  return session->copy_db_to(p_db, p_db_length);
2344
2167
}
2345
2168
 
2346
2169
/*
2358
2181
 
2359
2182
  val= sl->select_limit ? sl->select_limit->val_uint() : HA_POS_ERROR;
2360
2183
  select_limit_val= (ha_rows)val;
2361
 
#ifndef BIG_TABLES
2362
 
  /* 
 
2184
  /*
2363
2185
    Check for overflow : ha_rows can be smaller then uint64_t if
2364
2186
    BIG_TABLES is off.
2365
2187
    */
2366
2188
  if (val != (uint64_t)select_limit_val)
2367
2189
    select_limit_val= HA_POS_ERROR;
2368
 
#endif
2369
2190
  offset_limit_cnt= (ha_rows)(sl->offset_limit ? sl->offset_limit->val_uint() :
2370
 
                                                 0ULL);
 
2191
                                                 0UL);
2371
2192
  select_limit_cnt= select_limit_val + offset_limit_cnt;
2372
2193
  if (select_limit_cnt < select_limit_val)
2373
2194
    select_limit_cnt= HA_POS_ERROR;             // no limit
2392
2213
      In this case link_to_local is set.
2393
2214
 
2394
2215
*/
2395
 
TABLE_LIST *st_lex::unlink_first_table(bool *link_to_local)
 
2216
TableList *LEX::unlink_first_table(bool *link_to_local)
2396
2217
{
2397
 
  TABLE_LIST *first;
 
2218
  TableList *first;
2398
2219
  if ((first= query_tables))
2399
2220
  {
2400
2221
    /*
2411
2232
    */
2412
2233
    if ((*link_to_local= test(select_lex.table_list.first)))
2413
2234
    {
2414
 
      select_lex.context.table_list= 
 
2235
      select_lex.context.table_list=
2415
2236
        select_lex.context.first_name_resolution_table= first->next_local;
2416
 
      select_lex.table_list.first= (uchar*) (first->next_local);
 
2237
      select_lex.table_list.first= (unsigned char*) (first->next_local);
2417
2238
      select_lex.table_list.elements--; //safety
2418
2239
      first->next_local= 0;
2419
2240
      /*
2432
2253
  table list
2433
2254
 
2434
2255
  SYNOPSYS
2435
 
     st_lex::first_lists_tables_same()
 
2256
     LEX::first_lists_tables_same()
2436
2257
 
2437
2258
  NOTES
2438
2259
    In many cases (for example, usual INSERT/DELETE/...) the first table of
2443
2264
    the global list first.
2444
2265
*/
2445
2266
 
2446
 
void st_lex::first_lists_tables_same()
 
2267
void LEX::first_lists_tables_same()
2447
2268
{
2448
 
  TABLE_LIST *first_table= (TABLE_LIST*) select_lex.table_list.first;
 
2269
  TableList *first_table= (TableList*) select_lex.table_list.first;
2449
2270
  if (query_tables != first_table && first_table != 0)
2450
2271
  {
2451
 
    TABLE_LIST *next;
 
2272
    TableList *next;
2452
2273
    if (query_tables_last == &first_table->next_global)
2453
2274
      query_tables_last= first_table->prev_global;
2454
2275
 
2479
2300
    global list
2480
2301
*/
2481
2302
 
2482
 
void st_lex::link_first_table_back(TABLE_LIST *first,
 
2303
void LEX::link_first_table_back(TableList *first,
2483
2304
                                   bool link_to_local)
2484
2305
{
2485
2306
  if (first)
2492
2313
 
2493
2314
    if (link_to_local)
2494
2315
    {
2495
 
      first->next_local= (TABLE_LIST*) select_lex.table_list.first;
 
2316
      first->next_local= (TableList*) select_lex.table_list.first;
2496
2317
      select_lex.context.table_list= first;
2497
 
      select_lex.table_list.first= (uchar*) first;
 
2318
      select_lex.table_list.first= (unsigned char*) first;
2498
2319
      select_lex.table_list.elements++; //safety
2499
2320
    }
2500
2321
  }
2506
2327
  cleanup lex for case when we open table by table for processing
2507
2328
 
2508
2329
  SYNOPSIS
2509
 
    st_lex::cleanup_after_one_table_open()
 
2330
    LEX::cleanup_after_one_table_open()
2510
2331
 
2511
2332
  NOTE
2512
2333
    This method is mostly responsible for cleaning up of selects lists and
2514
2335
    to call Query_tables_list::reset_query_tables_list(false).
2515
2336
*/
2516
2337
 
2517
 
void st_lex::cleanup_after_one_table_open()
 
2338
void LEX::cleanup_after_one_table_open()
2518
2339
{
2519
2340
  /*
2520
 
    thd->lex->derived_tables & additional units may be set if we open
2521
 
    a view. It is necessary to clear thd->lex->derived_tables flag
 
2341
    session->lex->derived_tables & additional units may be set if we open
 
2342
    a view. It is necessary to clear session->lex->derived_tables flag
2522
2343
    to prevent processing of derived tables during next open_and_lock_tables
2523
2344
    if next table is a real table and cleanup & remove underlying units
2524
 
    NOTE: all units will be connected to thd->lex->select_lex, because we
 
2345
    NOTE: all units will be connected to session->lex->select_lex, because we
2525
2346
    have not UNION on most upper level.
2526
2347
    */
2527
2348
  if (all_selects_list != &select_lex)
2541
2362
 
2542
2363
 
2543
2364
/*
2544
 
  Save current state of Query_tables_list for this LEX, and prepare it
2545
 
  for processing of new statemnt.
2546
 
 
2547
 
  SYNOPSIS
2548
 
    reset_n_backup_query_tables_list()
2549
 
      backup  Pointer to Query_tables_list instance to be used for backup
2550
 
*/
2551
 
 
2552
 
void st_lex::reset_n_backup_query_tables_list(Query_tables_list *backup __attribute__((unused)))
2553
 
{
2554
 
}
2555
 
 
2556
 
 
2557
 
/*
2558
 
  Restore state of Query_tables_list for this LEX from backup.
2559
 
 
2560
 
  SYNOPSIS
2561
 
    restore_backup_query_tables_list()
2562
 
      backup  Pointer to Query_tables_list instance used for backup
2563
 
*/
2564
 
 
2565
 
void st_lex::restore_backup_query_tables_list(Query_tables_list *backup __attribute__((unused)))
2566
 
{
2567
 
}
2568
 
 
2569
 
 
2570
 
/*
2571
 
  Checks for usage of routines and/or tables in a parsed statement
2572
 
 
2573
 
  SYNOPSIS
2574
 
    st_lex:table_or_sp_used()
2575
 
 
2576
 
  RETURN
2577
 
    false  No routines and tables used
2578
 
    true   Either or both routines and tables are used.
2579
 
*/
2580
 
 
2581
 
bool st_lex::table_or_sp_used()
2582
 
{
2583
 
  if (sroutines.records || query_tables)
2584
 
    return(true);
2585
 
 
2586
 
  return(false);
2587
 
}
2588
 
 
2589
 
 
2590
 
/*
2591
2365
  Do end-of-prepare fixup for list of tables and their merge-VIEWed tables
2592
2366
 
2593
2367
  SYNOPSIS
2594
2368
    fix_prepare_info_in_table_list()
2595
 
      thd  Thread handle
 
2369
      session  Thread handle
2596
2370
      tbl  List of tables to process
2597
2371
 
2598
2372
  DESCRIPTION
2602
2376
 
2603
2377
*/
2604
2378
 
2605
 
static void fix_prepare_info_in_table_list(THD *thd, TABLE_LIST *tbl)
 
2379
static void fix_prepare_info_in_table_list(Session *session, TableList *tbl)
2606
2380
{
2607
2381
  for (; tbl; tbl= tbl->next_local)
2608
2382
  {
2609
2383
    if (tbl->on_expr)
2610
2384
    {
2611
2385
      tbl->prep_on_expr= tbl->on_expr;
2612
 
      tbl->on_expr= tbl->on_expr->copy_andor_structure(thd);
 
2386
      tbl->on_expr= tbl->on_expr->copy_andor_structure(session);
2613
2387
    }
2614
 
    fix_prepare_info_in_table_list(thd, tbl->merge_underlying_list);
 
2388
    fix_prepare_info_in_table_list(session, tbl->merge_underlying_list);
2615
2389
  }
2616
2390
}
2617
2391
 
2638
2412
 
2639
2413
  DESCRIPTION
2640
2414
    Used in filling up the tagged hints list.
2641
 
    This list is filled by first setting the kind of the hint as a 
 
2415
    This list is filled by first setting the kind of the hint as a
2642
2416
    context variable and then adding hints of the current kind.
2643
2417
    Then the context variable index_hint_type can be reset to the
2644
2418
    next hint type.
2645
2419
*/
2646
2420
void st_select_lex::set_index_hint_type(enum index_hint_type type_arg,
2647
2421
                                        index_clause_map clause)
2648
 
 
2422
{
2649
2423
  current_index_hint_type= type_arg;
2650
2424
  current_index_hint_clause= clause;
2651
2425
}
2656
2430
 
2657
2431
  SYNOPSIS
2658
2432
    alloc_index_hints()
2659
 
      thd         current thread.
 
2433
      session         current thread.
2660
2434
*/
2661
2435
 
2662
 
void st_select_lex::alloc_index_hints (THD *thd)
2663
 
2664
 
  index_hints= new (thd->mem_root) List<Index_hint>(); 
 
2436
void st_select_lex::alloc_index_hints (Session *session)
 
2437
{
 
2438
  index_hints= new (session->mem_root) List<Index_hint>();
2665
2439
}
2666
2440
 
2667
2441
 
2668
2442
 
2669
2443
/*
2670
 
  adds an element to the array storing index usage hints 
 
2444
  adds an element to the array storing index usage hints
2671
2445
  (ADD/FORCE/IGNORE INDEX).
2672
2446
 
2673
2447
  SYNOPSIS
2674
2448
    add_index_hint()
2675
 
      thd         current thread.
 
2449
      session         current thread.
2676
2450
      str         name of the index.
2677
2451
      length      number of characters in str.
2678
2452
 
2679
2453
  RETURN VALUE
2680
2454
    0 on success, non-zero otherwise
2681
2455
*/
2682
 
bool st_select_lex::add_index_hint (THD *thd, char *str, uint length)
 
2456
bool st_select_lex::add_index_hint (Session *session, char *str, uint32_t length)
2683
2457
{
2684
 
  return index_hints->push_front (new (thd->mem_root) 
 
2458
  return index_hints->push_front (new (session->mem_root)
2685
2459
                                 Index_hint(current_index_hint_type,
2686
2460
                                            current_index_hint_clause,
2687
2461
                                            str, length));