~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_lex.h

  • Committer: Brian Aker
  • Date: 2009-01-09 22:07:54 UTC
  • Revision ID: brian@tangent.org-20090109220754-1y50h7lqi9i1ifcs
Dead test/wrong test.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
{
 
26
 
 
27
#include <drizzled/sql_udf.h>
 
28
#include <drizzled/name_resolution_context.h>
 
29
#include <drizzled/item/subselect.h>
 
30
#include <drizzled/item/param.h>
 
31
#include <drizzled/item/outer_ref.h>
 
32
#include <drizzled/table_list.h>
 
33
#include <drizzled/function/math/real.h>
 
34
#include <drizzled/alter_drop.h>
 
35
#include <drizzled/alter_column.h>
 
36
#include <drizzled/key.h>
 
37
#include <drizzled/foreign_key.h>
 
38
#include <drizzled/item/param.h>
46
39
 
47
40
class select_result_interceptor;
 
41
class virtual_column_info;
48
42
 
49
43
/* YACC and LEX Definitions */
50
44
 
51
45
/* These may not be declared yet */
52
46
class Table_ident;
53
 
class file_exchange;
54
 
class Lex_Column;
 
47
class sql_exchange;
 
48
class LEX_COLUMN;
55
49
class Item_outer_ref;
56
50
 
57
 
} /* namespace drizzled */
58
 
 
59
51
/*
60
52
  The following hack is needed because mysql_yacc.cc does not define
61
53
  YYSTYPE before including this file
62
54
*/
63
55
 
64
56
#ifdef DRIZZLE_SERVER
65
 
/* set_var should change to set_var here ... */
66
 
# include <drizzled/sys_var.h>
 
57
# include <drizzled/set_var.h>
67
58
# include <drizzled/item/func.h>
68
59
# ifdef DRIZZLE_YACC
69
60
#  define LEX_YYSTYPE void *
70
61
# else
71
62
#  if defined(DRIZZLE_LEX)
72
 
#   include <drizzled/foreign_key.h>
73
63
#   include <drizzled/lex_symbol.h>
74
64
#   include <drizzled/sql_yacc.h>
75
65
#   define LEX_YYSTYPE YYSTYPE *
88
78
#define DERIVED_NONE    0
89
79
#define DERIVED_SUBQUERY        1
90
80
 
91
 
namespace drizzled
92
 
{
93
 
 
94
81
typedef List<Item> List_item;
95
82
 
 
83
/* SERVERS CACHE CHANGES */
 
84
typedef struct st_lex_server_options
 
85
{
 
86
  int32_t port;
 
87
  uint32_t server_name_length;
 
88
  char *server_name, *host, *db, *username, *password, *scheme, *owner;
 
89
} LEX_SERVER_OPTIONS;
 
90
 
 
91
typedef struct st_lex_master_info
 
92
{
 
93
  char *host, *user, *password, *log_file_name;
 
94
  uint32_t port, connect_retry;
 
95
  float heartbeat_period;
 
96
  uint64_t pos;
 
97
  uint32_t server_id;
 
98
  /*
 
99
    Enum is used for making it possible to detect if the user
 
100
    changed variable or if it should be left at old value
 
101
   */
 
102
  enum {LEX_MI_UNCHANGED, LEX_MI_DISABLE, LEX_MI_ENABLE} heartbeat_opt;
 
103
  char *relay_log_name;
 
104
  uint32_t relay_log_pos;
 
105
} LEX_MASTER_INFO;
 
106
 
 
107
 
96
108
enum sub_select_type
97
109
{
98
 
  UNSPECIFIED_TYPE,
99
 
  UNION_TYPE,
100
 
  INTERSECT_TYPE,
101
 
  EXCEPT_TYPE,
102
 
  GLOBAL_OPTIONS_TYPE,
103
 
  DERIVED_TABLE_TYPE,
104
 
  OLAP_TYPE
 
110
  UNSPECIFIED_TYPE,UNION_TYPE, INTERSECT_TYPE,
 
111
  EXCEPT_TYPE, GLOBAL_OPTIONS_TYPE, DERIVED_TABLE_TYPE, OLAP_TYPE
105
112
};
106
113
 
107
114
enum olap_type
108
115
{
109
 
  UNSPECIFIED_OLAP_TYPE,
110
 
  CUBE_TYPE,
111
 
  ROLLUP_TYPE
 
116
  UNSPECIFIED_OLAP_TYPE, CUBE_TYPE, ROLLUP_TYPE
 
117
};
 
118
 
 
119
enum tablespace_op_type
 
120
{
 
121
  NO_TABLESPACE_OP, DISCARD_TABLESPACE, IMPORT_TABLESPACE
 
122
};
 
123
 
 
124
/*
 
125
  String names used to print a statement with index hints.
 
126
  Keep in sync with index_hint_type.
 
127
*/
 
128
extern const char * index_hint_type_name[];
 
129
typedef unsigned char index_clause_map;
 
130
 
 
131
/*
 
132
  Bits in index_clause_map : one for each possible FOR clause in
 
133
  USE/FORCE/IGNORE INDEX index hint specification
 
134
*/
 
135
#define INDEX_HINT_MASK_JOIN  (1)
 
136
#define INDEX_HINT_MASK_GROUP (1 << 1)
 
137
#define INDEX_HINT_MASK_ORDER (1 << 2)
 
138
 
 
139
#define INDEX_HINT_MASK_ALL (INDEX_HINT_MASK_JOIN | INDEX_HINT_MASK_GROUP | \
 
140
                             INDEX_HINT_MASK_ORDER)
 
141
 
 
142
/* Single element of an USE/FORCE/IGNORE INDEX list specified as a SQL hint  */
 
143
class Index_hint : public Sql_alloc
 
144
{
 
145
public:
 
146
  /* The type of the hint : USE/FORCE/IGNORE */
 
147
  enum index_hint_type type;
 
148
  /* Where the hit applies to. A bitmask of INDEX_HINT_MASK_<place> values */
 
149
  index_clause_map clause;
 
150
  /*
 
151
    The index name. Empty (str=NULL) name represents an empty list
 
152
    USE INDEX () clause
 
153
  */
 
154
  LEX_STRING key_name;
 
155
 
 
156
  Index_hint (enum index_hint_type type_arg, index_clause_map clause_arg,
 
157
              char *str, uint32_t length) :
 
158
    type(type_arg), clause(clause_arg)
 
159
  {
 
160
    key_name.str= str;
 
161
    key_name.length= length;
 
162
  }
 
163
 
 
164
  void print(Session *session, String *str);
112
165
};
113
166
 
114
167
/*
226
279
*/
227
280
 
228
281
/*
229
 
    Base class for Select_Lex (Select_Lex) &
230
 
    Select_Lex_Unit (Select_Lex_Unit)
 
282
    Base class for st_select_lex (SELECT_LEX) &
 
283
    st_select_lex_unit (SELECT_LEX_UNIT)
231
284
*/
232
285
class LEX;
233
 
class Select_Lex;
234
 
class Select_Lex_Unit;
235
 
class Select_Lex_Node {
 
286
class st_select_lex;
 
287
class st_select_lex_unit;
 
288
class st_select_lex_node {
236
289
protected:
237
 
  Select_Lex_Node *next, **prev,   /* neighbor list */
 
290
  st_select_lex_node *next, **prev,   /* neighbor list */
238
291
    *master, *slave,                  /* vertical links */
239
 
    *link_next, **link_prev;          /* list of whole Select_Lex */
 
292
    *link_next, **link_prev;          /* list of whole SELECT_LEX */
240
293
public:
241
294
 
242
295
  uint64_t options;
249
302
      UNCACHEABLE_EXPLAIN
250
303
      UNCACHEABLE_PREPARE
251
304
  */
252
 
  std::bitset<8> uncacheable;
 
305
  uint8_t uncacheable;
253
306
  enum sub_select_type linkage;
254
307
  bool no_table_names_allowed; /* used for global order by */
255
308
  bool no_error; /* suppress error message (convert it to warnings) */
256
309
 
257
310
  static void *operator new(size_t size)
258
311
  {
259
 
    return memory::sql_alloc(size);
 
312
    return sql_alloc(size);
260
313
  }
261
 
  static void *operator new(size_t size, memory::Root *mem_root)
262
 
  { return (void*) mem_root->alloc_root((uint32_t) size); }
 
314
  static void *operator new(size_t size, MEM_ROOT *mem_root)
 
315
  { return (void*) alloc_root(mem_root, (uint32_t) size); }
263
316
  static void operator delete(void *, size_t)
264
 
  {  }
265
 
  static void operator delete(void *, memory::Root *)
 
317
  { TRASH(ptr, size); }
 
318
  static void operator delete(void *, MEM_ROOT *)
266
319
  {}
267
 
  Select_Lex_Node(): linkage(UNSPECIFIED_TYPE) {}
268
 
  virtual ~Select_Lex_Node() {}
269
 
  inline Select_Lex_Node* get_master() { return master; }
 
320
  st_select_lex_node(): linkage(UNSPECIFIED_TYPE) {}
 
321
  virtual ~st_select_lex_node() {}
 
322
  inline st_select_lex_node* get_master() { return master; }
270
323
  virtual void init_query();
271
324
  virtual void init_select();
272
 
  void include_down(Select_Lex_Node *upper);
273
 
  void include_neighbour(Select_Lex_Node *before);
274
 
  void include_standalone(Select_Lex_Node *sel, Select_Lex_Node **ref);
275
 
  void include_global(Select_Lex_Node **plink);
 
325
  void include_down(st_select_lex_node *upper);
 
326
  void include_neighbour(st_select_lex_node *before);
 
327
  void include_standalone(st_select_lex_node *sel, st_select_lex_node **ref);
 
328
  void include_global(st_select_lex_node **plink);
276
329
  void exclude();
277
330
 
278
 
  virtual Select_Lex_Unit* master_unit()= 0;
279
 
  virtual Select_Lex* outer_select()= 0;
280
 
  virtual Select_Lex* return_after_parsing()= 0;
 
331
  virtual st_select_lex_unit* master_unit()= 0;
 
332
  virtual st_select_lex* outer_select()= 0;
 
333
  virtual st_select_lex* return_after_parsing()= 0;
281
334
 
282
335
  virtual bool set_braces(bool value);
283
336
  virtual bool inc_in_sum_expr();
284
337
  virtual uint32_t get_in_sum_expr();
285
338
  virtual TableList* get_table_list();
286
339
  virtual List<Item>* get_item_list();
 
340
  virtual uint32_t get_table_join_options();
287
341
  virtual TableList *add_table_to_list(Session *session, Table_ident *table,
288
 
                                       LEX_STRING *alias,
289
 
                                       const std::bitset<NUM_OF_TABLE_OPTIONS>& table_options,
290
 
                                       thr_lock_type flags= TL_UNLOCK,
291
 
                                       List<Index_hint> *hints= 0,
292
 
                                       LEX_STRING *option= 0);
 
342
                                        LEX_STRING *alias,
 
343
                                        uint32_t table_options,
 
344
                                        thr_lock_type flags= TL_UNLOCK,
 
345
                                        List<Index_hint> *hints= 0,
 
346
                                        LEX_STRING *option= 0);
293
347
  virtual void set_lock_for_tables(thr_lock_type)
294
348
  {}
295
349
 
296
 
  friend class Select_Lex_Unit;
 
350
  friend class st_select_lex_unit;
297
351
  friend bool mysql_new_select(LEX *lex, bool move_down);
298
352
private:
299
353
  void fast_exclude();
300
354
};
 
355
typedef class st_select_lex_node SELECT_LEX_NODE;
301
356
 
302
357
/*
303
 
   Select_Lex_Unit - unit of selects (UNION, INTERSECT, ...) group
304
 
   Select_Lexs
 
358
   SELECT_LEX_UNIT - unit of selects (UNION, INTERSECT, ...) group
 
359
   SELECT_LEXs
305
360
*/
306
361
class Session;
307
362
class select_result;
308
 
class Join;
 
363
class JOIN;
309
364
class select_union;
310
 
class Select_Lex_Unit: public Select_Lex_Node {
 
365
class st_select_lex_unit: public st_select_lex_node {
311
366
protected:
312
367
  TableList result_table_list;
313
368
  select_union *union_result;
341
396
    Pointer to 'last' select or pointer to unit where stored
342
397
    global parameters for union
343
398
  */
344
 
  Select_Lex *global_parameters;
 
399
  st_select_lex *global_parameters;
345
400
  //node on wich we should return current_select pointer after parsing subquery
346
 
  Select_Lex *return_to;
 
401
  st_select_lex *return_to;
347
402
  /* LIMIT clause runtime counters */
348
403
  ha_rows select_limit_cnt, offset_limit_cnt;
349
404
  /* not NULL if unit used in subselect, point to subselect item */
351
406
  /* thread handler */
352
407
  Session *session;
353
408
  /*
354
 
    Select_Lex for hidden SELECT in onion which process global
 
409
    SELECT_LEX for hidden SELECT in onion which process global
355
410
    ORDER BY and LIMIT
356
411
  */
357
 
  Select_Lex *fake_select_lex;
 
412
  st_select_lex *fake_select_lex;
358
413
 
359
 
  Select_Lex *union_distinct; /* pointer to the last UNION DISTINCT */
 
414
  st_select_lex *union_distinct; /* pointer to the last UNION DISTINCT */
360
415
  bool describe; /* union exec() called for EXPLAIN */
361
416
 
362
417
  void init_query();
363
 
  Select_Lex_Unit* master_unit();
364
 
  Select_Lex* outer_select();
365
 
  Select_Lex* first_select()
366
 
  {
367
 
    return reinterpret_cast<Select_Lex*>(slave);
368
 
  }
369
 
  Select_Lex_Unit* next_unit()
370
 
  {
371
 
    return reinterpret_cast<Select_Lex_Unit*>(next);
372
 
  }
373
 
  Select_Lex* return_after_parsing() { return return_to; }
 
418
  st_select_lex_unit* master_unit();
 
419
  st_select_lex* outer_select();
 
420
  st_select_lex* first_select()
 
421
  {
 
422
    return reinterpret_cast<st_select_lex*>(slave);
 
423
  }
 
424
  st_select_lex_unit* next_unit()
 
425
  {
 
426
    return reinterpret_cast<st_select_lex_unit*>(next);
 
427
  }
 
428
  st_select_lex* return_after_parsing() { return return_to; }
374
429
  void exclude_level();
375
430
  void exclude_tree();
376
431
 
377
432
  /* UNION methods */
378
 
  bool prepare(Session *session, select_result *result,
379
 
               uint64_t additional_options);
 
433
  bool prepare(Session *session, select_result *result, uint32_t additional_options);
380
434
  bool exec();
381
435
  bool cleanup();
382
436
  inline void unclean() { cleaned= 0; }
388
442
  void init_prepare_fake_select_lex(Session *session);
389
443
  bool change_result(select_result_interceptor *result,
390
444
                     select_result_interceptor *old_result);
391
 
  void set_limit(Select_Lex *values);
 
445
  void set_limit(st_select_lex *values);
392
446
  void set_session(Session *session_arg) { session= session_arg; }
393
447
  inline bool is_union ();
394
448
 
398
452
  List<Item> *get_unit_column_types();
399
453
};
400
454
 
 
455
typedef class st_select_lex_unit SELECT_LEX_UNIT;
 
456
 
401
457
/*
402
 
  Select_Lex - store information of parsed SELECT statment
 
458
  SELECT_LEX - store information of parsed SELECT statment
403
459
*/
404
 
class Select_Lex: public Select_Lex_Node
 
460
class st_select_lex: public st_select_lex_node
405
461
{
406
462
public:
407
 
 
408
 
  Select_Lex() :
409
 
    context(),
410
 
    db(0),
411
 
    where(0),
412
 
    having(0),
413
 
    cond_value(),
414
 
    having_value(),
415
 
    parent_lex(0),
416
 
    olap(UNSPECIFIED_OLAP_TYPE),
417
 
    table_list(),
418
 
    group_list(),
419
 
    item_list(),
420
 
    interval_list(),
421
 
    is_item_list_lookup(false),
422
 
    join(0),
423
 
    top_join_list(),
424
 
    join_list(0),
425
 
    embedding(0),
426
 
    sj_nests(),
427
 
    leaf_tables(0),
428
 
    type(optimizer::ST_PRIMARY),
429
 
    order_list(),
430
 
    gorder_list(0),
431
 
    select_limit(0),
432
 
    offset_limit(0),
433
 
    ref_pointer_array(0),
434
 
    select_n_having_items(0),
435
 
    cond_count(0),
436
 
    between_count(0),
437
 
    max_equal_elems(0),
438
 
    select_n_where_fields(0),
439
 
    parsing_place(NO_MATTER),
440
 
    with_sum_func(0),
441
 
    in_sum_expr(0),
442
 
    select_number(0),
443
 
    nest_level(0),
444
 
    inner_sum_func_list(0),
445
 
    with_wild(0),
446
 
    braces(0),
447
 
    having_fix_field(0),
448
 
    inner_refs_list(),
449
 
    n_sum_items(0),
450
 
    n_child_sum_items(0),
451
 
    explicit_limit(0),
452
 
    subquery_in_having(0),
453
 
    is_correlated(0),
454
 
    exclude_from_table_unique_test(0),
455
 
    non_agg_fields(),
456
 
    cur_pos_in_select_list(0),
457
 
    prev_join_using(0),
458
 
    full_group_by_flag(),
459
 
    current_index_hint_type(INDEX_HINT_IGNORE),
460
 
    current_index_hint_clause(),
461
 
    index_hints(0)
462
 
  {
463
 
  }
464
 
 
465
463
  Name_resolution_context context;
466
464
  char *db;
467
 
  /* An Item representing the WHERE clause */
468
 
  Item *where;
469
 
  /* An Item representing the HAVING clause */
470
 
  Item *having;
 
465
  Item *where, *having;                         /* WHERE & HAVING clauses */
471
466
  /* Saved values of the WHERE and HAVING clauses*/
472
 
  Item::cond_result cond_value;
473
 
  Item::cond_result having_value;
 
467
  Item::cond_result cond_value, having_value;
474
468
  /* point on lex in which it was created, used in view subquery detection */
475
469
  LEX *parent_lex;
476
470
  enum olap_type olap;
477
471
  /* FROM clause - points to the beginning of the TableList::next_local list. */
478
 
  SQL_LIST table_list;
479
 
  SQL_LIST group_list; /* GROUP BY clause. */
480
 
  List<Item> item_list;  /* list of fields & expressions */
481
 
  List<String> interval_list;
482
 
  bool is_item_list_lookup;
483
 
  Join *join; /* after Join::prepare it is pointer to corresponding JOIN */
 
472
  SQL_LIST            table_list;
 
473
  SQL_LIST            group_list; /* GROUP BY clause. */
 
474
  List<Item>          item_list;  /* list of fields & expressions */
 
475
  List<String>        interval_list;
 
476
  bool                is_item_list_lookup;
 
477
  /*
 
478
    Despite their names, the following are used in unions. This should
 
479
    be rewritten. -Brian
 
480
  */
 
481
  List<Item_real_func> *ftfunc_list;
 
482
  List<Item_real_func> ftfunc_list_alloc;
 
483
  JOIN *join; /* after JOIN::prepare it is pointer to corresponding JOIN */
484
484
  List<TableList> top_join_list; /* join list of the top level          */
485
485
  List<TableList> *join_list;    /* list for the currently parsed join  */
486
486
  TableList *embedding;          /* table embedding to the above list   */
491
491
    by TableList::next_leaf, so leaf_tables points to the left-most leaf.
492
492
  */
493
493
  TableList *leaf_tables;
494
 
  enum drizzled::optimizer::select_type type; /* type of select for EXPLAIN */
 
494
  const char *type;               /* type of select for EXPLAIN          */
495
495
 
496
496
  SQL_LIST order_list;                /* ORDER clause */
497
497
  SQL_LIST *gorder_list;
498
498
  Item *select_limit, *offset_limit;  /* LIMIT clause parameters */
499
 
  /* Arrays of pointers to top elements of all_fields list */
 
499
  // Arrays of pointers to top elements of all_fields list
500
500
  Item **ref_pointer_array;
501
501
 
502
502
  /*
516
516
  enum_parsing_place parsing_place; /* where we are parsing expression */
517
517
  bool with_sum_func;   /* sum function indicator */
518
518
 
 
519
  uint32_t table_join_options;
519
520
  uint32_t in_sum_expr;
520
521
  uint32_t select_number; /* number of select (used for EXPLAIN) */
521
 
  int8_t nest_level;     /* nesting level of select */
 
522
  int nest_level;     /* nesting level of select */
522
523
  Item_sum *inner_sum_func_list; /* list of sum func in nested selects */
523
524
  uint32_t with_wild; /* item list contain '*' */
524
 
  bool braces;          /* SELECT ... UNION (SELECT ... ) <- this braces */
 
525
  bool  braces;         /* SELECT ... UNION (SELECT ... ) <- this braces */
525
526
  /* true when having fix field called in processing of this SELECT */
526
527
  bool having_fix_field;
527
528
  /* List of references to fields referenced from inner selects */
547
548
  /* index in the select list of the expression currently being fixed */
548
549
  int cur_pos_in_select_list;
549
550
 
 
551
  List<udf_func>     udf_list;                  /* udf function calls stack */
550
552
  /*
551
553
    This is a copy of the original JOIN USING list that comes from
552
554
    the parser. The parser :
553
555
      1. Sets the natural_join of the second TableList in the join
554
 
         and the Select_Lex::prev_join_using.
 
556
         and the st_select_lex::prev_join_using.
555
557
      2. Makes a parent TableList and sets its is_natural_join/
556
558
       join_using_fields members.
557
559
      3. Uses the wrapper TableList as a table in the upper level.
570
572
      1 - aggregate functions are used in this select,
571
573
          defined as SUM_FUNC_USED.
572
574
  */
573
 
  std::bitset<2> full_group_by_flag;
574
 
 
 
575
  uint8_t full_group_by_flag;
575
576
  void init_query();
576
577
  void init_select();
577
 
  Select_Lex_Unit* master_unit();
578
 
  Select_Lex_Unit* first_inner_unit()
579
 
  {
580
 
    return (Select_Lex_Unit*) slave;
581
 
  }
582
 
  Select_Lex* outer_select();
583
 
  Select_Lex* next_select()
584
 
  {
585
 
    return (Select_Lex*) next;
586
 
  }
587
 
  Select_Lex* next_select_in_list()
588
 
  {
589
 
    return (Select_Lex*) link_next;
590
 
  }
591
 
  Select_Lex_Node** next_select_in_list_addr()
 
578
  st_select_lex_unit* master_unit();
 
579
  st_select_lex_unit* first_inner_unit()
 
580
  {
 
581
    return (st_select_lex_unit*) slave;
 
582
  }
 
583
  st_select_lex* outer_select();
 
584
  st_select_lex* next_select() { return (st_select_lex*) next; }
 
585
  st_select_lex* next_select_in_list()
 
586
  {
 
587
    return (st_select_lex*) link_next;
 
588
  }
 
589
  st_select_lex_node** next_select_in_list_addr()
592
590
  {
593
591
    return &link_next;
594
592
  }
595
 
  Select_Lex* return_after_parsing()
 
593
  st_select_lex* return_after_parsing()
596
594
  {
597
595
    return master_unit()->return_after_parsing();
598
596
  }
599
597
 
600
 
  void mark_as_dependent(Select_Lex *last);
 
598
  void mark_as_dependent(st_select_lex *last);
601
599
 
602
600
  bool set_braces(bool value);
603
601
  bool inc_in_sum_expr();
606
604
  bool add_item_to_list(Session *session, Item *item);
607
605
  bool add_group_to_list(Session *session, Item *item, bool asc);
608
606
  bool add_order_to_list(Session *session, Item *item, bool asc);
609
 
  TableList* add_table_to_list(Session *session,
610
 
                               Table_ident *table,
611
 
                               LEX_STRING *alias,
612
 
                               const std::bitset<NUM_OF_TABLE_OPTIONS>& table_options,
613
 
                               thr_lock_type flags= TL_UNLOCK,
614
 
                               List<Index_hint> *hints= 0,
615
 
                               LEX_STRING *option= 0);
 
607
  TableList* add_table_to_list(Session *session, Table_ident *table,
 
608
                                LEX_STRING *alias,
 
609
                                uint32_t table_options,
 
610
                                thr_lock_type flags= TL_UNLOCK,
 
611
                                List<Index_hint> *hints= 0,
 
612
                                LEX_STRING *option= 0);
616
613
  TableList* get_table_list();
617
614
  bool init_nested_join(Session *session);
618
615
  TableList *end_nested_join(Session *session);
620
617
  void add_joined_table(TableList *table);
621
618
  TableList *convert_right_join();
622
619
  List<Item>* get_item_list();
 
620
  uint32_t get_table_join_options();
623
621
  void set_lock_for_tables(thr_lock_type lock_type);
624
622
  inline void init_order()
625
623
  {
629
627
  }
630
628
  /*
631
629
    This method created for reiniting LEX in mysql_admin_table() and can be
632
 
    used only if you are going remove all Select_Lex & units except belonger
 
630
    used only if you are going remove all SELECT_LEX & units except belonger
633
631
    to LEX (LEX::unit & LEX::select, for other purposes there are
634
 
    Select_Lex_Unit::exclude_level & Select_Lex_Unit::exclude_tree
 
632
    SELECT_LEX_UNIT::exclude_level & SELECT_LEX_UNIT::exclude_tree
635
633
  */
636
 
  void cut_subtree()
637
 
  {
638
 
    slave= 0;
639
 
  }
 
634
  void cut_subtree() { slave= 0; }
640
635
  bool test_limit();
641
636
 
642
637
  friend void lex_start(Session *session);
 
638
  st_select_lex() : n_sum_items(0), n_child_sum_items(0) {}
643
639
  void make_empty_select()
644
640
  {
645
641
    init_query();
648
644
  bool setup_ref_array(Session *session, uint32_t order_group_num);
649
645
  void print(Session *session, String *str, enum_query_type query_type);
650
646
  static void print_order(String *str,
651
 
                          Order *order,
 
647
                          order_st *order,
652
648
                          enum_query_type query_type);
653
649
  void print_limit(Session *session, String *str, enum_query_type query_type);
654
650
  void fix_prepare_information(Session *session, Item **conds, Item **having_conds);
655
651
  /*
656
652
    Destroy the used execution plan (JOIN) of this subtree (this
657
 
    Select_Lex and all nested Select_Lexes and Select_Lex_Units).
 
653
    SELECT_LEX and all nested SELECT_LEXes and SELECT_LEX_UNITs).
658
654
  */
659
655
  bool cleanup();
660
656
  /*
690
686
  /* a list of USE/FORCE/IGNORE INDEX */
691
687
  List<Index_hint> *index_hints;
692
688
};
 
689
typedef class st_select_lex SELECT_LEX;
693
690
 
694
 
inline bool Select_Lex_Unit::is_union ()
 
691
inline bool st_select_lex_unit::is_union ()
695
692
{
696
693
  return first_select()->next_select() &&
697
694
    first_select()->next_select()->linkage == UNION_TYPE;
698
695
}
699
696
 
700
 
enum xa_option_words
 
697
#define ALTER_ADD_COLUMN        (1L << 0)
 
698
#define ALTER_DROP_COLUMN       (1L << 1)
 
699
#define ALTER_CHANGE_COLUMN     (1L << 2)
 
700
#define ALTER_COLUMN_STORAGE    (1L << 3)
 
701
#define ALTER_COLUMN_FORMAT     (1L << 4)
 
702
#define ALTER_COLUMN_ORDER      (1L << 5)
 
703
#define ALTER_ADD_INDEX         (1L << 6)
 
704
#define ALTER_DROP_INDEX        (1L << 7)
 
705
#define ALTER_RENAME            (1L << 8)
 
706
#define ALTER_ORDER             (1L << 9)
 
707
#define ALTER_OPTIONS           (1L << 10)
 
708
#define ALTER_COLUMN_DEFAULT    (1L << 11)
 
709
#define ALTER_KEYS_ONOFF        (1L << 12)
 
710
#define ALTER_STORAGE           (1L << 13)
 
711
#define ALTER_ROW_FORMAT        (1L << 14)
 
712
#define ALTER_CONVERT           (1L << 15)
 
713
#define ALTER_FORCE             (1L << 16)
 
714
#define ALTER_RECREATE          (1L << 17)
 
715
#define ALTER_TABLE_REORG        (1L << 24)
 
716
#define ALTER_FOREIGN_KEY         (1L << 31)
 
717
 
 
718
/**
 
719
  @brief Parsing data for CREATE or ALTER Table.
 
720
 
 
721
  This structure contains a list of columns or indexes to be created,
 
722
  altered or dropped.
 
723
*/
 
724
 
 
725
class Alter_info
701
726
{
702
 
  XA_NONE
703
 
, XA_JOIN
704
 
, XA_RESUME
705
 
, XA_ONE_PHASE
706
 
, XA_SUSPEND
707
 
, XA_FOR_MIGRATE
 
727
public:
 
728
  List<Alter_drop>              drop_list;
 
729
  List<Alter_column>            alter_list;
 
730
  List<Key>                     key_list;
 
731
  List<Create_field>            create_list;
 
732
  uint32_t                          flags;
 
733
  enum enum_enable_or_disable   keys_onoff;
 
734
  enum tablespace_op_type       tablespace_op;
 
735
  uint32_t                          no_parts;
 
736
  enum ha_build_method          build_method;
 
737
  Create_field                 *datetime_field;
 
738
  bool                          error_if_not_empty;
 
739
 
 
740
 
 
741
  Alter_info() :
 
742
    flags(0),
 
743
    keys_onoff(LEAVE_AS_IS),
 
744
    tablespace_op(NO_TABLESPACE_OP),
 
745
    no_parts(0),
 
746
    build_method(HA_BUILD_DEFAULT),
 
747
    datetime_field(NULL),
 
748
    error_if_not_empty(false)
 
749
  {}
 
750
 
 
751
  void reset()
 
752
  {
 
753
    drop_list.empty();
 
754
    alter_list.empty();
 
755
    key_list.empty();
 
756
    create_list.empty();
 
757
    flags= 0;
 
758
    keys_onoff= LEAVE_AS_IS;
 
759
    tablespace_op= NO_TABLESPACE_OP;
 
760
    no_parts= 0;
 
761
    build_method= HA_BUILD_DEFAULT;
 
762
    datetime_field= 0;
 
763
    error_if_not_empty= false;
 
764
  }
 
765
  Alter_info(const Alter_info &rhs, MEM_ROOT *mem_root);
 
766
private:
 
767
  Alter_info &operator=(const Alter_info &rhs); // not implemented
 
768
  Alter_info(const Alter_info &rhs);            // not implemented
708
769
};
709
770
 
 
771
enum xa_option_words {XA_NONE, XA_JOIN, XA_RESUME, XA_ONE_PHASE,
 
772
                      XA_SUSPEND, XA_FOR_MIGRATE};
 
773
 
710
774
extern const LEX_STRING null_lex_str;
711
775
 
 
776
 
712
777
/*
713
778
  Class representing list of all tables used by statement.
714
779
  It also contains information about stored functions used by statement
719
784
  Also used by st_lex::reset_n_backup/restore_backup_query_tables_list()
720
785
  methods to save and restore this information.
721
786
*/
 
787
 
722
788
class Query_tables_list
723
789
{
724
790
public:
739
805
    of Query_tables_list instances which are used as backup storage.
740
806
  */
741
807
  Query_tables_list() {}
742
 
  virtual ~Query_tables_list() {}
 
808
  ~Query_tables_list() {}
743
809
 
744
810
  /* Initializes (or resets) Query_tables_list object for "real" use. */
745
811
  void reset_query_tables_list(bool init);
 
812
  void destroy_query_tables_list();
 
813
  void set_query_tables_list(Query_tables_list *state)
 
814
  {
 
815
    *this= *state;
 
816
  }
746
817
 
747
818
  /*
748
819
    Direct addition to the list of query tables.
770
841
  }
771
842
};
772
843
 
 
844
 
 
845
/*
 
846
  st_parsing_options contains the flags for constructions that are
 
847
  allowed in the current statement.
 
848
*/
 
849
 
 
850
struct st_parsing_options
 
851
{
 
852
  bool allows_select_procedure;
 
853
 
 
854
  st_parsing_options() { reset(); }
 
855
  void reset();
 
856
};
 
857
 
 
858
 
773
859
/**
774
860
  The state of the lexical parser, when parsing comments.
775
861
*/
793
879
  DISCARD_COMMENT
794
880
};
795
881
 
796
 
} /* namespace drizzled */
797
 
 
798
 
#include "drizzled/lex_input_stream.h"
799
 
 
800
 
namespace drizzled
 
882
 
 
883
/**
 
884
  @brief This class represents the character input stream consumed during
 
885
  lexical analysis.
 
886
 
 
887
  In addition to consuming the input stream, this class performs some
 
888
  comment pre processing, by filtering out out of bound special text
 
889
  from the query input stream.
 
890
  Two buffers, with pointers inside each buffers, are maintained in
 
891
  parallel. The 'raw' buffer is the original query text, which may
 
892
  contain out-of-bound comments. The 'cpp' (for comments pre processor)
 
893
  is the pre-processed buffer that contains only the query text that
 
894
  should be seen once out-of-bound data is removed.
 
895
*/
 
896
 
 
897
class Lex_input_stream
801
898
{
 
899
public:
 
900
  Lex_input_stream(Session *session, const char* buff, unsigned int length);
 
901
  ~Lex_input_stream();
 
902
 
 
903
  /**
 
904
    Set the echo mode.
 
905
 
 
906
    When echo is true, characters parsed from the raw input stream are
 
907
    preserved. When false, characters parsed are silently ignored.
 
908
    @param echo the echo mode.
 
909
  */
 
910
  void set_echo(bool echo)
 
911
  {
 
912
    m_echo= echo;
 
913
  }
 
914
 
 
915
  /**
 
916
    Skip binary from the input stream.
 
917
    @param n number of bytes to accept.
 
918
  */
 
919
  void skip_binary(int n)
 
920
  {
 
921
    if (m_echo)
 
922
    {
 
923
      memcpy(m_cpp_ptr, m_ptr, n);
 
924
      m_cpp_ptr += n;
 
925
    }
 
926
    m_ptr += n;
 
927
  }
 
928
 
 
929
  /**
 
930
    Get a character, and advance in the stream.
 
931
    @return the next character to parse.
 
932
  */
 
933
  char yyGet()
 
934
  {
 
935
    char c= *m_ptr++;
 
936
    if (m_echo)
 
937
      *m_cpp_ptr++ = c;
 
938
    return c;
 
939
  }
 
940
 
 
941
  /**
 
942
    Get the last character accepted.
 
943
    @return the last character accepted.
 
944
  */
 
945
  char yyGetLast()
 
946
  {
 
947
    return m_ptr[-1];
 
948
  }
 
949
 
 
950
  /**
 
951
    Look at the next character to parse, but do not accept it.
 
952
  */
 
953
  char yyPeek()
 
954
  {
 
955
    return m_ptr[0];
 
956
  }
 
957
 
 
958
  /**
 
959
    Look ahead at some character to parse.
 
960
    @param n offset of the character to look up
 
961
  */
 
962
  char yyPeekn(int n)
 
963
  {
 
964
    return m_ptr[n];
 
965
  }
 
966
 
 
967
  /**
 
968
    Cancel the effect of the last yyGet() or yySkip().
 
969
    Note that the echo mode should not change between calls to yyGet / yySkip
 
970
    and yyUnget. The caller is responsible for ensuring that.
 
971
  */
 
972
  void yyUnget()
 
973
  {
 
974
    m_ptr--;
 
975
    if (m_echo)
 
976
      m_cpp_ptr--;
 
977
  }
 
978
 
 
979
  /**
 
980
    Accept a character, by advancing the input stream.
 
981
  */
 
982
  void yySkip()
 
983
  {
 
984
    if (m_echo)
 
985
      *m_cpp_ptr++ = *m_ptr++;
 
986
    else
 
987
      m_ptr++;
 
988
  }
 
989
 
 
990
  /**
 
991
    Accept multiple characters at once.
 
992
    @param n the number of characters to accept.
 
993
  */
 
994
  void yySkipn(int n)
 
995
  {
 
996
    if (m_echo)
 
997
    {
 
998
      memcpy(m_cpp_ptr, m_ptr, n);
 
999
      m_cpp_ptr += n;
 
1000
    }
 
1001
    m_ptr += n;
 
1002
  }
 
1003
 
 
1004
  /**
 
1005
    End of file indicator for the query text to parse.
 
1006
    @return true if there are no more characters to parse
 
1007
  */
 
1008
  bool eof()
 
1009
  {
 
1010
    return (m_ptr >= m_end_of_query);
 
1011
  }
 
1012
 
 
1013
  /**
 
1014
    End of file indicator for the query text to parse.
 
1015
    @param n number of characters expected
 
1016
    @return true if there are less than n characters to parse
 
1017
  */
 
1018
  bool eof(int n)
 
1019
  {
 
1020
    return ((m_ptr + n) >= m_end_of_query);
 
1021
  }
 
1022
 
 
1023
  /** Get the raw query buffer. */
 
1024
  const char *get_buf()
 
1025
  {
 
1026
    return m_buf;
 
1027
  }
 
1028
 
 
1029
  /** Get the pre-processed query buffer. */
 
1030
  const char *get_cpp_buf()
 
1031
  {
 
1032
    return m_cpp_buf;
 
1033
  }
 
1034
 
 
1035
  /** Get the end of the raw query buffer. */
 
1036
  const char *get_end_of_query()
 
1037
  {
 
1038
    return m_end_of_query;
 
1039
  }
 
1040
 
 
1041
  /** Mark the stream position as the start of a new token. */
 
1042
  void start_token()
 
1043
  {
 
1044
    m_tok_start_prev= m_tok_start;
 
1045
    m_tok_start= m_ptr;
 
1046
    m_tok_end= m_ptr;
 
1047
 
 
1048
    m_cpp_tok_start_prev= m_cpp_tok_start;
 
1049
    m_cpp_tok_start= m_cpp_ptr;
 
1050
    m_cpp_tok_end= m_cpp_ptr;
 
1051
  }
 
1052
 
 
1053
  /**
 
1054
    Adjust the starting position of the current token.
 
1055
    This is used to compensate for starting whitespace.
 
1056
  */
 
1057
  void restart_token()
 
1058
  {
 
1059
    m_tok_start= m_ptr;
 
1060
    m_cpp_tok_start= m_cpp_ptr;
 
1061
  }
 
1062
 
 
1063
  /** Get the token start position, in the raw buffer. */
 
1064
  const char *get_tok_start()
 
1065
  {
 
1066
    return m_tok_start;
 
1067
  }
 
1068
 
 
1069
  /** Get the token start position, in the pre-processed buffer. */
 
1070
  const char *get_cpp_tok_start()
 
1071
  {
 
1072
    return m_cpp_tok_start;
 
1073
  }
 
1074
 
 
1075
  /** Get the token end position, in the raw buffer. */
 
1076
  const char *get_tok_end()
 
1077
  {
 
1078
    return m_tok_end;
 
1079
  }
 
1080
 
 
1081
  /** Get the token end position, in the pre-processed buffer. */
 
1082
  const char *get_cpp_tok_end()
 
1083
  {
 
1084
    return m_cpp_tok_end;
 
1085
  }
 
1086
 
 
1087
  /** Get the previous token start position, in the raw buffer. */
 
1088
  const char *get_tok_start_prev()
 
1089
  {
 
1090
    return m_tok_start_prev;
 
1091
  }
 
1092
 
 
1093
  /** Get the current stream pointer, in the raw buffer. */
 
1094
  const char *get_ptr()
 
1095
  {
 
1096
    return m_ptr;
 
1097
  }
 
1098
 
 
1099
  /** Get the current stream pointer, in the pre-processed buffer. */
 
1100
  const char *get_cpp_ptr()
 
1101
  {
 
1102
    return m_cpp_ptr;
 
1103
  }
 
1104
 
 
1105
  /** Get the length of the current token, in the raw buffer. */
 
1106
  uint32_t yyLength()
 
1107
  {
 
1108
    /*
 
1109
      The assumption is that the lexical analyser is always 1 character ahead,
 
1110
      which the -1 account for.
 
1111
    */
 
1112
    assert(m_ptr > m_tok_start);
 
1113
    return (uint32_t) ((m_ptr - m_tok_start) - 1);
 
1114
  }
 
1115
 
 
1116
  /** Get the utf8-body string. */
 
1117
  const char *get_body_utf8_str()
 
1118
  {
 
1119
    return m_body_utf8;
 
1120
  }
 
1121
 
 
1122
  /** Get the utf8-body length. */
 
1123
  uint32_t get_body_utf8_length()
 
1124
  {
 
1125
    return m_body_utf8_ptr - m_body_utf8;
 
1126
  }
 
1127
 
 
1128
  void body_utf8_start(Session *session, const char *begin_ptr);
 
1129
  void body_utf8_append(const char *ptr);
 
1130
  void body_utf8_append(const char *ptr, const char *end_ptr);
 
1131
  void body_utf8_append_literal(Session *session,
 
1132
                                const LEX_STRING *txt,
 
1133
                                const CHARSET_INFO * const txt_cs,
 
1134
                                const char *end_ptr);
 
1135
 
 
1136
  /** Current thread. */
 
1137
  Session *m_session;
 
1138
 
 
1139
  /** Current line number. */
 
1140
  uint32_t yylineno;
 
1141
 
 
1142
  /** Length of the last token parsed. */
 
1143
  uint32_t yytoklen;
 
1144
 
 
1145
  /** Interface with bison, value of the last token parsed. */
 
1146
  LEX_YYSTYPE yylval;
 
1147
 
 
1148
  /** LALR(2) resolution, look ahead token.*/
 
1149
  int lookahead_token;
 
1150
 
 
1151
  /** LALR(2) resolution, value of the look ahead token.*/
 
1152
  LEX_YYSTYPE lookahead_yylval;
 
1153
 
 
1154
private:
 
1155
  /** Pointer to the current position in the raw input stream. */
 
1156
  const char *m_ptr;
 
1157
 
 
1158
  /** Starting position of the last token parsed, in the raw buffer. */
 
1159
  const char *m_tok_start;
 
1160
 
 
1161
  /** Ending position of the previous token parsed, in the raw buffer. */
 
1162
  const char *m_tok_end;
 
1163
 
 
1164
  /** End of the query text in the input stream, in the raw buffer. */
 
1165
  const char *m_end_of_query;
 
1166
 
 
1167
  /** Starting position of the previous token parsed, in the raw buffer. */
 
1168
  const char *m_tok_start_prev;
 
1169
 
 
1170
  /** Begining of the query text in the input stream, in the raw buffer. */
 
1171
  const char *m_buf;
 
1172
 
 
1173
  /** Length of the raw buffer. */
 
1174
  uint32_t m_buf_length;
 
1175
 
 
1176
  /** Echo the parsed stream to the pre-processed buffer. */
 
1177
  bool m_echo;
 
1178
 
 
1179
  /** Pre-processed buffer. */
 
1180
  char *m_cpp_buf;
 
1181
 
 
1182
  /** Pointer to the current position in the pre-processed input stream. */
 
1183
  char *m_cpp_ptr;
 
1184
 
 
1185
  /**
 
1186
    Starting position of the last token parsed,
 
1187
    in the pre-processed buffer.
 
1188
  */
 
1189
  const char *m_cpp_tok_start;
 
1190
 
 
1191
  /**
 
1192
    Starting position of the previous token parsed,
 
1193
    in the pre-procedded buffer.
 
1194
  */
 
1195
  const char *m_cpp_tok_start_prev;
 
1196
 
 
1197
  /**
 
1198
    Ending position of the previous token parsed,
 
1199
    in the pre-processed buffer.
 
1200
  */
 
1201
  const char *m_cpp_tok_end;
 
1202
 
 
1203
  /** UTF8-body buffer created during parsing. */
 
1204
  char *m_body_utf8;
 
1205
 
 
1206
  /** Pointer to the current position in the UTF8-body buffer. */
 
1207
  char *m_body_utf8_ptr;
 
1208
 
 
1209
  /**
 
1210
    Position in the pre-processed buffer. The query from m_cpp_buf to
 
1211
    m_cpp_utf_processed_ptr is converted to UTF8-body.
 
1212
  */
 
1213
  const char *m_cpp_utf8_processed_ptr;
 
1214
 
 
1215
public:
 
1216
 
 
1217
  /** Current state of the lexical analyser. */
 
1218
  enum my_lex_states next_state;
 
1219
 
 
1220
  /**
 
1221
    Position of ';' in the stream, to delimit multiple queries.
 
1222
    This delimiter is in the raw buffer.
 
1223
  */
 
1224
  const char *found_semicolon;
 
1225
 
 
1226
  /** Token character bitmaps, to detect 7bit strings. */
 
1227
  unsigned char tok_bitmap;
 
1228
 
 
1229
  /** SQL_MODE = IGNORE_SPACE. */
 
1230
  bool ignore_space;
 
1231
 
 
1232
  /** State of the lexical analyser for comments. */
 
1233
  enum_comment_state in_comment;
 
1234
 
 
1235
  /**
 
1236
    Starting position of the TEXT_STRING or IDENT in the pre-processed
 
1237
    buffer.
 
1238
 
 
1239
    NOTE: this member must be used within DRIZZLElex() function only.
 
1240
  */
 
1241
  const char *m_cpp_text_start;
 
1242
 
 
1243
  /**
 
1244
    Ending position of the TEXT_STRING or IDENT in the pre-processed
 
1245
    buffer.
 
1246
 
 
1247
    NOTE: this member must be used within DRIZZLElex() function only.
 
1248
    */
 
1249
  const char *m_cpp_text_end;
 
1250
 
 
1251
  /**
 
1252
    Character set specified by the character-set-introducer.
 
1253
 
 
1254
    NOTE: this member must be used within DRIZZLElex() function only.
 
1255
  */
 
1256
  const CHARSET_INFO *m_underscore_cs;
 
1257
};
 
1258
 
802
1259
 
803
1260
/* The state of the lex parsing. This is saved in the Session struct */
 
1261
 
804
1262
class LEX : public Query_tables_list
805
1263
{
806
1264
public:
807
 
  Select_Lex_Unit unit;                         /* most upper unit */
808
 
  Select_Lex select_lex;                        /* first Select_Lex */
809
 
  /* current Select_Lex in parsing */
810
 
  Select_Lex *current_select;
811
 
  /* list of all Select_Lex */
812
 
  Select_Lex *all_selects_list;
 
1265
  SELECT_LEX_UNIT unit;                         /* most upper unit */
 
1266
  SELECT_LEX select_lex;                        /* first SELECT_LEX */
 
1267
  /* current SELECT_LEX in parsing */
 
1268
  SELECT_LEX *current_select;
 
1269
  /* list of all SELECT_LEX */
 
1270
  SELECT_LEX *all_selects_list;
813
1271
 
814
 
  /* This is the "scale" for DECIMAL (S,P) notation */ 
815
 
  char *length;
816
 
  /* This is the decimal precision in DECIMAL(S,P) notation */
817
 
  char *dec;
818
 
  
819
 
  /**
820
 
   * This is used kind of like the "ident" member variable below, as 
821
 
   * a place to store certain names of identifiers.  Unfortunately, it
822
 
   * is used differently depending on the Command (SELECT on a derived
823
 
   * table vs CREATE)
824
 
   */
 
1272
  char *length,*dec,*change;
825
1273
  LEX_STRING name;
826
 
  /* The string literal used in a LIKE expression */
 
1274
  char *help_arg;
 
1275
  char* to_log;                                 /* For PURGE MASTER LOGS TO */
827
1276
  String *wild;
828
 
  file_exchange *exchange;
 
1277
  sql_exchange *exchange;
829
1278
  select_result *result;
830
 
 
831
 
  /**
832
 
   * This is current used to store the name of a named key cache
833
 
   * or a named savepoint.  It should probably be refactored out into
834
 
   * the eventual Command class built for the Keycache and Savepoint
835
 
   * commands.
836
 
   */ 
837
 
  LEX_STRING ident;
838
 
 
 
1279
  Item *default_value, *on_update_value;
 
1280
  LEX_STRING comment, ident;
 
1281
  XID *xid;
839
1282
  unsigned char* yacc_yyss, *yacc_yyvs;
840
 
  /* The owning Session of this LEX */
841
1283
  Session *session;
 
1284
  virtual_column_info *vcol_info;
 
1285
 
842
1286
  const CHARSET_INFO *charset;
843
1287
  bool text_string_is_7bit;
844
1288
  /* store original leaf_tables for INSERT SELECT and PS/SP */
847
1291
  List<Key_part_spec> col_list;
848
1292
  List<Key_part_spec> ref_list;
849
1293
  List<String>        interval_list;
850
 
  List<Lex_Column>    columns;
 
1294
  List<LEX_COLUMN>    columns;
851
1295
  List<Item>          *insert_list,field_list,value_list,update_list;
852
1296
  List<List_item>     many_values;
853
1297
  List<set_var_base>  var_list;
 
1298
  List<Item_param>    param_list;
854
1299
  /*
855
1300
    A stack of name resolution contexts for the query. This stack is used
856
1301
    at parse time to set local name resolution contexts for various parts
865
1310
    required a local context, the parser pops the top-most context.
866
1311
  */
867
1312
  List<Name_resolution_context> context_stack;
 
1313
  List<LEX_STRING>     db_list;
868
1314
 
869
 
  SQL_LIST auxiliary_table_list;
870
 
  SQL_LIST save_list;
871
 
  CreateField *last_field;
 
1315
  SQL_LIST            proc_list, auxiliary_table_list, save_list;
 
1316
  Create_field        *last_field;
872
1317
  Item_sum *in_sum_func;
873
 
  plugin::Function *udf;
 
1318
  udf_func udf;
 
1319
  HA_CHECK_OPT   check_opt;                     // check/repair options
 
1320
  HA_CREATE_INFO create_info;
 
1321
  KEY_CREATE_INFO key_create_info;
 
1322
  LEX_MASTER_INFO mi;                           // used by CHANGE MASTER
874
1323
  uint32_t type;
875
1324
  /*
876
1325
    This variable is used in post-parse stage to declare that sum-functions,
883
1332
  */
884
1333
  nesting_map allow_sum_func;
885
1334
  enum_sql_command sql_command;
886
 
  statement::Statement *statement;
887
1335
  /*
888
1336
    Usually `expr` rule of yacc is quite reused but some commands better
889
1337
    not support subqueries which comes standard with this rule, like
891
1339
    syntax error back.
892
1340
  */
893
1341
  bool expr_allows_subselect;
 
1342
  /*
 
1343
    A special command "PARSE_VCOL_EXPR" is defined for the parser
 
1344
    to translate an expression statement of a virtual column \
 
1345
    (stored in the *.frm file as a string) into an Item object.
 
1346
    The following flag is used to prevent other applications to use
 
1347
    this command.
 
1348
  */
 
1349
  bool parse_vcol_expr;
894
1350
 
895
1351
  thr_lock_type lock_option;
896
1352
  enum enum_duplicates duplicates;
 
1353
  enum enum_tx_isolation tx_isolation;
 
1354
  enum enum_ha_read_modes ha_read_mode;
897
1355
  union {
898
1356
    enum ha_rkey_function ha_rkey_mode;
899
1357
    enum xa_option_words xa_opt;
 
1358
    bool lock_transactional;            /* For LOCK Table ... IN ... MODE */
900
1359
  };
901
 
  sql_var_t option_type;
 
1360
  enum enum_var_type option_type;
902
1361
 
 
1362
  uint32_t profile_query_id;
 
1363
  uint32_t profile_options;
 
1364
  enum column_format_type column_format;
 
1365
  uint32_t which_columns;
 
1366
  enum Foreign_key::fk_match_opt fk_match_option;
 
1367
  enum Foreign_key::fk_option fk_update_opt;
 
1368
  enum Foreign_key::fk_option fk_delete_opt;
 
1369
  uint32_t slave_session_opt, start_transaction_opt;
903
1370
  int nest_level;
 
1371
  /*
 
1372
    In LEX representing update which were transformed to multi-update
 
1373
    stores total number of tables. For LEX representing multi-delete
 
1374
    holds number of tables from which we will delete records.
 
1375
  */
 
1376
  uint32_t table_count;
904
1377
  uint8_t describe;
905
1378
  /*
906
1379
    A flag that indicates what kinds of derived tables are present in the
907
1380
    query (0 if no derived tables, otherwise DERIVED_SUBQUERY).
908
1381
  */
909
1382
  uint8_t derived_tables;
910
 
 
911
 
  /* Was the IGNORE symbol found in statement */
912
 
  bool ignore;
 
1383
  bool drop_if_exists, drop_temporary, local_file, one_shot_set;
 
1384
  bool autocommit;
 
1385
  bool verbose;
 
1386
 
 
1387
  bool tx_chain, tx_release;
 
1388
  bool subqueries, ignore;
 
1389
  st_parsing_options parsing_options;
 
1390
  Alter_info alter_info;
 
1391
 
 
1392
  /*
 
1393
    Pointers to part of LOAD DATA statement that should be rewritten
 
1394
    during replication ("LOCAL 'filename' REPLACE INTO" part).
 
1395
  */
 
1396
  const char *fname_start;
 
1397
  const char *fname_end;
913
1398
 
914
1399
  /**
915
1400
    During name resolution search only in the table list given by
919
1404
  */
920
1405
  bool use_only_table_context;
921
1406
 
922
 
  /* Was the ESCAPE keyword used? */
923
1407
  bool escape_used;
924
1408
  bool is_lex_started; /* If lex_start() did run. For debugging. */
925
1409
 
926
1410
  LEX();
927
1411
 
928
 
  /* Note that init and de-init mostly happen in lex_start and lex_end
929
 
     and not here. This is because LEX isn't delete/new for each new
930
 
     statement in a session. It's re-used by doing lex_end, lex_start
931
 
     in sql_lex.cc
932
 
  */
933
1412
  virtual ~LEX()
934
1413
  {
 
1414
    destroy_query_tables_list();
935
1415
  }
936
1416
 
937
1417
  TableList *unlink_first_table(bool *link_to_local);
938
1418
  void link_first_table_back(TableList *first, bool link_to_local);
939
1419
  void first_lists_tables_same();
940
1420
 
 
1421
  bool only_view_structure();
 
1422
  bool need_correct_ident();
 
1423
 
941
1424
  void cleanup_after_one_table_open();
942
1425
 
943
1426
  bool push_context(Name_resolution_context *context)
982
1465
    }
983
1466
    return false;
984
1467
  }
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
 
  }
999
 
 
1000
 
  void setSumExprUsed()
1001
 
  {
1002
 
    sum_expr_used= true;
1003
 
  }
1004
 
 
1005
 
  bool isSumExprUsed()
1006
 
  {
1007
 
    return sum_expr_used;
1008
 
  }
1009
 
 
1010
 
  void start(Session *session);
1011
 
  void end();
1012
 
 
1013
 
private: 
1014
 
  bool cacheable;
1015
 
  bool sum_expr_used;
1016
 
};
1017
 
 
 
1468
};
 
1469
 
 
1470
struct st_lex_local: public LEX
 
1471
{
 
1472
  static void *operator new(size_t size) throw()
 
1473
  {
 
1474
    return sql_alloc(size);
 
1475
  }
 
1476
  static void *operator new(size_t size, MEM_ROOT *mem_root) throw()
 
1477
  {
 
1478
    return (void*) alloc_root(mem_root, (uint32_t) size);
 
1479
  }
 
1480
  static void operator delete(void *, size_t)
 
1481
  { TRASH(ptr, size); }
 
1482
  static void operator delete(void *, MEM_ROOT *)
 
1483
  { /* Never called */ }
 
1484
};
 
1485
 
 
1486
extern void lex_init(void);
 
1487
extern void lex_free(void);
1018
1488
extern void lex_start(Session *session);
 
1489
extern void lex_end(LEX *lex);
 
1490
 
1019
1491
extern void trim_whitespace(const CHARSET_INFO * const cs, LEX_STRING *str);
 
1492
 
1020
1493
extern bool is_lex_native_function(const LEX_STRING *name);
1021
1494
 
 
1495
int lex_casecmp(const char *s, const char *t, uint32_t len);
 
1496
 
1022
1497
/**
1023
1498
  @} (End of group Semantic_Analysis)
1024
1499
*/
1025
1500
 
1026
 
} /* namespace drizzled */
1027
 
 
1028
1501
#endif /* DRIZZLE_SERVER */
1029
 
#endif /* DRIZZLED_SQL_LEX_H */
 
1502
#endif /* DRIZZLE_SERVER_SQL_LEX_H */