~drizzle-trunk/drizzle/development

390.1.2 by Monty Taylor
Fixed copyright headers in drizzled/
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (C) 2008 Sun Microsystems
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; version 2 of the License.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU General Public License
16
 *  along with this program; if not, write to the Free Software
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 */
1 by brian
clean slate
19
243.1.8 by Jay Pipes
More cleanup and revert broken base.h
20
#ifndef DRIZZLE_SERVER_SQL_LEX_H
21
#define DRIZZLE_SERVER_SQL_LEX_H
22
1 by brian
clean slate
23
/**
24
  @defgroup Semantic_Analysis Semantic Analysis
25
*/
26
584.4.4 by Monty Taylor
Split out Name_resolution_context.
27
#include <drizzled/sql_udf.h>
28
#include <drizzled/name_resolution_context.h>
584.4.7 by Monty Taylor
Removed a big bank of includes from item.h.
29
#include <drizzled/item/subselect.h>
642.1.18 by Lee
header file clean up
30
#include <drizzled/item/param.h>
642.1.19 by Lee
header file clean up
31
#include <drizzled/item/outer_ref.h>
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
32
#include <drizzled/table_list.h>
642.1.30 by Lee
move math functions to drizzled/function/math directory
33
#include <drizzled/function/math/real.h>
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
34
#include <drizzled/alter_drop.h>
35
#include <drizzled/alter_column.h>
36
#include <drizzled/key.h>
37
#include <drizzled/foreign_key.h>
675 by Brian Aker
Cleanup around item includes.
38
#include <drizzled/item/param.h>
139.1.8 by Stewart Smith
UDFs are now normal Item_func objects. Simplifies handling them a lot.
39
584.4.7 by Monty Taylor
Removed a big bank of includes from item.h.
40
class select_result_interceptor;
584.1.14 by Monty Taylor
Removed field.h from common_includes.
41
class virtual_column_info;
42
1 by brian
clean slate
43
/* YACC and LEX Definitions */
44
45
/* These may not be declared yet */
46
class Table_ident;
831.1.2 by Brian Aker
Rename class file_exchange
47
class file_exchange;
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
48
class Lex_Column;
675 by Brian Aker
Cleanup around item includes.
49
class Item_outer_ref;
1 by brian
clean slate
50
51
/*
52
  The following hack is needed because mysql_yacc.cc does not define
53
  YYSTYPE before including this file
54
*/
55
722.1.4 by Monty Taylor
Removed all the setting of DEFS everywhere. Use configmake.h to get the values
56
#ifdef DRIZZLE_SERVER
57
# include <drizzled/set_var.h>
58
# include <drizzled/item/func.h>
59
# ifdef DRIZZLE_YACC
60
#  define LEX_YYSTYPE void *
61
# else
62
#  if defined(DRIZZLE_LEX)
63
#   include <drizzled/lex_symbol.h>
64
#   include <drizzled/sql_yacc.h>
65
#   define LEX_YYSTYPE YYSTYPE *
66
#  else
67
#   define LEX_YYSTYPE void *
68
#  endif /* defined(DRIZZLE_LEX) */
69
# endif /* DRIZZLE_YACC */
70
#endif /* DRIZZLE_SERVER */
1 by brian
clean slate
71
72
// describe/explain types
73
#define DESCRIBE_NORMAL		1
74
#define DESCRIBE_EXTENDED	2
75
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
76
#ifdef DRIZZLE_SERVER
1 by brian
clean slate
77
78
#define DERIVED_NONE	0
79
#define DERIVED_SUBQUERY	1
80
81
typedef List<Item> List_item;
82
83
/* SERVERS CACHE CHANGES */
84
typedef struct st_lex_server_options
85
{
202 by Brian Aker
Cleanup sql_lex to modern types.
86
  int32_t port;
87
  uint32_t server_name_length;
185 by Brian Aker
More dead code baby... it has become a little like drilling for oil. Alaska
88
  char *server_name, *host, *db, *username, *password, *scheme, *owner;
1 by brian
clean slate
89
} LEX_SERVER_OPTIONS;
90
91
92
enum sub_select_type
93
{
94
  UNSPECIFIED_TYPE,UNION_TYPE, INTERSECT_TYPE,
95
  EXCEPT_TYPE, GLOBAL_OPTIONS_TYPE, DERIVED_TABLE_TYPE, OLAP_TYPE
96
};
97
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
98
enum olap_type
1 by brian
clean slate
99
{
100
  UNSPECIFIED_OLAP_TYPE, CUBE_TYPE, ROLLUP_TYPE
101
};
102
103
enum tablespace_op_type
104
{
105
  NO_TABLESPACE_OP, DISCARD_TABLESPACE, IMPORT_TABLESPACE
106
};
107
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
108
/*
1 by brian
clean slate
109
  String names used to print a statement with index hints.
110
  Keep in sync with index_hint_type.
111
*/
112
extern const char * index_hint_type_name[];
481 by Brian Aker
Remove all of uchar.
113
typedef unsigned char index_clause_map;
1 by brian
clean slate
114
115
/*
116
  Bits in index_clause_map : one for each possible FOR clause in
117
  USE/FORCE/IGNORE INDEX index hint specification
118
*/
119
#define INDEX_HINT_MASK_JOIN  (1)
120
#define INDEX_HINT_MASK_GROUP (1 << 1)
121
#define INDEX_HINT_MASK_ORDER (1 << 2)
122
123
#define INDEX_HINT_MASK_ALL (INDEX_HINT_MASK_JOIN | INDEX_HINT_MASK_GROUP | \
124
                             INDEX_HINT_MASK_ORDER)
125
126
/* Single element of an USE/FORCE/IGNORE INDEX list specified as a SQL hint  */
127
class Index_hint : public Sql_alloc
128
{
129
public:
130
  /* The type of the hint : USE/FORCE/IGNORE */
131
  enum index_hint_type type;
132
  /* Where the hit applies to. A bitmask of INDEX_HINT_MASK_<place> values */
133
  index_clause_map clause;
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
134
  /*
135
    The index name. Empty (str=NULL) name represents an empty list
136
    USE INDEX () clause
137
  */
1 by brian
clean slate
138
  LEX_STRING key_name;
139
140
  Index_hint (enum index_hint_type type_arg, index_clause_map clause_arg,
202 by Brian Aker
Cleanup sql_lex to modern types.
141
              char *str, uint32_t length) :
1 by brian
clean slate
142
    type(type_arg), clause(clause_arg)
143
  {
144
    key_name.str= str;
145
    key_name.length= length;
146
  }
147
520.1.22 by Brian Aker
Second pass of thd cleanup
148
  void print(Session *session, String *str);
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
149
};
150
151
/*
152
  The state of the lex parsing for selects
153
1 by brian
clean slate
154
   master and slaves are pointers to select_lex.
155
   master is pointer to upper level node.
156
   slave is pointer to lower level node
157
   select_lex is a SELECT without union
158
   unit is container of either
159
     - One SELECT
160
     - UNION of selects
161
   select_lex and unit are both inherited form select_lex_node
162
   neighbors are two select_lex or units on the same level
163
164
   All select describing structures linked with following pointers:
165
   - list of neighbors (next/prev) (prev of first element point to slave
166
     pointer of upper structure)
167
     - For select this is a list of UNION's (or one element list)
168
     - For units this is a list of sub queries for the upper level select
169
170
   - pointer to master (master), which is
171
     If this is a unit
172
       - pointer to outer select_lex
173
     If this is a select_lex
174
       - pointer to outer unit structure for select
175
176
   - pointer to slave (slave), which is either:
177
     If this is a unit:
178
       - first SELECT that belong to this unit
179
     If this is a select_lex
180
       - first unit that belong to this SELECT (subquries or derived tables)
181
182
   - list of all select_lex (link_next/link_prev)
183
     This is to be used for things like derived tables creation, where we
184
     go through this list and create the derived tables.
185
186
   If unit contain several selects (UNION now, INTERSECT etc later)
187
   then it have special select_lex called fake_select_lex. It used for
188
   storing global parameters (like ORDER BY, LIMIT) and executing union.
189
   Subqueries used in global ORDER BY clause will be attached to this
190
   fake_select_lex, which will allow them correctly resolve fields of
191
   'upper' UNION and outer selects.
192
193
   For example for following query:
194
195
   select *
196
     from table1
197
     where table1.field IN (select * from table1_1_1 union
198
                            select * from table1_1_2)
199
     union
200
   select *
201
     from table2
202
     where table2.field=(select (select f1 from table2_1_1_1_1
203
                                   where table2_1_1_1_1.f2=table2_1_1.f3)
204
                           from table2_1_1
205
                           where table2_1_1.f1=table2.f2)
206
     union
207
   select * from table3;
208
209
   we will have following structure:
210
211
   select1: (select * from table1 ...)
212
   select2: (select * from table2 ...)
213
   select3: (select * from table3)
214
   select1.1.1: (select * from table1_1_1)
215
   ...
216
217
     main unit
218
     fake0
219
     select1 select2 select3
220
     |^^     |^
221
    s|||     ||master
222
    l|||     |+---------------------------------+
223
    a|||     +---------------------------------+|
224
    v|||master                         slave   ||
225
    e||+-------------------------+             ||
226
     V|            neighbor      |             V|
227
     unit1.1<+==================>unit1.2       unit2.1
228
     fake1.1
229
     select1.1.1 select 1.1.2    select1.2.1   select2.1.1
230
                                               |^
231
                                               ||
232
                                               V|
233
                                               unit2.1.1.1
234
                                               select2.1.1.1.1
235
236
237
   relation in main unit will be following:
238
   (bigger picture for:
239
      main unit
240
      fake0
241
      select1 select2 select3
242
   in the above picture)
243
244
         main unit
245
         |^^^^|fake_select_lex
246
         |||||+--------------------------------------------+
247
         ||||+--------------------------------------------+|
248
         |||+------------------------------+              ||
249
         ||+--------------+                |              ||
250
    slave||master         |                |              ||
251
         V|      neighbor |       neighbor |        master|V
252
         select1<========>select2<========>select3        fake0
253
254
    list of all select_lex will be following (as it will be constructed by
255
    parser):
256
257
    select1->select2->select3->select2.1.1->select 2.1.2->select2.1.1.1.1-+
258
                                                                          |
259
    +---------------------------------------------------------------------+
260
    |
261
    +->select1.1.1->select1.1.2
262
263
*/
264
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
265
/*
846 by Brian Aker
Removing on typedeffed class.
266
    Base class for Select_Lex (Select_Lex) &
848 by Brian Aker
typdef class removal (just... use the name of the class).
267
    Select_Lex_Unit (Select_Lex_Unit)
1 by brian
clean slate
268
*/
575.4.7 by Monty Taylor
More header cleanup.
269
class LEX;
846 by Brian Aker
Removing on typedeffed class.
270
class Select_Lex;
848 by Brian Aker
typdef class removal (just... use the name of the class).
271
class Select_Lex_Unit;
847 by Brian Aker
More typdef class removal.
272
class Select_Lex_Node {
1 by brian
clean slate
273
protected:
847 by Brian Aker
More typdef class removal.
274
  Select_Lex_Node *next, **prev,   /* neighbor list */
1 by brian
clean slate
275
    *master, *slave,                  /* vertical links */
846 by Brian Aker
Removing on typedeffed class.
276
    *link_next, **link_prev;          /* list of whole Select_Lex */
1 by brian
clean slate
277
public:
278
151 by Brian Aker
Ulonglong to uint64_t
279
  uint64_t options;
1 by brian
clean slate
280
281
  /*
282
    result of this query can't be cached, bit field, can be :
283
      UNCACHEABLE_DEPENDENT
284
      UNCACHEABLE_RAND
285
      UNCACHEABLE_SIDEEFFECT
286
      UNCACHEABLE_EXPLAIN
287
      UNCACHEABLE_PREPARE
288
  */
202 by Brian Aker
Cleanup sql_lex to modern types.
289
  uint8_t uncacheable;
1 by brian
clean slate
290
  enum sub_select_type linkage;
291
  bool no_table_names_allowed; /* used for global order by */
292
  bool no_error; /* suppress error message (convert it to warnings) */
293
294
  static void *operator new(size_t size)
295
  {
296
    return sql_alloc(size);
297
  }
298
  static void *operator new(size_t size, MEM_ROOT *mem_root)
202 by Brian Aker
Cleanup sql_lex to modern types.
299
  { return (void*) alloc_root(mem_root, (uint32_t) size); }
644 by Brian Aker
Clean up warnings for Solaris.
300
  static void operator delete(void *, size_t)
77.1.7 by Monty Taylor
Heap builds clean.
301
  { TRASH(ptr, size); }
644 by Brian Aker
Clean up warnings for Solaris.
302
  static void operator delete(void *, MEM_ROOT *)
77.1.7 by Monty Taylor
Heap builds clean.
303
  {}
847 by Brian Aker
More typdef class removal.
304
  Select_Lex_Node(): linkage(UNSPECIFIED_TYPE) {}
305
  virtual ~Select_Lex_Node() {}
306
  inline Select_Lex_Node* get_master() { return master; }
1 by brian
clean slate
307
  virtual void init_query();
308
  virtual void init_select();
847 by Brian Aker
More typdef class removal.
309
  void include_down(Select_Lex_Node *upper);
310
  void include_neighbour(Select_Lex_Node *before);
311
  void include_standalone(Select_Lex_Node *sel, Select_Lex_Node **ref);
312
  void include_global(Select_Lex_Node **plink);
1 by brian
clean slate
313
  void exclude();
314
848 by Brian Aker
typdef class removal (just... use the name of the class).
315
  virtual Select_Lex_Unit* master_unit()= 0;
846 by Brian Aker
Removing on typedeffed class.
316
  virtual Select_Lex* outer_select()= 0;
317
  virtual Select_Lex* return_after_parsing()= 0;
1 by brian
clean slate
318
319
  virtual bool set_braces(bool value);
320
  virtual bool inc_in_sum_expr();
202 by Brian Aker
Cleanup sql_lex to modern types.
321
  virtual uint32_t get_in_sum_expr();
327.2.4 by Brian Aker
Refactoring table.h
322
  virtual TableList* get_table_list();
1 by brian
clean slate
323
  virtual List<Item>* get_item_list();
202 by Brian Aker
Cleanup sql_lex to modern types.
324
  virtual uint32_t get_table_join_options();
520.1.22 by Brian Aker
Second pass of thd cleanup
325
  virtual TableList *add_table_to_list(Session *session, Table_ident *table,
77.1.7 by Monty Taylor
Heap builds clean.
326
                                        LEX_STRING *alias,
202 by Brian Aker
Cleanup sql_lex to modern types.
327
                                        uint32_t table_options,
77.1.7 by Monty Taylor
Heap builds clean.
328
                                        thr_lock_type flags= TL_UNLOCK,
329
                                        List<Index_hint> *hints= 0,
1 by brian
clean slate
330
                                        LEX_STRING *option= 0);
644 by Brian Aker
Clean up warnings for Solaris.
331
  virtual void set_lock_for_tables(thr_lock_type)
77.1.7 by Monty Taylor
Heap builds clean.
332
  {}
1 by brian
clean slate
333
848 by Brian Aker
typdef class removal (just... use the name of the class).
334
  friend class Select_Lex_Unit;
575.4.7 by Monty Taylor
More header cleanup.
335
  friend bool mysql_new_select(LEX *lex, bool move_down);
1 by brian
clean slate
336
private:
337
  void fast_exclude();
338
};
339
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
340
/*
848 by Brian Aker
typdef class removal (just... use the name of the class).
341
   Select_Lex_Unit - unit of selects (UNION, INTERSECT, ...) group
846 by Brian Aker
Removing on typedeffed class.
342
   Select_Lexs
1 by brian
clean slate
343
*/
520.1.21 by Brian Aker
THD -> Session rename
344
class Session;
1 by brian
clean slate
345
class select_result;
346
class JOIN;
347
class select_union;
848 by Brian Aker
typdef class removal (just... use the name of the class).
348
class Select_Lex_Unit: public Select_Lex_Node {
1 by brian
clean slate
349
protected:
327.2.4 by Brian Aker
Refactoring table.h
350
  TableList result_table_list;
1 by brian
clean slate
351
  select_union *union_result;
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
352
  Table *table; /* temporary table using for appending UNION results */
1 by brian
clean slate
353
354
  select_result *result;
151 by Brian Aker
Ulonglong to uint64_t
355
  uint64_t found_rows_for_union;
1 by brian
clean slate
356
  bool saved_error;
357
358
public:
359
  bool  prepared, // prepare phase already performed for UNION (unit)
360
    optimized, // optimize phase already performed for UNION (unit)
361
    executed, // already executed
362
    cleaned;
363
364
  // list of fields which points to temporary table for union
365
  List<Item> item_list;
366
  /*
367
    list of types of items inside union (used for union & derived tables)
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
368
1 by brian
clean slate
369
    Item_type_holders from which this list consist may have pointers to Field,
370
    pointers is valid only after preparing SELECTS of this unit and before
371
    any SELECT of this unit execution
372
373
    TODO:
374
    Possibly this member should be protected, and its direct use replaced
375
    by get_unit_column_types(). Check the places where it is used.
376
  */
377
  List<Item> types;
378
  /*
379
    Pointer to 'last' select or pointer to unit where stored
380
    global parameters for union
381
  */
846 by Brian Aker
Removing on typedeffed class.
382
  Select_Lex *global_parameters;
1 by brian
clean slate
383
  //node on wich we should return current_select pointer after parsing subquery
846 by Brian Aker
Removing on typedeffed class.
384
  Select_Lex *return_to;
1 by brian
clean slate
385
  /* LIMIT clause runtime counters */
386
  ha_rows select_limit_cnt, offset_limit_cnt;
387
  /* not NULL if unit used in subselect, point to subselect item */
388
  Item_subselect *item;
389
  /* thread handler */
520.1.22 by Brian Aker
Second pass of thd cleanup
390
  Session *session;
1 by brian
clean slate
391
  /*
846 by Brian Aker
Removing on typedeffed class.
392
    Select_Lex for hidden SELECT in onion which process global
1 by brian
clean slate
393
    ORDER BY and LIMIT
394
  */
846 by Brian Aker
Removing on typedeffed class.
395
  Select_Lex *fake_select_lex;
1 by brian
clean slate
396
846 by Brian Aker
Removing on typedeffed class.
397
  Select_Lex *union_distinct; /* pointer to the last UNION DISTINCT */
1 by brian
clean slate
398
  bool describe; /* union exec() called for EXPLAIN */
399
400
  void init_query();
848 by Brian Aker
typdef class removal (just... use the name of the class).
401
  Select_Lex_Unit* master_unit();
846 by Brian Aker
Removing on typedeffed class.
402
  Select_Lex* outer_select();
403
  Select_Lex* first_select()
404
  {
405
    return reinterpret_cast<Select_Lex*>(slave);
406
  }
848 by Brian Aker
typdef class removal (just... use the name of the class).
407
  Select_Lex_Unit* next_unit()
846 by Brian Aker
Removing on typedeffed class.
408
  {
848 by Brian Aker
typdef class removal (just... use the name of the class).
409
    return reinterpret_cast<Select_Lex_Unit*>(next);
846 by Brian Aker
Removing on typedeffed class.
410
  }
411
  Select_Lex* return_after_parsing() { return return_to; }
1 by brian
clean slate
412
  void exclude_level();
413
  void exclude_tree();
414
415
  /* UNION methods */
520.1.22 by Brian Aker
Second pass of thd cleanup
416
  bool prepare(Session *session, select_result *result, uint32_t additional_options);
1 by brian
clean slate
417
  bool exec();
418
  bool cleanup();
419
  inline void unclean() { cleaned= 0; }
420
  void reinit_exec_mechanism();
421
422
  void print(String *str, enum_query_type query_type);
423
520.1.22 by Brian Aker
Second pass of thd cleanup
424
  bool add_fake_select_lex(Session *session);
425
  void init_prepare_fake_select_lex(Session *session);
1 by brian
clean slate
426
  bool change_result(select_result_interceptor *result,
427
                     select_result_interceptor *old_result);
846 by Brian Aker
Removing on typedeffed class.
428
  void set_limit(Select_Lex *values);
520.1.22 by Brian Aker
Second pass of thd cleanup
429
  void set_session(Session *session_arg) { session= session_arg; }
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
430
  inline bool is_union ();
1 by brian
clean slate
431
520.1.22 by Brian Aker
Second pass of thd cleanup
432
  friend void lex_start(Session *session);
1 by brian
clean slate
433
  friend int subselect_union_engine::exec();
434
435
  List<Item> *get_unit_column_types();
436
};
437
438
/*
846 by Brian Aker
Removing on typedeffed class.
439
  Select_Lex - store information of parsed SELECT statment
1 by brian
clean slate
440
*/
847 by Brian Aker
More typdef class removal.
441
class Select_Lex: public Select_Lex_Node
1 by brian
clean slate
442
{
443
public:
444
  Name_resolution_context context;
445
  char *db;
446
  Item *where, *having;                         /* WHERE & HAVING clauses */
447
  /* Saved values of the WHERE and HAVING clauses*/
448
  Item::cond_result cond_value, having_value;
449
  /* point on lex in which it was created, used in view subquery detection */
575.4.7 by Monty Taylor
More header cleanup.
450
  LEX *parent_lex;
1 by brian
clean slate
451
  enum olap_type olap;
327.2.4 by Brian Aker
Refactoring table.h
452
  /* FROM clause - points to the beginning of the TableList::next_local list. */
1 by brian
clean slate
453
  SQL_LIST	      table_list;
454
  SQL_LIST	      group_list; /* GROUP BY clause. */
455
  List<Item>          item_list;  /* list of fields & expressions */
456
  List<String>        interval_list;
457
  bool	              is_item_list_lookup;
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
458
  /*
459
    Despite their names, the following are used in unions. This should
1 by brian
clean slate
460
    be rewritten. -Brian
461
  */
462
  List<Item_real_func> *ftfunc_list;
463
  List<Item_real_func> ftfunc_list_alloc;
464
  JOIN *join; /* after JOIN::prepare it is pointer to corresponding JOIN */
327.2.4 by Brian Aker
Refactoring table.h
465
  List<TableList> top_join_list; /* join list of the top level          */
466
  List<TableList> *join_list;    /* list for the currently parsed join  */
467
  TableList *embedding;          /* table embedding to the above list   */
468
  List<TableList> sj_nests;
1 by brian
clean slate
469
  /*
470
    Beginning of the list of leaves in a FROM clause, where the leaves
471
    inlcude all base tables including view tables. The tables are connected
327.2.4 by Brian Aker
Refactoring table.h
472
    by TableList::next_leaf, so leaf_tables points to the left-most leaf.
1 by brian
clean slate
473
  */
327.2.4 by Brian Aker
Refactoring table.h
474
  TableList *leaf_tables;
1 by brian
clean slate
475
  const char *type;               /* type of select for EXPLAIN          */
476
477
  SQL_LIST order_list;                /* ORDER clause */
478
  SQL_LIST *gorder_list;
479
  Item *select_limit, *offset_limit;  /* LIMIT clause parameters */
480
  // Arrays of pointers to top elements of all_fields list
481
  Item **ref_pointer_array;
482
483
  /*
484
    number of items in select_list and HAVING clause used to get number
485
    bigger then can be number of entries that will be added to all item
486
    list during split_sum_func
487
  */
202 by Brian Aker
Cleanup sql_lex to modern types.
488
  uint32_t select_n_having_items;
489
  uint32_t cond_count;    /* number of arguments of and/or/xor in where/having/on */
490
  uint32_t between_count; /* number of between predicates in where/having/on      */
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
491
  uint32_t max_equal_elems; /* maximal number of elements in multiple equalities  */
1 by brian
clean slate
492
  /*
493
    Number of fields used in select list or where clause of current select
494
    and all inner subselects.
495
  */
202 by Brian Aker
Cleanup sql_lex to modern types.
496
  uint32_t select_n_where_fields;
1 by brian
clean slate
497
  enum_parsing_place parsing_place; /* where we are parsing expression */
498
  bool with_sum_func;   /* sum function indicator */
499
202 by Brian Aker
Cleanup sql_lex to modern types.
500
  uint32_t table_join_options;
501
  uint32_t in_sum_expr;
502
  uint32_t select_number; /* number of select (used for EXPLAIN) */
1 by brian
clean slate
503
  int nest_level;     /* nesting level of select */
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
504
  Item_sum *inner_sum_func_list; /* list of sum func in nested selects */
202 by Brian Aker
Cleanup sql_lex to modern types.
505
  uint32_t with_wild; /* item list contain '*' */
1 by brian
clean slate
506
  bool  braces;   	/* SELECT ... UNION (SELECT ... ) <- this braces */
51.1.52 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
507
  /* true when having fix field called in processing of this SELECT */
1 by brian
clean slate
508
  bool having_fix_field;
509
  /* List of references to fields referenced from inner selects */
510
  List<Item_outer_ref> inner_refs_list;
511
  /* Number of Item_sum-derived objects in this SELECT */
202 by Brian Aker
Cleanup sql_lex to modern types.
512
  uint32_t n_sum_items;
1 by brian
clean slate
513
  /* Number of Item_sum-derived objects in children and descendant SELECTs */
202 by Brian Aker
Cleanup sql_lex to modern types.
514
  uint32_t n_child_sum_items;
1 by brian
clean slate
515
516
  /* explicit LIMIT clause was used */
517
  bool explicit_limit;
518
  /*
519
    there are subquery in HAVING clause => we can't close tables before
520
    query processing end even if we use temporary table
521
  */
522
  bool subquery_in_having;
51.1.52 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
523
  /* true <=> this SELECT is correlated w.r.t. some ancestor select */
1 by brian
clean slate
524
  bool is_correlated;
525
  /* exclude this select from check of unique_table() */
526
  bool exclude_from_table_unique_test;
527
  /* List of fields that aren't under an aggregate function */
528
  List<Item_field> non_agg_fields;
529
  /* index in the select list of the expression currently being fixed */
530
  int cur_pos_in_select_list;
531
532
  List<udf_func>     udf_list;                  /* udf function calls stack */
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
533
  /*
1 by brian
clean slate
534
    This is a copy of the original JOIN USING list that comes from
535
    the parser. The parser :
327.2.4 by Brian Aker
Refactoring table.h
536
      1. Sets the natural_join of the second TableList in the join
846 by Brian Aker
Removing on typedeffed class.
537
         and the Select_Lex::prev_join_using.
327.2.4 by Brian Aker
Refactoring table.h
538
      2. Makes a parent TableList and sets its is_natural_join/
1 by brian
clean slate
539
       join_using_fields members.
327.2.4 by Brian Aker
Refactoring table.h
540
      3. Uses the wrapper TableList as a table in the upper level.
1 by brian
clean slate
541
    We cannot assign directly to join_using_fields in the parser because
327.2.4 by Brian Aker
Refactoring table.h
542
    at stage (1.) the parent TableList is not constructed yet and
1 by brian
clean slate
543
    the assignment will override the JOIN USING fields of the lower level
544
    joins on the right.
545
  */
546
  List<String> *prev_join_using;
547
  /*
548
    Bitmap used in the ONLY_FULL_GROUP_BY_MODE to prevent mixture of aggregate
549
    functions and non aggregated fields when GROUP BY list is absent.
550
    Bits:
551
      0 - non aggregated fields are used in this select,
552
          defined as NON_AGG_FIELD_USED.
553
      1 - aggregate functions are used in this select,
554
          defined as SUM_FUNC_USED.
555
  */
202 by Brian Aker
Cleanup sql_lex to modern types.
556
  uint8_t full_group_by_flag;
1 by brian
clean slate
557
  void init_query();
558
  void init_select();
848 by Brian Aker
typdef class removal (just... use the name of the class).
559
  Select_Lex_Unit* master_unit();
560
  Select_Lex_Unit* first_inner_unit()
846 by Brian Aker
Removing on typedeffed class.
561
  {
848 by Brian Aker
typdef class removal (just... use the name of the class).
562
    return (Select_Lex_Unit*) slave;
846 by Brian Aker
Removing on typedeffed class.
563
  }
564
  Select_Lex* outer_select();
565
  Select_Lex* next_select() { return (Select_Lex*) next; }
566
  Select_Lex* next_select_in_list()
567
  {
568
    return (Select_Lex*) link_next;
569
  }
847 by Brian Aker
More typdef class removal.
570
  Select_Lex_Node** next_select_in_list_addr()
1 by brian
clean slate
571
  {
572
    return &link_next;
573
  }
846 by Brian Aker
Removing on typedeffed class.
574
  Select_Lex* return_after_parsing()
1 by brian
clean slate
575
  {
576
    return master_unit()->return_after_parsing();
577
  }
578
846 by Brian Aker
Removing on typedeffed class.
579
  void mark_as_dependent(Select_Lex *last);
1 by brian
clean slate
580
581
  bool set_braces(bool value);
582
  bool inc_in_sum_expr();
202 by Brian Aker
Cleanup sql_lex to modern types.
583
  uint32_t get_in_sum_expr();
1 by brian
clean slate
584
520.1.22 by Brian Aker
Second pass of thd cleanup
585
  bool add_item_to_list(Session *session, Item *item);
586
  bool add_group_to_list(Session *session, Item *item, bool asc);
587
  bool add_order_to_list(Session *session, Item *item, bool asc);
588
  TableList* add_table_to_list(Session *session, Table_ident *table,
1 by brian
clean slate
589
				LEX_STRING *alias,
202 by Brian Aker
Cleanup sql_lex to modern types.
590
				uint32_t table_options,
1 by brian
clean slate
591
				thr_lock_type flags= TL_UNLOCK,
592
				List<Index_hint> *hints= 0,
593
                                LEX_STRING *option= 0);
327.2.4 by Brian Aker
Refactoring table.h
594
  TableList* get_table_list();
520.1.22 by Brian Aker
Second pass of thd cleanup
595
  bool init_nested_join(Session *session);
596
  TableList *end_nested_join(Session *session);
597
  TableList *nest_last_join(Session *session);
327.2.4 by Brian Aker
Refactoring table.h
598
  void add_joined_table(TableList *table);
599
  TableList *convert_right_join();
1 by brian
clean slate
600
  List<Item>* get_item_list();
202 by Brian Aker
Cleanup sql_lex to modern types.
601
  uint32_t get_table_join_options();
1 by brian
clean slate
602
  void set_lock_for_tables(thr_lock_type lock_type);
603
  inline void init_order()
604
  {
605
    order_list.elements= 0;
606
    order_list.first= 0;
481 by Brian Aker
Remove all of uchar.
607
    order_list.next= (unsigned char**) &order_list.first;
1 by brian
clean slate
608
  }
609
  /*
610
    This method created for reiniting LEX in mysql_admin_table() and can be
846 by Brian Aker
Removing on typedeffed class.
611
    used only if you are going remove all Select_Lex & units except belonger
1 by brian
clean slate
612
    to LEX (LEX::unit & LEX::select, for other purposes there are
848 by Brian Aker
typdef class removal (just... use the name of the class).
613
    Select_Lex_Unit::exclude_level & Select_Lex_Unit::exclude_tree
1 by brian
clean slate
614
  */
615
  void cut_subtree() { slave= 0; }
616
  bool test_limit();
617
520.1.22 by Brian Aker
Second pass of thd cleanup
618
  friend void lex_start(Session *session);
846 by Brian Aker
Removing on typedeffed class.
619
  Select_Lex() : n_sum_items(0), n_child_sum_items(0) {}
1 by brian
clean slate
620
  void make_empty_select()
621
  {
622
    init_query();
623
    init_select();
624
  }
520.1.22 by Brian Aker
Second pass of thd cleanup
625
  bool setup_ref_array(Session *session, uint32_t order_group_num);
626
  void print(Session *session, String *str, enum_query_type query_type);
1 by brian
clean slate
627
  static void print_order(String *str,
327.2.3 by Brian Aker
Refactoring of class Table
628
                          order_st *order,
1 by brian
clean slate
629
                          enum_query_type query_type);
520.1.22 by Brian Aker
Second pass of thd cleanup
630
  void print_limit(Session *session, String *str, enum_query_type query_type);
631
  void fix_prepare_information(Session *session, Item **conds, Item **having_conds);
1 by brian
clean slate
632
  /*
633
    Destroy the used execution plan (JOIN) of this subtree (this
848 by Brian Aker
typdef class removal (just... use the name of the class).
634
    Select_Lex and all nested Select_Lexes and Select_Lex_Units).
1 by brian
clean slate
635
  */
636
  bool cleanup();
637
  /*
638
    Recursively cleanup the join of this select lex and of all nested
639
    select lexes.
640
  */
641
  void cleanup_all_joins(bool full);
642
643
  void set_index_hint_type(enum index_hint_type type, index_clause_map clause);
644
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
645
  /*
1 by brian
clean slate
646
   Add a index hint to the tagged list of hints. The type and clause of the
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
647
   hint will be the current ones (set by set_index_hint())
1 by brian
clean slate
648
  */
520.1.22 by Brian Aker
Second pass of thd cleanup
649
  bool add_index_hint (Session *session, char *str, uint32_t length);
1 by brian
clean slate
650
651
  /* make a list to hold index hints */
520.1.22 by Brian Aker
Second pass of thd cleanup
652
  void alloc_index_hints (Session *session);
1 by brian
clean slate
653
  /* read and clear the index hints */
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
654
  List<Index_hint>* pop_index_hints(void)
1 by brian
clean slate
655
  {
656
    List<Index_hint> *hints= index_hints;
657
    index_hints= NULL;
658
    return hints;
659
  }
660
661
  void clear_index_hints(void) { index_hints= NULL; }
662
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
663
private:
1 by brian
clean slate
664
  /* current index hint kind. used in filling up index_hints */
665
  enum index_hint_type current_index_hint_type;
666
  index_clause_map current_index_hint_clause;
667
  /* a list of USE/FORCE/IGNORE INDEX */
668
  List<Index_hint> *index_hints;
669
};
670
848 by Brian Aker
typdef class removal (just... use the name of the class).
671
inline bool Select_Lex_Unit::is_union ()
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
672
{
673
  return first_select()->next_select() &&
1 by brian
clean slate
674
    first_select()->next_select()->linkage == UNION_TYPE;
675
}
676
677
#define ALTER_ADD_COLUMN	(1L << 0)
678
#define ALTER_DROP_COLUMN	(1L << 1)
679
#define ALTER_CHANGE_COLUMN	(1L << 2)
680
#define ALTER_COLUMN_STORAGE	(1L << 3)
681
#define ALTER_COLUMN_FORMAT	(1L << 4)
682
#define ALTER_COLUMN_ORDER      (1L << 5)
683
#define ALTER_ADD_INDEX		(1L << 6)
684
#define ALTER_DROP_INDEX	(1L << 7)
685
#define ALTER_RENAME		(1L << 8)
686
#define ALTER_ORDER		(1L << 9)
687
#define ALTER_OPTIONS		(1L << 10)
688
#define ALTER_COLUMN_DEFAULT    (1L << 11)
689
#define ALTER_KEYS_ONOFF        (1L << 12)
690
#define ALTER_STORAGE	        (1L << 13)
691
#define ALTER_ROW_FORMAT        (1L << 14)
692
#define ALTER_CONVERT           (1L << 15)
693
#define ALTER_FORCE		(1L << 16)
694
#define ALTER_RECREATE          (1L << 17)
695
#define ALTER_TABLE_REORG        (1L << 24)
696
#define ALTER_FOREIGN_KEY         (1L << 31)
697
698
/**
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
699
  @brief Parsing data for CREATE or ALTER Table.
1 by brian
clean slate
700
701
  This structure contains a list of columns or indexes to be created,
702
  altered or dropped.
703
*/
704
705
class Alter_info
706
{
707
public:
708
  List<Alter_drop>              drop_list;
709
  List<Alter_column>            alter_list;
710
  List<Key>                     key_list;
711
  List<Create_field>            create_list;
202 by Brian Aker
Cleanup sql_lex to modern types.
712
  uint32_t                          flags;
1 by brian
clean slate
713
  enum enum_enable_or_disable   keys_onoff;
714
  enum tablespace_op_type       tablespace_op;
202 by Brian Aker
Cleanup sql_lex to modern types.
715
  uint32_t                          no_parts;
1 by brian
clean slate
716
  enum ha_build_method          build_method;
717
  Create_field                 *datetime_field;
718
  bool                          error_if_not_empty;
719
720
721
  Alter_info() :
722
    flags(0),
723
    keys_onoff(LEAVE_AS_IS),
724
    tablespace_op(NO_TABLESPACE_OP),
725
    no_parts(0),
726
    build_method(HA_BUILD_DEFAULT),
727
    datetime_field(NULL),
51.1.52 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
728
    error_if_not_empty(false)
1 by brian
clean slate
729
  {}
730
731
  void reset()
732
  {
733
    drop_list.empty();
734
    alter_list.empty();
735
    key_list.empty();
736
    create_list.empty();
737
    flags= 0;
738
    keys_onoff= LEAVE_AS_IS;
739
    tablespace_op= NO_TABLESPACE_OP;
740
    no_parts= 0;
741
    build_method= HA_BUILD_DEFAULT;
742
    datetime_field= 0;
51.1.52 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
743
    error_if_not_empty= false;
1 by brian
clean slate
744
  }
745
  Alter_info(const Alter_info &rhs, MEM_ROOT *mem_root);
746
private:
747
  Alter_info &operator=(const Alter_info &rhs); // not implemented
748
  Alter_info(const Alter_info &rhs);            // not implemented
749
};
750
751
enum xa_option_words {XA_NONE, XA_JOIN, XA_RESUME, XA_ONE_PHASE,
752
                      XA_SUSPEND, XA_FOR_MIGRATE};
753
754
extern const LEX_STRING null_lex_str;
755
756
757
/*
758
  Class representing list of all tables used by statement.
759
  It also contains information about stored functions used by statement
760
  since during its execution we may have to add all tables used by its
761
  stored functions/triggers to this list in order to pre-open and lock
762
  them.
763
764
  Also used by st_lex::reset_n_backup/restore_backup_query_tables_list()
765
  methods to save and restore this information.
766
*/
767
768
class Query_tables_list
769
{
770
public:
771
  /* Global list of all tables used by this statement */
327.2.4 by Brian Aker
Refactoring table.h
772
  TableList *query_tables;
1 by brian
clean slate
773
  /* Pointer to next_global member of last element in the previous list. */
327.2.4 by Brian Aker
Refactoring table.h
774
  TableList **query_tables_last;
1 by brian
clean slate
775
  /*
776
    If non-0 then indicates that query requires prelocking and points to
777
    next_global member of last own element in query table list (i.e. last
778
    table which was not added to it as part of preparation to prelocking).
779
    0 - indicates that this query does not need prelocking.
780
  */
327.2.4 by Brian Aker
Refactoring table.h
781
  TableList **query_tables_own_last;
1 by brian
clean slate
782
783
  /*
784
    These constructor and destructor serve for creation/destruction
785
    of Query_tables_list instances which are used as backup storage.
786
  */
787
  Query_tables_list() {}
788
  ~Query_tables_list() {}
789
790
  /* Initializes (or resets) Query_tables_list object for "real" use. */
791
  void reset_query_tables_list(bool init);
792
  void destroy_query_tables_list();
793
  void set_query_tables_list(Query_tables_list *state)
794
  {
795
    *this= *state;
796
  }
797
798
  /*
799
    Direct addition to the list of query tables.
800
    If you are using this function, you must ensure that the table
801
    object, in particular table->db member, is initialized.
802
  */
327.2.4 by Brian Aker
Refactoring table.h
803
  void add_to_query_tables(TableList *table)
1 by brian
clean slate
804
  {
805
    *(table->prev_global= query_tables_last)= table;
806
    query_tables_last= &table->next_global;
807
  }
808
  /* Return pointer to first not-own table in query-tables or 0 */
327.2.4 by Brian Aker
Refactoring table.h
809
  TableList* first_not_own_table()
1 by brian
clean slate
810
  {
811
    return ( query_tables_own_last ? *query_tables_own_last : 0);
812
  }
813
  void chop_off_not_own_tables()
814
  {
815
    if (query_tables_own_last)
816
    {
817
      *query_tables_own_last= 0;
818
      query_tables_last= query_tables_own_last;
819
      query_tables_own_last= 0;
820
    }
821
  }
822
};
823
824
825
/*
826
  st_parsing_options contains the flags for constructions that are
827
  allowed in the current statement.
828
*/
829
830
struct st_parsing_options
831
{
832
  bool allows_select_procedure;
833
834
  st_parsing_options() { reset(); }
835
  void reset();
836
};
837
838
839
/**
840
  The state of the lexical parser, when parsing comments.
841
*/
842
enum enum_comment_state
843
{
844
  /**
845
    Not parsing comments.
846
  */
847
  NO_COMMENT,
848
  /**
849
    Parsing comments that need to be preserved.
850
    Typically, these are user comments '/' '*' ... '*' '/'.
851
  */
852
  PRESERVE_COMMENT,
853
  /**
854
    Parsing comments that need to be discarded.
855
    Typically, these are special comments '/' '*' '!' ... '*' '/',
856
    or '/' '*' '!' 'M' 'M' 'm' 'm' 'm' ... '*' '/', where the comment
857
    markers should not be expanded.
858
  */
859
  DISCARD_COMMENT
860
};
861
862
863
/**
864
  @brief This class represents the character input stream consumed during
865
  lexical analysis.
866
867
  In addition to consuming the input stream, this class performs some
868
  comment pre processing, by filtering out out of bound special text
869
  from the query input stream.
870
  Two buffers, with pointers inside each buffers, are maintained in
871
  parallel. The 'raw' buffer is the original query text, which may
872
  contain out-of-bound comments. The 'cpp' (for comments pre processor)
873
  is the pre-processed buffer that contains only the query text that
874
  should be seen once out-of-bound data is removed.
875
*/
876
877
class Lex_input_stream
878
{
879
public:
520.1.22 by Brian Aker
Second pass of thd cleanup
880
  Lex_input_stream(Session *session, const char* buff, unsigned int length);
1 by brian
clean slate
881
  ~Lex_input_stream();
882
883
  /**
884
    Set the echo mode.
885
886
    When echo is true, characters parsed from the raw input stream are
887
    preserved. When false, characters parsed are silently ignored.
888
    @param echo the echo mode.
889
  */
890
  void set_echo(bool echo)
891
  {
892
    m_echo= echo;
893
  }
894
895
  /**
896
    Skip binary from the input stream.
897
    @param n number of bytes to accept.
898
  */
899
  void skip_binary(int n)
900
  {
901
    if (m_echo)
902
    {
903
      memcpy(m_cpp_ptr, m_ptr, n);
904
      m_cpp_ptr += n;
905
    }
906
    m_ptr += n;
907
  }
908
909
  /**
910
    Get a character, and advance in the stream.
911
    @return the next character to parse.
912
  */
913
  char yyGet()
914
  {
915
    char c= *m_ptr++;
916
    if (m_echo)
917
      *m_cpp_ptr++ = c;
918
    return c;
919
  }
920
921
  /**
922
    Get the last character accepted.
923
    @return the last character accepted.
924
  */
925
  char yyGetLast()
926
  {
927
    return m_ptr[-1];
928
  }
929
930
  /**
931
    Look at the next character to parse, but do not accept it.
932
  */
933
  char yyPeek()
934
  {
935
    return m_ptr[0];
936
  }
937
938
  /**
939
    Look ahead at some character to parse.
940
    @param n offset of the character to look up
941
  */
942
  char yyPeekn(int n)
943
  {
944
    return m_ptr[n];
945
  }
946
947
  /**
948
    Cancel the effect of the last yyGet() or yySkip().
949
    Note that the echo mode should not change between calls to yyGet / yySkip
950
    and yyUnget. The caller is responsible for ensuring that.
951
  */
952
  void yyUnget()
953
  {
954
    m_ptr--;
955
    if (m_echo)
956
      m_cpp_ptr--;
957
  }
958
959
  /**
960
    Accept a character, by advancing the input stream.
961
  */
962
  void yySkip()
963
  {
964
    if (m_echo)
965
      *m_cpp_ptr++ = *m_ptr++;
966
    else
967
      m_ptr++;
968
  }
969
970
  /**
971
    Accept multiple characters at once.
972
    @param n the number of characters to accept.
973
  */
974
  void yySkipn(int n)
975
  {
976
    if (m_echo)
977
    {
978
      memcpy(m_cpp_ptr, m_ptr, n);
979
      m_cpp_ptr += n;
980
    }
981
    m_ptr += n;
982
  }
983
984
  /**
985
    End of file indicator for the query text to parse.
986
    @return true if there are no more characters to parse
987
  */
988
  bool eof()
989
  {
990
    return (m_ptr >= m_end_of_query);
991
  }
992
993
  /**
994
    End of file indicator for the query text to parse.
995
    @param n number of characters expected
996
    @return true if there are less than n characters to parse
997
  */
998
  bool eof(int n)
999
  {
1000
    return ((m_ptr + n) >= m_end_of_query);
1001
  }
1002
1003
  /** Get the raw query buffer. */
1004
  const char *get_buf()
1005
  {
1006
    return m_buf;
1007
  }
1008
1009
  /** Get the pre-processed query buffer. */
1010
  const char *get_cpp_buf()
1011
  {
1012
    return m_cpp_buf;
1013
  }
1014
1015
  /** Get the end of the raw query buffer. */
1016
  const char *get_end_of_query()
1017
  {
1018
    return m_end_of_query;
1019
  }
1020
1021
  /** Mark the stream position as the start of a new token. */
1022
  void start_token()
1023
  {
1024
    m_tok_start_prev= m_tok_start;
1025
    m_tok_start= m_ptr;
1026
    m_tok_end= m_ptr;
1027
1028
    m_cpp_tok_start_prev= m_cpp_tok_start;
1029
    m_cpp_tok_start= m_cpp_ptr;
1030
    m_cpp_tok_end= m_cpp_ptr;
1031
  }
1032
1033
  /**
1034
    Adjust the starting position of the current token.
1035
    This is used to compensate for starting whitespace.
1036
  */
1037
  void restart_token()
1038
  {
1039
    m_tok_start= m_ptr;
1040
    m_cpp_tok_start= m_cpp_ptr;
1041
  }
1042
1043
  /** Get the token start position, in the raw buffer. */
1044
  const char *get_tok_start()
1045
  {
1046
    return m_tok_start;
1047
  }
1048
1049
  /** Get the token start position, in the pre-processed buffer. */
1050
  const char *get_cpp_tok_start()
1051
  {
1052
    return m_cpp_tok_start;
1053
  }
1054
1055
  /** Get the token end position, in the raw buffer. */
1056
  const char *get_tok_end()
1057
  {
1058
    return m_tok_end;
1059
  }
1060
1061
  /** Get the token end position, in the pre-processed buffer. */
1062
  const char *get_cpp_tok_end()
1063
  {
1064
    return m_cpp_tok_end;
1065
  }
1066
1067
  /** Get the previous token start position, in the raw buffer. */
1068
  const char *get_tok_start_prev()
1069
  {
1070
    return m_tok_start_prev;
1071
  }
1072
1073
  /** Get the current stream pointer, in the raw buffer. */
1074
  const char *get_ptr()
1075
  {
1076
    return m_ptr;
1077
  }
1078
1079
  /** Get the current stream pointer, in the pre-processed buffer. */
1080
  const char *get_cpp_ptr()
1081
  {
1082
    return m_cpp_ptr;
1083
  }
1084
1085
  /** Get the length of the current token, in the raw buffer. */
202 by Brian Aker
Cleanup sql_lex to modern types.
1086
  uint32_t yyLength()
1 by brian
clean slate
1087
  {
1088
    /*
1089
      The assumption is that the lexical analyser is always 1 character ahead,
1090
      which the -1 account for.
1091
    */
51.1.52 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
1092
    assert(m_ptr > m_tok_start);
202 by Brian Aker
Cleanup sql_lex to modern types.
1093
    return (uint32_t) ((m_ptr - m_tok_start) - 1);
1 by brian
clean slate
1094
  }
1095
1096
  /** Get the utf8-body string. */
1097
  const char *get_body_utf8_str()
1098
  {
1099
    return m_body_utf8;
1100
  }
1101
1102
  /** Get the utf8-body length. */
202 by Brian Aker
Cleanup sql_lex to modern types.
1103
  uint32_t get_body_utf8_length()
1 by brian
clean slate
1104
  {
1105
    return m_body_utf8_ptr - m_body_utf8;
1106
  }
1107
520.1.22 by Brian Aker
Second pass of thd cleanup
1108
  void body_utf8_start(Session *session, const char *begin_ptr);
1 by brian
clean slate
1109
  void body_utf8_append(const char *ptr);
1110
  void body_utf8_append(const char *ptr, const char *end_ptr);
520.1.22 by Brian Aker
Second pass of thd cleanup
1111
  void body_utf8_append_literal(Session *session,
1 by brian
clean slate
1112
                                const LEX_STRING *txt,
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
1113
                                const CHARSET_INFO * const txt_cs,
1 by brian
clean slate
1114
                                const char *end_ptr);
1115
1116
  /** Current thread. */
520.1.22 by Brian Aker
Second pass of thd cleanup
1117
  Session *m_session;
1 by brian
clean slate
1118
1119
  /** Current line number. */
202 by Brian Aker
Cleanup sql_lex to modern types.
1120
  uint32_t yylineno;
1 by brian
clean slate
1121
1122
  /** Length of the last token parsed. */
202 by Brian Aker
Cleanup sql_lex to modern types.
1123
  uint32_t yytoklen;
1 by brian
clean slate
1124
1125
  /** Interface with bison, value of the last token parsed. */
1126
  LEX_YYSTYPE yylval;
1127
1128
  /** LALR(2) resolution, look ahead token.*/
1129
  int lookahead_token;
1130
1131
  /** LALR(2) resolution, value of the look ahead token.*/
1132
  LEX_YYSTYPE lookahead_yylval;
1133
1134
private:
1135
  /** Pointer to the current position in the raw input stream. */
1136
  const char *m_ptr;
1137
1138
  /** Starting position of the last token parsed, in the raw buffer. */
1139
  const char *m_tok_start;
1140
1141
  /** Ending position of the previous token parsed, in the raw buffer. */
1142
  const char *m_tok_end;
1143
1144
  /** End of the query text in the input stream, in the raw buffer. */
1145
  const char *m_end_of_query;
1146
1147
  /** Starting position of the previous token parsed, in the raw buffer. */
1148
  const char *m_tok_start_prev;
1149
1150
  /** Begining of the query text in the input stream, in the raw buffer. */
1151
  const char *m_buf;
1152
1153
  /** Length of the raw buffer. */
202 by Brian Aker
Cleanup sql_lex to modern types.
1154
  uint32_t m_buf_length;
1 by brian
clean slate
1155
1156
  /** Echo the parsed stream to the pre-processed buffer. */
1157
  bool m_echo;
1158
1159
  /** Pre-processed buffer. */
1160
  char *m_cpp_buf;
1161
1162
  /** Pointer to the current position in the pre-processed input stream. */
1163
  char *m_cpp_ptr;
1164
1165
  /**
1166
    Starting position of the last token parsed,
1167
    in the pre-processed buffer.
1168
  */
1169
  const char *m_cpp_tok_start;
1170
1171
  /**
1172
    Starting position of the previous token parsed,
1173
    in the pre-procedded buffer.
1174
  */
1175
  const char *m_cpp_tok_start_prev;
1176
1177
  /**
1178
    Ending position of the previous token parsed,
1179
    in the pre-processed buffer.
1180
  */
1181
  const char *m_cpp_tok_end;
1182
1183
  /** UTF8-body buffer created during parsing. */
1184
  char *m_body_utf8;
1185
1186
  /** Pointer to the current position in the UTF8-body buffer. */
1187
  char *m_body_utf8_ptr;
1188
1189
  /**
1190
    Position in the pre-processed buffer. The query from m_cpp_buf to
1191
    m_cpp_utf_processed_ptr is converted to UTF8-body.
1192
  */
1193
  const char *m_cpp_utf8_processed_ptr;
1194
1195
public:
1196
1197
  /** Current state of the lexical analyser. */
1198
  enum my_lex_states next_state;
1199
1200
  /**
1201
    Position of ';' in the stream, to delimit multiple queries.
1202
    This delimiter is in the raw buffer.
1203
  */
1204
  const char *found_semicolon;
1205
1206
  /** Token character bitmaps, to detect 7bit strings. */
481 by Brian Aker
Remove all of uchar.
1207
  unsigned char tok_bitmap;
1 by brian
clean slate
1208
1209
  /** SQL_MODE = IGNORE_SPACE. */
1210
  bool ignore_space;
1211
1212
  /** State of the lexical analyser for comments. */
1213
  enum_comment_state in_comment;
1214
1215
  /**
1216
    Starting position of the TEXT_STRING or IDENT in the pre-processed
1217
    buffer.
1218
520.4.50 by Monty Taylor
Finish changing the bison namespace argument from MYSQL to DRIZZLE
1219
    NOTE: this member must be used within DRIZZLElex() function only.
1 by brian
clean slate
1220
  */
1221
  const char *m_cpp_text_start;
1222
1223
  /**
1224
    Ending position of the TEXT_STRING or IDENT in the pre-processed
1225
    buffer.
1226
520.4.50 by Monty Taylor
Finish changing the bison namespace argument from MYSQL to DRIZZLE
1227
    NOTE: this member must be used within DRIZZLElex() function only.
1 by brian
clean slate
1228
    */
1229
  const char *m_cpp_text_end;
1230
1231
  /**
1232
    Character set specified by the character-set-introducer.
1233
520.4.50 by Monty Taylor
Finish changing the bison namespace argument from MYSQL to DRIZZLE
1234
    NOTE: this member must be used within DRIZZLElex() function only.
1 by brian
clean slate
1235
  */
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
1236
  const CHARSET_INFO *m_underscore_cs;
1 by brian
clean slate
1237
};
1238
1239
520.1.21 by Brian Aker
THD -> Session rename
1240
/* The state of the lex parsing. This is saved in the Session struct */
1 by brian
clean slate
1241
575.4.7 by Monty Taylor
More header cleanup.
1242
class LEX : public Query_tables_list
1 by brian
clean slate
1243
{
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1244
public:
848 by Brian Aker
typdef class removal (just... use the name of the class).
1245
  Select_Lex_Unit unit;                         /* most upper unit */
846 by Brian Aker
Removing on typedeffed class.
1246
  Select_Lex select_lex;                        /* first Select_Lex */
1247
  /* current Select_Lex in parsing */
1248
  Select_Lex *current_select;
1249
  /* list of all Select_Lex */
1250
  Select_Lex *all_selects_list;
1 by brian
clean slate
1251
1252
  char *length,*dec,*change;
1253
  LEX_STRING name;
1254
  String *wild;
831.1.2 by Brian Aker
Rename class file_exchange
1255
  file_exchange *exchange;
1 by brian
clean slate
1256
  select_result *result;
1257
  Item *default_value, *on_update_value;
1258
  LEX_STRING comment, ident;
1259
  XID *xid;
481 by Brian Aker
Remove all of uchar.
1260
  unsigned char* yacc_yyss, *yacc_yyvs;
520.1.22 by Brian Aker
Second pass of thd cleanup
1261
  Session *session;
383.7.1 by Andrey Zhakov
Initial submit of code and tests
1262
  virtual_column_info *vcol_info;
1 by brian
clean slate
1263
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
1264
  const CHARSET_INFO *charset;
1 by brian
clean slate
1265
  bool text_string_is_7bit;
1266
  /* store original leaf_tables for INSERT SELECT and PS/SP */
327.2.4 by Brian Aker
Refactoring table.h
1267
  TableList *leaf_tables_insert;
1 by brian
clean slate
1268
1269
  List<Key_part_spec> col_list;
1270
  List<Key_part_spec> ref_list;
1271
  List<String>	      interval_list;
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
1272
  List<Lex_Column>    columns;
1 by brian
clean slate
1273
  List<Item>	      *insert_list,field_list,value_list,update_list;
1274
  List<List_item>     many_values;
1275
  List<set_var_base>  var_list;
1276
  List<Item_param>    param_list;
1277
  /*
1278
    A stack of name resolution contexts for the query. This stack is used
1279
    at parse time to set local name resolution contexts for various parts
1280
    of a query. For example, in a JOIN ... ON (some_condition) clause the
1281
    Items in 'some_condition' must be resolved only against the operands
1282
    of the the join, and not against the whole clause. Similarly, Items in
1283
    subqueries should be resolved against the subqueries (and outer queries).
1284
    The stack is used in the following way: when the parser detects that
1285
    all Items in some clause need a local context, it creates a new context
1286
    and pushes it on the stack. All newly created Items always store the
1287
    top-most context in the stack. Once the parser leaves the clause that
1288
    required a local context, the parser pops the top-most context.
1289
  */
1290
  List<Name_resolution_context> context_stack;
1291
  List<LEX_STRING>     db_list;
1292
1293
  SQL_LIST	      proc_list, auxiliary_table_list, save_list;
1294
  Create_field	      *last_field;
1295
  Item_sum *in_sum_func;
1296
  udf_func udf;
1297
  HA_CHECK_OPT   check_opt;			// check/repair options
1298
  HA_CREATE_INFO create_info;
1299
  KEY_CREATE_INFO key_create_info;
202 by Brian Aker
Cleanup sql_lex to modern types.
1300
  uint32_t type;
1 by brian
clean slate
1301
  /*
1302
    This variable is used in post-parse stage to declare that sum-functions,
1303
    or functions which have sense only if GROUP BY is present, are allowed.
1304
    For example in a query
1305
    SELECT ... FROM ...WHERE MIN(i) == 1 GROUP BY ... HAVING MIN(i) > 2
1306
    MIN(i) in the WHERE clause is not allowed in the opposite to MIN(i)
1307
    in the HAVING clause. Due to possible nesting of select construct
1308
    the variable can contain 0 or 1 for each nest level.
1309
  */
1310
  nesting_map allow_sum_func;
1311
  enum_sql_command sql_command;
1312
  /*
1313
    Usually `expr` rule of yacc is quite reused but some commands better
1314
    not support subqueries which comes standard with this rule, like
1315
    KILL, HA_READ, CREATE/ALTER EVENT etc. Set this to `false` to get
1316
    syntax error back.
1317
  */
1318
  bool expr_allows_subselect;
383.7.1 by Andrey Zhakov
Initial submit of code and tests
1319
  /*
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1320
    A special command "PARSE_VCOL_EXPR" is defined for the parser
383.7.1 by Andrey Zhakov
Initial submit of code and tests
1321
    to translate an expression statement of a virtual column \
1322
    (stored in the *.frm file as a string) into an Item object.
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1323
    The following flag is used to prevent other applications to use
383.7.1 by Andrey Zhakov
Initial submit of code and tests
1324
    this command.
1325
  */
1326
  bool parse_vcol_expr;
1 by brian
clean slate
1327
1328
  thr_lock_type lock_option;
1329
  enum enum_duplicates duplicates;
1330
  enum enum_tx_isolation tx_isolation;
1331
  enum enum_ha_read_modes ha_read_mode;
1332
  union {
1333
    enum ha_rkey_function ha_rkey_mode;
1334
    enum xa_option_words xa_opt;
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
1335
    bool lock_transactional;            /* For LOCK Table ... IN ... MODE */
1 by brian
clean slate
1336
  };
1337
  enum enum_var_type option_type;
1338
202 by Brian Aker
Cleanup sql_lex to modern types.
1339
  uint32_t profile_query_id;
1340
  uint32_t profile_options;
1 by brian
clean slate
1341
  enum column_format_type column_format;
202 by Brian Aker
Cleanup sql_lex to modern types.
1342
  uint32_t which_columns;
1 by brian
clean slate
1343
  enum Foreign_key::fk_match_opt fk_match_option;
1344
  enum Foreign_key::fk_option fk_update_opt;
1345
  enum Foreign_key::fk_option fk_delete_opt;
520.1.22 by Brian Aker
Second pass of thd cleanup
1346
  uint32_t slave_session_opt, start_transaction_opt;
1 by brian
clean slate
1347
  int nest_level;
1348
  /*
1349
    In LEX representing update which were transformed to multi-update
1350
    stores total number of tables. For LEX representing multi-delete
1351
    holds number of tables from which we will delete records.
1352
  */
202 by Brian Aker
Cleanup sql_lex to modern types.
1353
  uint32_t table_count;
1354
  uint8_t describe;
1 by brian
clean slate
1355
  /*
1356
    A flag that indicates what kinds of derived tables are present in the
1357
    query (0 if no derived tables, otherwise DERIVED_SUBQUERY).
1358
  */
202 by Brian Aker
Cleanup sql_lex to modern types.
1359
  uint8_t derived_tables;
1 by brian
clean slate
1360
  bool drop_if_exists, drop_temporary, local_file, one_shot_set;
1361
  bool autocommit;
383.1.26 by Brian Aker
Removed option for single command replication and have now left disable of
1362
  bool verbose;
1 by brian
clean slate
1363
1364
  bool tx_chain, tx_release;
1365
  bool subqueries, ignore;
1366
  st_parsing_options parsing_options;
1367
  Alter_info alter_info;
1368
1369
  /*
1370
    Pointers to part of LOAD DATA statement that should be rewritten
1371
    during replication ("LOCAL 'filename' REPLACE INTO" part).
1372
  */
1373
  const char *fname_start;
1374
  const char *fname_end;
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1375
1 by brian
clean slate
1376
  /**
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1377
    During name resolution search only in the table list given by
1 by brian
clean slate
1378
    Name_resolution_context::first_name_resolution_table and
1379
    Name_resolution_context::last_name_resolution_table
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1380
    (see Item_field::fix_fields()).
1 by brian
clean slate
1381
  */
1382
  bool use_only_table_context;
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1383
1 by brian
clean slate
1384
  bool escape_used;
1385
  bool is_lex_started; /* If lex_start() did run. For debugging. */
1386
575.4.7 by Monty Taylor
More header cleanup.
1387
  LEX();
1 by brian
clean slate
1388
575.4.7 by Monty Taylor
More header cleanup.
1389
  virtual ~LEX()
1 by brian
clean slate
1390
  {
1391
    destroy_query_tables_list();
1392
  }
1393
327.2.4 by Brian Aker
Refactoring table.h
1394
  TableList *unlink_first_table(bool *link_to_local);
1395
  void link_first_table_back(TableList *first, bool link_to_local);
1 by brian
clean slate
1396
  void first_lists_tables_same();
1397
1398
  bool only_view_structure();
1399
  bool need_correct_ident();
1400
1401
  void cleanup_after_one_table_open();
1402
1403
  bool push_context(Name_resolution_context *context)
1404
  {
1405
    return context_stack.push_front(context);
1406
  }
1407
1408
  void pop_context()
1409
  {
1410
    context_stack.pop();
1411
  }
1412
1413
  bool copy_db_to(char **p_db, size_t *p_db_length) const;
1414
1415
  Name_resolution_context *current_context()
1416
  {
1417
    return context_stack.head();
1418
  }
1419
  /*
520.1.21 by Brian Aker
THD -> Session rename
1420
    Restore the LEX and Session in case of a parse error.
1 by brian
clean slate
1421
  */
520.1.22 by Brian Aker
Second pass of thd cleanup
1422
  static void cleanup_lex_after_parse_error(Session *session);
1 by brian
clean slate
1423
1424
  /**
1425
    @brief check if the statement is a single-level join
1426
    @return result of the check
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1427
      @retval true  The statement doesn't contain subqueries, unions and
1 by brian
clean slate
1428
                    stored procedure calls.
51.1.52 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
1429
      @retval false There are subqueries, UNIONs or stored procedure calls.
1 by brian
clean slate
1430
  */
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1431
  bool is_single_level_stmt()
1432
  {
1433
    /*
1 by brian
clean slate
1434
      This check exploits the fact that the last added to all_select_list is
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1435
      on its top. So select_lex (as the first added) will be at the tail
1 by brian
clean slate
1436
      of the list.
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1437
    */
628 by Brian Aker
Collection of dead code removal
1438
    if (&select_lex == all_selects_list)
1 by brian
clean slate
1439
    {
51.1.52 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
1440
      assert(!all_selects_list->next_select_in_list());
1441
      return true;
1 by brian
clean slate
1442
    }
51.1.52 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
1443
    return false;
1 by brian
clean slate
1444
  }
575.4.7 by Monty Taylor
More header cleanup.
1445
};
1 by brian
clean slate
1446
575.4.7 by Monty Taylor
More header cleanup.
1447
struct st_lex_local: public LEX
1 by brian
clean slate
1448
{
1449
  static void *operator new(size_t size) throw()
1450
  {
1451
    return sql_alloc(size);
1452
  }
1453
  static void *operator new(size_t size, MEM_ROOT *mem_root) throw()
1454
  {
202 by Brian Aker
Cleanup sql_lex to modern types.
1455
    return (void*) alloc_root(mem_root, (uint32_t) size);
1 by brian
clean slate
1456
  }
644 by Brian Aker
Clean up warnings for Solaris.
1457
  static void operator delete(void *, size_t)
1 by brian
clean slate
1458
  { TRASH(ptr, size); }
644 by Brian Aker
Clean up warnings for Solaris.
1459
  static void operator delete(void *, MEM_ROOT *)
1 by brian
clean slate
1460
  { /* Never called */ }
1461
};
1462
520.1.22 by Brian Aker
Second pass of thd cleanup
1463
extern void lex_start(Session *session);
1 by brian
clean slate
1464
extern void lex_end(LEX *lex);
1465
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
1466
extern void trim_whitespace(const CHARSET_INFO * const cs, LEX_STRING *str);
1 by brian
clean slate
1467
1468
extern bool is_lex_native_function(const LEX_STRING *name);
1469
1470
/**
1471
  @} (End of group Semantic_Analysis)
1472
*/
1473
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
1474
#endif /* DRIZZLE_SERVER */
243.1.8 by Jay Pipes
More cleanup and revert broken base.h
1475
#endif /* DRIZZLE_SERVER_SQL_LEX_H */