~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_lex.h

  • Committer: Mark Atwood
  • Date: 2008-10-16 11:33:16 UTC
  • mto: (520.1.13 drizzle)
  • mto: This revision was merged to the branch mainline in revision 530.
  • Revision ID: mark@fallenpegasus.com-20081016113316-ff6jdt31ck90sjdh
an implemention of the errmsg plugin

Show diffs side-by-side

added added

removed removed

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