~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_lex.cc

  • Committer: Monty Taylor
  • Date: 2008-09-15 17:24:04 UTC
  • Revision ID: monty@inaugust.com-20080915172404-ygh6hiyu0q7qpa9x
Removed strndup calls.

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/error.h>
22
21
 
23
 
static int lex_one_token(void *arg, void *yysession);
 
22
static int lex_one_token(void *arg, void *yythd);
24
23
 
25
24
/*
26
25
  We are using pointer to this variable for distinguishing between assignment
34
33
*/
35
34
const LEX_STRING null_lex_str= {NULL, 0};
36
35
 
 
36
/* Longest standard keyword name */
 
37
 
 
38
#define TOCK_NAME_LENGTH 24
37
39
 
38
40
/*
39
41
  The following data is based on the latin1 character set, and is only
40
42
  used when comparing keywords
41
43
*/
42
44
 
43
 
static unsigned char to_upper_lex[]=
 
45
static uchar to_upper_lex[]=
44
46
{
45
47
    0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
46
48
   16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
72
74
  "FORCE INDEX"
73
75
};
74
76
 
75
 
inline int lex_casecmp(const char *s, const char *t, uint32_t len)
 
77
inline int lex_casecmp(const char *s, const char *t, uint len)
76
78
{
77
79
  while (len-- != 0 &&
78
 
         to_upper_lex[(unsigned char) *s++] == to_upper_lex[(unsigned char) *t++]) ;
 
80
         to_upper_lex[(uchar) *s++] == to_upper_lex[(uchar) *t++]) ;
79
81
  return (int) len+1;
80
82
}
81
83
 
84
86
 
85
87
void lex_init(void)
86
88
{
87
 
  uint32_t i;
 
89
  uint i;
88
90
  for (i=0 ; i < array_elements(symbols) ; i++)
89
 
    symbols[i].length=(unsigned char) strlen(symbols[i].name);
 
91
    symbols[i].length=(uchar) strlen(symbols[i].name);
90
92
  for (i=0 ; i < array_elements(sql_functions) ; i++)
91
 
    sql_functions[i].length=(unsigned char) strlen(sql_functions[i].name);
 
93
    sql_functions[i].length=(uchar) strlen(sql_functions[i].name);
92
94
 
93
95
  return;
94
96
}
109
111
  allows_derived= true;
110
112
}
111
113
 
112
 
Lex_input_stream::Lex_input_stream(Session *session,
 
114
Lex_input_stream::Lex_input_stream(THD *thd,
113
115
                                   const char* buffer,
114
116
                                   unsigned int length)
115
 
: m_session(session),
 
117
: m_thd(thd),
116
118
  yylineno(1),
117
119
  yytoklen(0),
118
120
  yylval(NULL),
137
139
  in_comment(NO_COMMENT),
138
140
  m_underscore_cs(NULL)
139
141
{
140
 
  m_cpp_buf= (char*) session->alloc(length + 1);
 
142
  m_cpp_buf= (char*) thd->alloc(length + 1);
141
143
  m_cpp_ptr= m_cpp_buf;
142
144
}
143
145
 
151
153
     statement;
152
154
  2) Determine the beginning of the body.
153
155
 
154
 
  @param session        Thread context.
 
156
  @param thd        Thread context.
155
157
  @param begin_ptr  Pointer to the start of the body in the pre-processed
156
158
                    buffer.
157
159
*/
158
160
 
159
 
void Lex_input_stream::body_utf8_start(Session *session, const char *begin_ptr)
 
161
void Lex_input_stream::body_utf8_start(THD *thd, const char *begin_ptr)
160
162
{
161
163
  assert(begin_ptr);
162
164
  assert(m_cpp_buf <= begin_ptr && begin_ptr <= m_cpp_buf + m_buf_length);
163
165
 
164
 
  uint32_t body_utf8_length=
165
 
    (m_buf_length / session->variables.character_set_client->mbminlen) *
 
166
  uint body_utf8_length=
 
167
    (m_buf_length / thd->variables.character_set_client->mbminlen) *
166
168
    my_charset_utf8_bin.mbmaxlen;
167
169
 
168
 
  m_body_utf8= (char *) session->alloc(body_utf8_length + 1);
 
170
  m_body_utf8= (char *) thd->alloc(body_utf8_length + 1);
169
171
  m_body_utf8_ptr= m_body_utf8;
170
172
  *m_body_utf8_ptr= 0;
171
173
 
231
233
  The operation converts the specified text literal to the utf8 and appends
232
234
  the result to the utf8-body.
233
235
 
234
 
  @param session      Thread context.
 
236
  @param thd      Thread context.
235
237
  @param txt      Text literal.
236
238
  @param txt_cs   Character set of the text literal.
237
239
  @param end_ptr  Pointer in the pre-processed buffer, to which
239
241
                  operation.
240
242
*/
241
243
 
242
 
void Lex_input_stream::body_utf8_append_literal(Session *session,
 
244
void Lex_input_stream::body_utf8_append_literal(THD *thd,
243
245
                                                const LEX_STRING *txt,
244
246
                                                const CHARSET_INFO * const txt_cs,
245
247
                                                const char *end_ptr)
251
253
 
252
254
  if (!my_charset_same(txt_cs, &my_charset_utf8_general_ci))
253
255
  {
254
 
    session->convert_string(&utf_txt,
 
256
    thd->convert_string(&utf_txt,
255
257
                        &my_charset_utf8_general_ci,
256
258
                        txt->str, txt->length,
257
259
                        txt_cs);
278
280
  (We already do too much here)
279
281
*/
280
282
 
281
 
void lex_start(Session *session)
 
283
void lex_start(THD *thd)
282
284
{
283
 
  LEX *lex= session->lex;
 
285
  LEX *lex= thd->lex;
284
286
 
285
 
  lex->session= lex->unit.session= session;
 
287
  lex->thd= lex->unit.thd= thd;
286
288
 
287
289
  lex->context_stack.empty();
288
290
  lex->unit.init_query();
329
331
  lex->reset_query_tables_list(false);
330
332
  lex->expr_allows_subselect= true;
331
333
  lex->use_only_table_context= false;
332
 
  lex->parse_vcol_expr= false;
333
334
 
334
335
  lex->name.str= 0;
335
336
  lex->name.length= 0;
359
360
{
360
361
  if (lex->yacc_yyss)
361
362
  {
362
 
    free(lex->yacc_yyss);
363
 
    free(lex->yacc_yyvs);
 
363
    my_free(lex->yacc_yyss, MYF(0));
 
364
    my_free(lex->yacc_yyvs, MYF(0));
364
365
    lex->yacc_yyss= 0;
365
366
    lex->yacc_yyvs= 0;
366
367
  }
370
371
                     lex->plugins.elements);
371
372
  reset_dynamic(&lex->plugins);
372
373
 
373
 
  delete lex->result;
374
 
  lex->result= 0;
375
 
 
376
374
  return;
377
375
}
378
376
 
379
377
 
380
 
static int find_keyword(Lex_input_stream *lip, uint32_t len, bool function)
 
378
static int find_keyword(Lex_input_stream *lip, uint len, bool function)
381
379
{
382
380
  const char *tok= lip->get_tok_start();
383
381
 
406
404
    1         name isn't a keyword
407
405
*/
408
406
 
409
 
bool is_keyword(const char *name, uint32_t len)
 
407
bool is_keyword(const char *name, uint len)
410
408
{
411
409
  assert(len != 0);
412
410
  return get_hash_symbol(name,len,0)!=0;
420
418
 
421
419
/* make a copy of token before ptr and set yytoklen */
422
420
 
423
 
static LEX_STRING get_token(Lex_input_stream *lip, uint32_t skip, uint32_t length)
 
421
static LEX_STRING get_token(Lex_input_stream *lip, uint skip, uint length)
424
422
{
425
423
  LEX_STRING tmp;
426
424
  lip->yyUnget();                       // ptr points now after last token char
427
425
  tmp.length=lip->yytoklen=length;
428
 
  tmp.str= lip->m_session->strmake(lip->get_tok_start() + skip, tmp.length);
 
426
  tmp.str= lip->m_thd->strmake(lip->get_tok_start() + skip, tmp.length);
429
427
 
430
428
  lip->m_cpp_text_start= lip->get_cpp_tok_start() + skip;
431
429
  lip->m_cpp_text_end= lip->m_cpp_text_start + tmp.length;
441
439
*/
442
440
 
443
441
static LEX_STRING get_quoted_token(Lex_input_stream *lip,
444
 
                                   uint32_t skip,
445
 
                                   uint32_t length, char quote)
 
442
                                   uint skip,
 
443
                                   uint length, char quote)
446
444
{
447
445
  LEX_STRING tmp;
448
446
  const char *from, *end;
449
447
  char *to;
450
448
  lip->yyUnget();                       // ptr points now after last token char
451
449
  tmp.length= lip->yytoklen=length;
452
 
  tmp.str=(char*) lip->m_session->alloc(tmp.length+1);
 
450
  tmp.str=(char*) lip->m_thd->alloc(tmp.length+1);
453
451
  from= lip->get_tok_start() + skip;
454
452
  to= tmp.str;
455
453
  end= to+length;
477
475
 
478
476
static char *get_text(Lex_input_stream *lip, int pre_skip, int post_skip)
479
477
{
480
 
  register unsigned char c,sep;
481
 
  uint32_t found_escape=0;
482
 
  const CHARSET_INFO * const cs= lip->m_session->charset();
 
478
  register uchar c,sep;
 
479
  uint found_escape=0;
 
480
  const CHARSET_INFO * const cs= lip->m_thd->charset();
483
481
 
484
482
  lip->tok_bitmap= 0;
485
483
  sep= lip->yyGetLast();                        // String should end with this
527
525
      end -= post_skip;
528
526
      assert(end >= str);
529
527
 
530
 
      if (!(start= (char*) lip->m_session->alloc((uint) (end-str)+1)))
 
528
      if (!(start= (char*) lip->m_thd->alloc((uint) (end-str)+1)))
531
529
        return (char*) "";              // Sql_alloc has set error flag
532
530
 
533
531
      lip->m_cpp_text_start= lip->get_cpp_tok_start() + pre_skip;
603
601
/*
604
602
** Calc type of integer; long integer, int64_t integer or real.
605
603
** Returns smallest type that match the string.
606
 
** When using uint64_t values the result is converted to a real
 
604
** When using unsigned long long values the result is converted to a real
607
605
** because else they will be unexpected sign changes because all calculation
608
606
** is done with int64_t or double.
609
607
*/
610
608
 
611
609
static const char *long_str="2147483647";
612
 
static const uint32_t long_len=10;
 
610
static const uint long_len=10;
613
611
static const char *signed_long_str="-2147483648";
614
612
static const char *int64_t_str="9223372036854775807";
615
 
static const uint32_t int64_t_len=19;
 
613
static const uint int64_t_len=19;
616
614
static const char *signed_int64_t_str="-9223372036854775808";
617
 
static const uint32_t signed_int64_t_len=19;
 
615
static const uint signed_int64_t_len=19;
618
616
static const char *unsigned_int64_t_str="18446744073709551615";
619
 
static const uint32_t unsigned_int64_t_len=20;
 
617
static const uint unsigned_int64_t_len=20;
620
618
 
621
 
static inline uint32_t int_token(const char *str,uint32_t length)
 
619
static inline uint int_token(const char *str,uint length)
622
620
{
623
621
  if (length < long_len)                        // quick normal case
624
622
    return NUM;
640
638
  if (length < long_len)
641
639
    return NUM;
642
640
 
643
 
  uint32_t smaller,bigger;
 
641
  uint smaller,bigger;
644
642
  const char *cmp;
645
643
  if (neg)
646
644
  {
687
685
    }
688
686
  }
689
687
  while (*cmp && *cmp++ == *str++) ;
690
 
  return ((unsigned char) str[-1] <= (unsigned char) cmp[-1]) ? smaller : bigger;
 
688
  return ((uchar) str[-1] <= (uchar) cmp[-1]) ? smaller : bigger;
691
689
}
692
690
 
693
691
 
694
692
/*
695
 
  DRIZZLElex remember the following states from the following DRIZZLElex()
 
693
  MYSQLlex remember the following states from the following MYSQLlex()
696
694
 
697
695
  - MY_LEX_EOQ                  Found end of query
698
696
  - MY_LEX_OPERATOR_OR_IDENT    Last state was an ident, text or number
699
697
                                (which can't be followed by a signed number)
700
698
*/
701
699
 
702
 
int DRIZZLElex(void *arg, void *yysession)
 
700
int MYSQLlex(void *arg, void *yythd)
703
701
{
704
 
  Session *session= (Session *)yysession;
705
 
  Lex_input_stream *lip= session->m_lip;
 
702
  THD *thd= (THD *)yythd;
 
703
  Lex_input_stream *lip= thd->m_lip;
706
704
  YYSTYPE *yylval=(YYSTYPE*) arg;
707
705
  int token;
708
706
 
719
717
    return token;
720
718
  }
721
719
 
722
 
  token= lex_one_token(arg, yysession);
 
720
  token= lex_one_token(arg, yythd);
723
721
 
724
722
  switch(token) {
725
723
  case WITH:
726
724
    /*
727
 
      Parsing 'WITH' 'ROLLUP' requires 2 look ups,
 
725
      Parsing 'WITH' 'ROLLUP' or 'WITH' 'CUBE' requires 2 look ups,
728
726
      which makes the grammar LALR(2).
729
727
      Replace by a single 'WITH_ROLLUP' or 'WITH_CUBE' token,
730
728
      to transform the grammar into a LALR(1) grammar,
731
729
      which sql_yacc.yy can process.
732
730
    */
733
 
    token= lex_one_token(arg, yysession);
734
 
    if (token == ROLLUP_SYM)
735
 
    {
 
731
    token= lex_one_token(arg, yythd);
 
732
    switch(token) {
 
733
    case CUBE_SYM:
 
734
      return WITH_CUBE_SYM;
 
735
    case ROLLUP_SYM:
736
736
      return WITH_ROLLUP_SYM;
737
 
    }
738
 
    else
739
 
    {
 
737
    default:
740
738
      /*
741
739
        Save the token following 'WITH'
742
740
      */
753
751
  return token;
754
752
}
755
753
 
756
 
int lex_one_token(void *arg, void *yysession)
 
754
int lex_one_token(void *arg, void *yythd)
757
755
{
758
756
  register unsigned char c= 0; /* Just set to shutup GCC */
759
757
  bool comment_closed;
760
758
  int   tokval, result_state;
761
759
  unsigned int length;
762
760
  enum my_lex_states state;
763
 
  Session *session= (Session *)yysession;
764
 
  Lex_input_stream *lip= session->m_lip;
765
 
  LEX *lex= session->lex;
 
761
  THD *thd= (THD *)yythd;
 
762
  Lex_input_stream *lip= thd->m_lip;
 
763
  LEX *lex= thd->lex;
766
764
  YYSTYPE *yylval=(YYSTYPE*) arg;
767
 
  const CHARSET_INFO * const cs= session->charset();
768
 
  unsigned char *state_map= cs->state_map;
769
 
  unsigned char *ident_map= cs->ident_map;
 
765
  const CHARSET_INFO * const cs= thd->charset();
 
766
  uchar *state_map= cs->state_map;
 
767
  uchar *ident_map= cs->ident_map;
770
768
 
771
769
  lip->yylval=yylval;                   // The global state
772
770
 
925
923
 
926
924
      lip->body_utf8_append(lip->m_cpp_text_start);
927
925
 
928
 
      lip->body_utf8_append_literal(session, &yylval->lex_str, cs,
 
926
      lip->body_utf8_append_literal(thd, &yylval->lex_str, cs,
929
927
                                    lip->m_cpp_text_end);
930
928
 
931
929
      return(result_state);                     // IDENT or IDENT_QUOTED
1028
1026
 
1029
1027
      lip->body_utf8_append(lip->m_cpp_text_start);
1030
1028
 
1031
 
      lip->body_utf8_append_literal(session, &yylval->lex_str, cs,
 
1029
      lip->body_utf8_append_literal(thd, &yylval->lex_str, cs,
1032
1030
                                    lip->m_cpp_text_end);
1033
1031
 
1034
1032
      return(result_state);
1035
1033
 
1036
1034
    case MY_LEX_USER_VARIABLE_DELIMITER:        // Found quote char
1037
1035
    {
1038
 
      uint32_t double_quotes= 0;
 
1036
      uint double_quotes= 0;
1039
1037
      char quote_char= c;                       // Used char
1040
1038
      while ((c=lip->yyGet()))
1041
1039
      {
1069
1067
 
1070
1068
      lip->body_utf8_append(lip->m_cpp_text_start);
1071
1069
 
1072
 
      lip->body_utf8_append_literal(session, &yylval->lex_str, cs,
 
1070
      lip->body_utf8_append_literal(thd, &yylval->lex_str, cs,
1073
1071
                                    lip->m_cpp_text_end);
1074
1072
 
1075
1073
      return(IDENT_QUOTED);
1183
1181
 
1184
1182
      lip->body_utf8_append(lip->m_cpp_text_start);
1185
1183
 
1186
 
      lip->body_utf8_append_literal(session, &yylval->lex_str,
 
1184
      lip->body_utf8_append_literal(thd, &yylval->lex_str,
1187
1185
        lip->m_underscore_cs ? lip->m_underscore_cs : cs,
1188
1186
        lip->m_cpp_text_end);
1189
1187
 
1325
1323
    case MY_LEX_SEMICOLON:                      // optional line terminator
1326
1324
      if (lip->yyPeek())
1327
1325
      {
1328
 
        if ((session->client_capabilities & CLIENT_MULTI_STATEMENTS))
 
1326
        if ((thd->client_capabilities & CLIENT_MULTI_STATEMENTS))
1329
1327
        {
1330
1328
          lip->found_semicolon= lip->get_ptr();
1331
 
          session->server_status|= SERVER_MORE_RESULTS_EXISTS;
 
1329
          thd->server_status|= SERVER_MORE_RESULTS_EXISTS;
1332
1330
          lip->next_state= MY_LEX_END;
1333
1331
          lip->set_echo(true);
1334
1332
          return (END_OF_INPUT);
1423
1421
 
1424
1422
      lip->body_utf8_append(lip->m_cpp_text_start);
1425
1423
 
1426
 
      lip->body_utf8_append_literal(session, &yylval->lex_str, cs,
 
1424
      lip->body_utf8_append_literal(thd, &yylval->lex_str, cs,
1427
1425
                                    lip->m_cpp_text_end);
1428
1426
 
1429
1427
      return(result_state);
1441
1439
  statements and stored procedures and is compensated by always
1442
1440
  supplying a copy of Alter_info to these functions.
1443
1441
 
1444
 
  @return You need to use check the error in Session for out
 
1442
  @return You need to use check the error in THD for out
1445
1443
  of memory condition after calling this function.
1446
1444
*/
1447
1445
 
1566
1564
  select_n_having_items= 0;
1567
1565
  subquery_in_having= explicit_limit= 0;
1568
1566
  is_item_list_lookup= 0;
 
1567
  first_execution= 1;
 
1568
  first_cond_optimization= 1;
1569
1569
  parsing_place= NO_MATTER;
1570
1570
  exclude_from_table_unique_test= false;
1571
1571
  nest_level= 0;
1590
1590
  linkage= UNSPECIFIED_TYPE;
1591
1591
  order_list.elements= 0;
1592
1592
  order_list.first= 0;
1593
 
  order_list.next= (unsigned char**) &order_list.first;
 
1593
  order_list.next= (uchar**) &order_list.first;
1594
1594
  /* Set limit and offset to default values */
1595
1595
  select_limit= 0;      /* denotes the default limit = HA_POS_ERROR */
1596
1596
  offset_limit= 0;      /* denotes the default offset = 0 */
1813
1813
bool st_select_lex_node::set_braces(bool value __attribute__((unused)))
1814
1814
{ return 1; }
1815
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; }
 
1816
uint st_select_lex_node::get_in_sum_expr()           { return 0; }
1817
1817
TableList* st_select_lex_node::get_table_list()     { return 0; }
1818
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)),
 
1819
TableList *st_select_lex_node::add_table_to_list (THD *thd __attribute__((unused)),
1820
1820
                                                   Table_ident *table __attribute__((unused)),
1821
1821
                                                  LEX_STRING *alias __attribute__((unused)),
1822
1822
                                                  uint32_t table_join_options __attribute__((unused)),
1858
1858
}
1859
1859
 
1860
1860
 
1861
 
bool st_select_lex::add_order_to_list(Session *session, Item *item, bool asc)
 
1861
bool st_select_lex::add_order_to_list(THD *thd, Item *item, bool asc)
1862
1862
{
1863
 
  return add_to_list(session, order_list, item, asc);
 
1863
  return add_to_list(thd, order_list, item, asc);
1864
1864
}
1865
1865
 
1866
1866
 
1867
 
bool st_select_lex::add_item_to_list(Session *session __attribute__((unused)),
 
1867
bool st_select_lex::add_item_to_list(THD *thd __attribute__((unused)),
1868
1868
                                     Item *item)
1869
1869
{
1870
1870
  return(item_list.push_back(item));
1871
1871
}
1872
1872
 
1873
1873
 
1874
 
bool st_select_lex::add_group_to_list(Session *session, Item *item, bool asc)
 
1874
bool st_select_lex::add_group_to_list(THD *thd, Item *item, bool asc)
1875
1875
{
1876
 
  return add_to_list(session, group_list, item, asc);
 
1876
  return add_to_list(thd, group_list, item, asc);
1877
1877
}
1878
1878
 
1879
1879
 
1903
1903
}
1904
1904
 
1905
1905
 
1906
 
uint32_t st_select_lex::get_in_sum_expr()
 
1906
uint st_select_lex::get_in_sum_expr()
1907
1907
{
1908
1908
  return in_sum_expr;
1909
1909
}
1925
1925
}
1926
1926
 
1927
1927
 
1928
 
bool st_select_lex::setup_ref_array(Session *session, uint32_t order_group_num)
 
1928
bool st_select_lex::setup_ref_array(THD *thd, uint order_group_num)
1929
1929
{
1930
1930
  if (ref_pointer_array)
1931
1931
    return 0;
1932
1932
 
 
1933
  /*
 
1934
    We have to create array in prepared statement memory if it is
 
1935
    prepared statement
 
1936
  */
 
1937
  Query_arena *arena= thd->stmt_arena;
1933
1938
  return (ref_pointer_array=
1934
 
          (Item **)session->alloc(sizeof(Item*) * (n_child_sum_items +
 
1939
          (Item **)arena->alloc(sizeof(Item*) * (n_child_sum_items +
1935
1940
                                                 item_list.elements +
1936
1941
                                                 select_n_having_items +
1937
1942
                                                 select_n_where_fields +
1954
1959
    }
1955
1960
    if (sl->braces)
1956
1961
      str->append('(');
1957
 
    sl->print(session, str, query_type);
 
1962
    sl->print(thd, str, query_type);
1958
1963
    if (sl->braces)
1959
1964
      str->append(')');
1960
1965
  }
1968
1973
        (order_st *) fake_select_lex->order_list.first,
1969
1974
        query_type);
1970
1975
    }
1971
 
    fake_select_lex->print_limit(session, str, query_type);
 
1976
    fake_select_lex->print_limit(thd, str, query_type);
1972
1977
  }
1973
1978
}
1974
1979
 
1982
1987
    if (order->counter_used)
1983
1988
    {
1984
1989
      char buffer[20];
1985
 
      uint32_t length= snprintf(buffer, 20, "%d", order->counter);
 
1990
      uint length= snprintf(buffer, 20, "%d", order->counter);
1986
1991
      str->append(buffer, length);
1987
1992
    }
1988
1993
    else
1995
2000
}
1996
2001
 
1997
2002
 
1998
 
void st_select_lex::print_limit(Session *session __attribute__((unused)),
 
2003
void st_select_lex::print_limit(THD *thd __attribute__((unused)),
1999
2004
                                String *str,
2000
2005
                                enum_query_type query_type)
2001
2006
{
2018
2023
                    ((Item_in_subselect*)item)->exec_method ==
2019
2024
                    Item_in_subselect::MATERIALIZATION) ?
2020
2025
                   true :
2021
 
                   (select_limit->val_int() == 1L) &&
 
2026
                   (select_limit->val_int() == 1LL) &&
2022
2027
                   offset_limit == 0));
2023
2028
      return;
2024
2029
    }
2036
2041
}
2037
2042
 
2038
2043
/**
2039
 
  @brief Restore the LEX and Session in case of a parse error.
 
2044
  @brief Restore the LEX and THD in case of a parse error.
2040
2045
 
2041
2046
  This is a clean up call that is invoked by the Bison generated
2042
 
  parser before returning an error from DRIZZLEparse. If your
 
2047
  parser before returning an error from MYSQLparse. If your
2043
2048
  semantic actions manipulate with the global thread state (which
2044
2049
  is a very bad practice and should not normally be employed) and
2045
2050
  need a clean-up in case of error, and you can not use %destructor
2047
2052
  to implement the clean up.
2048
2053
*/
2049
2054
 
2050
 
void st_lex::cleanup_lex_after_parse_error(Session *session __attribute__((unused)))
 
2055
void st_lex::cleanup_lex_after_parse_error(THD *thd __attribute__((unused)))
2051
2056
{
2052
2057
}
2053
2058
 
2125
2130
 
2126
2131
  NOTE
2127
2132
    LEX object initialized with this constructor can be used as part of
2128
 
    Session object for which one can safely call open_tables(), lock_tables()
 
2133
    THD object for which one can safely call open_tables(), lock_tables()
2129
2134
    and close_thread_tables() functions. But it is not yet ready for
2130
2135
    statement parsing. On should use lex_start() function to prepare LEX
2131
2136
    for this.
2334
2339
bool
2335
2340
st_lex::copy_db_to(char **p_db, size_t *p_db_length) const
2336
2341
{
2337
 
  return session->copy_db_to(p_db, p_db_length);
 
2342
  return thd->copy_db_to(p_db, p_db_length);
2338
2343
}
2339
2344
 
2340
2345
/*
2352
2357
 
2353
2358
  val= sl->select_limit ? sl->select_limit->val_uint() : HA_POS_ERROR;
2354
2359
  select_limit_val= (ha_rows)val;
 
2360
#ifndef BIG_TABLES
2355
2361
  /* 
2356
2362
    Check for overflow : ha_rows can be smaller then uint64_t if
2357
2363
    BIG_TABLES is off.
2358
2364
    */
2359
2365
  if (val != (uint64_t)select_limit_val)
2360
2366
    select_limit_val= HA_POS_ERROR;
 
2367
#endif
2361
2368
  offset_limit_cnt= (ha_rows)(sl->offset_limit ? sl->offset_limit->val_uint() :
2362
 
                                                 0UL);
 
2369
                                                 0ULL);
2363
2370
  select_limit_cnt= select_limit_val + offset_limit_cnt;
2364
2371
  if (select_limit_cnt < select_limit_val)
2365
2372
    select_limit_cnt= HA_POS_ERROR;             // no limit
2405
2412
    {
2406
2413
      select_lex.context.table_list= 
2407
2414
        select_lex.context.first_name_resolution_table= first->next_local;
2408
 
      select_lex.table_list.first= (unsigned char*) (first->next_local);
 
2415
      select_lex.table_list.first= (uchar*) (first->next_local);
2409
2416
      select_lex.table_list.elements--; //safety
2410
2417
      first->next_local= 0;
2411
2418
      /*
2486
2493
    {
2487
2494
      first->next_local= (TableList*) select_lex.table_list.first;
2488
2495
      select_lex.context.table_list= first;
2489
 
      select_lex.table_list.first= (unsigned char*) first;
 
2496
      select_lex.table_list.first= (uchar*) first;
2490
2497
      select_lex.table_list.elements++; //safety
2491
2498
    }
2492
2499
  }
2509
2516
void st_lex::cleanup_after_one_table_open()
2510
2517
{
2511
2518
  /*
2512
 
    session->lex->derived_tables & additional units may be set if we open
2513
 
    a view. It is necessary to clear session->lex->derived_tables flag
 
2519
    thd->lex->derived_tables & additional units may be set if we open
 
2520
    a view. It is necessary to clear thd->lex->derived_tables flag
2514
2521
    to prevent processing of derived tables during next open_and_lock_tables
2515
2522
    if next table is a real table and cleanup & remove underlying units
2516
 
    NOTE: all units will be connected to session->lex->select_lex, because we
 
2523
    NOTE: all units will be connected to thd->lex->select_lex, because we
2517
2524
    have not UNION on most upper level.
2518
2525
    */
2519
2526
  if (all_selects_list != &select_lex)
2584
2591
 
2585
2592
  SYNOPSIS
2586
2593
    fix_prepare_info_in_table_list()
2587
 
      session  Thread handle
 
2594
      thd  Thread handle
2588
2595
      tbl  List of tables to process
2589
2596
 
2590
2597
  DESCRIPTION
2594
2601
 
2595
2602
*/
2596
2603
 
2597
 
static void fix_prepare_info_in_table_list(Session *session, TableList *tbl)
 
2604
static void fix_prepare_info_in_table_list(THD *thd, TableList *tbl)
2598
2605
{
2599
2606
  for (; tbl; tbl= tbl->next_local)
2600
2607
  {
2601
2608
    if (tbl->on_expr)
2602
2609
    {
2603
2610
      tbl->prep_on_expr= tbl->on_expr;
2604
 
      tbl->on_expr= tbl->on_expr->copy_andor_structure(session);
 
2611
      tbl->on_expr= tbl->on_expr->copy_andor_structure(thd);
2605
2612
    }
2606
 
    fix_prepare_info_in_table_list(session, tbl->merge_underlying_list);
 
2613
    fix_prepare_info_in_table_list(thd, tbl->merge_underlying_list);
2607
2614
  }
2608
2615
}
2609
2616
 
2648
2655
 
2649
2656
  SYNOPSIS
2650
2657
    alloc_index_hints()
2651
 
      session         current thread.
 
2658
      thd         current thread.
2652
2659
*/
2653
2660
 
2654
 
void st_select_lex::alloc_index_hints (Session *session)
 
2661
void st_select_lex::alloc_index_hints (THD *thd)
2655
2662
2656
 
  index_hints= new (session->mem_root) List<Index_hint>(); 
 
2663
  index_hints= new (thd->mem_root) List<Index_hint>(); 
2657
2664
}
2658
2665
 
2659
2666
 
2664
2671
 
2665
2672
  SYNOPSIS
2666
2673
    add_index_hint()
2667
 
      session         current thread.
 
2674
      thd         current thread.
2668
2675
      str         name of the index.
2669
2676
      length      number of characters in str.
2670
2677
 
2671
2678
  RETURN VALUE
2672
2679
    0 on success, non-zero otherwise
2673
2680
*/
2674
 
bool st_select_lex::add_index_hint (Session *session, char *str, uint32_t length)
 
2681
bool st_select_lex::add_index_hint (THD *thd, char *str, uint length)
2675
2682
{
2676
 
  return index_hints->push_front (new (session->mem_root) 
 
2683
  return index_hints->push_front (new (thd->mem_root) 
2677
2684
                                 Index_hint(current_index_hint_type,
2678
2685
                                            current_index_hint_clause,
2679
2686
                                            str, length));