~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
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
390.1.2 by Monty Taylor
Fixed copyright headers in drizzled/
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
1014.4.1 by Jay Pipes
Cosmetic: make sql_lex.h include guard match rest of drizzled/ headers.
20
#ifndef DRIZZLED_SQL_LEX_H
21
#define DRIZZLED_SQL_LEX_H
243.1.8 by Jay Pipes
More cleanup and revert broken base.h
22
1 by brian
clean slate
23
/**
24
  @defgroup Semantic_Analysis Semantic Analysis
25
*/
1008.3.17 by Stewart Smith
Start work to construct table proto in parser:
26
#include <drizzled/message/table.pb.h>
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
27
#include <drizzled/name_resolution_context.h>
28
#include <drizzled/table_list.h>
29
#include <drizzled/function/math/real.h>
30
#include <drizzled/key_part_spec.h>
31
#include <drizzled/index_hint.h>
32
#include <drizzled/statement.h>
33
#include <drizzled/optimizer/explain_plan.h>
139.1.8 by Stewart Smith
UDFs are now normal Item_func objects. Simplifies handling them a lot.
34
1089.6.3 by Padraig O'Sullivan
Replaced an instance where a uint8_t type was being used to hold a
35
#include <bitset>
1240.7.3 by Padraig O'Sullivan
Used std::string for the type in Select_Lex instead of char *.
36
#include <string>
1089.6.3 by Padraig O'Sullivan
Replaced an instance where a uint8_t type was being used to hold a
37
2198.1.2 by Olaf van der Spek
Refactor includes
38
namespace drizzled {
39
40
namespace plugin { class Function; }
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
41
2029.1.26 by Brian Aker
Merge in work for reserved words in SQL standard.
42
class st_lex_symbol;
584.4.7 by Monty Taylor
Removed a big bank of includes from item.h.
43
class select_result_interceptor;
584.1.14 by Monty Taylor
Removed field.h from common_includes.
44
1 by brian
clean slate
45
/* YACC and LEX Definitions */
46
47
/* These may not be declared yet */
48
class Table_ident;
831.1.2 by Brian Aker
Rename class file_exchange
49
class file_exchange;
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
50
class Lex_Column;
675 by Brian Aker
Cleanup around item includes.
51
class Item_outer_ref;
1 by brian
clean slate
52
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
53
} /* namespace drizzled */
54
1 by brian
clean slate
55
/*
56
  The following hack is needed because mysql_yacc.cc does not define
57
  YYSTYPE before including this file
58
*/
59
722.1.4 by Monty Taylor
Removed all the setting of DEFS everywhere. Use configmake.h to get the values
60
#ifdef DRIZZLE_SERVER
1878.3.1 by Monty Taylor
Split set_var.* into sys_var.* and set_var.*
61
/* set_var should change to set_var here ... */
62
# include <drizzled/sys_var.h>
722.1.4 by Monty Taylor
Removed all the setting of DEFS everywhere. Use configmake.h to get the values
63
# include <drizzled/item/func.h>
64
# ifdef DRIZZLE_YACC
65
#  define LEX_YYSTYPE void *
66
# else
67
#  if defined(DRIZZLE_LEX)
1237.9.4 by Padraig O'Sullivan
Removed the inclusion of drizzled/field.h in the server_includes header file.
68
#   include <drizzled/foreign_key.h>
722.1.4 by Monty Taylor
Removed all the setting of DEFS everywhere. Use configmake.h to get the values
69
#   include <drizzled/lex_symbol.h>
70
#   include <drizzled/sql_yacc.h>
71
#   define LEX_YYSTYPE YYSTYPE *
72
#  else
73
#   define LEX_YYSTYPE void *
74
#  endif /* defined(DRIZZLE_LEX) */
75
# endif /* DRIZZLE_YACC */
76
#endif /* DRIZZLE_SERVER */
1 by brian
clean slate
77
78
// describe/explain types
79
#define DESCRIBE_NORMAL		1
80
#define DESCRIBE_EXTENDED	2
81
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
82
#ifdef DRIZZLE_SERVER
1 by brian
clean slate
83
84
#define DERIVED_NONE	0
85
#define DERIVED_SUBQUERY	1
86
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
87
namespace drizzled
88
{
89
1 by brian
clean slate
90
typedef List<Item> List_item;
91
92
enum sub_select_type
93
{
1027 by Brian Aker
Merge Jay
94
  UNSPECIFIED_TYPE,
95
  UNION_TYPE,
96
  INTERSECT_TYPE,
97
  EXCEPT_TYPE,
98
  GLOBAL_OPTIONS_TYPE,
99
  DERIVED_TABLE_TYPE,
100
  OLAP_TYPE
1 by brian
clean slate
101
};
102
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
103
enum olap_type
1 by brian
clean slate
104
{
1027 by Brian Aker
Merge Jay
105
  UNSPECIFIED_OLAP_TYPE,
106
  CUBE_TYPE,
107
  ROLLUP_TYPE
1 by brian
clean slate
108
};
109
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
110
/*
111
  The state of the lex parsing for selects
112
1 by brian
clean slate
113
   master and slaves are pointers to select_lex.
114
   master is pointer to upper level node.
115
   slave is pointer to lower level node
116
   select_lex is a SELECT without union
117
   unit is container of either
118
     - One SELECT
119
     - UNION of selects
120
   select_lex and unit are both inherited form select_lex_node
121
   neighbors are two select_lex or units on the same level
122
123
   All select describing structures linked with following pointers:
124
   - list of neighbors (next/prev) (prev of first element point to slave
125
     pointer of upper structure)
126
     - For select this is a list of UNION's (or one element list)
127
     - For units this is a list of sub queries for the upper level select
128
129
   - pointer to master (master), which is
130
     If this is a unit
131
       - pointer to outer select_lex
132
     If this is a select_lex
133
       - pointer to outer unit structure for select
134
135
   - pointer to slave (slave), which is either:
136
     If this is a unit:
137
       - first SELECT that belong to this unit
138
     If this is a select_lex
139
       - first unit that belong to this SELECT (subquries or derived tables)
140
141
   - list of all select_lex (link_next/link_prev)
142
     This is to be used for things like derived tables creation, where we
143
     go through this list and create the derived tables.
144
145
   If unit contain several selects (UNION now, INTERSECT etc later)
146
   then it have special select_lex called fake_select_lex. It used for
147
   storing global parameters (like ORDER BY, LIMIT) and executing union.
148
   Subqueries used in global ORDER BY clause will be attached to this
149
   fake_select_lex, which will allow them correctly resolve fields of
150
   'upper' UNION and outer selects.
151
152
   For example for following query:
153
154
   select *
155
     from table1
156
     where table1.field IN (select * from table1_1_1 union
157
                            select * from table1_1_2)
158
     union
159
   select *
160
     from table2
161
     where table2.field=(select (select f1 from table2_1_1_1_1
162
                                   where table2_1_1_1_1.f2=table2_1_1.f3)
163
                           from table2_1_1
164
                           where table2_1_1.f1=table2.f2)
165
     union
166
   select * from table3;
167
168
   we will have following structure:
169
170
   select1: (select * from table1 ...)
171
   select2: (select * from table2 ...)
172
   select3: (select * from table3)
173
   select1.1.1: (select * from table1_1_1)
174
   ...
175
176
     main unit
177
     fake0
178
     select1 select2 select3
179
     |^^     |^
180
    s|||     ||master
181
    l|||     |+---------------------------------+
182
    a|||     +---------------------------------+|
183
    v|||master                         slave   ||
184
    e||+-------------------------+             ||
185
     V|            neighbor      |             V|
186
     unit1.1<+==================>unit1.2       unit2.1
187
     fake1.1
188
     select1.1.1 select 1.1.2    select1.2.1   select2.1.1
189
                                               |^
190
                                               ||
191
                                               V|
192
                                               unit2.1.1.1
193
                                               select2.1.1.1.1
194
195
196
   relation in main unit will be following:
197
   (bigger picture for:
198
      main unit
199
      fake0
200
      select1 select2 select3
201
   in the above picture)
202
203
         main unit
204
         |^^^^|fake_select_lex
205
         |||||+--------------------------------------------+
206
         ||||+--------------------------------------------+|
207
         |||+------------------------------+              ||
208
         ||+--------------+                |              ||
209
    slave||master         |                |              ||
210
         V|      neighbor |       neighbor |        master|V
211
         select1<========>select2<========>select3        fake0
212
213
    list of all select_lex will be following (as it will be constructed by
214
    parser):
215
216
    select1->select2->select3->select2.1.1->select 2.1.2->select2.1.1.1.1-+
217
                                                                          |
218
    +---------------------------------------------------------------------+
219
    |
220
    +->select1.1.1->select1.1.2
221
222
*/
223
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
224
/*
846 by Brian Aker
Removing on typedeffed class.
225
    Base class for Select_Lex (Select_Lex) &
848 by Brian Aker
typdef class removal (just... use the name of the class).
226
    Select_Lex_Unit (Select_Lex_Unit)
1 by brian
clean slate
227
*/
575.4.7 by Monty Taylor
More header cleanup.
228
class LEX;
846 by Brian Aker
Removing on typedeffed class.
229
class Select_Lex;
848 by Brian Aker
typdef class removal (just... use the name of the class).
230
class Select_Lex_Unit;
847 by Brian Aker
More typdef class removal.
231
class Select_Lex_Node {
1 by brian
clean slate
232
protected:
847 by Brian Aker
More typdef class removal.
233
  Select_Lex_Node *next, **prev,   /* neighbor list */
1 by brian
clean slate
234
    *master, *slave,                  /* vertical links */
846 by Brian Aker
Removing on typedeffed class.
235
    *link_next, **link_prev;          /* list of whole Select_Lex */
1 by brian
clean slate
236
public:
237
151 by Brian Aker
Ulonglong to uint64_t
238
  uint64_t options;
1 by brian
clean slate
239
240
  /*
241
    result of this query can't be cached, bit field, can be :
242
      UNCACHEABLE_DEPENDENT
243
      UNCACHEABLE_RAND
244
      UNCACHEABLE_SIDEEFFECT
245
      UNCACHEABLE_EXPLAIN
246
      UNCACHEABLE_PREPARE
247
  */
1858.1.1 by Padraig O'Sullivan
Replaced a uint8_t member with a standard bitset since it was being used as a bitset....
248
  std::bitset<8> uncacheable;
1 by brian
clean slate
249
  enum sub_select_type linkage;
250
  bool no_table_names_allowed; /* used for global order by */
251
  bool no_error; /* suppress error message (convert it to warnings) */
252
253
  static void *operator new(size_t size)
254
  {
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
255
    return memory::sql_alloc(size);
1 by brian
clean slate
256
  }
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
257
  static void *operator new(size_t size, memory::Root *mem_root)
1485 by Brian Aker
Updates to confine memroot
258
  { return (void*) mem_root->alloc_root((uint32_t) size); }
644 by Brian Aker
Clean up warnings for Solaris.
259
  static void operator delete(void *, size_t)
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
260
  {  }
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
261
  static void operator delete(void *, memory::Root *)
77.1.7 by Monty Taylor
Heap builds clean.
262
  {}
847 by Brian Aker
More typdef class removal.
263
  Select_Lex_Node(): linkage(UNSPECIFIED_TYPE) {}
264
  virtual ~Select_Lex_Node() {}
265
  inline Select_Lex_Node* get_master() { return master; }
1 by brian
clean slate
266
  virtual void init_query();
267
  virtual void init_select();
847 by Brian Aker
More typdef class removal.
268
  void include_down(Select_Lex_Node *upper);
269
  void include_neighbour(Select_Lex_Node *before);
270
  void include_standalone(Select_Lex_Node *sel, Select_Lex_Node **ref);
271
  void include_global(Select_Lex_Node **plink);
1 by brian
clean slate
272
  void exclude();
273
848 by Brian Aker
typdef class removal (just... use the name of the class).
274
  virtual Select_Lex_Unit* master_unit()= 0;
846 by Brian Aker
Removing on typedeffed class.
275
  virtual Select_Lex* outer_select()= 0;
276
  virtual Select_Lex* return_after_parsing()= 0;
1 by brian
clean slate
277
278
  virtual bool set_braces(bool value);
279
  virtual bool inc_in_sum_expr();
202 by Brian Aker
Cleanup sql_lex to modern types.
280
  virtual uint32_t get_in_sum_expr();
327.2.4 by Brian Aker
Refactoring table.h
281
  virtual TableList* get_table_list();
1 by brian
clean slate
282
  virtual List<Item>* get_item_list();
520.1.22 by Brian Aker
Second pass of thd cleanup
283
  virtual TableList *add_table_to_list(Session *session, Table_ident *table,
1858.1.2 by Padraig O'Sullivan
Converted another uint8_t type to be a bitset.
284
                                       LEX_STRING *alias,
285
                                       const std::bitset<NUM_OF_TABLE_OPTIONS>& table_options,
286
                                       thr_lock_type flags= TL_UNLOCK,
287
                                       List<Index_hint> *hints= 0,
288
                                       LEX_STRING *option= 0);
644 by Brian Aker
Clean up warnings for Solaris.
289
  virtual void set_lock_for_tables(thr_lock_type)
77.1.7 by Monty Taylor
Heap builds clean.
290
  {}
1 by brian
clean slate
291
848 by Brian Aker
typdef class removal (just... use the name of the class).
292
  friend class Select_Lex_Unit;
2026.2.1 by Monty Taylor
Renamed things prefixed mysql_ or mysqld_
293
  friend bool new_select(LEX *lex, bool move_down);
1 by brian
clean slate
294
private:
295
  void fast_exclude();
296
};
297
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
298
/*
848 by Brian Aker
typdef class removal (just... use the name of the class).
299
   Select_Lex_Unit - unit of selects (UNION, INTERSECT, ...) group
846 by Brian Aker
Removing on typedeffed class.
300
   Select_Lexs
1 by brian
clean slate
301
*/
520.1.21 by Brian Aker
THD -> Session rename
302
class Session;
1 by brian
clean slate
303
class select_result;
1541.1.1 by Brian Aker
JOIN -> Join rename
304
class Join;
1 by brian
clean slate
305
class select_union;
848 by Brian Aker
typdef class removal (just... use the name of the class).
306
class Select_Lex_Unit: public Select_Lex_Node {
1 by brian
clean slate
307
protected:
327.2.4 by Brian Aker
Refactoring table.h
308
  TableList result_table_list;
1 by brian
clean slate
309
  select_union *union_result;
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
310
  Table *table; /* temporary table using for appending UNION results */
1 by brian
clean slate
311
312
  select_result *result;
151 by Brian Aker
Ulonglong to uint64_t
313
  uint64_t found_rows_for_union;
1 by brian
clean slate
314
  bool saved_error;
315
316
public:
317
  bool  prepared, // prepare phase already performed for UNION (unit)
318
    optimized, // optimize phase already performed for UNION (unit)
319
    executed, // already executed
320
    cleaned;
321
322
  // list of fields which points to temporary table for union
323
  List<Item> item_list;
324
  /*
325
    list of types of items inside union (used for union & derived tables)
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
326
1 by brian
clean slate
327
    Item_type_holders from which this list consist may have pointers to Field,
328
    pointers is valid only after preparing SELECTS of this unit and before
329
    any SELECT of this unit execution
330
331
    TODO:
332
    Possibly this member should be protected, and its direct use replaced
333
    by get_unit_column_types(). Check the places where it is used.
334
  */
335
  List<Item> types;
336
  /*
337
    Pointer to 'last' select or pointer to unit where stored
338
    global parameters for union
339
  */
846 by Brian Aker
Removing on typedeffed class.
340
  Select_Lex *global_parameters;
1 by brian
clean slate
341
  //node on wich we should return current_select pointer after parsing subquery
846 by Brian Aker
Removing on typedeffed class.
342
  Select_Lex *return_to;
1 by brian
clean slate
343
  /* LIMIT clause runtime counters */
344
  ha_rows select_limit_cnt, offset_limit_cnt;
345
  /* not NULL if unit used in subselect, point to subselect item */
346
  Item_subselect *item;
347
  /* thread handler */
520.1.22 by Brian Aker
Second pass of thd cleanup
348
  Session *session;
1 by brian
clean slate
349
  /*
846 by Brian Aker
Removing on typedeffed class.
350
    Select_Lex for hidden SELECT in onion which process global
1 by brian
clean slate
351
    ORDER BY and LIMIT
352
  */
846 by Brian Aker
Removing on typedeffed class.
353
  Select_Lex *fake_select_lex;
1 by brian
clean slate
354
846 by Brian Aker
Removing on typedeffed class.
355
  Select_Lex *union_distinct; /* pointer to the last UNION DISTINCT */
1 by brian
clean slate
356
  bool describe; /* union exec() called for EXPLAIN */
357
358
  void init_query();
848 by Brian Aker
typdef class removal (just... use the name of the class).
359
  Select_Lex_Unit* master_unit();
846 by Brian Aker
Removing on typedeffed class.
360
  Select_Lex* outer_select();
361
  Select_Lex* first_select()
362
  {
363
    return reinterpret_cast<Select_Lex*>(slave);
364
  }
848 by Brian Aker
typdef class removal (just... use the name of the class).
365
  Select_Lex_Unit* next_unit()
846 by Brian Aker
Removing on typedeffed class.
366
  {
848 by Brian Aker
typdef class removal (just... use the name of the class).
367
    return reinterpret_cast<Select_Lex_Unit*>(next);
846 by Brian Aker
Removing on typedeffed class.
368
  }
369
  Select_Lex* return_after_parsing() { return return_to; }
1 by brian
clean slate
370
  void exclude_level();
371
  void exclude_tree();
372
373
  /* UNION methods */
892.2.4 by Monty Taylor
Fixed more warnings.
374
  bool prepare(Session *session, select_result *result,
375
               uint64_t additional_options);
1 by brian
clean slate
376
  bool exec();
377
  bool cleanup();
378
  inline void unclean() { cleaned= 0; }
379
  void reinit_exec_mechanism();
380
2215.2.1 by Stewart Smith
remove enum_query_type which was effectively unused. It was set to one value once, compared to it once (i.e. always true) and passed around everywhere doing nothing.
381
  void print(String *str);
1 by brian
clean slate
382
520.1.22 by Brian Aker
Second pass of thd cleanup
383
  bool add_fake_select_lex(Session *session);
384
  void init_prepare_fake_select_lex(Session *session);
1 by brian
clean slate
385
  bool change_result(select_result_interceptor *result,
386
                     select_result_interceptor *old_result);
846 by Brian Aker
Removing on typedeffed class.
387
  void set_limit(Select_Lex *values);
520.1.22 by Brian Aker
Second pass of thd cleanup
388
  void set_session(Session *session_arg) { session= session_arg; }
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
389
  inline bool is_union ();
1 by brian
clean slate
390
520.1.22 by Brian Aker
Second pass of thd cleanup
391
  friend void lex_start(Session *session);
1 by brian
clean slate
392
393
  List<Item> *get_unit_column_types();
394
};
395
396
/*
846 by Brian Aker
Removing on typedeffed class.
397
  Select_Lex - store information of parsed SELECT statment
1 by brian
clean slate
398
*/
847 by Brian Aker
More typdef class removal.
399
class Select_Lex: public Select_Lex_Node
1 by brian
clean slate
400
{
401
public:
1889.1.3 by Brian Aker
Merge in additional C++ warning fixes.
402
403
  Select_Lex() :
404
    context(),
405
    db(0),
406
    where(0),
407
    having(0),
408
    cond_value(),
409
    having_value(),
410
    parent_lex(0),
411
    olap(UNSPECIFIED_OLAP_TYPE),
412
    table_list(),
413
    group_list(),
414
    item_list(),
415
    interval_list(),
416
    is_item_list_lookup(false),
417
    join(0),
418
    top_join_list(),
419
    join_list(0),
420
    embedding(0),
421
    sj_nests(),
422
    leaf_tables(0),
423
    type(optimizer::ST_PRIMARY),
424
    order_list(),
425
    gorder_list(0),
426
    select_limit(0),
427
    offset_limit(0),
428
    ref_pointer_array(0),
429
    select_n_having_items(0),
430
    cond_count(0),
431
    between_count(0),
432
    max_equal_elems(0),
433
    select_n_where_fields(0),
434
    parsing_place(NO_MATTER),
435
    with_sum_func(0),
436
    in_sum_expr(0),
437
    select_number(0),
438
    nest_level(0),
439
    inner_sum_func_list(0),
440
    with_wild(0),
441
    braces(0),
442
    having_fix_field(0),
443
    inner_refs_list(),
444
    n_sum_items(0),
445
    n_child_sum_items(0),
446
    explicit_limit(0),
2141.4.2 by Andrew Hutchings
Implicit joins of the form "SELECT * FROM t1, t2" without WHERE or ON now error.
447
    is_cross(false),
1889.1.3 by Brian Aker
Merge in additional C++ warning fixes.
448
    subquery_in_having(0),
449
    is_correlated(0),
450
    exclude_from_table_unique_test(0),
451
    non_agg_fields(),
452
    cur_pos_in_select_list(0),
453
    prev_join_using(0),
454
    full_group_by_flag(),
455
    current_index_hint_type(INDEX_HINT_IGNORE),
456
    current_index_hint_clause(),
457
    index_hints(0)
458
  {
459
  }
460
1 by brian
clean slate
461
  Name_resolution_context context;
462
  char *db;
1014.4.9 by Jay Pipes
Code style cleanup and removal of dead LEX_SERVER_OPTIONS struct
463
  /* An Item representing the WHERE clause */
464
  Item *where;
465
  /* An Item representing the HAVING clause */
466
  Item *having;
1 by brian
clean slate
467
  /* Saved values of the WHERE and HAVING clauses*/
1014.4.9 by Jay Pipes
Code style cleanup and removal of dead LEX_SERVER_OPTIONS struct
468
  Item::cond_result cond_value;
469
  Item::cond_result having_value;
1 by brian
clean slate
470
  /* point on lex in which it was created, used in view subquery detection */
575.4.7 by Monty Taylor
More header cleanup.
471
  LEX *parent_lex;
1 by brian
clean slate
472
  enum olap_type olap;
327.2.4 by Brian Aker
Refactoring table.h
473
  /* FROM clause - points to the beginning of the TableList::next_local list. */
1014.4.9 by Jay Pipes
Code style cleanup and removal of dead LEX_SERVER_OPTIONS struct
474
  SQL_LIST table_list;
475
  SQL_LIST group_list; /* GROUP BY clause. */
476
  List<Item> item_list;  /* list of fields & expressions */
477
  List<String> interval_list;
478
  bool is_item_list_lookup;
1541.1.1 by Brian Aker
JOIN -> Join rename
479
  Join *join; /* after Join::prepare it is pointer to corresponding JOIN */
327.2.4 by Brian Aker
Refactoring table.h
480
  List<TableList> top_join_list; /* join list of the top level          */
481
  List<TableList> *join_list;    /* list for the currently parsed join  */
482
  TableList *embedding;          /* table embedding to the above list   */
483
  List<TableList> sj_nests;
1 by brian
clean slate
484
  /*
485
    Beginning of the list of leaves in a FROM clause, where the leaves
486
    inlcude all base tables including view tables. The tables are connected
327.2.4 by Brian Aker
Refactoring table.h
487
    by TableList::next_leaf, so leaf_tables points to the left-most leaf.
1 by brian
clean slate
488
  */
327.2.4 by Brian Aker
Refactoring table.h
489
  TableList *leaf_tables;
1237.13.30 by Padraig O'Sullivan
Corrected a valgrind warning due to using std::string in the Select_Lex class whose memory is
490
  enum drizzled::optimizer::select_type type; /* type of select for EXPLAIN */
1 by brian
clean slate
491
492
  SQL_LIST order_list;                /* ORDER clause */
493
  SQL_LIST *gorder_list;
494
  Item *select_limit, *offset_limit;  /* LIMIT clause parameters */
1014.4.9 by Jay Pipes
Code style cleanup and removal of dead LEX_SERVER_OPTIONS struct
495
  /* Arrays of pointers to top elements of all_fields list */
1 by brian
clean slate
496
  Item **ref_pointer_array;
497
498
  /*
499
    number of items in select_list and HAVING clause used to get number
500
    bigger then can be number of entries that will be added to all item
501
    list during split_sum_func
502
  */
202 by Brian Aker
Cleanup sql_lex to modern types.
503
  uint32_t select_n_having_items;
504
  uint32_t cond_count;    /* number of arguments of and/or/xor in where/having/on */
505
  uint32_t between_count; /* number of between predicates in where/having/on      */
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
506
  uint32_t max_equal_elems; /* maximal number of elements in multiple equalities  */
1 by brian
clean slate
507
  /*
508
    Number of fields used in select list or where clause of current select
509
    and all inner subselects.
510
  */
202 by Brian Aker
Cleanup sql_lex to modern types.
511
  uint32_t select_n_where_fields;
1 by brian
clean slate
512
  enum_parsing_place parsing_place; /* where we are parsing expression */
513
  bool with_sum_func;   /* sum function indicator */
514
202 by Brian Aker
Cleanup sql_lex to modern types.
515
  uint32_t in_sum_expr;
516
  uint32_t select_number; /* number of select (used for EXPLAIN) */
937.2.6 by Stewart Smith
make set_if_bigger typesafe for C and C++. Fix up everywhere.
517
  int8_t nest_level;     /* nesting level of select */
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
518
  Item_sum *inner_sum_func_list; /* list of sum func in nested selects */
202 by Brian Aker
Cleanup sql_lex to modern types.
519
  uint32_t with_wild; /* item list contain '*' */
1014.4.9 by Jay Pipes
Code style cleanup and removal of dead LEX_SERVER_OPTIONS struct
520
  bool braces;   	/* SELECT ... UNION (SELECT ... ) <- this braces */
51.1.52 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
521
  /* true when having fix field called in processing of this SELECT */
1 by brian
clean slate
522
  bool having_fix_field;
523
  /* List of references to fields referenced from inner selects */
524
  List<Item_outer_ref> inner_refs_list;
525
  /* Number of Item_sum-derived objects in this SELECT */
202 by Brian Aker
Cleanup sql_lex to modern types.
526
  uint32_t n_sum_items;
1 by brian
clean slate
527
  /* Number of Item_sum-derived objects in children and descendant SELECTs */
202 by Brian Aker
Cleanup sql_lex to modern types.
528
  uint32_t n_child_sum_items;
1 by brian
clean slate
529
530
  /* explicit LIMIT clause was used */
531
  bool explicit_limit;
2141.4.2 by Andrew Hutchings
Implicit joins of the form "SELECT * FROM t1, t2" without WHERE or ON now error.
532
533
  /* explicit CROSS JOIN was used */
534
  bool is_cross;
535
1 by brian
clean slate
536
  /*
537
    there are subquery in HAVING clause => we can't close tables before
538
    query processing end even if we use temporary table
539
  */
540
  bool subquery_in_having;
51.1.52 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
541
  /* true <=> this SELECT is correlated w.r.t. some ancestor select */
1 by brian
clean slate
542
  bool is_correlated;
543
  /* exclude this select from check of unique_table() */
544
  bool exclude_from_table_unique_test;
545
  /* List of fields that aren't under an aggregate function */
546
  List<Item_field> non_agg_fields;
547
  /* index in the select list of the expression currently being fixed */
548
  int cur_pos_in_select_list;
549
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
550
  /*
1 by brian
clean slate
551
    This is a copy of the original JOIN USING list that comes from
552
    the parser. The parser :
327.2.4 by Brian Aker
Refactoring table.h
553
      1. Sets the natural_join of the second TableList in the join
846 by Brian Aker
Removing on typedeffed class.
554
         and the Select_Lex::prev_join_using.
327.2.4 by Brian Aker
Refactoring table.h
555
      2. Makes a parent TableList and sets its is_natural_join/
1 by brian
clean slate
556
       join_using_fields members.
327.2.4 by Brian Aker
Refactoring table.h
557
      3. Uses the wrapper TableList as a table in the upper level.
1 by brian
clean slate
558
    We cannot assign directly to join_using_fields in the parser because
327.2.4 by Brian Aker
Refactoring table.h
559
    at stage (1.) the parent TableList is not constructed yet and
1 by brian
clean slate
560
    the assignment will override the JOIN USING fields of the lower level
561
    joins on the right.
562
  */
563
  List<String> *prev_join_using;
564
  /*
565
    Bitmap used in the ONLY_FULL_GROUP_BY_MODE to prevent mixture of aggregate
566
    functions and non aggregated fields when GROUP BY list is absent.
567
    Bits:
568
      0 - non aggregated fields are used in this select,
569
          defined as NON_AGG_FIELD_USED.
570
      1 - aggregate functions are used in this select,
571
          defined as SUM_FUNC_USED.
572
  */
1089.6.3 by Padraig O'Sullivan
Replaced an instance where a uint8_t type was being used to hold a
573
  std::bitset<2> full_group_by_flag;
1637.1.3 by Brian Aker
This fixes the parser to no longer do the bad syntax around the cross join
574
1 by brian
clean slate
575
  void init_query();
576
  void init_select();
848 by Brian Aker
typdef class removal (just... use the name of the class).
577
  Select_Lex_Unit* master_unit();
578
  Select_Lex_Unit* first_inner_unit()
846 by Brian Aker
Removing on typedeffed class.
579
  {
848 by Brian Aker
typdef class removal (just... use the name of the class).
580
    return (Select_Lex_Unit*) slave;
846 by Brian Aker
Removing on typedeffed class.
581
  }
582
  Select_Lex* outer_select();
1014.4.9 by Jay Pipes
Code style cleanup and removal of dead LEX_SERVER_OPTIONS struct
583
  Select_Lex* next_select()
584
  {
585
    return (Select_Lex*) next;
586
  }
846 by Brian Aker
Removing on typedeffed class.
587
  Select_Lex* next_select_in_list()
588
  {
589
    return (Select_Lex*) link_next;
590
  }
847 by Brian Aker
More typdef class removal.
591
  Select_Lex_Node** next_select_in_list_addr()
1 by brian
clean slate
592
  {
593
    return &link_next;
594
  }
846 by Brian Aker
Removing on typedeffed class.
595
  Select_Lex* return_after_parsing()
1 by brian
clean slate
596
  {
597
    return master_unit()->return_after_parsing();
598
  }
599
846 by Brian Aker
Removing on typedeffed class.
600
  void mark_as_dependent(Select_Lex *last);
1 by brian
clean slate
601
602
  bool set_braces(bool value);
603
  bool inc_in_sum_expr();
202 by Brian Aker
Cleanup sql_lex to modern types.
604
  uint32_t get_in_sum_expr();
1 by brian
clean slate
605
520.1.22 by Brian Aker
Second pass of thd cleanup
606
  bool add_item_to_list(Session *session, Item *item);
607
  bool add_group_to_list(Session *session, Item *item, bool asc);
608
  bool add_order_to_list(Session *session, Item *item, bool asc);
1027 by Brian Aker
Merge Jay
609
  TableList* add_table_to_list(Session *session,
610
                               Table_ident *table,
611
                               LEX_STRING *alias,
1858.1.2 by Padraig O'Sullivan
Converted another uint8_t type to be a bitset.
612
                               const std::bitset<NUM_OF_TABLE_OPTIONS>& table_options,
1027 by Brian Aker
Merge Jay
613
                               thr_lock_type flags= TL_UNLOCK,
614
                               List<Index_hint> *hints= 0,
615
                               LEX_STRING *option= 0);
327.2.4 by Brian Aker
Refactoring table.h
616
  TableList* get_table_list();
520.1.22 by Brian Aker
Second pass of thd cleanup
617
  bool init_nested_join(Session *session);
618
  TableList *end_nested_join(Session *session);
619
  TableList *nest_last_join(Session *session);
327.2.4 by Brian Aker
Refactoring table.h
620
  void add_joined_table(TableList *table);
621
  TableList *convert_right_join();
1 by brian
clean slate
622
  List<Item>* get_item_list();
623
  void set_lock_for_tables(thr_lock_type lock_type);
624
  inline void init_order()
625
  {
626
    order_list.elements= 0;
627
    order_list.first= 0;
481 by Brian Aker
Remove all of uchar.
628
    order_list.next= (unsigned char**) &order_list.first;
1 by brian
clean slate
629
  }
630
  /*
2026.2.1 by Monty Taylor
Renamed things prefixed mysql_ or mysqld_
631
    This method created for reiniting LEX in admin_table() and can be
846 by Brian Aker
Removing on typedeffed class.
632
    used only if you are going remove all Select_Lex & units except belonger
1 by brian
clean slate
633
    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).
634
    Select_Lex_Unit::exclude_level & Select_Lex_Unit::exclude_tree
1 by brian
clean slate
635
  */
1014.4.9 by Jay Pipes
Code style cleanup and removal of dead LEX_SERVER_OPTIONS struct
636
  void cut_subtree()
637
  {
638
    slave= 0;
639
  }
1 by brian
clean slate
640
  bool test_limit();
641
520.1.22 by Brian Aker
Second pass of thd cleanup
642
  friend void lex_start(Session *session);
1 by brian
clean slate
643
  void make_empty_select()
644
  {
645
    init_query();
646
    init_select();
647
  }
520.1.22 by Brian Aker
Second pass of thd cleanup
648
  bool setup_ref_array(Session *session, uint32_t order_group_num);
2215.2.1 by Stewart Smith
remove enum_query_type which was effectively unused. It was set to one value once, compared to it once (i.e. always true) and passed around everywhere doing nothing.
649
  void print(Session *session, String *str);
650
  static void print_order(String *str, Order *order);
651
652
  void print_limit(Session *session, String *str);
520.1.22 by Brian Aker
Second pass of thd cleanup
653
  void fix_prepare_information(Session *session, Item **conds, Item **having_conds);
1 by brian
clean slate
654
  /*
655
    Destroy the used execution plan (JOIN) of this subtree (this
848 by Brian Aker
typdef class removal (just... use the name of the class).
656
    Select_Lex and all nested Select_Lexes and Select_Lex_Units).
1 by brian
clean slate
657
  */
658
  bool cleanup();
659
  /*
660
    Recursively cleanup the join of this select lex and of all nested
661
    select lexes.
662
  */
663
  void cleanup_all_joins(bool full);
664
665
  void set_index_hint_type(enum index_hint_type type, index_clause_map clause);
666
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
667
  /*
1 by brian
clean slate
668
   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:
669
   hint will be the current ones (set by set_index_hint())
1 by brian
clean slate
670
  */
520.1.22 by Brian Aker
Second pass of thd cleanup
671
  bool add_index_hint (Session *session, char *str, uint32_t length);
1 by brian
clean slate
672
673
  /* make a list to hold index hints */
520.1.22 by Brian Aker
Second pass of thd cleanup
674
  void alloc_index_hints (Session *session);
1 by brian
clean slate
675
  /* read and clear the index hints */
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
676
  List<Index_hint>* pop_index_hints(void)
1 by brian
clean slate
677
  {
678
    List<Index_hint> *hints= index_hints;
679
    index_hints= NULL;
680
    return hints;
681
  }
682
683
  void clear_index_hints(void) { index_hints= NULL; }
684
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
685
private:
1 by brian
clean slate
686
  /* current index hint kind. used in filling up index_hints */
687
  enum index_hint_type current_index_hint_type;
688
  index_clause_map current_index_hint_clause;
689
  /* a list of USE/FORCE/IGNORE INDEX */
690
  List<Index_hint> *index_hints;
691
};
692
848 by Brian Aker
typdef class removal (just... use the name of the class).
693
inline bool Select_Lex_Unit::is_union ()
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
694
{
695
  return first_select()->next_select() &&
1 by brian
clean slate
696
    first_select()->next_select()->linkage == UNION_TYPE;
697
}
698
1014.4.9 by Jay Pipes
Code style cleanup and removal of dead LEX_SERVER_OPTIONS struct
699
enum xa_option_words
700
{
701
  XA_NONE
702
, XA_JOIN
703
, XA_RESUME
704
, XA_ONE_PHASE
705
, XA_SUSPEND
706
, XA_FOR_MIGRATE
707
};
1 by brian
clean slate
708
709
extern const LEX_STRING null_lex_str;
710
711
/*
712
  Class representing list of all tables used by statement.
713
  It also contains information about stored functions used by statement
714
  since during its execution we may have to add all tables used by its
715
  stored functions/triggers to this list in order to pre-open and lock
716
  them.
717
718
  Also used by st_lex::reset_n_backup/restore_backup_query_tables_list()
719
  methods to save and restore this information.
720
*/
721
class Query_tables_list
722
{
723
public:
724
  /* Global list of all tables used by this statement */
327.2.4 by Brian Aker
Refactoring table.h
725
  TableList *query_tables;
1 by brian
clean slate
726
  /* Pointer to next_global member of last element in the previous list. */
327.2.4 by Brian Aker
Refactoring table.h
727
  TableList **query_tables_last;
1 by brian
clean slate
728
  /*
729
    If non-0 then indicates that query requires prelocking and points to
730
    next_global member of last own element in query table list (i.e. last
731
    table which was not added to it as part of preparation to prelocking).
732
    0 - indicates that this query does not need prelocking.
733
  */
327.2.4 by Brian Aker
Refactoring table.h
734
  TableList **query_tables_own_last;
1 by brian
clean slate
735
736
  /*
737
    These constructor and destructor serve for creation/destruction
738
    of Query_tables_list instances which are used as backup storage.
739
  */
740
  Query_tables_list() {}
1240.9.3 by Monty Taylor
remark #444: destructor for base class "Query_tables_list" (declared at line 656) is not virtual
741
  virtual ~Query_tables_list() {}
1 by brian
clean slate
742
743
  /* Initializes (or resets) Query_tables_list object for "real" use. */
744
  void reset_query_tables_list(bool init);
745
746
  /*
747
    Direct addition to the list of query tables.
748
    If you are using this function, you must ensure that the table
749
    object, in particular table->db member, is initialized.
750
  */
327.2.4 by Brian Aker
Refactoring table.h
751
  void add_to_query_tables(TableList *table)
1 by brian
clean slate
752
  {
753
    *(table->prev_global= query_tables_last)= table;
754
    query_tables_last= &table->next_global;
755
  }
756
  /* Return pointer to first not-own table in query-tables or 0 */
327.2.4 by Brian Aker
Refactoring table.h
757
  TableList* first_not_own_table()
1 by brian
clean slate
758
  {
759
    return ( query_tables_own_last ? *query_tables_own_last : 0);
760
  }
761
  void chop_off_not_own_tables()
762
  {
763
    if (query_tables_own_last)
764
    {
765
      *query_tables_own_last= 0;
766
      query_tables_last= query_tables_own_last;
767
      query_tables_own_last= 0;
768
    }
769
  }
770
};
771
772
/**
773
  The state of the lexical parser, when parsing comments.
774
*/
775
enum enum_comment_state
776
{
777
  /**
778
    Not parsing comments.
779
  */
780
  NO_COMMENT,
781
  /**
782
    Parsing comments that need to be preserved.
783
    Typically, these are user comments '/' '*' ... '*' '/'.
784
  */
785
  PRESERVE_COMMENT,
786
  /**
787
    Parsing comments that need to be discarded.
788
    Typically, these are special comments '/' '*' '!' ... '*' '/',
789
    or '/' '*' '!' 'M' 'M' 'm' 'm' 'm' ... '*' '/', where the comment
790
    markers should not be expanded.
791
  */
792
  DISCARD_COMMENT
793
};
794
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
795
} /* namespace drizzled */
796
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
797
#include <drizzled/lex_input_stream.h>
1 by brian
clean slate
798
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
799
namespace drizzled
800
{
801
520.1.21 by Brian Aker
THD -> Session rename
802
/* The state of the lex parsing. This is saved in the Session struct */
575.4.7 by Monty Taylor
More header cleanup.
803
class LEX : public Query_tables_list
1 by brian
clean slate
804
{
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
805
public:
848 by Brian Aker
typdef class removal (just... use the name of the class).
806
  Select_Lex_Unit unit;                         /* most upper unit */
846 by Brian Aker
Removing on typedeffed class.
807
  Select_Lex select_lex;                        /* first Select_Lex */
808
  /* current Select_Lex in parsing */
809
  Select_Lex *current_select;
810
  /* list of all Select_Lex */
811
  Select_Lex *all_selects_list;
1 by brian
clean slate
812
1014.4.5 by Jay Pipes
Cleanup of LEX structure. Removed unused xid member variable, documented a number of member variables.
813
  /* This is the "scale" for DECIMAL (S,P) notation */ 
814
  char *length;
815
  /* This is the decimal precision in DECIMAL(S,P) notation */
816
  char *dec;
817
  
1014.4.7 by Jay Pipes
More documentation of LEX member variables and removal of slave_session_opt unused member variable.
818
  /**
819
   * This is used kind of like the "ident" member variable below, as 
820
   * a place to store certain names of identifiers.  Unfortunately, it
821
   * is used differently depending on the Command (SELECT on a derived
822
   * table vs CREATE)
823
   */
1 by brian
clean slate
824
  LEX_STRING name;
1014.4.7 by Jay Pipes
More documentation of LEX member variables and removal of slave_session_opt unused member variable.
825
  /* The string literal used in a LIKE expression */
1 by brian
clean slate
826
  String *wild;
831.1.2 by Brian Aker
Rename class file_exchange
827
  file_exchange *exchange;
1 by brian
clean slate
828
  select_result *result;
1014.4.5 by Jay Pipes
Cleanup of LEX structure. Removed unused xid member variable, documented a number of member variables.
829
1014.4.7 by Jay Pipes
More documentation of LEX member variables and removal of slave_session_opt unused member variable.
830
  /**
831
   * This is current used to store the name of a named key cache
832
   * or a named savepoint.  It should probably be refactored out into
833
   * the eventual Command class built for the Keycache and Savepoint
834
   * commands.
835
   */ 
1014.4.5 by Jay Pipes
Cleanup of LEX structure. Removed unused xid member variable, documented a number of member variables.
836
  LEX_STRING ident;
837
481 by Brian Aker
Remove all of uchar.
838
  unsigned char* yacc_yyss, *yacc_yyvs;
1014.4.7 by Jay Pipes
More documentation of LEX member variables and removal of slave_session_opt unused member variable.
839
  /* The owning Session of this LEX */
520.1.22 by Brian Aker
Second pass of thd cleanup
840
  Session *session;
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
841
  const CHARSET_INFO *charset;
1 by brian
clean slate
842
  bool text_string_is_7bit;
843
  /* store original leaf_tables for INSERT SELECT and PS/SP */
327.2.4 by Brian Aker
Refactoring table.h
844
  TableList *leaf_tables_insert;
1 by brian
clean slate
845
846
  List<Key_part_spec> col_list;
847
  List<Key_part_spec> ref_list;
848
  List<String>	      interval_list;
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
849
  List<Lex_Column>    columns;
1 by brian
clean slate
850
  List<Item>	      *insert_list,field_list,value_list,update_list;
851
  List<List_item>     many_values;
2040.6.4 by Monty Taylor
Replaced List<set_var_base> with
852
  SetVarVector  var_list;
1 by brian
clean slate
853
  /*
854
    A stack of name resolution contexts for the query. This stack is used
855
    at parse time to set local name resolution contexts for various parts
856
    of a query. For example, in a JOIN ... ON (some_condition) clause the
857
    Items in 'some_condition' must be resolved only against the operands
858
    of the the join, and not against the whole clause. Similarly, Items in
859
    subqueries should be resolved against the subqueries (and outer queries).
860
    The stack is used in the following way: when the parser detects that
861
    all Items in some clause need a local context, it creates a new context
862
    and pushes it on the stack. All newly created Items always store the
863
    top-most context in the stack. Once the parser leaves the clause that
864
    required a local context, the parser pops the top-most context.
865
  */
866
  List<Name_resolution_context> context_stack;
867
1014.4.5 by Jay Pipes
Cleanup of LEX structure. Removed unused xid member variable, documented a number of member variables.
868
  SQL_LIST auxiliary_table_list;
869
  SQL_LIST save_list;
1052.2.3 by Nathan Williams
No actual code changes. Changed Create_field to CreateField to be consistent with coding standards.
870
  CreateField *last_field;
1 by brian
clean slate
871
  Item_sum *in_sum_func;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
872
  plugin::Function *udf;
202 by Brian Aker
Cleanup sql_lex to modern types.
873
  uint32_t type;
1 by brian
clean slate
874
  /*
875
    This variable is used in post-parse stage to declare that sum-functions,
876
    or functions which have sense only if GROUP BY is present, are allowed.
877
    For example in a query
878
    SELECT ... FROM ...WHERE MIN(i) == 1 GROUP BY ... HAVING MIN(i) > 2
879
    MIN(i) in the WHERE clause is not allowed in the opposite to MIN(i)
880
    in the HAVING clause. Due to possible nesting of select construct
881
    the variable can contain 0 or 1 for each nest level.
882
  */
883
  nesting_map allow_sum_func;
884
  enum_sql_command sql_command;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
885
  statement::Statement *statement;
1 by brian
clean slate
886
  /*
887
    Usually `expr` rule of yacc is quite reused but some commands better
888
    not support subqueries which comes standard with this rule, like
889
    KILL, HA_READ, CREATE/ALTER EVENT etc. Set this to `false` to get
890
    syntax error back.
891
  */
892
  bool expr_allows_subselect;
893
894
  thr_lock_type lock_option;
895
  enum enum_duplicates duplicates;
896
  union {
897
    enum ha_rkey_function ha_rkey_mode;
898
    enum xa_option_words xa_opt;
899
  };
1273.13.24 by Brian Aker
Updating style, simplified code.
900
  sql_var_t option_type;
1 by brian
clean slate
901
902
  int nest_level;
202 by Brian Aker
Cleanup sql_lex to modern types.
903
  uint8_t describe;
1 by brian
clean slate
904
  /*
905
    A flag that indicates what kinds of derived tables are present in the
906
    query (0 if no derived tables, otherwise DERIVED_SUBQUERY).
907
  */
202 by Brian Aker
Cleanup sql_lex to modern types.
908
  uint8_t derived_tables;
1014.4.7 by Jay Pipes
More documentation of LEX member variables and removal of slave_session_opt unused member variable.
909
910
  /* Was the IGNORE symbol found in statement */
1014.4.5 by Jay Pipes
Cleanup of LEX structure. Removed unused xid member variable, documented a number of member variables.
911
  bool ignore;
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
912
1 by brian
clean slate
913
  /**
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
914
    During name resolution search only in the table list given by
1 by brian
clean slate
915
    Name_resolution_context::first_name_resolution_table and
916
    Name_resolution_context::last_name_resolution_table
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
917
    (see Item_field::fix_fields()).
1 by brian
clean slate
918
  */
919
  bool use_only_table_context;
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
920
1014.4.7 by Jay Pipes
More documentation of LEX member variables and removal of slave_session_opt unused member variable.
921
  /* Was the ESCAPE keyword used? */
1 by brian
clean slate
922
  bool escape_used;
923
  bool is_lex_started; /* If lex_start() did run. For debugging. */
924
575.4.7 by Monty Taylor
More header cleanup.
925
  LEX();
1 by brian
clean slate
926
1008.3.17 by Stewart Smith
Start work to construct table proto in parser:
927
  /* Note that init and de-init mostly happen in lex_start and lex_end
928
     and not here. This is because LEX isn't delete/new for each new
929
     statement in a session. It's re-used by doing lex_end, lex_start
930
     in sql_lex.cc
931
  */
2029.1.2 by Brian Aker
Merge in refactor of LIKE up to its own calling pointer in the parser.
932
  virtual ~LEX();
1 by brian
clean slate
933
327.2.4 by Brian Aker
Refactoring table.h
934
  TableList *unlink_first_table(bool *link_to_local);
935
  void link_first_table_back(TableList *first, bool link_to_local);
1 by brian
clean slate
936
  void first_lists_tables_same();
937
938
  void cleanup_after_one_table_open();
939
940
  bool push_context(Name_resolution_context *context)
941
  {
942
    return context_stack.push_front(context);
943
  }
944
945
  void pop_context()
946
  {
947
    context_stack.pop();
948
  }
949
950
  bool copy_db_to(char **p_db, size_t *p_db_length) const;
951
952
  Name_resolution_context *current_context()
953
  {
2183.2.21 by Olaf van der Spek
Use List::front()
954
    return &context_stack.front();
1 by brian
clean slate
955
  }
956
957
  /**
958
    @brief check if the statement is a single-level join
959
    @return result of the check
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
960
      @retval true  The statement doesn't contain subqueries, unions and
1 by brian
clean slate
961
                    stored procedure calls.
51.1.52 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
962
      @retval false There are subqueries, UNIONs or stored procedure calls.
1 by brian
clean slate
963
  */
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
964
  bool is_single_level_stmt()
965
  {
966
    /*
1 by brian
clean slate
967
      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:
968
      on its top. So select_lex (as the first added) will be at the tail
1 by brian
clean slate
969
      of the list.
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
970
    */
628 by Brian Aker
Collection of dead code removal
971
    if (&select_lex == all_selects_list)
1 by brian
clean slate
972
    {
51.1.52 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
973
      assert(!all_selects_list->next_select_in_list());
974
      return true;
1 by brian
clean slate
975
    }
51.1.52 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
976
    return false;
1 by brian
clean slate
977
  }
1637.1.3 by Brian Aker
This fixes the parser to no longer do the bad syntax around the cross join
978
  bool is_cross; // CROSS keyword was used
1643.6.13 by Djellel E. Difallah
adding tests
979
  bool isCacheable()
980
  {
981
    return cacheable;
982
  }
983
  void setCacheable(bool val)
984
  {
985
    cacheable= val;
986
  }
1751.3.1 by Brian Aker
This add a couple of utility table functions to be used with testing.
987
988
  void reset()
989
  {
990
    sum_expr_used= false;
2029.1.5 by Brian Aker
Move exists into LEX.
991
    _exists= false;
1751.3.1 by Brian Aker
This add a couple of utility table functions to be used with testing.
992
  }
993
994
  void setSumExprUsed()
995
  {
996
    sum_expr_used= true;
997
  }
998
999
  bool isSumExprUsed()
1000
  {
1001
    return sum_expr_used;
1002
  }
1897.1.5 by Brian Aker
Move lex_end to be class member.
1003
1897.1.7 by Brian Aker
Partial encapsulation of lex_start.
1004
  void start(Session *session);
1897.1.5 by Brian Aker
Move lex_end to be class member.
1005
  void end();
1006
2029.1.2 by Brian Aker
Merge in refactor of LIKE up to its own calling pointer in the parser.
1007
  message::Table *table()
1008
  {
1009
    if (not _create_table)
1010
      _create_table= new message::Table;
1011
1012
    return _create_table;
1013
  }
1014
2029.1.20 by Brian Aker
Make use of lex for its pointer for field creation.
1015
  message::Table::Field *field()
1016
  {
1017
    return _create_field;
1018
  }
1019
1020
  void setField(message::Table::Field *arg)
1021
  {
1022
    _create_field= arg;
1023
  }
1024
2029.1.5 by Brian Aker
Move exists into LEX.
1025
  void setExists()
1026
  {
1027
    _exists= true;
1028
  }
1029
1030
  bool exists() const
1031
  {
1032
    return _exists;
1033
  }
1034
1643.6.13 by Djellel E. Difallah
adding tests
1035
private: 
1036
  bool cacheable;
1751.3.1 by Brian Aker
This add a couple of utility table functions to be used with testing.
1037
  bool sum_expr_used;
2029.1.2 by Brian Aker
Merge in refactor of LIKE up to its own calling pointer in the parser.
1038
  message::Table *_create_table;
2029.1.20 by Brian Aker
Make use of lex for its pointer for field creation.
1039
  message::Table::Field *_create_field;
2029.1.5 by Brian Aker
Move exists into LEX.
1040
  bool _exists;
575.4.7 by Monty Taylor
More header cleanup.
1041
};
1 by brian
clean slate
1042
520.1.22 by Brian Aker
Second pass of thd cleanup
1043
extern void lex_start(Session *session);
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
1044
extern void trim_whitespace(const CHARSET_INFO * const cs, LEX_STRING *str);
1 by brian
clean slate
1045
extern bool is_lex_native_function(const LEX_STRING *name);
1046
2029.1.26 by Brian Aker
Merge in work for reserved words in SQL standard.
1047
bool check_for_sql_keyword(drizzled::st_lex_symbol const&);
2073.1.2 by Brian Aker
Basic DDL for catalog.
1048
bool check_for_sql_keyword(drizzled::lex_string_t const&);
2029.1.26 by Brian Aker
Merge in work for reserved words in SQL standard.
1049
1 by brian
clean slate
1050
/**
1051
  @} (End of group Semantic_Analysis)
1052
*/
1053
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1054
} /* namespace drizzled */
1055
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
1056
#endif /* DRIZZLE_SERVER */
1014.4.1 by Jay Pipes
Cosmetic: make sql_lex.h include guard match rest of drizzled/ headers.
1057
#endif /* DRIZZLED_SQL_LEX_H */