~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_lex.h

  • Committer: Brian Aker
  • Date: 2009-12-29 01:38:38 UTC
  • mfrom: (1251.1.1 drizzle)
  • Revision ID: brian@gaz-20091229013838-03kb2z5xbqw03ddt
Merge of Diego fix.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000-2006 MySQL AB
2
 
 
3
 
   This program is free software; you can redistribute it and/or modify
4
 
   it under the terms of the GNU General Public License as published by
5
 
   the Free Software Foundation; version 2 of the License.
6
 
 
7
 
   This program is distributed in the hope that it will be useful,
8
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 
   GNU General Public License for more details.
11
 
 
12
 
   You should have received a copy of the GNU General Public License
13
 
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
 
 
16
 
#ifndef DRIZZLE_SERVER_SQL_LEX_H
17
 
#define DRIZZLE_SERVER_SQL_LEX_H
 
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2008 Sun Microsystems
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; version 2 of the License.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 */
 
19
 
 
20
#ifndef DRIZZLED_SQL_LEX_H
 
21
#define DRIZZLED_SQL_LEX_H
18
22
 
19
23
/**
20
24
  @defgroup Semantic_Analysis Semantic Analysis
21
25
*/
 
26
#include <drizzled/message/table.pb.h>
 
27
 
 
28
#include "drizzled/plugin/function.h"
 
29
#include "drizzled/name_resolution_context.h"
 
30
#include "drizzled/item/subselect.h"
 
31
#include "drizzled/table_list.h"
 
32
#include "drizzled/function/math/real.h"
 
33
#include "drizzled/alter_drop.h"
 
34
#include "drizzled/alter_column.h"
 
35
#include "drizzled/alter_info.h"
 
36
#include "drizzled/key_part_spec.h"
 
37
#include "drizzled/index_hint.h"
 
38
#include "drizzled/statement.h"
 
39
 
 
40
#include <bitset>
 
41
#include <string>
 
42
 
 
43
class select_result_interceptor;
22
44
 
23
45
/* YACC and LEX Definitions */
24
46
 
25
47
/* These may not be declared yet */
26
48
class Table_ident;
27
 
class sql_exchange;
28
 
class LEX_COLUMN;
 
49
class file_exchange;
 
50
class Lex_Column;
 
51
class Item_outer_ref;
29
52
 
30
 
#ifdef DRIZZLE_SERVER
31
53
/*
32
54
  The following hack is needed because mysql_yacc.cc does not define
33
55
  YYSTYPE before including this file
34
56
*/
35
57
 
36
 
#include "set_var.h"
37
 
 
38
 
#ifdef DRIZZLE_YACC
39
 
#define LEX_YYSTYPE void *
40
 
#else
41
 
#if defined(DRIZZLE_LEX)
42
 
#include "lex_symbol.h"
43
 
#include "sql_yacc.h"
44
 
#define LEX_YYSTYPE YYSTYPE *
45
 
#else
46
 
#define LEX_YYSTYPE void *
47
 
#endif
48
 
#endif
49
 
#endif
50
 
 
51
 
/*
52
 
  When a command is added here, be sure it's also added in mysqld.cc
53
 
  in "struct show_var_st status_vars[]= {" ...
54
 
 
55
 
  If the command returns a result set or is not allowed in stored
56
 
  functions or triggers, please also make sure that
57
 
  sp_get_flags_for_command (sp_head.cc) returns proper flags for the
58
 
  added SQLCOM_.
59
 
*/
60
 
 
61
 
enum enum_sql_command {
62
 
  SQLCOM_SELECT, SQLCOM_CREATE_TABLE, SQLCOM_CREATE_INDEX, SQLCOM_ALTER_TABLE,
63
 
  SQLCOM_UPDATE, SQLCOM_INSERT, SQLCOM_INSERT_SELECT,
64
 
  SQLCOM_DELETE, SQLCOM_TRUNCATE, SQLCOM_DROP_TABLE, SQLCOM_DROP_INDEX,
65
 
  SQLCOM_SHOW_DATABASES, SQLCOM_SHOW_TABLES, SQLCOM_SHOW_FIELDS,
66
 
  SQLCOM_SHOW_KEYS, SQLCOM_SHOW_VARIABLES, SQLCOM_SHOW_STATUS,
67
 
  SQLCOM_SHOW_ENGINE_LOGS, SQLCOM_SHOW_ENGINE_STATUS, SQLCOM_SHOW_ENGINE_MUTEX,
68
 
  SQLCOM_SHOW_PROCESSLIST, SQLCOM_SHOW_MASTER_STAT, SQLCOM_SHOW_SLAVE_STAT,
69
 
  SQLCOM_SHOW_CREATE, SQLCOM_SHOW_CHARSETS,
70
 
  SQLCOM_SHOW_COLLATIONS, SQLCOM_SHOW_CREATE_DB, SQLCOM_SHOW_TABLE_STATUS,
71
 
  SQLCOM_LOAD,SQLCOM_SET_OPTION,SQLCOM_LOCK_TABLES,SQLCOM_UNLOCK_TABLES,
72
 
  SQLCOM_CHANGE_DB, SQLCOM_CREATE_DB, SQLCOM_DROP_DB, SQLCOM_ALTER_DB,
73
 
  SQLCOM_REPAIR, SQLCOM_REPLACE, SQLCOM_REPLACE_SELECT,
74
 
  SQLCOM_OPTIMIZE, SQLCOM_CHECK,
75
 
  SQLCOM_ASSIGN_TO_KEYCACHE,
76
 
  SQLCOM_FLUSH, SQLCOM_KILL, SQLCOM_ANALYZE,
77
 
  SQLCOM_ROLLBACK, SQLCOM_ROLLBACK_TO_SAVEPOINT,
78
 
  SQLCOM_COMMIT, SQLCOM_SAVEPOINT, SQLCOM_RELEASE_SAVEPOINT,
79
 
  SQLCOM_SLAVE_START, SQLCOM_SLAVE_STOP,
80
 
  SQLCOM_BEGIN, SQLCOM_CHANGE_MASTER,
81
 
  SQLCOM_RENAME_TABLE,  
82
 
  SQLCOM_RESET, SQLCOM_PURGE, SQLCOM_PURGE_BEFORE, SQLCOM_SHOW_BINLOGS,
83
 
  SQLCOM_SHOW_OPEN_TABLES,
84
 
  SQLCOM_SHOW_SLAVE_HOSTS, SQLCOM_DELETE_MULTI, SQLCOM_UPDATE_MULTI,
85
 
  SQLCOM_SHOW_BINLOG_EVENTS,
86
 
  SQLCOM_SHOW_WARNS, SQLCOM_EMPTY_QUERY, SQLCOM_SHOW_ERRORS,
87
 
  SQLCOM_CHECKSUM,
88
 
  SQLCOM_BINLOG_BASE64_EVENT,
89
 
  SQLCOM_SHOW_PLUGINS,
90
 
  /*
91
 
    When a command is added here, be sure it's also added in mysqld.cc
92
 
    in "struct show_var_st status_vars[]= {" ...
93
 
  */
94
 
  /* This should be the last !!! */
95
 
  SQLCOM_END
96
 
};
 
58
#ifdef DRIZZLE_SERVER
 
59
# include <drizzled/set_var.h>
 
60
# include <drizzled/item/func.h>
 
61
# ifdef DRIZZLE_YACC
 
62
#  define LEX_YYSTYPE void *
 
63
# else
 
64
#  if defined(DRIZZLE_LEX)
 
65
#   include <drizzled/foreign_key.h>
 
66
#   include <drizzled/lex_symbol.h>
 
67
#   include <drizzled/sql_yacc.h>
 
68
#   define LEX_YYSTYPE YYSTYPE *
 
69
#  else
 
70
#   define LEX_YYSTYPE void *
 
71
#  endif /* defined(DRIZZLE_LEX) */
 
72
# endif /* DRIZZLE_YACC */
 
73
#endif /* DRIZZLE_SERVER */
97
74
 
98
75
// describe/explain types
99
76
#define DESCRIBE_NORMAL         1
106
83
 
107
84
typedef List<Item> List_item;
108
85
 
109
 
/* SERVERS CACHE CHANGES */
110
 
typedef struct st_lex_server_options
111
 
{
112
 
  int32_t port;
113
 
  uint32_t server_name_length;
114
 
  char *server_name, *host, *db, *username, *password, *scheme, *owner;
115
 
} LEX_SERVER_OPTIONS;
116
 
 
117
 
typedef struct st_lex_master_info
118
 
{
119
 
  char *host, *user, *password, *log_file_name;
120
 
  uint32_t port, connect_retry;
121
 
  float heartbeat_period;
122
 
  uint64_t pos;
123
 
  uint32_t server_id;
124
 
  /*
125
 
    Enum is used for making it possible to detect if the user
126
 
    changed variable or if it should be left at old value
127
 
   */
128
 
  enum {LEX_MI_UNCHANGED, LEX_MI_DISABLE, LEX_MI_ENABLE}
129
 
    ssl, ssl_verify_server_cert, heartbeat_opt;
130
 
  char *ssl_key, *ssl_cert, *ssl_ca, *ssl_capath, *ssl_cipher;
131
 
  char *relay_log_name;
132
 
  uint32_t relay_log_pos;
133
 
} LEX_MASTER_INFO;
134
 
 
135
 
 
136
86
enum sub_select_type
137
87
{
138
 
  UNSPECIFIED_TYPE,UNION_TYPE, INTERSECT_TYPE,
139
 
  EXCEPT_TYPE, GLOBAL_OPTIONS_TYPE, DERIVED_TABLE_TYPE, OLAP_TYPE
140
 
};
141
 
 
142
 
enum olap_type 
143
 
{
144
 
  UNSPECIFIED_OLAP_TYPE, CUBE_TYPE, ROLLUP_TYPE
145
 
};
146
 
 
147
 
enum tablespace_op_type
148
 
{
149
 
  NO_TABLESPACE_OP, DISCARD_TABLESPACE, IMPORT_TABLESPACE
150
 
};
151
 
 
152
 
/* 
153
 
  String names used to print a statement with index hints.
154
 
  Keep in sync with index_hint_type.
155
 
*/
156
 
extern const char * index_hint_type_name[];
157
 
typedef uchar index_clause_map;
 
88
  UNSPECIFIED_TYPE,
 
89
  UNION_TYPE,
 
90
  INTERSECT_TYPE,
 
91
  EXCEPT_TYPE,
 
92
  GLOBAL_OPTIONS_TYPE,
 
93
  DERIVED_TABLE_TYPE,
 
94
  OLAP_TYPE
 
95
};
 
96
 
 
97
enum olap_type
 
98
{
 
99
  UNSPECIFIED_OLAP_TYPE,
 
100
  CUBE_TYPE,
 
101
  ROLLUP_TYPE
 
102
};
158
103
 
159
104
/*
160
 
  Bits in index_clause_map : one for each possible FOR clause in
161
 
  USE/FORCE/IGNORE INDEX index hint specification
162
 
*/
163
 
#define INDEX_HINT_MASK_JOIN  (1)
164
 
#define INDEX_HINT_MASK_GROUP (1 << 1)
165
 
#define INDEX_HINT_MASK_ORDER (1 << 2)
166
 
 
167
 
#define INDEX_HINT_MASK_ALL (INDEX_HINT_MASK_JOIN | INDEX_HINT_MASK_GROUP | \
168
 
                             INDEX_HINT_MASK_ORDER)
169
 
 
170
 
/* Single element of an USE/FORCE/IGNORE INDEX list specified as a SQL hint  */
171
 
class Index_hint : public Sql_alloc
172
 
{
173
 
public:
174
 
  /* The type of the hint : USE/FORCE/IGNORE */
175
 
  enum index_hint_type type;
176
 
  /* Where the hit applies to. A bitmask of INDEX_HINT_MASK_<place> values */
177
 
  index_clause_map clause;
178
 
  /* 
179
 
    The index name. Empty (str=NULL) name represents an empty list 
180
 
    USE INDEX () clause 
181
 
  */ 
182
 
  LEX_STRING key_name;
183
 
 
184
 
  Index_hint (enum index_hint_type type_arg, index_clause_map clause_arg,
185
 
              char *str, uint32_t length) :
186
 
    type(type_arg), clause(clause_arg)
187
 
  {
188
 
    key_name.str= str;
189
 
    key_name.length= length;
190
 
  }
191
 
 
192
 
  void print(THD *thd, String *str);
193
 
}; 
194
 
 
195
 
/* 
196
 
  The state of the lex parsing for selects 
197
 
   
 
105
  The state of the lex parsing for selects
 
106
 
198
107
   master and slaves are pointers to select_lex.
199
108
   master is pointer to upper level node.
200
109
   slave is pointer to lower level node
306
215
 
307
216
*/
308
217
 
309
 
/* 
310
 
    Base class for st_select_lex (SELECT_LEX) & 
311
 
    st_select_lex_unit (SELECT_LEX_UNIT)
 
218
/*
 
219
    Base class for Select_Lex (Select_Lex) &
 
220
    Select_Lex_Unit (Select_Lex_Unit)
312
221
*/
313
 
struct st_lex;
314
 
class st_select_lex;
315
 
class st_select_lex_unit;
316
 
class st_select_lex_node {
 
222
class LEX;
 
223
class Select_Lex;
 
224
class Select_Lex_Unit;
 
225
class Select_Lex_Node {
317
226
protected:
318
 
  st_select_lex_node *next, **prev,   /* neighbor list */
 
227
  Select_Lex_Node *next, **prev,   /* neighbor list */
319
228
    *master, *slave,                  /* vertical links */
320
 
    *link_next, **link_prev;          /* list of whole SELECT_LEX */
 
229
    *link_next, **link_prev;          /* list of whole Select_Lex */
321
230
public:
322
231
 
323
232
  uint64_t options;
337
246
 
338
247
  static void *operator new(size_t size)
339
248
  {
340
 
    return sql_alloc(size);
 
249
    return drizzled::memory::sql_alloc(size);
341
250
  }
342
 
  static void *operator new(size_t size, MEM_ROOT *mem_root)
 
251
  static void *operator new(size_t size, drizzled::memory::Root *mem_root)
343
252
  { return (void*) alloc_root(mem_root, (uint32_t) size); }
344
 
  static void operator delete(void *ptr __attribute__((unused)),
345
 
                              size_t size __attribute__((unused)))
346
 
  { TRASH(ptr, size); }
347
 
  static void operator delete(void *ptr __attribute__((unused)),
348
 
                              MEM_ROOT *mem_root __attribute__((unused)))
 
253
  static void operator delete(void *, size_t)
 
254
  {  }
 
255
  static void operator delete(void *, drizzled::memory::Root *)
349
256
  {}
350
 
  st_select_lex_node(): linkage(UNSPECIFIED_TYPE) {}
351
 
  virtual ~st_select_lex_node() {}
352
 
  inline st_select_lex_node* get_master() { return master; }
 
257
  Select_Lex_Node(): linkage(UNSPECIFIED_TYPE) {}
 
258
  virtual ~Select_Lex_Node() {}
 
259
  inline Select_Lex_Node* get_master() { return master; }
353
260
  virtual void init_query();
354
261
  virtual void init_select();
355
 
  void include_down(st_select_lex_node *upper);
356
 
  void include_neighbour(st_select_lex_node *before);
357
 
  void include_standalone(st_select_lex_node *sel, st_select_lex_node **ref);
358
 
  void include_global(st_select_lex_node **plink);
 
262
  void include_down(Select_Lex_Node *upper);
 
263
  void include_neighbour(Select_Lex_Node *before);
 
264
  void include_standalone(Select_Lex_Node *sel, Select_Lex_Node **ref);
 
265
  void include_global(Select_Lex_Node **plink);
359
266
  void exclude();
360
267
 
361
 
  virtual st_select_lex_unit* master_unit()= 0;
362
 
  virtual st_select_lex* outer_select()= 0;
363
 
  virtual st_select_lex* return_after_parsing()= 0;
 
268
  virtual Select_Lex_Unit* master_unit()= 0;
 
269
  virtual Select_Lex* outer_select()= 0;
 
270
  virtual Select_Lex* return_after_parsing()= 0;
364
271
 
365
272
  virtual bool set_braces(bool value);
366
273
  virtual bool inc_in_sum_expr();
367
274
  virtual uint32_t get_in_sum_expr();
368
 
  virtual TABLE_LIST* get_table_list();
 
275
  virtual TableList* get_table_list();
369
276
  virtual List<Item>* get_item_list();
370
277
  virtual uint32_t get_table_join_options();
371
 
  virtual TABLE_LIST *add_table_to_list(THD *thd, Table_ident *table,
 
278
  virtual TableList *add_table_to_list(Session *session, Table_ident *table,
372
279
                                        LEX_STRING *alias,
373
280
                                        uint32_t table_options,
374
281
                                        thr_lock_type flags= TL_UNLOCK,
375
282
                                        List<Index_hint> *hints= 0,
376
283
                                        LEX_STRING *option= 0);
377
 
  virtual void set_lock_for_tables(thr_lock_type lock_type __attribute__((unused)))
 
284
  virtual void set_lock_for_tables(thr_lock_type)
378
285
  {}
379
286
 
380
 
  friend class st_select_lex_unit;
381
 
  friend bool mysql_new_select(struct st_lex *lex, bool move_down);
 
287
  friend class Select_Lex_Unit;
 
288
  friend bool mysql_new_select(LEX *lex, bool move_down);
382
289
private:
383
290
  void fast_exclude();
384
291
};
385
 
typedef class st_select_lex_node SELECT_LEX_NODE;
386
292
 
387
 
/* 
388
 
   SELECT_LEX_UNIT - unit of selects (UNION, INTERSECT, ...) group 
389
 
   SELECT_LEXs
 
293
/*
 
294
   Select_Lex_Unit - unit of selects (UNION, INTERSECT, ...) group
 
295
   Select_Lexs
390
296
*/
391
 
class THD;
 
297
class Session;
392
298
class select_result;
393
299
class JOIN;
394
300
class select_union;
395
 
class st_select_lex_unit: public st_select_lex_node {
 
301
class Select_Lex_Unit: public Select_Lex_Node {
396
302
protected:
397
 
  TABLE_LIST result_table_list;
 
303
  TableList result_table_list;
398
304
  select_union *union_result;
399
 
  TABLE *table; /* temporary table using for appending UNION results */
 
305
  Table *table; /* temporary table using for appending UNION results */
400
306
 
401
307
  select_result *result;
402
308
  uint64_t found_rows_for_union;
412
318
  List<Item> item_list;
413
319
  /*
414
320
    list of types of items inside union (used for union & derived tables)
415
 
    
 
321
 
416
322
    Item_type_holders from which this list consist may have pointers to Field,
417
323
    pointers is valid only after preparing SELECTS of this unit and before
418
324
    any SELECT of this unit execution
426
332
    Pointer to 'last' select or pointer to unit where stored
427
333
    global parameters for union
428
334
  */
429
 
  st_select_lex *global_parameters;
 
335
  Select_Lex *global_parameters;
430
336
  //node on wich we should return current_select pointer after parsing subquery
431
 
  st_select_lex *return_to;
 
337
  Select_Lex *return_to;
432
338
  /* LIMIT clause runtime counters */
433
339
  ha_rows select_limit_cnt, offset_limit_cnt;
434
340
  /* not NULL if unit used in subselect, point to subselect item */
435
341
  Item_subselect *item;
436
342
  /* thread handler */
437
 
  THD *thd;
 
343
  Session *session;
438
344
  /*
439
 
    SELECT_LEX for hidden SELECT in onion which process global
 
345
    Select_Lex for hidden SELECT in onion which process global
440
346
    ORDER BY and LIMIT
441
347
  */
442
 
  st_select_lex *fake_select_lex;
 
348
  Select_Lex *fake_select_lex;
443
349
 
444
 
  st_select_lex *union_distinct; /* pointer to the last UNION DISTINCT */
 
350
  Select_Lex *union_distinct; /* pointer to the last UNION DISTINCT */
445
351
  bool describe; /* union exec() called for EXPLAIN */
446
352
 
447
353
  void init_query();
448
 
  st_select_lex_unit* master_unit();
449
 
  st_select_lex* outer_select();
450
 
  st_select_lex* first_select()
451
 
  {
452
 
    return my_reinterpret_cast(st_select_lex*)(slave);
453
 
  }
454
 
  st_select_lex_unit* next_unit()
455
 
  {
456
 
    return my_reinterpret_cast(st_select_lex_unit*)(next);
457
 
  }
458
 
  st_select_lex* return_after_parsing() { return return_to; }
 
354
  Select_Lex_Unit* master_unit();
 
355
  Select_Lex* outer_select();
 
356
  Select_Lex* first_select()
 
357
  {
 
358
    return reinterpret_cast<Select_Lex*>(slave);
 
359
  }
 
360
  Select_Lex_Unit* next_unit()
 
361
  {
 
362
    return reinterpret_cast<Select_Lex_Unit*>(next);
 
363
  }
 
364
  Select_Lex* return_after_parsing() { return return_to; }
459
365
  void exclude_level();
460
366
  void exclude_tree();
461
367
 
462
368
  /* UNION methods */
463
 
  bool prepare(THD *thd, select_result *result, uint32_t additional_options);
 
369
  bool prepare(Session *session, select_result *result,
 
370
               uint64_t additional_options);
464
371
  bool exec();
465
372
  bool cleanup();
466
373
  inline void unclean() { cleaned= 0; }
468
375
 
469
376
  void print(String *str, enum_query_type query_type);
470
377
 
471
 
  bool add_fake_select_lex(THD *thd);
472
 
  void init_prepare_fake_select_lex(THD *thd);
 
378
  bool add_fake_select_lex(Session *session);
 
379
  void init_prepare_fake_select_lex(Session *session);
473
380
  bool change_result(select_result_interceptor *result,
474
381
                     select_result_interceptor *old_result);
475
 
  void set_limit(st_select_lex *values);
476
 
  void set_thd(THD *thd_arg) { thd= thd_arg; }
477
 
  inline bool is_union (); 
 
382
  void set_limit(Select_Lex *values);
 
383
  void set_session(Session *session_arg) { session= session_arg; }
 
384
  inline bool is_union ();
478
385
 
479
 
  friend void lex_start(THD *thd);
 
386
  friend void lex_start(Session *session);
480
387
  friend int subselect_union_engine::exec();
481
388
 
482
389
  List<Item> *get_unit_column_types();
483
390
};
484
391
 
485
 
typedef class st_select_lex_unit SELECT_LEX_UNIT;
486
 
 
487
392
/*
488
 
  SELECT_LEX - store information of parsed SELECT statment
 
393
  Select_Lex - store information of parsed SELECT statment
489
394
*/
490
 
class st_select_lex: public st_select_lex_node
 
395
class Select_Lex: public Select_Lex_Node
491
396
{
492
397
public:
493
398
  Name_resolution_context context;
494
399
  char *db;
495
 
  Item *where, *having;                         /* WHERE & HAVING clauses */
496
 
  Item *prep_where; /* saved WHERE clause for prepared statement processing */
497
 
  Item *prep_having;/* saved HAVING clause for prepared statement processing */
 
400
  /* An Item representing the WHERE clause */
 
401
  Item *where;
 
402
  /* An Item representing the HAVING clause */
 
403
  Item *having;
498
404
  /* Saved values of the WHERE and HAVING clauses*/
499
 
  Item::cond_result cond_value, having_value;
 
405
  Item::cond_result cond_value;
 
406
  Item::cond_result having_value;
500
407
  /* point on lex in which it was created, used in view subquery detection */
501
 
  st_lex *parent_lex;
 
408
  LEX *parent_lex;
502
409
  enum olap_type olap;
503
 
  /* FROM clause - points to the beginning of the TABLE_LIST::next_local list. */
504
 
  SQL_LIST            table_list;
505
 
  SQL_LIST            group_list; /* GROUP BY clause. */
506
 
  List<Item>          item_list;  /* list of fields & expressions */
507
 
  List<String>        interval_list;
508
 
  bool                is_item_list_lookup;
509
 
  /* 
510
 
    Despite their names, the following are used in unions. This should 
511
 
    be rewritten. -Brian
512
 
  */
513
 
  List<Item_real_func> *ftfunc_list;
514
 
  List<Item_real_func> ftfunc_list_alloc;
 
410
  /* FROM clause - points to the beginning of the TableList::next_local list. */
 
411
  SQL_LIST table_list;
 
412
  SQL_LIST group_list; /* GROUP BY clause. */
 
413
  List<Item> item_list;  /* list of fields & expressions */
 
414
  List<String> interval_list;
 
415
  bool is_item_list_lookup;
515
416
  JOIN *join; /* after JOIN::prepare it is pointer to corresponding JOIN */
516
 
  List<TABLE_LIST> top_join_list; /* join list of the top level          */
517
 
  List<TABLE_LIST> *join_list;    /* list for the currently parsed join  */
518
 
  TABLE_LIST *embedding;          /* table embedding to the above list   */
519
 
  List<TABLE_LIST> sj_nests;
 
417
  List<TableList> top_join_list; /* join list of the top level          */
 
418
  List<TableList> *join_list;    /* list for the currently parsed join  */
 
419
  TableList *embedding;          /* table embedding to the above list   */
 
420
  List<TableList> sj_nests;
520
421
  /*
521
422
    Beginning of the list of leaves in a FROM clause, where the leaves
522
423
    inlcude all base tables including view tables. The tables are connected
523
 
    by TABLE_LIST::next_leaf, so leaf_tables points to the left-most leaf.
 
424
    by TableList::next_leaf, so leaf_tables points to the left-most leaf.
524
425
  */
525
 
  TABLE_LIST *leaf_tables;
526
 
  const char *type;               /* type of select for EXPLAIN          */
 
426
  TableList *leaf_tables;
 
427
  std::string type; /* type of select for EXPLAIN          */
527
428
 
528
429
  SQL_LIST order_list;                /* ORDER clause */
529
430
  SQL_LIST *gorder_list;
530
431
  Item *select_limit, *offset_limit;  /* LIMIT clause parameters */
531
 
  // Arrays of pointers to top elements of all_fields list
 
432
  /* Arrays of pointers to top elements of all_fields list */
532
433
  Item **ref_pointer_array;
533
434
 
534
435
  /*
539
440
  uint32_t select_n_having_items;
540
441
  uint32_t cond_count;    /* number of arguments of and/or/xor in where/having/on */
541
442
  uint32_t between_count; /* number of between predicates in where/having/on      */
542
 
  uint32_t max_equal_elems; /* maximal number of elements in multiple equalities  */   
 
443
  uint32_t max_equal_elems; /* maximal number of elements in multiple equalities  */
543
444
  /*
544
445
    Number of fields used in select list or where clause of current select
545
446
    and all inner subselects.
547
448
  uint32_t select_n_where_fields;
548
449
  enum_parsing_place parsing_place; /* where we are parsing expression */
549
450
  bool with_sum_func;   /* sum function indicator */
550
 
  /* 
551
 
    PS or SP cond natural joins was alredy processed with permanent
552
 
    arena and all additional items which we need alredy stored in it
553
 
  */
554
 
  bool conds_processed_with_permanent_arena;
555
451
 
556
452
  uint32_t table_join_options;
557
453
  uint32_t in_sum_expr;
558
454
  uint32_t select_number; /* number of select (used for EXPLAIN) */
559
 
  int nest_level;     /* nesting level of select */
560
 
  Item_sum *inner_sum_func_list; /* list of sum func in nested selects */ 
 
455
  int8_t nest_level;     /* nesting level of select */
 
456
  Item_sum *inner_sum_func_list; /* list of sum func in nested selects */
561
457
  uint32_t with_wild; /* item list contain '*' */
562
 
  bool  braces;         /* SELECT ... UNION (SELECT ... ) <- this braces */
 
458
  bool braces;          /* SELECT ... UNION (SELECT ... ) <- this braces */
563
459
  /* true when having fix field called in processing of this SELECT */
564
460
  bool having_fix_field;
565
461
  /* List of references to fields referenced from inner selects */
578
474
  bool subquery_in_having;
579
475
  /* true <=> this SELECT is correlated w.r.t. some ancestor select */
580
476
  bool is_correlated;
581
 
  /*
582
 
    This variable is required to ensure proper work of subqueries and
583
 
    stored procedures. Generally, one should use the states of
584
 
    Query_arena to determine if it's a statement prepare or first
585
 
    execution of a stored procedure. However, in case when there was an
586
 
    error during the first execution of a stored procedure, the SP body
587
 
    is not expelled from the SP cache. Therefore, a deeply nested
588
 
    subquery might be left unoptimized. So we need this per-subquery
589
 
    variable to inidicate the optimization/execution state of every
590
 
    subquery. Prepared statements work OK in that regard, as in
591
 
    case of an error during prepare the PS is not created.
592
 
  */
593
 
  bool first_execution;
594
 
  bool first_cond_optimization;
595
477
  /* exclude this select from check of unique_table() */
596
478
  bool exclude_from_table_unique_test;
597
479
  /* List of fields that aren't under an aggregate function */
599
481
  /* index in the select list of the expression currently being fixed */
600
482
  int cur_pos_in_select_list;
601
483
 
602
 
  List<udf_func>     udf_list;                  /* udf function calls stack */
603
 
  /* 
 
484
  /*
604
485
    This is a copy of the original JOIN USING list that comes from
605
486
    the parser. The parser :
606
 
      1. Sets the natural_join of the second TABLE_LIST in the join
607
 
         and the st_select_lex::prev_join_using.
608
 
      2. Makes a parent TABLE_LIST and sets its is_natural_join/
 
487
      1. Sets the natural_join of the second TableList in the join
 
488
         and the Select_Lex::prev_join_using.
 
489
      2. Makes a parent TableList and sets its is_natural_join/
609
490
       join_using_fields members.
610
 
      3. Uses the wrapper TABLE_LIST as a table in the upper level.
 
491
      3. Uses the wrapper TableList as a table in the upper level.
611
492
    We cannot assign directly to join_using_fields in the parser because
612
 
    at stage (1.) the parent TABLE_LIST is not constructed yet and
 
493
    at stage (1.) the parent TableList is not constructed yet and
613
494
    the assignment will override the JOIN USING fields of the lower level
614
495
    joins on the right.
615
496
  */
623
504
      1 - aggregate functions are used in this select,
624
505
          defined as SUM_FUNC_USED.
625
506
  */
626
 
  uint8_t full_group_by_flag;
 
507
  std::bitset<2> full_group_by_flag;
627
508
  void init_query();
628
509
  void init_select();
629
 
  st_select_lex_unit* master_unit();
630
 
  st_select_lex_unit* first_inner_unit() 
631
 
  { 
632
 
    return (st_select_lex_unit*) slave; 
633
 
  }
634
 
  st_select_lex* outer_select();
635
 
  st_select_lex* next_select() { return (st_select_lex*) next; }
636
 
  st_select_lex* next_select_in_list() 
637
 
  {
638
 
    return (st_select_lex*) link_next;
639
 
  }
640
 
  st_select_lex_node** next_select_in_list_addr()
 
510
  Select_Lex_Unit* master_unit();
 
511
  Select_Lex_Unit* first_inner_unit()
 
512
  {
 
513
    return (Select_Lex_Unit*) slave;
 
514
  }
 
515
  Select_Lex* outer_select();
 
516
  Select_Lex* next_select()
 
517
  {
 
518
    return (Select_Lex*) next;
 
519
  }
 
520
  Select_Lex* next_select_in_list()
 
521
  {
 
522
    return (Select_Lex*) link_next;
 
523
  }
 
524
  Select_Lex_Node** next_select_in_list_addr()
641
525
  {
642
526
    return &link_next;
643
527
  }
644
 
  st_select_lex* return_after_parsing()
 
528
  Select_Lex* return_after_parsing()
645
529
  {
646
530
    return master_unit()->return_after_parsing();
647
531
  }
648
532
 
649
 
  void mark_as_dependent(st_select_lex *last);
 
533
  void mark_as_dependent(Select_Lex *last);
650
534
 
651
535
  bool set_braces(bool value);
652
536
  bool inc_in_sum_expr();
653
537
  uint32_t get_in_sum_expr();
654
538
 
655
 
  bool add_item_to_list(THD *thd, Item *item);
656
 
  bool add_group_to_list(THD *thd, Item *item, bool asc);
657
 
  bool add_order_to_list(THD *thd, Item *item, bool asc);
658
 
  TABLE_LIST* add_table_to_list(THD *thd, Table_ident *table,
659
 
                                LEX_STRING *alias,
660
 
                                uint32_t table_options,
661
 
                                thr_lock_type flags= TL_UNLOCK,
662
 
                                List<Index_hint> *hints= 0,
663
 
                                LEX_STRING *option= 0);
664
 
  TABLE_LIST* get_table_list();
665
 
  bool init_nested_join(THD *thd);
666
 
  TABLE_LIST *end_nested_join(THD *thd);
667
 
  TABLE_LIST *nest_last_join(THD *thd);
668
 
  void add_joined_table(TABLE_LIST *table);
669
 
  TABLE_LIST *convert_right_join();
 
539
  bool add_item_to_list(Session *session, Item *item);
 
540
  bool add_group_to_list(Session *session, Item *item, bool asc);
 
541
  bool add_order_to_list(Session *session, Item *item, bool asc);
 
542
  TableList* add_table_to_list(Session *session,
 
543
                               Table_ident *table,
 
544
                               LEX_STRING *alias,
 
545
                               uint32_t table_options,
 
546
                               thr_lock_type flags= TL_UNLOCK,
 
547
                               List<Index_hint> *hints= 0,
 
548
                               LEX_STRING *option= 0);
 
549
  TableList* get_table_list();
 
550
  bool init_nested_join(Session *session);
 
551
  TableList *end_nested_join(Session *session);
 
552
  TableList *nest_last_join(Session *session);
 
553
  void add_joined_table(TableList *table);
 
554
  TableList *convert_right_join();
670
555
  List<Item>* get_item_list();
671
556
  uint32_t get_table_join_options();
672
557
  void set_lock_for_tables(thr_lock_type lock_type);
674
559
  {
675
560
    order_list.elements= 0;
676
561
    order_list.first= 0;
677
 
    order_list.next= (uchar**) &order_list.first;
 
562
    order_list.next= (unsigned char**) &order_list.first;
678
563
  }
679
564
  /*
680
565
    This method created for reiniting LEX in mysql_admin_table() and can be
681
 
    used only if you are going remove all SELECT_LEX & units except belonger
 
566
    used only if you are going remove all Select_Lex & units except belonger
682
567
    to LEX (LEX::unit & LEX::select, for other purposes there are
683
 
    SELECT_LEX_UNIT::exclude_level & SELECT_LEX_UNIT::exclude_tree
 
568
    Select_Lex_Unit::exclude_level & Select_Lex_Unit::exclude_tree
684
569
  */
685
 
  void cut_subtree() { slave= 0; }
 
570
  void cut_subtree()
 
571
  {
 
572
    slave= 0;
 
573
  }
686
574
  bool test_limit();
687
575
 
688
 
  friend void lex_start(THD *thd);
689
 
  st_select_lex() : n_sum_items(0), n_child_sum_items(0) {}
 
576
  friend void lex_start(Session *session);
 
577
  Select_Lex() : n_sum_items(0), n_child_sum_items(0) {}
690
578
  void make_empty_select()
691
579
  {
692
580
    init_query();
693
581
    init_select();
694
582
  }
695
 
  bool setup_ref_array(THD *thd, uint32_t order_group_num);
696
 
  void print(THD *thd, String *str, enum_query_type query_type);
 
583
  bool setup_ref_array(Session *session, uint32_t order_group_num);
 
584
  void print(Session *session, String *str, enum_query_type query_type);
697
585
  static void print_order(String *str,
698
 
                          ORDER *order,
 
586
                          order_st *order,
699
587
                          enum_query_type query_type);
700
 
  void print_limit(THD *thd, String *str, enum_query_type query_type);
701
 
  void fix_prepare_information(THD *thd, Item **conds, Item **having_conds);
 
588
  void print_limit(Session *session, String *str, enum_query_type query_type);
 
589
  void fix_prepare_information(Session *session, Item **conds, Item **having_conds);
702
590
  /*
703
591
    Destroy the used execution plan (JOIN) of this subtree (this
704
 
    SELECT_LEX and all nested SELECT_LEXes and SELECT_LEX_UNITs).
 
592
    Select_Lex and all nested Select_Lexes and Select_Lex_Units).
705
593
  */
706
594
  bool cleanup();
707
595
  /*
712
600
 
713
601
  void set_index_hint_type(enum index_hint_type type, index_clause_map clause);
714
602
 
715
 
  /* 
 
603
  /*
716
604
   Add a index hint to the tagged list of hints. The type and clause of the
717
 
   hint will be the current ones (set by set_index_hint()) 
 
605
   hint will be the current ones (set by set_index_hint())
718
606
  */
719
 
  bool add_index_hint (THD *thd, char *str, uint32_t length);
 
607
  bool add_index_hint (Session *session, char *str, uint32_t length);
720
608
 
721
609
  /* make a list to hold index hints */
722
 
  void alloc_index_hints (THD *thd);
 
610
  void alloc_index_hints (Session *session);
723
611
  /* read and clear the index hints */
724
 
  List<Index_hint>* pop_index_hints(void) 
 
612
  List<Index_hint>* pop_index_hints(void)
725
613
  {
726
614
    List<Index_hint> *hints= index_hints;
727
615
    index_hints= NULL;
730
618
 
731
619
  void clear_index_hints(void) { index_hints= NULL; }
732
620
 
733
 
private:  
 
621
private:
734
622
  /* current index hint kind. used in filling up index_hints */
735
623
  enum index_hint_type current_index_hint_type;
736
624
  index_clause_map current_index_hint_clause;
737
625
  /* a list of USE/FORCE/IGNORE INDEX */
738
626
  List<Index_hint> *index_hints;
739
627
};
740
 
typedef class st_select_lex SELECT_LEX;
741
628
 
742
 
inline bool st_select_lex_unit::is_union ()
743
 
744
 
  return first_select()->next_select() && 
 
629
inline bool Select_Lex_Unit::is_union ()
 
630
{
 
631
  return first_select()->next_select() &&
745
632
    first_select()->next_select()->linkage == UNION_TYPE;
746
633
}
747
634
 
748
 
#define ALTER_ADD_COLUMN        (1L << 0)
749
 
#define ALTER_DROP_COLUMN       (1L << 1)
750
 
#define ALTER_CHANGE_COLUMN     (1L << 2)
751
 
#define ALTER_COLUMN_STORAGE    (1L << 3)
752
 
#define ALTER_COLUMN_FORMAT     (1L << 4)
753
 
#define ALTER_COLUMN_ORDER      (1L << 5)
754
 
#define ALTER_ADD_INDEX         (1L << 6)
755
 
#define ALTER_DROP_INDEX        (1L << 7)
756
 
#define ALTER_RENAME            (1L << 8)
757
 
#define ALTER_ORDER             (1L << 9)
758
 
#define ALTER_OPTIONS           (1L << 10)
759
 
#define ALTER_COLUMN_DEFAULT    (1L << 11)
760
 
#define ALTER_KEYS_ONOFF        (1L << 12)
761
 
#define ALTER_STORAGE           (1L << 13)
762
 
#define ALTER_ROW_FORMAT        (1L << 14)
763
 
#define ALTER_CONVERT           (1L << 15)
764
 
#define ALTER_FORCE             (1L << 16)
765
 
#define ALTER_RECREATE          (1L << 17)
766
 
#define ALTER_TABLE_REORG        (1L << 24)
767
 
#define ALTER_FOREIGN_KEY         (1L << 31)
768
 
 
769
 
/**
770
 
  @brief Parsing data for CREATE or ALTER TABLE.
771
 
 
772
 
  This structure contains a list of columns or indexes to be created,
773
 
  altered or dropped.
774
 
*/
775
 
 
776
 
class Alter_info
 
635
enum xa_option_words
777
636
{
778
 
public:
779
 
  List<Alter_drop>              drop_list;
780
 
  List<Alter_column>            alter_list;
781
 
  List<Key>                     key_list;
782
 
  List<Create_field>            create_list;
783
 
  uint32_t                          flags;
784
 
  enum enum_enable_or_disable   keys_onoff;
785
 
  enum tablespace_op_type       tablespace_op;
786
 
  uint32_t                          no_parts;
787
 
  enum ha_build_method          build_method;
788
 
  Create_field                 *datetime_field;
789
 
  bool                          error_if_not_empty;
790
 
 
791
 
 
792
 
  Alter_info() :
793
 
    flags(0),
794
 
    keys_onoff(LEAVE_AS_IS),
795
 
    tablespace_op(NO_TABLESPACE_OP),
796
 
    no_parts(0),
797
 
    build_method(HA_BUILD_DEFAULT),
798
 
    datetime_field(NULL),
799
 
    error_if_not_empty(false)
800
 
  {}
801
 
 
802
 
  void reset()
803
 
  {
804
 
    drop_list.empty();
805
 
    alter_list.empty();
806
 
    key_list.empty();
807
 
    create_list.empty();
808
 
    flags= 0;
809
 
    keys_onoff= LEAVE_AS_IS;
810
 
    tablespace_op= NO_TABLESPACE_OP;
811
 
    no_parts= 0;
812
 
    build_method= HA_BUILD_DEFAULT;
813
 
    datetime_field= 0;
814
 
    error_if_not_empty= false;
815
 
  }
816
 
  Alter_info(const Alter_info &rhs, MEM_ROOT *mem_root);
817
 
private:
818
 
  Alter_info &operator=(const Alter_info &rhs); // not implemented
819
 
  Alter_info(const Alter_info &rhs);            // not implemented
 
637
  XA_NONE
 
638
, XA_JOIN
 
639
, XA_RESUME
 
640
, XA_ONE_PHASE
 
641
, XA_SUSPEND
 
642
, XA_FOR_MIGRATE
820
643
};
821
644
 
822
 
enum xa_option_words {XA_NONE, XA_JOIN, XA_RESUME, XA_ONE_PHASE,
823
 
                      XA_SUSPEND, XA_FOR_MIGRATE};
824
 
 
825
645
extern const LEX_STRING null_lex_str;
826
646
 
827
 
 
828
647
/*
829
648
  Class representing list of all tables used by statement.
830
649
  It also contains information about stored functions used by statement
835
654
  Also used by st_lex::reset_n_backup/restore_backup_query_tables_list()
836
655
  methods to save and restore this information.
837
656
*/
838
 
 
839
657
class Query_tables_list
840
658
{
841
659
public:
842
660
  /* Global list of all tables used by this statement */
843
 
  TABLE_LIST *query_tables;
 
661
  TableList *query_tables;
844
662
  /* Pointer to next_global member of last element in the previous list. */
845
 
  TABLE_LIST **query_tables_last;
 
663
  TableList **query_tables_last;
846
664
  /*
847
665
    If non-0 then indicates that query requires prelocking and points to
848
666
    next_global member of last own element in query table list (i.e. last
849
667
    table which was not added to it as part of preparation to prelocking).
850
668
    0 - indicates that this query does not need prelocking.
851
669
  */
852
 
  TABLE_LIST **query_tables_own_last;
853
 
  /*
854
 
    Set of stored routines called by statement.
855
 
    (Note that we use lazy-initialization for this hash).
856
 
  */
857
 
  enum { START_SROUTINES_HASH_SIZE= 16 };
858
 
  HASH sroutines;
859
 
  /*
860
 
    List linking elements of 'sroutines' set. Allows you to add new elements
861
 
    to this set as you iterate through the list of existing elements.
862
 
    'sroutines_list_own_last' is pointer to ::next member of last element of
863
 
    this list which represents routine which is explicitly used by query.
864
 
    'sroutines_list_own_elements' number of explicitly used routines.
865
 
    We use these two members for restoring of 'sroutines_list' to the state
866
 
    in which it was right after query parsing.
867
 
  */
868
 
  SQL_LIST sroutines_list;
869
 
  uchar    **sroutines_list_own_last;
870
 
  uint32_t     sroutines_list_own_elements;
 
670
  TableList **query_tables_own_last;
871
671
 
872
672
  /*
873
673
    These constructor and destructor serve for creation/destruction
874
674
    of Query_tables_list instances which are used as backup storage.
875
675
  */
876
676
  Query_tables_list() {}
877
 
  ~Query_tables_list() {}
 
677
  virtual ~Query_tables_list() {}
878
678
 
879
679
  /* Initializes (or resets) Query_tables_list object for "real" use. */
880
680
  void reset_query_tables_list(bool init);
881
 
  void destroy_query_tables_list();
882
 
  void set_query_tables_list(Query_tables_list *state)
883
 
  {
884
 
    *this= *state;
885
 
  }
886
681
 
887
682
  /*
888
683
    Direct addition to the list of query tables.
889
684
    If you are using this function, you must ensure that the table
890
685
    object, in particular table->db member, is initialized.
891
686
  */
892
 
  void add_to_query_tables(TABLE_LIST *table)
 
687
  void add_to_query_tables(TableList *table)
893
688
  {
894
689
    *(table->prev_global= query_tables_last)= table;
895
690
    query_tables_last= &table->next_global;
896
691
  }
897
692
  /* Return pointer to first not-own table in query-tables or 0 */
898
 
  TABLE_LIST* first_not_own_table()
 
693
  TableList* first_not_own_table()
899
694
  {
900
695
    return ( query_tables_own_last ? *query_tables_own_last : 0);
901
696
  }
908
703
      query_tables_own_last= 0;
909
704
    }
910
705
  }
911
 
 
912
 
  /**
913
 
     Has the parser/scanner detected that this statement is unsafe?
914
 
   */
915
 
  inline bool is_stmt_unsafe() const {
916
 
    return binlog_stmt_flags & (1U << BINLOG_STMT_FLAG_UNSAFE);
917
 
  }
918
 
 
919
 
  /**
920
 
     Flag the current (top-level) statement as unsafe.
921
 
 
922
 
     The flag will be reset after the statement has finished.
923
 
 
924
 
   */
925
 
  inline void set_stmt_unsafe() {
926
 
    binlog_stmt_flags|= (1U << BINLOG_STMT_FLAG_UNSAFE);
927
 
  }
928
 
 
929
 
  inline void clear_stmt_unsafe() {
930
 
    binlog_stmt_flags&= ~(1U << BINLOG_STMT_FLAG_UNSAFE);
931
 
  }
932
 
 
933
 
  /**
934
 
    true if the parsed tree contains references to stored procedures
935
 
    or functions, false otherwise
936
 
  */
937
 
  bool uses_stored_routines() const
938
 
  { return sroutines_list.elements != 0; }
939
 
 
940
 
private:
941
 
  enum enum_binlog_stmt_flag {
942
 
    BINLOG_STMT_FLAG_UNSAFE,
943
 
    BINLOG_STMT_FLAG_COUNT
944
 
  };
945
 
 
946
 
  /*
947
 
    Tells if the parsing stage detected properties of the statement,
948
 
    for example: that some items require row-based binlogging to give
949
 
    a reliable binlog/replication, or if we will use stored functions
950
 
    or triggers which themselves need require row-based binlogging.
951
 
  */
952
 
  uint32_t binlog_stmt_flags;
953
 
};
954
 
 
955
 
 
956
 
/*
957
 
  st_parsing_options contains the flags for constructions that are
958
 
  allowed in the current statement.
959
 
*/
960
 
 
961
 
struct st_parsing_options
962
 
{
963
 
  bool allows_variable;
964
 
  bool allows_select_into;
965
 
  bool allows_select_procedure;
966
 
  bool allows_derived;
967
 
 
968
 
  st_parsing_options() { reset(); }
969
 
  void reset();
970
 
};
971
 
 
 
706
};
972
707
 
973
708
/**
974
709
  The state of the lexical parser, when parsing comments.
993
728
  DISCARD_COMMENT
994
729
};
995
730
 
996
 
 
997
 
/**
998
 
  @brief This class represents the character input stream consumed during
999
 
  lexical analysis.
1000
 
 
1001
 
  In addition to consuming the input stream, this class performs some
1002
 
  comment pre processing, by filtering out out of bound special text
1003
 
  from the query input stream.
1004
 
  Two buffers, with pointers inside each buffers, are maintained in
1005
 
  parallel. The 'raw' buffer is the original query text, which may
1006
 
  contain out-of-bound comments. The 'cpp' (for comments pre processor)
1007
 
  is the pre-processed buffer that contains only the query text that
1008
 
  should be seen once out-of-bound data is removed.
1009
 
*/
1010
 
 
1011
 
class Lex_input_stream
1012
 
{
1013
 
public:
1014
 
  Lex_input_stream(THD *thd, const char* buff, unsigned int length);
1015
 
  ~Lex_input_stream();
1016
 
 
1017
 
  /**
1018
 
    Set the echo mode.
1019
 
 
1020
 
    When echo is true, characters parsed from the raw input stream are
1021
 
    preserved. When false, characters parsed are silently ignored.
1022
 
    @param echo the echo mode.
1023
 
  */
1024
 
  void set_echo(bool echo)
1025
 
  {
1026
 
    m_echo= echo;
1027
 
  }
1028
 
 
1029
 
  /**
1030
 
    Skip binary from the input stream.
1031
 
    @param n number of bytes to accept.
1032
 
  */
1033
 
  void skip_binary(int n)
1034
 
  {
1035
 
    if (m_echo)
1036
 
    {
1037
 
      memcpy(m_cpp_ptr, m_ptr, n);
1038
 
      m_cpp_ptr += n;
1039
 
    }
1040
 
    m_ptr += n;
1041
 
  }
1042
 
 
1043
 
  /**
1044
 
    Get a character, and advance in the stream.
1045
 
    @return the next character to parse.
1046
 
  */
1047
 
  char yyGet()
1048
 
  {
1049
 
    char c= *m_ptr++;
1050
 
    if (m_echo)
1051
 
      *m_cpp_ptr++ = c;
1052
 
    return c;
1053
 
  }
1054
 
 
1055
 
  /**
1056
 
    Get the last character accepted.
1057
 
    @return the last character accepted.
1058
 
  */
1059
 
  char yyGetLast()
1060
 
  {
1061
 
    return m_ptr[-1];
1062
 
  }
1063
 
 
1064
 
  /**
1065
 
    Look at the next character to parse, but do not accept it.
1066
 
  */
1067
 
  char yyPeek()
1068
 
  {
1069
 
    return m_ptr[0];
1070
 
  }
1071
 
 
1072
 
  /**
1073
 
    Look ahead at some character to parse.
1074
 
    @param n offset of the character to look up
1075
 
  */
1076
 
  char yyPeekn(int n)
1077
 
  {
1078
 
    return m_ptr[n];
1079
 
  }
1080
 
 
1081
 
  /**
1082
 
    Cancel the effect of the last yyGet() or yySkip().
1083
 
    Note that the echo mode should not change between calls to yyGet / yySkip
1084
 
    and yyUnget. The caller is responsible for ensuring that.
1085
 
  */
1086
 
  void yyUnget()
1087
 
  {
1088
 
    m_ptr--;
1089
 
    if (m_echo)
1090
 
      m_cpp_ptr--;
1091
 
  }
1092
 
 
1093
 
  /**
1094
 
    Accept a character, by advancing the input stream.
1095
 
  */
1096
 
  void yySkip()
1097
 
  {
1098
 
    if (m_echo)
1099
 
      *m_cpp_ptr++ = *m_ptr++;
1100
 
    else
1101
 
      m_ptr++;
1102
 
  }
1103
 
 
1104
 
  /**
1105
 
    Accept multiple characters at once.
1106
 
    @param n the number of characters to accept.
1107
 
  */
1108
 
  void yySkipn(int n)
1109
 
  {
1110
 
    if (m_echo)
1111
 
    {
1112
 
      memcpy(m_cpp_ptr, m_ptr, n);
1113
 
      m_cpp_ptr += n;
1114
 
    }
1115
 
    m_ptr += n;
1116
 
  }
1117
 
 
1118
 
  /**
1119
 
    End of file indicator for the query text to parse.
1120
 
    @return true if there are no more characters to parse
1121
 
  */
1122
 
  bool eof()
1123
 
  {
1124
 
    return (m_ptr >= m_end_of_query);
1125
 
  }
1126
 
 
1127
 
  /**
1128
 
    End of file indicator for the query text to parse.
1129
 
    @param n number of characters expected
1130
 
    @return true if there are less than n characters to parse
1131
 
  */
1132
 
  bool eof(int n)
1133
 
  {
1134
 
    return ((m_ptr + n) >= m_end_of_query);
1135
 
  }
1136
 
 
1137
 
  /** Get the raw query buffer. */
1138
 
  const char *get_buf()
1139
 
  {
1140
 
    return m_buf;
1141
 
  }
1142
 
 
1143
 
  /** Get the pre-processed query buffer. */
1144
 
  const char *get_cpp_buf()
1145
 
  {
1146
 
    return m_cpp_buf;
1147
 
  }
1148
 
 
1149
 
  /** Get the end of the raw query buffer. */
1150
 
  const char *get_end_of_query()
1151
 
  {
1152
 
    return m_end_of_query;
1153
 
  }
1154
 
 
1155
 
  /** Mark the stream position as the start of a new token. */
1156
 
  void start_token()
1157
 
  {
1158
 
    m_tok_start_prev= m_tok_start;
1159
 
    m_tok_start= m_ptr;
1160
 
    m_tok_end= m_ptr;
1161
 
 
1162
 
    m_cpp_tok_start_prev= m_cpp_tok_start;
1163
 
    m_cpp_tok_start= m_cpp_ptr;
1164
 
    m_cpp_tok_end= m_cpp_ptr;
1165
 
  }
1166
 
 
1167
 
  /**
1168
 
    Adjust the starting position of the current token.
1169
 
    This is used to compensate for starting whitespace.
1170
 
  */
1171
 
  void restart_token()
1172
 
  {
1173
 
    m_tok_start= m_ptr;
1174
 
    m_cpp_tok_start= m_cpp_ptr;
1175
 
  }
1176
 
 
1177
 
  /** Get the token start position, in the raw buffer. */
1178
 
  const char *get_tok_start()
1179
 
  {
1180
 
    return m_tok_start;
1181
 
  }
1182
 
 
1183
 
  /** Get the token start position, in the pre-processed buffer. */
1184
 
  const char *get_cpp_tok_start()
1185
 
  {
1186
 
    return m_cpp_tok_start;
1187
 
  }
1188
 
 
1189
 
  /** Get the token end position, in the raw buffer. */
1190
 
  const char *get_tok_end()
1191
 
  {
1192
 
    return m_tok_end;
1193
 
  }
1194
 
 
1195
 
  /** Get the token end position, in the pre-processed buffer. */
1196
 
  const char *get_cpp_tok_end()
1197
 
  {
1198
 
    return m_cpp_tok_end;
1199
 
  }
1200
 
 
1201
 
  /** Get the previous token start position, in the raw buffer. */
1202
 
  const char *get_tok_start_prev()
1203
 
  {
1204
 
    return m_tok_start_prev;
1205
 
  }
1206
 
 
1207
 
  /** Get the current stream pointer, in the raw buffer. */
1208
 
  const char *get_ptr()
1209
 
  {
1210
 
    return m_ptr;
1211
 
  }
1212
 
 
1213
 
  /** Get the current stream pointer, in the pre-processed buffer. */
1214
 
  const char *get_cpp_ptr()
1215
 
  {
1216
 
    return m_cpp_ptr;
1217
 
  }
1218
 
 
1219
 
  /** Get the length of the current token, in the raw buffer. */
1220
 
  uint32_t yyLength()
1221
 
  {
1222
 
    /*
1223
 
      The assumption is that the lexical analyser is always 1 character ahead,
1224
 
      which the -1 account for.
1225
 
    */
1226
 
    assert(m_ptr > m_tok_start);
1227
 
    return (uint32_t) ((m_ptr - m_tok_start) - 1);
1228
 
  }
1229
 
 
1230
 
  /** Get the utf8-body string. */
1231
 
  const char *get_body_utf8_str()
1232
 
  {
1233
 
    return m_body_utf8;
1234
 
  }
1235
 
 
1236
 
  /** Get the utf8-body length. */
1237
 
  uint32_t get_body_utf8_length()
1238
 
  {
1239
 
    return m_body_utf8_ptr - m_body_utf8;
1240
 
  }
1241
 
 
1242
 
  void body_utf8_start(THD *thd, const char *begin_ptr);
1243
 
  void body_utf8_append(const char *ptr);
1244
 
  void body_utf8_append(const char *ptr, const char *end_ptr);
1245
 
  void body_utf8_append_literal(THD *thd,
1246
 
                                const LEX_STRING *txt,
1247
 
                                const CHARSET_INFO * const txt_cs,
1248
 
                                const char *end_ptr);
1249
 
 
1250
 
  /** Current thread. */
1251
 
  THD *m_thd;
1252
 
 
1253
 
  /** Current line number. */
1254
 
  uint32_t yylineno;
1255
 
 
1256
 
  /** Length of the last token parsed. */
1257
 
  uint32_t yytoklen;
1258
 
 
1259
 
  /** Interface with bison, value of the last token parsed. */
1260
 
  LEX_YYSTYPE yylval;
1261
 
 
1262
 
  /** LALR(2) resolution, look ahead token.*/
1263
 
  int lookahead_token;
1264
 
 
1265
 
  /** LALR(2) resolution, value of the look ahead token.*/
1266
 
  LEX_YYSTYPE lookahead_yylval;
1267
 
 
1268
 
private:
1269
 
  /** Pointer to the current position in the raw input stream. */
1270
 
  const char *m_ptr;
1271
 
 
1272
 
  /** Starting position of the last token parsed, in the raw buffer. */
1273
 
  const char *m_tok_start;
1274
 
 
1275
 
  /** Ending position of the previous token parsed, in the raw buffer. */
1276
 
  const char *m_tok_end;
1277
 
 
1278
 
  /** End of the query text in the input stream, in the raw buffer. */
1279
 
  const char *m_end_of_query;
1280
 
 
1281
 
  /** Starting position of the previous token parsed, in the raw buffer. */
1282
 
  const char *m_tok_start_prev;
1283
 
 
1284
 
  /** Begining of the query text in the input stream, in the raw buffer. */
1285
 
  const char *m_buf;
1286
 
 
1287
 
  /** Length of the raw buffer. */
1288
 
  uint32_t m_buf_length;
1289
 
 
1290
 
  /** Echo the parsed stream to the pre-processed buffer. */
1291
 
  bool m_echo;
1292
 
 
1293
 
  /** Pre-processed buffer. */
1294
 
  char *m_cpp_buf;
1295
 
 
1296
 
  /** Pointer to the current position in the pre-processed input stream. */
1297
 
  char *m_cpp_ptr;
1298
 
 
1299
 
  /**
1300
 
    Starting position of the last token parsed,
1301
 
    in the pre-processed buffer.
1302
 
  */
1303
 
  const char *m_cpp_tok_start;
1304
 
 
1305
 
  /**
1306
 
    Starting position of the previous token parsed,
1307
 
    in the pre-procedded buffer.
1308
 
  */
1309
 
  const char *m_cpp_tok_start_prev;
1310
 
 
1311
 
  /**
1312
 
    Ending position of the previous token parsed,
1313
 
    in the pre-processed buffer.
1314
 
  */
1315
 
  const char *m_cpp_tok_end;
1316
 
 
1317
 
  /** UTF8-body buffer created during parsing. */
1318
 
  char *m_body_utf8;
1319
 
 
1320
 
  /** Pointer to the current position in the UTF8-body buffer. */
1321
 
  char *m_body_utf8_ptr;
1322
 
 
1323
 
  /**
1324
 
    Position in the pre-processed buffer. The query from m_cpp_buf to
1325
 
    m_cpp_utf_processed_ptr is converted to UTF8-body.
1326
 
  */
1327
 
  const char *m_cpp_utf8_processed_ptr;
1328
 
 
1329
 
public:
1330
 
 
1331
 
  /** Current state of the lexical analyser. */
1332
 
  enum my_lex_states next_state;
1333
 
 
1334
 
  /**
1335
 
    Position of ';' in the stream, to delimit multiple queries.
1336
 
    This delimiter is in the raw buffer.
1337
 
  */
1338
 
  const char *found_semicolon;
1339
 
 
1340
 
  /** Token character bitmaps, to detect 7bit strings. */
1341
 
  uchar tok_bitmap;
1342
 
 
1343
 
  /** SQL_MODE = IGNORE_SPACE. */
1344
 
  bool ignore_space;
1345
 
 
1346
 
  /** State of the lexical analyser for comments. */
1347
 
  enum_comment_state in_comment;
1348
 
 
1349
 
  /**
1350
 
    Starting position of the TEXT_STRING or IDENT in the pre-processed
1351
 
    buffer.
1352
 
 
1353
 
    NOTE: this member must be used within MYSQLlex() function only.
1354
 
  */
1355
 
  const char *m_cpp_text_start;
1356
 
 
1357
 
  /**
1358
 
    Ending position of the TEXT_STRING or IDENT in the pre-processed
1359
 
    buffer.
1360
 
 
1361
 
    NOTE: this member must be used within MYSQLlex() function only.
1362
 
    */
1363
 
  const char *m_cpp_text_end;
1364
 
 
1365
 
  /**
1366
 
    Character set specified by the character-set-introducer.
1367
 
 
1368
 
    NOTE: this member must be used within MYSQLlex() function only.
1369
 
  */
1370
 
  const CHARSET_INFO *m_underscore_cs;
1371
 
};
1372
 
 
1373
 
 
1374
 
/* The state of the lex parsing. This is saved in the THD struct */
1375
 
 
1376
 
typedef struct st_lex : public Query_tables_list
1377
 
{
1378
 
  SELECT_LEX_UNIT unit;                         /* most upper unit */
1379
 
  SELECT_LEX select_lex;                        /* first SELECT_LEX */
1380
 
  /* current SELECT_LEX in parsing */
1381
 
  SELECT_LEX *current_select;
1382
 
  /* list of all SELECT_LEX */
1383
 
  SELECT_LEX *all_selects_list;
1384
 
 
1385
 
  char *length,*dec,*change;
 
731
#include "drizzled/lex_input_stream.h"
 
732
 
 
733
/* The state of the lex parsing. This is saved in the Session struct */
 
734
class LEX : public Query_tables_list
 
735
{
 
736
public:
 
737
  Select_Lex_Unit unit;                         /* most upper unit */
 
738
  Select_Lex select_lex;                        /* first Select_Lex */
 
739
  /* current Select_Lex in parsing */
 
740
  Select_Lex *current_select;
 
741
  /* list of all Select_Lex */
 
742
  Select_Lex *all_selects_list;
 
743
 
 
744
  /* This is the "scale" for DECIMAL (S,P) notation */ 
 
745
  char *length;
 
746
  /* This is the decimal precision in DECIMAL(S,P) notation */
 
747
  char *dec;
 
748
  
 
749
  /**
 
750
   * This is used kind of like the "ident" member variable below, as 
 
751
   * a place to store certain names of identifiers.  Unfortunately, it
 
752
   * is used differently depending on the Command (SELECT on a derived
 
753
   * table vs CREATE)
 
754
   */
1386
755
  LEX_STRING name;
1387
 
  char *help_arg;
1388
 
  char* to_log;                                 /* For PURGE MASTER LOGS TO */
1389
 
  char* x509_subject,*x509_issuer,*ssl_cipher;
 
756
  /* The string literal used in a LIKE expression */
1390
757
  String *wild;
1391
 
  sql_exchange *exchange;
 
758
  file_exchange *exchange;
1392
759
  select_result *result;
1393
 
  Item *default_value, *on_update_value;
1394
 
  LEX_STRING comment, ident;
1395
 
  XID *xid;
1396
 
  uchar* yacc_yyss, *yacc_yyvs;
1397
 
  THD *thd;
1398
 
 
1399
 
  /* maintain a list of used plugins for this LEX */
1400
 
  DYNAMIC_ARRAY plugins;
1401
 
  plugin_ref plugins_static_buffer[INITIAL_LEX_PLUGIN_LIST_SIZE];
1402
 
 
 
760
 
 
761
  /**
 
762
   * This is current used to store the name of a named key cache
 
763
   * or a named savepoint.  It should probably be refactored out into
 
764
   * the eventual Command class built for the Keycache and Savepoint
 
765
   * commands.
 
766
   */ 
 
767
  LEX_STRING ident;
 
768
 
 
769
  unsigned char* yacc_yyss, *yacc_yyvs;
 
770
  /* The owning Session of this LEX */
 
771
  Session *session;
1403
772
  const CHARSET_INFO *charset;
1404
773
  bool text_string_is_7bit;
1405
774
  /* store original leaf_tables for INSERT SELECT and PS/SP */
1406
 
  TABLE_LIST *leaf_tables_insert;
 
775
  TableList *leaf_tables_insert;
1407
776
 
1408
777
  List<Key_part_spec> col_list;
1409
778
  List<Key_part_spec> ref_list;
1410
779
  List<String>        interval_list;
1411
 
  List<LEX_COLUMN>    columns;
 
780
  List<Lex_Column>    columns;
1412
781
  List<Item>          *insert_list,field_list,value_list,update_list;
1413
782
  List<List_item>     many_values;
1414
783
  List<set_var_base>  var_list;
1415
 
  List<Item_param>    param_list;
1416
784
  /*
1417
785
    A stack of name resolution contexts for the query. This stack is used
1418
786
    at parse time to set local name resolution contexts for various parts
1427
795
    required a local context, the parser pops the top-most context.
1428
796
  */
1429
797
  List<Name_resolution_context> context_stack;
1430
 
  List<LEX_STRING>     db_list;
1431
798
 
1432
 
  SQL_LIST            proc_list, auxiliary_table_list, save_list;
1433
 
  Create_field        *last_field;
 
799
  SQL_LIST auxiliary_table_list;
 
800
  SQL_LIST save_list;
 
801
  CreateField *last_field;
1434
802
  Item_sum *in_sum_func;
1435
 
  udf_func udf;
1436
 
  HA_CHECK_OPT   check_opt;                     // check/repair options
1437
 
  HA_CREATE_INFO create_info;
1438
 
  KEY_CREATE_INFO key_create_info;
1439
 
  LEX_MASTER_INFO mi;                           // used by CHANGE MASTER
1440
 
  LEX_SERVER_OPTIONS server_options;
 
803
  drizzled::plugin::Function *udf;
1441
804
  uint32_t type;
1442
805
  /*
1443
806
    This variable is used in post-parse stage to declare that sum-functions,
1450
813
  */
1451
814
  nesting_map allow_sum_func;
1452
815
  enum_sql_command sql_command;
 
816
  drizzled::statement::Statement *statement;
1453
817
  /*
1454
818
    Usually `expr` rule of yacc is quite reused but some commands better
1455
819
    not support subqueries which comes standard with this rule, like
1460
824
 
1461
825
  thr_lock_type lock_option;
1462
826
  enum enum_duplicates duplicates;
1463
 
  enum enum_tx_isolation tx_isolation;
1464
 
  enum enum_ha_read_modes ha_read_mode;
1465
827
  union {
1466
828
    enum ha_rkey_function ha_rkey_mode;
1467
829
    enum xa_option_words xa_opt;
1468
 
    bool lock_transactional;            /* For LOCK TABLE ... IN ... MODE */
1469
830
  };
1470
831
  enum enum_var_type option_type;
1471
832
 
1472
 
  uint32_t profile_query_id;
1473
 
  uint32_t profile_options;
1474
 
  enum column_format_type column_format;
1475
 
  uint32_t which_columns;
1476
 
  enum Foreign_key::fk_match_opt fk_match_option;
1477
 
  enum Foreign_key::fk_option fk_update_opt;
1478
 
  enum Foreign_key::fk_option fk_delete_opt;
1479
 
  uint32_t slave_thd_opt, start_transaction_opt;
1480
833
  int nest_level;
1481
 
  /*
1482
 
    In LEX representing update which were transformed to multi-update
1483
 
    stores total number of tables. For LEX representing multi-delete
1484
 
    holds number of tables from which we will delete records.
1485
 
  */
1486
 
  uint32_t table_count;
1487
834
  uint8_t describe;
1488
835
  /*
1489
836
    A flag that indicates what kinds of derived tables are present in the
1490
837
    query (0 if no derived tables, otherwise DERIVED_SUBQUERY).
1491
838
  */
1492
839
  uint8_t derived_tables;
1493
 
  bool drop_if_exists, drop_temporary, local_file, one_shot_set;
1494
 
  bool autocommit;
1495
 
  bool verbose, no_write_to_binlog;
1496
 
 
1497
 
  bool tx_chain, tx_release;
1498
 
  bool subqueries, ignore;
1499
 
  st_parsing_options parsing_options;
1500
 
  Alter_info alter_info;
1501
 
 
1502
 
  /*
1503
 
    field_list was created for view and should be removed before PS/SP
1504
 
    rexecuton
1505
 
  */
1506
 
  bool empty_field_list_on_rset;
1507
 
 
1508
 
  /*
1509
 
    Pointers to part of LOAD DATA statement that should be rewritten
1510
 
    during replication ("LOCAL 'filename' REPLACE INTO" part).
1511
 
  */
1512
 
  const char *fname_start;
1513
 
  const char *fname_end;
 
840
 
 
841
  /* Only true when FULL symbol is found (e.g. SHOW FULL PROCESSLIST) */
 
842
  bool verbose;
1514
843
  
 
844
  /* Was the IGNORE symbol found in statement */
 
845
  bool ignore;
 
846
 
1515
847
  /**
1516
 
    During name resolution search only in the table list given by 
 
848
    During name resolution search only in the table list given by
1517
849
    Name_resolution_context::first_name_resolution_table and
1518
850
    Name_resolution_context::last_name_resolution_table
1519
 
    (see Item_field::fix_fields()). 
 
851
    (see Item_field::fix_fields()).
1520
852
  */
1521
853
  bool use_only_table_context;
1522
 
  
 
854
 
 
855
  /* Was the ESCAPE keyword used? */
1523
856
  bool escape_used;
1524
857
  bool is_lex_started; /* If lex_start() did run. For debugging. */
1525
858
 
1526
 
  st_lex();
 
859
  LEX();
1527
860
 
1528
 
  virtual ~st_lex()
 
861
  /* Note that init and de-init mostly happen in lex_start and lex_end
 
862
     and not here. This is because LEX isn't delete/new for each new
 
863
     statement in a session. It's re-used by doing lex_end, lex_start
 
864
     in sql_lex.cc
 
865
  */
 
866
  virtual ~LEX()
1529
867
  {
1530
 
    destroy_query_tables_list();
1531
 
    plugin_unlock_list(NULL, (plugin_ref *)plugins.buffer, plugins.elements);
1532
 
    delete_dynamic(&plugins);
1533
868
  }
1534
869
 
1535
 
  TABLE_LIST *unlink_first_table(bool *link_to_local);
1536
 
  void link_first_table_back(TABLE_LIST *first, bool link_to_local);
 
870
  TableList *unlink_first_table(bool *link_to_local);
 
871
  void link_first_table_back(TableList *first, bool link_to_local);
1537
872
  void first_lists_tables_same();
1538
873
 
1539
 
  bool can_be_merged();
1540
 
  bool can_use_merged();
1541
 
  bool can_not_use_merged();
1542
874
  bool only_view_structure();
1543
875
  bool need_correct_ident();
1544
876
 
1561
893
    return context_stack.head();
1562
894
  }
1563
895
  /*
1564
 
    Restore the LEX and THD in case of a parse error.
 
896
    Restore the LEX and Session in case of a parse error.
1565
897
  */
1566
 
  static void cleanup_lex_after_parse_error(THD *thd);
1567
 
 
1568
 
  void reset_n_backup_query_tables_list(Query_tables_list *backup);
1569
 
  void restore_backup_query_tables_list(Query_tables_list *backup);
1570
 
 
1571
 
  bool table_or_sp_used();
 
898
  static void cleanup_lex_after_parse_error(Session *session);
1572
899
 
1573
900
  /**
1574
901
    @brief check if the statement is a single-level join
1575
902
    @return result of the check
1576
 
      @retval true  The statement doesn't contain subqueries, unions and 
 
903
      @retval true  The statement doesn't contain subqueries, unions and
1577
904
                    stored procedure calls.
1578
905
      @retval false There are subqueries, UNIONs or stored procedure calls.
1579
906
  */
1580
 
  bool is_single_level_stmt() 
1581
 
  { 
1582
 
    /* 
 
907
  bool is_single_level_stmt()
 
908
  {
 
909
    /*
1583
910
      This check exploits the fact that the last added to all_select_list is
1584
 
      on its top. So select_lex (as the first added) will be at the tail 
 
911
      on its top. So select_lex (as the first added) will be at the tail
1585
912
      of the list.
1586
 
    */ 
1587
 
    if (&select_lex == all_selects_list && !sroutines.records)
 
913
    */
 
914
    if (&select_lex == all_selects_list)
1588
915
    {
1589
916
      assert(!all_selects_list->next_select_in_list());
1590
917
      return true;
1591
918
    }
1592
919
    return false;
1593
920
  }
1594
 
} LEX;
1595
 
 
1596
 
struct st_lex_local: public st_lex
1597
 
{
1598
 
  static void *operator new(size_t size) throw()
1599
 
  {
1600
 
    return sql_alloc(size);
1601
 
  }
1602
 
  static void *operator new(size_t size, MEM_ROOT *mem_root) throw()
1603
 
  {
1604
 
    return (void*) alloc_root(mem_root, (uint32_t) size);
1605
 
  }
1606
 
  static void operator delete(void *ptr __attribute__((unused)),
1607
 
                              size_t size __attribute__((unused)))
1608
 
  { TRASH(ptr, size); }
1609
 
  static void operator delete(void *ptr __attribute__((unused)),
1610
 
                              MEM_ROOT *mem_root __attribute__((unused)))
1611
 
  { /* Never called */ }
1612
921
};
1613
922
 
1614
 
extern void lex_init(void);
1615
 
extern void lex_free(void);
1616
 
extern void lex_start(THD *thd);
 
923
extern void lex_start(Session *session);
1617
924
extern void lex_end(LEX *lex);
1618
 
 
1619
925
extern void trim_whitespace(const CHARSET_INFO * const cs, LEX_STRING *str);
1620
 
 
1621
926
extern bool is_lex_native_function(const LEX_STRING *name);
1622
927
 
1623
928
/**
1625
930
*/
1626
931
 
1627
932
#endif /* DRIZZLE_SERVER */
1628
 
#endif /* DRIZZLE_SERVER_SQL_LEX_H */
 
933
#endif /* DRIZZLED_SQL_LEX_H */