~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 */
892.2.4 by Monty Taylor
Fixed more warnings.
416
  bool prepare(Session *session, select_result *result,
417
               uint64_t additional_options);
1 by brian
clean slate
418
  bool exec();
419
  bool cleanup();
420
  inline void unclean() { cleaned= 0; }
421
  void reinit_exec_mechanism();
422
423
  void print(String *str, enum_query_type query_type);
424
520.1.22 by Brian Aker
Second pass of thd cleanup
425
  bool add_fake_select_lex(Session *session);
426
  void init_prepare_fake_select_lex(Session *session);
1 by brian
clean slate
427
  bool change_result(select_result_interceptor *result,
428
                     select_result_interceptor *old_result);
846 by Brian Aker
Removing on typedeffed class.
429
  void set_limit(Select_Lex *values);
520.1.22 by Brian Aker
Second pass of thd cleanup
430
  void set_session(Session *session_arg) { session= session_arg; }
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
431
  inline bool is_union ();
1 by brian
clean slate
432
520.1.22 by Brian Aker
Second pass of thd cleanup
433
  friend void lex_start(Session *session);
1 by brian
clean slate
434
  friend int subselect_union_engine::exec();
435
436
  List<Item> *get_unit_column_types();
437
};
438
439
/*
846 by Brian Aker
Removing on typedeffed class.
440
  Select_Lex - store information of parsed SELECT statment
1 by brian
clean slate
441
*/
847 by Brian Aker
More typdef class removal.
442
class Select_Lex: public Select_Lex_Node
1 by brian
clean slate
443
{
444
public:
445
  Name_resolution_context context;
446
  char *db;
447
  Item *where, *having;                         /* WHERE & HAVING clauses */
448
  /* Saved values of the WHERE and HAVING clauses*/
449
  Item::cond_result cond_value, having_value;
450
  /* point on lex in which it was created, used in view subquery detection */
575.4.7 by Monty Taylor
More header cleanup.
451
  LEX *parent_lex;
1 by brian
clean slate
452
  enum olap_type olap;
327.2.4 by Brian Aker
Refactoring table.h
453
  /* FROM clause - points to the beginning of the TableList::next_local list. */
1 by brian
clean slate
454
  SQL_LIST	      table_list;
455
  SQL_LIST	      group_list; /* GROUP BY clause. */
456
  List<Item>          item_list;  /* list of fields & expressions */
457
  List<String>        interval_list;
458
  bool	              is_item_list_lookup;
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
459
  /*
460
    Despite their names, the following are used in unions. This should
1 by brian
clean slate
461
    be rewritten. -Brian
462
  */
463
  List<Item_real_func> *ftfunc_list;
464
  List<Item_real_func> ftfunc_list_alloc;
465
  JOIN *join; /* after JOIN::prepare it is pointer to corresponding JOIN */
327.2.4 by Brian Aker
Refactoring table.h
466
  List<TableList> top_join_list; /* join list of the top level          */
467
  List<TableList> *join_list;    /* list for the currently parsed join  */
468
  TableList *embedding;          /* table embedding to the above list   */
469
  List<TableList> sj_nests;
1 by brian
clean slate
470
  /*
471
    Beginning of the list of leaves in a FROM clause, where the leaves
472
    inlcude all base tables including view tables. The tables are connected
327.2.4 by Brian Aker
Refactoring table.h
473
    by TableList::next_leaf, so leaf_tables points to the left-most leaf.
1 by brian
clean slate
474
  */
327.2.4 by Brian Aker
Refactoring table.h
475
  TableList *leaf_tables;
1 by brian
clean slate
476
  const char *type;               /* type of select for EXPLAIN          */
477
478
  SQL_LIST order_list;                /* ORDER clause */
479
  SQL_LIST *gorder_list;
480
  Item *select_limit, *offset_limit;  /* LIMIT clause parameters */
481
  // Arrays of pointers to top elements of all_fields list
482
  Item **ref_pointer_array;
483
484
  /*
485
    number of items in select_list and HAVING clause used to get number
486
    bigger then can be number of entries that will be added to all item
487
    list during split_sum_func
488
  */
202 by Brian Aker
Cleanup sql_lex to modern types.
489
  uint32_t select_n_having_items;
490
  uint32_t cond_count;    /* number of arguments of and/or/xor in where/having/on */
491
  uint32_t between_count; /* number of between predicates in where/having/on      */
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
492
  uint32_t max_equal_elems; /* maximal number of elements in multiple equalities  */
1 by brian
clean slate
493
  /*
494
    Number of fields used in select list or where clause of current select
495
    and all inner subselects.
496
  */
202 by Brian Aker
Cleanup sql_lex to modern types.
497
  uint32_t select_n_where_fields;
1 by brian
clean slate
498
  enum_parsing_place parsing_place; /* where we are parsing expression */
499
  bool with_sum_func;   /* sum function indicator */
500
202 by Brian Aker
Cleanup sql_lex to modern types.
501
  uint32_t table_join_options;
502
  uint32_t in_sum_expr;
503
  uint32_t select_number; /* number of select (used for EXPLAIN) */
1 by brian
clean slate
504
  int nest_level;     /* nesting level of select */
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
505
  Item_sum *inner_sum_func_list; /* list of sum func in nested selects */
202 by Brian Aker
Cleanup sql_lex to modern types.
506
  uint32_t with_wild; /* item list contain '*' */
1 by brian
clean slate
507
  bool  braces;   	/* SELECT ... UNION (SELECT ... ) <- this braces */
51.1.52 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
508
  /* true when having fix field called in processing of this SELECT */
1 by brian
clean slate
509
  bool having_fix_field;
510
  /* List of references to fields referenced from inner selects */
511
  List<Item_outer_ref> inner_refs_list;
512
  /* Number of Item_sum-derived objects in this SELECT */
202 by Brian Aker
Cleanup sql_lex to modern types.
513
  uint32_t n_sum_items;
1 by brian
clean slate
514
  /* Number of Item_sum-derived objects in children and descendant SELECTs */
202 by Brian Aker
Cleanup sql_lex to modern types.
515
  uint32_t n_child_sum_items;
1 by brian
clean slate
516
517
  /* explicit LIMIT clause was used */
518
  bool explicit_limit;
519
  /*
520
    there are subquery in HAVING clause => we can't close tables before
521
    query processing end even if we use temporary table
522
  */
523
  bool subquery_in_having;
51.1.52 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
524
  /* true <=> this SELECT is correlated w.r.t. some ancestor select */
1 by brian
clean slate
525
  bool is_correlated;
526
  /* exclude this select from check of unique_table() */
527
  bool exclude_from_table_unique_test;
528
  /* List of fields that aren't under an aggregate function */
529
  List<Item_field> non_agg_fields;
530
  /* index in the select list of the expression currently being fixed */
531
  int cur_pos_in_select_list;
532
533
  List<udf_func>     udf_list;                  /* udf function calls stack */
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
534
  /*
1 by brian
clean slate
535
    This is a copy of the original JOIN USING list that comes from
536
    the parser. The parser :
327.2.4 by Brian Aker
Refactoring table.h
537
      1. Sets the natural_join of the second TableList in the join
846 by Brian Aker
Removing on typedeffed class.
538
         and the Select_Lex::prev_join_using.
327.2.4 by Brian Aker
Refactoring table.h
539
      2. Makes a parent TableList and sets its is_natural_join/
1 by brian
clean slate
540
       join_using_fields members.
327.2.4 by Brian Aker
Refactoring table.h
541
      3. Uses the wrapper TableList as a table in the upper level.
1 by brian
clean slate
542
    We cannot assign directly to join_using_fields in the parser because
327.2.4 by Brian Aker
Refactoring table.h
543
    at stage (1.) the parent TableList is not constructed yet and
1 by brian
clean slate
544
    the assignment will override the JOIN USING fields of the lower level
545
    joins on the right.
546
  */
547
  List<String> *prev_join_using;
548
  /*
549
    Bitmap used in the ONLY_FULL_GROUP_BY_MODE to prevent mixture of aggregate
550
    functions and non aggregated fields when GROUP BY list is absent.
551
    Bits:
552
      0 - non aggregated fields are used in this select,
553
          defined as NON_AGG_FIELD_USED.
554
      1 - aggregate functions are used in this select,
555
          defined as SUM_FUNC_USED.
556
  */
202 by Brian Aker
Cleanup sql_lex to modern types.
557
  uint8_t full_group_by_flag;
1 by brian
clean slate
558
  void init_query();
559
  void init_select();
848 by Brian Aker
typdef class removal (just... use the name of the class).
560
  Select_Lex_Unit* master_unit();
561
  Select_Lex_Unit* first_inner_unit()
846 by Brian Aker
Removing on typedeffed class.
562
  {
848 by Brian Aker
typdef class removal (just... use the name of the class).
563
    return (Select_Lex_Unit*) slave;
846 by Brian Aker
Removing on typedeffed class.
564
  }
565
  Select_Lex* outer_select();
566
  Select_Lex* next_select() { return (Select_Lex*) next; }
567
  Select_Lex* next_select_in_list()
568
  {
569
    return (Select_Lex*) link_next;
570
  }
847 by Brian Aker
More typdef class removal.
571
  Select_Lex_Node** next_select_in_list_addr()
1 by brian
clean slate
572
  {
573
    return &link_next;
574
  }
846 by Brian Aker
Removing on typedeffed class.
575
  Select_Lex* return_after_parsing()
1 by brian
clean slate
576
  {
577
    return master_unit()->return_after_parsing();
578
  }
579
846 by Brian Aker
Removing on typedeffed class.
580
  void mark_as_dependent(Select_Lex *last);
1 by brian
clean slate
581
582
  bool set_braces(bool value);
583
  bool inc_in_sum_expr();
202 by Brian Aker
Cleanup sql_lex to modern types.
584
  uint32_t get_in_sum_expr();
1 by brian
clean slate
585
520.1.22 by Brian Aker
Second pass of thd cleanup
586
  bool add_item_to_list(Session *session, Item *item);
587
  bool add_group_to_list(Session *session, Item *item, bool asc);
588
  bool add_order_to_list(Session *session, Item *item, bool asc);
589
  TableList* add_table_to_list(Session *session, Table_ident *table,
1 by brian
clean slate
590
				LEX_STRING *alias,
202 by Brian Aker
Cleanup sql_lex to modern types.
591
				uint32_t table_options,
1 by brian
clean slate
592
				thr_lock_type flags= TL_UNLOCK,
593
				List<Index_hint> *hints= 0,
594
                                LEX_STRING *option= 0);
327.2.4 by Brian Aker
Refactoring table.h
595
  TableList* get_table_list();
520.1.22 by Brian Aker
Second pass of thd cleanup
596
  bool init_nested_join(Session *session);
597
  TableList *end_nested_join(Session *session);
598
  TableList *nest_last_join(Session *session);
327.2.4 by Brian Aker
Refactoring table.h
599
  void add_joined_table(TableList *table);
600
  TableList *convert_right_join();
1 by brian
clean slate
601
  List<Item>* get_item_list();
202 by Brian Aker
Cleanup sql_lex to modern types.
602
  uint32_t get_table_join_options();
1 by brian
clean slate
603
  void set_lock_for_tables(thr_lock_type lock_type);
604
  inline void init_order()
605
  {
606
    order_list.elements= 0;
607
    order_list.first= 0;
481 by Brian Aker
Remove all of uchar.
608
    order_list.next= (unsigned char**) &order_list.first;
1 by brian
clean slate
609
  }
610
  /*
611
    This method created for reiniting LEX in mysql_admin_table() and can be
846 by Brian Aker
Removing on typedeffed class.
612
    used only if you are going remove all Select_Lex & units except belonger
1 by brian
clean slate
613
    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).
614
    Select_Lex_Unit::exclude_level & Select_Lex_Unit::exclude_tree
1 by brian
clean slate
615
  */
616
  void cut_subtree() { slave= 0; }
617
  bool test_limit();
618
520.1.22 by Brian Aker
Second pass of thd cleanup
619
  friend void lex_start(Session *session);
846 by Brian Aker
Removing on typedeffed class.
620
  Select_Lex() : n_sum_items(0), n_child_sum_items(0) {}
1 by brian
clean slate
621
  void make_empty_select()
622
  {
623
    init_query();
624
    init_select();
625
  }
520.1.22 by Brian Aker
Second pass of thd cleanup
626
  bool setup_ref_array(Session *session, uint32_t order_group_num);
627
  void print(Session *session, String *str, enum_query_type query_type);
1 by brian
clean slate
628
  static void print_order(String *str,
327.2.3 by Brian Aker
Refactoring of class Table
629
                          order_st *order,
1 by brian
clean slate
630
                          enum_query_type query_type);
520.1.22 by Brian Aker
Second pass of thd cleanup
631
  void print_limit(Session *session, String *str, enum_query_type query_type);
632
  void fix_prepare_information(Session *session, Item **conds, Item **having_conds);
1 by brian
clean slate
633
  /*
634
    Destroy the used execution plan (JOIN) of this subtree (this
848 by Brian Aker
typdef class removal (just... use the name of the class).
635
    Select_Lex and all nested Select_Lexes and Select_Lex_Units).
1 by brian
clean slate
636
  */
637
  bool cleanup();
638
  /*
639
    Recursively cleanup the join of this select lex and of all nested
640
    select lexes.
641
  */
642
  void cleanup_all_joins(bool full);
643
644
  void set_index_hint_type(enum index_hint_type type, index_clause_map clause);
645
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
646
  /*
1 by brian
clean slate
647
   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:
648
   hint will be the current ones (set by set_index_hint())
1 by brian
clean slate
649
  */
520.1.22 by Brian Aker
Second pass of thd cleanup
650
  bool add_index_hint (Session *session, char *str, uint32_t length);
1 by brian
clean slate
651
652
  /* make a list to hold index hints */
520.1.22 by Brian Aker
Second pass of thd cleanup
653
  void alloc_index_hints (Session *session);
1 by brian
clean slate
654
  /* read and clear the index hints */
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
655
  List<Index_hint>* pop_index_hints(void)
1 by brian
clean slate
656
  {
657
    List<Index_hint> *hints= index_hints;
658
    index_hints= NULL;
659
    return hints;
660
  }
661
662
  void clear_index_hints(void) { index_hints= NULL; }
663
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
664
private:
1 by brian
clean slate
665
  /* current index hint kind. used in filling up index_hints */
666
  enum index_hint_type current_index_hint_type;
667
  index_clause_map current_index_hint_clause;
668
  /* a list of USE/FORCE/IGNORE INDEX */
669
  List<Index_hint> *index_hints;
670
};
671
848 by Brian Aker
typdef class removal (just... use the name of the class).
672
inline bool Select_Lex_Unit::is_union ()
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
673
{
674
  return first_select()->next_select() &&
1 by brian
clean slate
675
    first_select()->next_select()->linkage == UNION_TYPE;
676
}
677
678
#define ALTER_ADD_COLUMN	(1L << 0)
679
#define ALTER_DROP_COLUMN	(1L << 1)
680
#define ALTER_CHANGE_COLUMN	(1L << 2)
681
#define ALTER_COLUMN_STORAGE	(1L << 3)
682
#define ALTER_COLUMN_FORMAT	(1L << 4)
683
#define ALTER_COLUMN_ORDER      (1L << 5)
684
#define ALTER_ADD_INDEX		(1L << 6)
685
#define ALTER_DROP_INDEX	(1L << 7)
686
#define ALTER_RENAME		(1L << 8)
687
#define ALTER_ORDER		(1L << 9)
688
#define ALTER_OPTIONS		(1L << 10)
689
#define ALTER_COLUMN_DEFAULT    (1L << 11)
690
#define ALTER_KEYS_ONOFF        (1L << 12)
691
#define ALTER_STORAGE	        (1L << 13)
692
#define ALTER_ROW_FORMAT        (1L << 14)
693
#define ALTER_CONVERT           (1L << 15)
694
#define ALTER_FORCE		(1L << 16)
695
#define ALTER_RECREATE          (1L << 17)
696
#define ALTER_TABLE_REORG        (1L << 24)
697
#define ALTER_FOREIGN_KEY         (1L << 31)
698
699
/**
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
700
  @brief Parsing data for CREATE or ALTER Table.
1 by brian
clean slate
701
702
  This structure contains a list of columns or indexes to be created,
703
  altered or dropped.
704
*/
705
706
class Alter_info
707
{
708
public:
709
  List<Alter_drop>              drop_list;
710
  List<Alter_column>            alter_list;
711
  List<Key>                     key_list;
712
  List<Create_field>            create_list;
202 by Brian Aker
Cleanup sql_lex to modern types.
713
  uint32_t                          flags;
1 by brian
clean slate
714
  enum enum_enable_or_disable   keys_onoff;
715
  enum tablespace_op_type       tablespace_op;
202 by Brian Aker
Cleanup sql_lex to modern types.
716
  uint32_t                          no_parts;
1 by brian
clean slate
717
  enum ha_build_method          build_method;
718
  Create_field                 *datetime_field;
719
  bool                          error_if_not_empty;
720
721
722
  Alter_info() :
723
    flags(0),
724
    keys_onoff(LEAVE_AS_IS),
725
    tablespace_op(NO_TABLESPACE_OP),
726
    no_parts(0),
727
    build_method(HA_BUILD_DEFAULT),
728
    datetime_field(NULL),
51.1.52 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
729
    error_if_not_empty(false)
1 by brian
clean slate
730
  {}
731
732
  void reset()
733
  {
734
    drop_list.empty();
735
    alter_list.empty();
736
    key_list.empty();
737
    create_list.empty();
738
    flags= 0;
739
    keys_onoff= LEAVE_AS_IS;
740
    tablespace_op= NO_TABLESPACE_OP;
741
    no_parts= 0;
742
    build_method= HA_BUILD_DEFAULT;
743
    datetime_field= 0;
51.1.52 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
744
    error_if_not_empty= false;
1 by brian
clean slate
745
  }
746
  Alter_info(const Alter_info &rhs, MEM_ROOT *mem_root);
747
private:
748
  Alter_info &operator=(const Alter_info &rhs); // not implemented
749
  Alter_info(const Alter_info &rhs);            // not implemented
750
};
751
752
enum xa_option_words {XA_NONE, XA_JOIN, XA_RESUME, XA_ONE_PHASE,
753
                      XA_SUSPEND, XA_FOR_MIGRATE};
754
755
extern const LEX_STRING null_lex_str;
756
757
758
/*
759
  Class representing list of all tables used by statement.
760
  It also contains information about stored functions used by statement
761
  since during its execution we may have to add all tables used by its
762
  stored functions/triggers to this list in order to pre-open and lock
763
  them.
764
765
  Also used by st_lex::reset_n_backup/restore_backup_query_tables_list()
766
  methods to save and restore this information.
767
*/
768
769
class Query_tables_list
770
{
771
public:
772
  /* Global list of all tables used by this statement */
327.2.4 by Brian Aker
Refactoring table.h
773
  TableList *query_tables;
1 by brian
clean slate
774
  /* Pointer to next_global member of last element in the previous list. */
327.2.4 by Brian Aker
Refactoring table.h
775
  TableList **query_tables_last;
1 by brian
clean slate
776
  /*
777
    If non-0 then indicates that query requires prelocking and points to
778
    next_global member of last own element in query table list (i.e. last
779
    table which was not added to it as part of preparation to prelocking).
780
    0 - indicates that this query does not need prelocking.
781
  */
327.2.4 by Brian Aker
Refactoring table.h
782
  TableList **query_tables_own_last;
1 by brian
clean slate
783
784
  /*
785
    These constructor and destructor serve for creation/destruction
786
    of Query_tables_list instances which are used as backup storage.
787
  */
788
  Query_tables_list() {}
789
  ~Query_tables_list() {}
790
791
  /* Initializes (or resets) Query_tables_list object for "real" use. */
792
  void reset_query_tables_list(bool init);
793
  void destroy_query_tables_list();
794
  void set_query_tables_list(Query_tables_list *state)
795
  {
796
    *this= *state;
797
  }
798
799
  /*
800
    Direct addition to the list of query tables.
801
    If you are using this function, you must ensure that the table
802
    object, in particular table->db member, is initialized.
803
  */
327.2.4 by Brian Aker
Refactoring table.h
804
  void add_to_query_tables(TableList *table)
1 by brian
clean slate
805
  {
806
    *(table->prev_global= query_tables_last)= table;
807
    query_tables_last= &table->next_global;
808
  }
809
  /* Return pointer to first not-own table in query-tables or 0 */
327.2.4 by Brian Aker
Refactoring table.h
810
  TableList* first_not_own_table()
1 by brian
clean slate
811
  {
812
    return ( query_tables_own_last ? *query_tables_own_last : 0);
813
  }
814
  void chop_off_not_own_tables()
815
  {
816
    if (query_tables_own_last)
817
    {
818
      *query_tables_own_last= 0;
819
      query_tables_last= query_tables_own_last;
820
      query_tables_own_last= 0;
821
    }
822
  }
823
};
824
825
826
/*
827
  st_parsing_options contains the flags for constructions that are
828
  allowed in the current statement.
829
*/
830
831
struct st_parsing_options
832
{
833
  bool allows_select_procedure;
834
835
  st_parsing_options() { reset(); }
836
  void reset();
837
};
838
839
840
/**
841
  The state of the lexical parser, when parsing comments.
842
*/
843
enum enum_comment_state
844
{
845
  /**
846
    Not parsing comments.
847
  */
848
  NO_COMMENT,
849
  /**
850
    Parsing comments that need to be preserved.
851
    Typically, these are user comments '/' '*' ... '*' '/'.
852
  */
853
  PRESERVE_COMMENT,
854
  /**
855
    Parsing comments that need to be discarded.
856
    Typically, these are special comments '/' '*' '!' ... '*' '/',
857
    or '/' '*' '!' 'M' 'M' 'm' 'm' 'm' ... '*' '/', where the comment
858
    markers should not be expanded.
859
  */
860
  DISCARD_COMMENT
861
};
862
863
864
/**
865
  @brief This class represents the character input stream consumed during
866
  lexical analysis.
867
868
  In addition to consuming the input stream, this class performs some
869
  comment pre processing, by filtering out out of bound special text
870
  from the query input stream.
871
  Two buffers, with pointers inside each buffers, are maintained in
872
  parallel. The 'raw' buffer is the original query text, which may
873
  contain out-of-bound comments. The 'cpp' (for comments pre processor)
874
  is the pre-processed buffer that contains only the query text that
875
  should be seen once out-of-bound data is removed.
876
*/
877
878
class Lex_input_stream
879
{
880
public:
520.1.22 by Brian Aker
Second pass of thd cleanup
881
  Lex_input_stream(Session *session, const char* buff, unsigned int length);
1 by brian
clean slate
882
  ~Lex_input_stream();
883
884
  /**
885
    Set the echo mode.
886
887
    When echo is true, characters parsed from the raw input stream are
888
    preserved. When false, characters parsed are silently ignored.
889
    @param echo the echo mode.
890
  */
891
  void set_echo(bool echo)
892
  {
893
    m_echo= echo;
894
  }
895
896
  /**
897
    Skip binary from the input stream.
898
    @param n number of bytes to accept.
899
  */
900
  void skip_binary(int n)
901
  {
902
    if (m_echo)
903
    {
904
      memcpy(m_cpp_ptr, m_ptr, n);
905
      m_cpp_ptr += n;
906
    }
907
    m_ptr += n;
908
  }
909
910
  /**
911
    Get a character, and advance in the stream.
912
    @return the next character to parse.
913
  */
914
  char yyGet()
915
  {
916
    char c= *m_ptr++;
917
    if (m_echo)
918
      *m_cpp_ptr++ = c;
919
    return c;
920
  }
921
922
  /**
923
    Get the last character accepted.
924
    @return the last character accepted.
925
  */
926
  char yyGetLast()
927
  {
928
    return m_ptr[-1];
929
  }
930
931
  /**
932
    Look at the next character to parse, but do not accept it.
933
  */
934
  char yyPeek()
935
  {
936
    return m_ptr[0];
937
  }
938
939
  /**
940
    Look ahead at some character to parse.
941
    @param n offset of the character to look up
942
  */
943
  char yyPeekn(int n)
944
  {
945
    return m_ptr[n];
946
  }
947
948
  /**
949
    Cancel the effect of the last yyGet() or yySkip().
950
    Note that the echo mode should not change between calls to yyGet / yySkip
951
    and yyUnget. The caller is responsible for ensuring that.
952
  */
953
  void yyUnget()
954
  {
955
    m_ptr--;
956
    if (m_echo)
957
      m_cpp_ptr--;
958
  }
959
960
  /**
961
    Accept a character, by advancing the input stream.
962
  */
963
  void yySkip()
964
  {
965
    if (m_echo)
966
      *m_cpp_ptr++ = *m_ptr++;
967
    else
968
      m_ptr++;
969
  }
970
971
  /**
972
    Accept multiple characters at once.
973
    @param n the number of characters to accept.
974
  */
975
  void yySkipn(int n)
976
  {
977
    if (m_echo)
978
    {
979
      memcpy(m_cpp_ptr, m_ptr, n);
980
      m_cpp_ptr += n;
981
    }
982
    m_ptr += n;
983
  }
984
985
  /**
986
    End of file indicator for the query text to parse.
987
    @return true if there are no more characters to parse
988
  */
989
  bool eof()
990
  {
991
    return (m_ptr >= m_end_of_query);
992
  }
993
994
  /**
995
    End of file indicator for the query text to parse.
996
    @param n number of characters expected
997
    @return true if there are less than n characters to parse
998
  */
999
  bool eof(int n)
1000
  {
1001
    return ((m_ptr + n) >= m_end_of_query);
1002
  }
1003
1004
  /** Get the raw query buffer. */
1005
  const char *get_buf()
1006
  {
1007
    return m_buf;
1008
  }
1009
1010
  /** Get the pre-processed query buffer. */
1011
  const char *get_cpp_buf()
1012
  {
1013
    return m_cpp_buf;
1014
  }
1015
1016
  /** Get the end of the raw query buffer. */
1017
  const char *get_end_of_query()
1018
  {
1019
    return m_end_of_query;
1020
  }
1021
1022
  /** Mark the stream position as the start of a new token. */
1023
  void start_token()
1024
  {
1025
    m_tok_start_prev= m_tok_start;
1026
    m_tok_start= m_ptr;
1027
    m_tok_end= m_ptr;
1028
1029
    m_cpp_tok_start_prev= m_cpp_tok_start;
1030
    m_cpp_tok_start= m_cpp_ptr;
1031
    m_cpp_tok_end= m_cpp_ptr;
1032
  }
1033
1034
  /**
1035
    Adjust the starting position of the current token.
1036
    This is used to compensate for starting whitespace.
1037
  */
1038
  void restart_token()
1039
  {
1040
    m_tok_start= m_ptr;
1041
    m_cpp_tok_start= m_cpp_ptr;
1042
  }
1043
1044
  /** Get the token start position, in the raw buffer. */
1045
  const char *get_tok_start()
1046
  {
1047
    return m_tok_start;
1048
  }
1049
1050
  /** Get the token start position, in the pre-processed buffer. */
1051
  const char *get_cpp_tok_start()
1052
  {
1053
    return m_cpp_tok_start;
1054
  }
1055
1056
  /** Get the token end position, in the raw buffer. */
1057
  const char *get_tok_end()
1058
  {
1059
    return m_tok_end;
1060
  }
1061
1062
  /** Get the token end position, in the pre-processed buffer. */
1063
  const char *get_cpp_tok_end()
1064
  {
1065
    return m_cpp_tok_end;
1066
  }
1067
1068
  /** Get the previous token start position, in the raw buffer. */
1069
  const char *get_tok_start_prev()
1070
  {
1071
    return m_tok_start_prev;
1072
  }
1073
1074
  /** Get the current stream pointer, in the raw buffer. */
1075
  const char *get_ptr()
1076
  {
1077
    return m_ptr;
1078
  }
1079
1080
  /** Get the current stream pointer, in the pre-processed buffer. */
1081
  const char *get_cpp_ptr()
1082
  {
1083
    return m_cpp_ptr;
1084
  }
1085
1086
  /** Get the length of the current token, in the raw buffer. */
202 by Brian Aker
Cleanup sql_lex to modern types.
1087
  uint32_t yyLength()
1 by brian
clean slate
1088
  {
1089
    /*
1090
      The assumption is that the lexical analyser is always 1 character ahead,
1091
      which the -1 account for.
1092
    */
51.1.52 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
1093
    assert(m_ptr > m_tok_start);
202 by Brian Aker
Cleanup sql_lex to modern types.
1094
    return (uint32_t) ((m_ptr - m_tok_start) - 1);
1 by brian
clean slate
1095
  }
1096
1097
  /** Get the utf8-body string. */
1098
  const char *get_body_utf8_str()
1099
  {
1100
    return m_body_utf8;
1101
  }
1102
1103
  /** Get the utf8-body length. */
202 by Brian Aker
Cleanup sql_lex to modern types.
1104
  uint32_t get_body_utf8_length()
1 by brian
clean slate
1105
  {
1106
    return m_body_utf8_ptr - m_body_utf8;
1107
  }
1108
520.1.22 by Brian Aker
Second pass of thd cleanup
1109
  void body_utf8_start(Session *session, const char *begin_ptr);
1 by brian
clean slate
1110
  void body_utf8_append(const char *ptr);
1111
  void body_utf8_append(const char *ptr, const char *end_ptr);
520.1.22 by Brian Aker
Second pass of thd cleanup
1112
  void body_utf8_append_literal(Session *session,
1 by brian
clean slate
1113
                                const LEX_STRING *txt,
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
1114
                                const CHARSET_INFO * const txt_cs,
1 by brian
clean slate
1115
                                const char *end_ptr);
1116
1117
  /** Current thread. */
520.1.22 by Brian Aker
Second pass of thd cleanup
1118
  Session *m_session;
1 by brian
clean slate
1119
1120
  /** Current line number. */
202 by Brian Aker
Cleanup sql_lex to modern types.
1121
  uint32_t yylineno;
1 by brian
clean slate
1122
1123
  /** Length of the last token parsed. */
202 by Brian Aker
Cleanup sql_lex to modern types.
1124
  uint32_t yytoklen;
1 by brian
clean slate
1125
1126
  /** Interface with bison, value of the last token parsed. */
1127
  LEX_YYSTYPE yylval;
1128
1129
  /** LALR(2) resolution, look ahead token.*/
1130
  int lookahead_token;
1131
1132
  /** LALR(2) resolution, value of the look ahead token.*/
1133
  LEX_YYSTYPE lookahead_yylval;
1134
1135
private:
1136
  /** Pointer to the current position in the raw input stream. */
1137
  const char *m_ptr;
1138
1139
  /** Starting position of the last token parsed, in the raw buffer. */
1140
  const char *m_tok_start;
1141
1142
  /** Ending position of the previous token parsed, in the raw buffer. */
1143
  const char *m_tok_end;
1144
1145
  /** End of the query text in the input stream, in the raw buffer. */
1146
  const char *m_end_of_query;
1147
1148
  /** Starting position of the previous token parsed, in the raw buffer. */
1149
  const char *m_tok_start_prev;
1150
1151
  /** Begining of the query text in the input stream, in the raw buffer. */
1152
  const char *m_buf;
1153
1154
  /** Length of the raw buffer. */
202 by Brian Aker
Cleanup sql_lex to modern types.
1155
  uint32_t m_buf_length;
1 by brian
clean slate
1156
1157
  /** Echo the parsed stream to the pre-processed buffer. */
1158
  bool m_echo;
1159
1160
  /** Pre-processed buffer. */
1161
  char *m_cpp_buf;
1162
1163
  /** Pointer to the current position in the pre-processed input stream. */
1164
  char *m_cpp_ptr;
1165
1166
  /**
1167
    Starting position of the last token parsed,
1168
    in the pre-processed buffer.
1169
  */
1170
  const char *m_cpp_tok_start;
1171
1172
  /**
1173
    Starting position of the previous token parsed,
1174
    in the pre-procedded buffer.
1175
  */
1176
  const char *m_cpp_tok_start_prev;
1177
1178
  /**
1179
    Ending position of the previous token parsed,
1180
    in the pre-processed buffer.
1181
  */
1182
  const char *m_cpp_tok_end;
1183
1184
  /** UTF8-body buffer created during parsing. */
1185
  char *m_body_utf8;
1186
1187
  /** Pointer to the current position in the UTF8-body buffer. */
1188
  char *m_body_utf8_ptr;
1189
1190
  /**
1191
    Position in the pre-processed buffer. The query from m_cpp_buf to
1192
    m_cpp_utf_processed_ptr is converted to UTF8-body.
1193
  */
1194
  const char *m_cpp_utf8_processed_ptr;
1195
1196
public:
1197
1198
  /** Current state of the lexical analyser. */
1199
  enum my_lex_states next_state;
1200
1201
  /**
1202
    Position of ';' in the stream, to delimit multiple queries.
1203
    This delimiter is in the raw buffer.
1204
  */
1205
  const char *found_semicolon;
1206
1207
  /** Token character bitmaps, to detect 7bit strings. */
481 by Brian Aker
Remove all of uchar.
1208
  unsigned char tok_bitmap;
1 by brian
clean slate
1209
1210
  /** SQL_MODE = IGNORE_SPACE. */
1211
  bool ignore_space;
1212
1213
  /** State of the lexical analyser for comments. */
1214
  enum_comment_state in_comment;
1215
1216
  /**
1217
    Starting position of the TEXT_STRING or IDENT in the pre-processed
1218
    buffer.
1219
520.4.50 by Monty Taylor
Finish changing the bison namespace argument from MYSQL to DRIZZLE
1220
    NOTE: this member must be used within DRIZZLElex() function only.
1 by brian
clean slate
1221
  */
1222
  const char *m_cpp_text_start;
1223
1224
  /**
1225
    Ending position of the TEXT_STRING or IDENT in the pre-processed
1226
    buffer.
1227
520.4.50 by Monty Taylor
Finish changing the bison namespace argument from MYSQL to DRIZZLE
1228
    NOTE: this member must be used within DRIZZLElex() function only.
1 by brian
clean slate
1229
    */
1230
  const char *m_cpp_text_end;
1231
1232
  /**
1233
    Character set specified by the character-set-introducer.
1234
520.4.50 by Monty Taylor
Finish changing the bison namespace argument from MYSQL to DRIZZLE
1235
    NOTE: this member must be used within DRIZZLElex() function only.
1 by brian
clean slate
1236
  */
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
1237
  const CHARSET_INFO *m_underscore_cs;
1 by brian
clean slate
1238
};
1239
1240
520.1.21 by Brian Aker
THD -> Session rename
1241
/* The state of the lex parsing. This is saved in the Session struct */
1 by brian
clean slate
1242
575.4.7 by Monty Taylor
More header cleanup.
1243
class LEX : public Query_tables_list
1 by brian
clean slate
1244
{
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1245
public:
848 by Brian Aker
typdef class removal (just... use the name of the class).
1246
  Select_Lex_Unit unit;                         /* most upper unit */
846 by Brian Aker
Removing on typedeffed class.
1247
  Select_Lex select_lex;                        /* first Select_Lex */
1248
  /* current Select_Lex in parsing */
1249
  Select_Lex *current_select;
1250
  /* list of all Select_Lex */
1251
  Select_Lex *all_selects_list;
1 by brian
clean slate
1252
1253
  char *length,*dec,*change;
1254
  LEX_STRING name;
1255
  String *wild;
831.1.2 by Brian Aker
Rename class file_exchange
1256
  file_exchange *exchange;
1 by brian
clean slate
1257
  select_result *result;
1258
  Item *default_value, *on_update_value;
1259
  LEX_STRING comment, ident;
1260
  XID *xid;
481 by Brian Aker
Remove all of uchar.
1261
  unsigned char* yacc_yyss, *yacc_yyvs;
520.1.22 by Brian Aker
Second pass of thd cleanup
1262
  Session *session;
383.7.1 by Andrey Zhakov
Initial submit of code and tests
1263
  virtual_column_info *vcol_info;
1 by brian
clean slate
1264
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
1265
  const CHARSET_INFO *charset;
1 by brian
clean slate
1266
  bool text_string_is_7bit;
1267
  /* store original leaf_tables for INSERT SELECT and PS/SP */
327.2.4 by Brian Aker
Refactoring table.h
1268
  TableList *leaf_tables_insert;
1 by brian
clean slate
1269
1270
  List<Key_part_spec> col_list;
1271
  List<Key_part_spec> ref_list;
1272
  List<String>	      interval_list;
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
1273
  List<Lex_Column>    columns;
1 by brian
clean slate
1274
  List<Item>	      *insert_list,field_list,value_list,update_list;
1275
  List<List_item>     many_values;
1276
  List<set_var_base>  var_list;
1277
  List<Item_param>    param_list;
1278
  /*
1279
    A stack of name resolution contexts for the query. This stack is used
1280
    at parse time to set local name resolution contexts for various parts
1281
    of a query. For example, in a JOIN ... ON (some_condition) clause the
1282
    Items in 'some_condition' must be resolved only against the operands
1283
    of the the join, and not against the whole clause. Similarly, Items in
1284
    subqueries should be resolved against the subqueries (and outer queries).
1285
    The stack is used in the following way: when the parser detects that
1286
    all Items in some clause need a local context, it creates a new context
1287
    and pushes it on the stack. All newly created Items always store the
1288
    top-most context in the stack. Once the parser leaves the clause that
1289
    required a local context, the parser pops the top-most context.
1290
  */
1291
  List<Name_resolution_context> context_stack;
1292
  List<LEX_STRING>     db_list;
1293
923.1.9 by Brian Aker
More cleanup for old proc and dead code (LCOV)
1294
  SQL_LIST	      auxiliary_table_list, save_list;
1 by brian
clean slate
1295
  Create_field	      *last_field;
1296
  Item_sum *in_sum_func;
1297
  udf_func udf;
1298
  HA_CHECK_OPT   check_opt;			// check/repair options
1299
  HA_CREATE_INFO create_info;
1300
  KEY_CREATE_INFO key_create_info;
202 by Brian Aker
Cleanup sql_lex to modern types.
1301
  uint32_t type;
1 by brian
clean slate
1302
  /*
1303
    This variable is used in post-parse stage to declare that sum-functions,
1304
    or functions which have sense only if GROUP BY is present, are allowed.
1305
    For example in a query
1306
    SELECT ... FROM ...WHERE MIN(i) == 1 GROUP BY ... HAVING MIN(i) > 2
1307
    MIN(i) in the WHERE clause is not allowed in the opposite to MIN(i)
1308
    in the HAVING clause. Due to possible nesting of select construct
1309
    the variable can contain 0 or 1 for each nest level.
1310
  */
1311
  nesting_map allow_sum_func;
1312
  enum_sql_command sql_command;
1313
  /*
1314
    Usually `expr` rule of yacc is quite reused but some commands better
1315
    not support subqueries which comes standard with this rule, like
1316
    KILL, HA_READ, CREATE/ALTER EVENT etc. Set this to `false` to get
1317
    syntax error back.
1318
  */
1319
  bool expr_allows_subselect;
383.7.1 by Andrey Zhakov
Initial submit of code and tests
1320
  /*
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1321
    A special command "PARSE_VCOL_EXPR" is defined for the parser
383.7.1 by Andrey Zhakov
Initial submit of code and tests
1322
    to translate an expression statement of a virtual column \
1323
    (stored in the *.frm file as a string) into an Item object.
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1324
    The following flag is used to prevent other applications to use
383.7.1 by Andrey Zhakov
Initial submit of code and tests
1325
    this command.
1326
  */
1327
  bool parse_vcol_expr;
1 by brian
clean slate
1328
1329
  thr_lock_type lock_option;
1330
  enum enum_duplicates duplicates;
1331
  enum enum_tx_isolation tx_isolation;
1332
  enum enum_ha_read_modes ha_read_mode;
1333
  union {
1334
    enum ha_rkey_function ha_rkey_mode;
1335
    enum xa_option_words xa_opt;
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
1336
    bool lock_transactional;            /* For LOCK Table ... IN ... MODE */
1 by brian
clean slate
1337
  };
1338
  enum enum_var_type option_type;
1339
202 by Brian Aker
Cleanup sql_lex to modern types.
1340
  uint32_t profile_query_id;
1341
  uint32_t profile_options;
1 by brian
clean slate
1342
  enum column_format_type column_format;
202 by Brian Aker
Cleanup sql_lex to modern types.
1343
  uint32_t which_columns;
1 by brian
clean slate
1344
  enum Foreign_key::fk_match_opt fk_match_option;
1345
  enum Foreign_key::fk_option fk_update_opt;
1346
  enum Foreign_key::fk_option fk_delete_opt;
520.1.22 by Brian Aker
Second pass of thd cleanup
1347
  uint32_t slave_session_opt, start_transaction_opt;
1 by brian
clean slate
1348
  int nest_level;
1349
  /*
1350
    In LEX representing update which were transformed to multi-update
1351
    stores total number of tables. For LEX representing multi-delete
1352
    holds number of tables from which we will delete records.
1353
  */
202 by Brian Aker
Cleanup sql_lex to modern types.
1354
  uint32_t table_count;
1355
  uint8_t describe;
1 by brian
clean slate
1356
  /*
1357
    A flag that indicates what kinds of derived tables are present in the
1358
    query (0 if no derived tables, otherwise DERIVED_SUBQUERY).
1359
  */
202 by Brian Aker
Cleanup sql_lex to modern types.
1360
  uint8_t derived_tables;
919.1.2 by Brian Aker
Comitting the removal of server code for LOAD DATA "LOCAL" INFILE
1361
  bool drop_if_exists, drop_temporary, one_shot_set;
1 by brian
clean slate
1362
  bool autocommit;
383.1.26 by Brian Aker
Removed option for single command replication and have now left disable of
1363
  bool verbose;
1 by brian
clean slate
1364
1365
  bool tx_chain, tx_release;
1366
  bool subqueries, ignore;
1367
  st_parsing_options parsing_options;
1368
  Alter_info alter_info;
1369
1370
  /*
1371
    Pointers to part of LOAD DATA statement that should be rewritten
1372
    during replication ("LOCAL 'filename' REPLACE INTO" part).
1373
  */
1374
  const char *fname_start;
1375
  const char *fname_end;
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1376
1 by brian
clean slate
1377
  /**
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1378
    During name resolution search only in the table list given by
1 by brian
clean slate
1379
    Name_resolution_context::first_name_resolution_table and
1380
    Name_resolution_context::last_name_resolution_table
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1381
    (see Item_field::fix_fields()).
1 by brian
clean slate
1382
  */
1383
  bool use_only_table_context;
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1384
1 by brian
clean slate
1385
  bool escape_used;
1386
  bool is_lex_started; /* If lex_start() did run. For debugging. */
1387
575.4.7 by Monty Taylor
More header cleanup.
1388
  LEX();
1 by brian
clean slate
1389
575.4.7 by Monty Taylor
More header cleanup.
1390
  virtual ~LEX()
1 by brian
clean slate
1391
  {
1392
    destroy_query_tables_list();
1393
  }
1394
327.2.4 by Brian Aker
Refactoring table.h
1395
  TableList *unlink_first_table(bool *link_to_local);
1396
  void link_first_table_back(TableList *first, bool link_to_local);
1 by brian
clean slate
1397
  void first_lists_tables_same();
1398
1399
  bool only_view_structure();
1400
  bool need_correct_ident();
1401
1402
  void cleanup_after_one_table_open();
1403
1404
  bool push_context(Name_resolution_context *context)
1405
  {
1406
    return context_stack.push_front(context);
1407
  }
1408
1409
  void pop_context()
1410
  {
1411
    context_stack.pop();
1412
  }
1413
1414
  bool copy_db_to(char **p_db, size_t *p_db_length) const;
1415
1416
  Name_resolution_context *current_context()
1417
  {
1418
    return context_stack.head();
1419
  }
1420
  /*
520.1.21 by Brian Aker
THD -> Session rename
1421
    Restore the LEX and Session in case of a parse error.
1 by brian
clean slate
1422
  */
520.1.22 by Brian Aker
Second pass of thd cleanup
1423
  static void cleanup_lex_after_parse_error(Session *session);
1 by brian
clean slate
1424
1425
  /**
1426
    @brief check if the statement is a single-level join
1427
    @return result of the check
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1428
      @retval true  The statement doesn't contain subqueries, unions and
1 by brian
clean slate
1429
                    stored procedure calls.
51.1.52 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
1430
      @retval false There are subqueries, UNIONs or stored procedure calls.
1 by brian
clean slate
1431
  */
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1432
  bool is_single_level_stmt()
1433
  {
1434
    /*
1 by brian
clean slate
1435
      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:
1436
      on its top. So select_lex (as the first added) will be at the tail
1 by brian
clean slate
1437
      of the list.
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1438
    */
628 by Brian Aker
Collection of dead code removal
1439
    if (&select_lex == all_selects_list)
1 by brian
clean slate
1440
    {
51.1.52 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
1441
      assert(!all_selects_list->next_select_in_list());
1442
      return true;
1 by brian
clean slate
1443
    }
51.1.52 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
1444
    return false;
1 by brian
clean slate
1445
  }
575.4.7 by Monty Taylor
More header cleanup.
1446
};
1 by brian
clean slate
1447
575.4.7 by Monty Taylor
More header cleanup.
1448
struct st_lex_local: public LEX
1 by brian
clean slate
1449
{
1450
  static void *operator new(size_t size) throw()
1451
  {
1452
    return sql_alloc(size);
1453
  }
1454
  static void *operator new(size_t size, MEM_ROOT *mem_root) throw()
1455
  {
202 by Brian Aker
Cleanup sql_lex to modern types.
1456
    return (void*) alloc_root(mem_root, (uint32_t) size);
1 by brian
clean slate
1457
  }
644 by Brian Aker
Clean up warnings for Solaris.
1458
  static void operator delete(void *, size_t)
1 by brian
clean slate
1459
  { TRASH(ptr, size); }
644 by Brian Aker
Clean up warnings for Solaris.
1460
  static void operator delete(void *, MEM_ROOT *)
1 by brian
clean slate
1461
  { /* Never called */ }
1462
};
1463
520.1.22 by Brian Aker
Second pass of thd cleanup
1464
extern void lex_start(Session *session);
1 by brian
clean slate
1465
extern void lex_end(LEX *lex);
1466
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
1467
extern void trim_whitespace(const CHARSET_INFO * const cs, LEX_STRING *str);
1 by brian
clean slate
1468
1469
extern bool is_lex_native_function(const LEX_STRING *name);
1470
1471
/**
1472
  @} (End of group Semantic_Analysis)
1473
*/
1474
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
1475
#endif /* DRIZZLE_SERVER */
243.1.8 by Jay Pipes
More cleanup and revert broken base.h
1476
#endif /* DRIZZLE_SERVER_SQL_LEX_H */