~ubuntu-branches/ubuntu/quantal/mysql-workbench/quantal

« back to all changes in this revision

Viewing changes to library/sql-parser/source/sql_lex.h

  • Committer: Package Import Robot
  • Author(s): Dmitry Smirnov
  • Date: 2012-03-01 21:57:30 UTC
  • Revision ID: package-import@ubuntu.com-20120301215730-o7y8av8y38n162ro
Tags: upstream-5.2.38+dfsg
ImportĀ upstreamĀ versionĀ 5.2.38+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; either version 2 of the License, or
 
6
   (at your option) any later version.
 
7
 
 
8
   This program is distributed in the hope that it will be useful,
 
9
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
   GNU General Public License for more details.
 
12
 
 
13
   You should have received a copy of the GNU General Public License
 
14
   along with this program; if not, write to the Free Software
 
15
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
16
 
 
17
 
 
18
/* YACC and LEX Definitions */
 
19
 
 
20
namespace mysql_parser
 
21
{
 
22
/* These may not be declared yet */
 
23
class Table_ident;
 
24
class sql_exchange;
 
25
class LEX_COLUMN;
 
26
class sp_head;
 
27
class sp_name;
 
28
class sp_instr;
 
29
class sp_pcontext;
 
30
class st_alter_tablespace;
 
31
class partition_info;
 
32
class Event_timed;
 
33
 
 
34
class SqlAstNode;
 
35
} // namespace mysql_parser
 
36
 
 
37
/*
 
38
  The following hack is needed because mysql_yacc.cc does not define
 
39
  YYSTYPE before including this file
 
40
*/
 
41
 
 
42
//#include "set_var.h"
 
43
 
 
44
#include "my_global.h"
 
45
#include "structs.h"
 
46
#include "m_ctype.h"
 
47
 
 
48
#ifdef MYSQL_YACC
 
49
#define LEX_YYSTYPE void *
 
50
#else
 
51
#include "lex_symbol.h"
 
52
//#if MYSQL_LEX
 
53
////#include "sql_yacc.h"
 
54
#include "myx_sql_parser.tab.hh"
 
55
 
 
56
//#define LEX_YYSTYPE YYSTYPE *
 
57
 
 
58
//#else
 
59
//#define LEX_YYSTYPE void *
 
60
//#endif
 
61
#endif
 
62
 
 
63
namespace mysql_parser
 
64
{
 
65
 
 
66
/*
 
67
  When a command is added here, be sure it's also added in mysqld.cc
 
68
  in "struct show_var_st status_vars[]= {" ...
 
69
 
 
70
  If the command returns a result set or is not allowed in stored
 
71
  functions or triggers, please also make sure that
 
72
  sp_get_flags_for_command (sp_head.cc) returns proper flags for the
 
73
  added SQLCOM_.
 
74
*/
 
75
 
 
76
enum enum_sql_command {
 
77
  SQLCOM_SELECT, SQLCOM_CREATE_TABLE, SQLCOM_CREATE_INDEX, SQLCOM_ALTER_TABLE,
 
78
  SQLCOM_UPDATE, SQLCOM_INSERT, SQLCOM_INSERT_SELECT,
 
79
  SQLCOM_DELETE, SQLCOM_TRUNCATE, SQLCOM_DROP_TABLE, SQLCOM_DROP_INDEX,
 
80
 
 
81
  SQLCOM_SHOW_DATABASES, SQLCOM_SHOW_TABLES, SQLCOM_SHOW_FIELDS,
 
82
  SQLCOM_SHOW_KEYS, SQLCOM_SHOW_VARIABLES, SQLCOM_SHOW_STATUS,
 
83
  SQLCOM_SHOW_ENGINE_LOGS, SQLCOM_SHOW_ENGINE_STATUS, SQLCOM_SHOW_ENGINE_MUTEX,
 
84
  SQLCOM_SHOW_PROCESSLIST, SQLCOM_SHOW_MASTER_STAT, SQLCOM_SHOW_SLAVE_STAT,
 
85
  SQLCOM_SHOW_GRANTS, SQLCOM_SHOW_CREATE, SQLCOM_SHOW_CHARSETS,
 
86
  SQLCOM_SHOW_COLLATIONS, SQLCOM_SHOW_CREATE_DB, SQLCOM_SHOW_TABLE_STATUS,
 
87
  SQLCOM_SHOW_TRIGGERS,
 
88
 
 
89
  SQLCOM_LOAD,SQLCOM_SET_OPTION,SQLCOM_LOCK_TABLES,SQLCOM_UNLOCK_TABLES,
 
90
  SQLCOM_GRANT,
 
91
  SQLCOM_CHANGE_DB, SQLCOM_CREATE_DB, SQLCOM_DROP_DB, SQLCOM_ALTER_DB,
 
92
  SQLCOM_RENAME_DB,
 
93
  SQLCOM_REPAIR, SQLCOM_REPLACE, SQLCOM_REPLACE_SELECT,
 
94
  SQLCOM_CREATE_FUNCTION, SQLCOM_DROP_FUNCTION,
 
95
  SQLCOM_REVOKE,SQLCOM_OPTIMIZE, SQLCOM_CHECK,
 
96
  SQLCOM_ASSIGN_TO_KEYCACHE, SQLCOM_PRELOAD_KEYS,
 
97
  SQLCOM_FLUSH, SQLCOM_KILL, SQLCOM_ANALYZE,
 
98
  SQLCOM_ROLLBACK, SQLCOM_ROLLBACK_TO_SAVEPOINT,
 
99
  SQLCOM_COMMIT, SQLCOM_SAVEPOINT, SQLCOM_RELEASE_SAVEPOINT,
 
100
  SQLCOM_SLAVE_START, SQLCOM_SLAVE_STOP,
 
101
  SQLCOM_BEGIN, SQLCOM_LOAD_MASTER_TABLE, SQLCOM_CHANGE_MASTER,
 
102
  SQLCOM_RENAME_TABLE, SQLCOM_BACKUP_TABLE, SQLCOM_RESTORE_TABLE,
 
103
  SQLCOM_RESET, SQLCOM_PURGE, SQLCOM_PURGE_BEFORE, SQLCOM_SHOW_BINLOGS,
 
104
  SQLCOM_SHOW_OPEN_TABLES, SQLCOM_LOAD_MASTER_DATA,
 
105
  SQLCOM_HA_OPEN, SQLCOM_HA_CLOSE, SQLCOM_HA_READ,
 
106
  SQLCOM_SHOW_SLAVE_HOSTS, SQLCOM_DELETE_MULTI, SQLCOM_UPDATE_MULTI,
 
107
  SQLCOM_SHOW_BINLOG_EVENTS, SQLCOM_SHOW_NEW_MASTER, SQLCOM_DO,
 
108
  SQLCOM_SHOW_WARNS, SQLCOM_EMPTY_QUERY, SQLCOM_SHOW_ERRORS,
 
109
  SQLCOM_SHOW_COLUMN_TYPES, SQLCOM_SHOW_STORAGE_ENGINES, SQLCOM_SHOW_PRIVILEGES,
 
110
  SQLCOM_HELP, SQLCOM_CREATE_USER, SQLCOM_DROP_USER, SQLCOM_RENAME_USER,
 
111
  SQLCOM_REVOKE_ALL, SQLCOM_CHECKSUM,
 
112
  SQLCOM_CREATE_PROCEDURE, SQLCOM_CREATE_SPFUNCTION, SQLCOM_CALL,
 
113
  SQLCOM_DROP_PROCEDURE, SQLCOM_ALTER_PROCEDURE,SQLCOM_ALTER_FUNCTION,
 
114
  SQLCOM_SHOW_CREATE_PROC, SQLCOM_SHOW_CREATE_FUNC,
 
115
  SQLCOM_SHOW_STATUS_PROC, SQLCOM_SHOW_STATUS_FUNC,
 
116
  SQLCOM_PREPARE, SQLCOM_EXECUTE, SQLCOM_DEALLOCATE_PREPARE,
 
117
  SQLCOM_CREATE_VIEW, SQLCOM_DROP_VIEW,
 
118
  SQLCOM_CREATE_TRIGGER, SQLCOM_DROP_TRIGGER,
 
119
  SQLCOM_XA_START, SQLCOM_XA_END, SQLCOM_XA_PREPARE,
 
120
  SQLCOM_XA_COMMIT, SQLCOM_XA_ROLLBACK, SQLCOM_XA_RECOVER,
 
121
  SQLCOM_SHOW_PROC_CODE, SQLCOM_SHOW_FUNC_CODE,
 
122
  SQLCOM_ALTER_TABLESPACE,
 
123
  SQLCOM_INSTALL_PLUGIN, SQLCOM_UNINSTALL_PLUGIN,
 
124
  SQLCOM_SHOW_AUTHORS, SQLCOM_BINLOG_BASE64_EVENT,
 
125
  SQLCOM_SHOW_PLUGINS,
 
126
  SQLCOM_CREATE_EVENT, SQLCOM_ALTER_EVENT, SQLCOM_DROP_EVENT,
 
127
  SQLCOM_SHOW_CREATE_EVENT, SQLCOM_SHOW_EVENTS,
 
128
 
 
129
  /* This should be the last !!! */
 
130
 
 
131
  SQLCOM_END
 
132
};
 
133
 
 
134
#if 0
 
135
// describe/explain types
 
136
#define DESCRIBE_NORMAL         1
 
137
#define DESCRIBE_EXTENDED       2
 
138
/*
 
139
  This is not within #ifdef because we want "EXPLAIN PARTITIONS ..." to produce
 
140
  additional "partitions" column even if partitioning is not compiled in.
 
141
*/
 
142
#define DESCRIBE_PARTITIONS     4
 
143
 
 
144
 
 
145
enum enum_sp_suid_behaviour
 
146
{
 
147
  SP_IS_DEFAULT_SUID= 0,
 
148
  SP_IS_NOT_SUID,
 
149
  SP_IS_SUID
 
150
};
 
151
 
 
152
enum enum_sp_data_access
 
153
{
 
154
  SP_DEFAULT_ACCESS= 0,
 
155
  SP_CONTAINS_SQL,
 
156
  SP_NO_SQL,
 
157
  SP_READS_SQL_DATA,
 
158
  SP_MODIFIES_SQL_DATA
 
159
};
 
160
 
 
161
const LEX_STRING sp_data_access_name[]=
 
162
{
 
163
  { (char*) STRING_WITH_LEN("") },
 
164
  { (char*) STRING_WITH_LEN("CONTAINS SQL") },
 
165
  { (char*) STRING_WITH_LEN("NO SQL") },
 
166
  { (char*) STRING_WITH_LEN("READS SQL DATA") },
 
167
  { (char*) STRING_WITH_LEN("MODIFIES SQL DATA") }
 
168
};
 
169
 
 
170
#define DERIVED_SUBQUERY        1
 
171
#define DERIVED_VIEW            2
 
172
 
 
173
enum enum_view_create_mode
 
174
{
 
175
  VIEW_CREATE_NEW,              // check that there are not such VIEW/table
 
176
  VIEW_ALTER,                   // check that VIEW .frm with such name exists
 
177
  VIEW_CREATE_OR_REPLACE        // check only that there are not such table
 
178
};
 
179
 
 
180
enum enum_drop_mode
 
181
{
 
182
  DROP_DEFAULT, // mode is not specified
 
183
  DROP_CASCADE, // CASCADE option
 
184
  DROP_RESTRICT // RESTRICT option
 
185
};
 
186
 
 
187
//typedef List<Item> List_item;
 
188
 
 
189
typedef struct st_lex_master_info
 
190
{
 
191
  char *host, *user, *password, *log_file_name;
 
192
  uint port, connect_retry;
 
193
  ulonglong pos;
 
194
  ulong server_id;
 
195
  /* 
 
196
     Variable for MASTER_SSL option.
 
197
     MASTER_SSL=0 in CHANGE MASTER TO corresponds to SSL_DISABLE
 
198
     MASTER_SSL=1 corresponds to SSL_ENABLE
 
199
  */
 
200
  enum {SSL_UNCHANGED=0, SSL_DISABLE, SSL_ENABLE} ssl; 
 
201
  char *ssl_key, *ssl_cert, *ssl_ca, *ssl_capath, *ssl_cipher;
 
202
  char *relay_log_name;
 
203
  ulong relay_log_pos;
 
204
} LEX_MASTER_INFO;
 
205
 
 
206
 
 
207
enum sub_select_type
 
208
{
 
209
  UNSPECIFIED_TYPE,UNION_TYPE, INTERSECT_TYPE,
 
210
  EXCEPT_TYPE, GLOBAL_OPTIONS_TYPE, DERIVED_TABLE_TYPE, OLAP_TYPE
 
211
};
 
212
 
 
213
enum olap_type 
 
214
{
 
215
  UNSPECIFIED_OLAP_TYPE, CUBE_TYPE, ROLLUP_TYPE
 
216
};
 
217
 
 
218
enum tablespace_op_type
 
219
{
 
220
  NO_TABLESPACE_OP, DISCARD_TABLESPACE, IMPORT_TABLESPACE
 
221
};
 
222
 
 
223
/* 
 
224
  The state of the lex parsing for selects 
 
225
   
 
226
   master and slaves are pointers to select_lex.
 
227
   master is pointer to upper level node.
 
228
   slave is pointer to lower level node
 
229
   select_lex is a SELECT without union
 
230
   unit is container of either
 
231
     - One SELECT
 
232
     - UNION of selects
 
233
   select_lex and unit are both inherited form select_lex_node
 
234
   neighbors are two select_lex or units on the same level
 
235
 
 
236
   All select describing structures linked with following pointers:
 
237
   - list of neighbors (next/prev) (prev of first element point to slave
 
238
     pointer of upper structure)
 
239
     - For select this is a list of UNION's (or one element list)
 
240
     - For units this is a list of sub queries for the upper level select
 
241
 
 
242
   - pointer to master (master), which is
 
243
     If this is a unit
 
244
       - pointer to outer select_lex
 
245
     If this is a select_lex
 
246
       - pointer to outer unit structure for select
 
247
 
 
248
   - pointer to slave (slave), which is either:
 
249
     If this is a unit:
 
250
       - first SELECT that belong to this unit
 
251
     If this is a select_lex
 
252
       - first unit that belong to this SELECT (subquries or derived tables)
 
253
 
 
254
   - list of all select_lex (link_next/link_prev)
 
255
     This is to be used for things like derived tables creation, where we
 
256
     go through this list and create the derived tables.
 
257
 
 
258
   If unit contain several selects (UNION now, INTERSECT etc later)
 
259
   then it have special select_lex called fake_select_lex. It used for
 
260
   storing global parameters (like ORDER BY, LIMIT) and executing union.
 
261
   Subqueries used in global ORDER BY clause will be attached to this
 
262
   fake_select_lex, which will allow them correctly resolve fields of
 
263
   'upper' UNION and outer selects.
 
264
 
 
265
   For example for following query:
 
266
 
 
267
   select *
 
268
     from table1
 
269
     where table1.field IN (select * from table1_1_1 union
 
270
                            select * from table1_1_2)
 
271
     union
 
272
   select *
 
273
     from table2
 
274
     where table2.field=(select (select f1 from table2_1_1_1_1
 
275
                                   where table2_1_1_1_1.f2=table2_1_1.f3)
 
276
                           from table2_1_1
 
277
                           where table2_1_1.f1=table2.f2)
 
278
     union
 
279
   select * from table3;
 
280
 
 
281
   we will have following structure:
 
282
 
 
283
   select1: (select * from table1 ...)
 
284
   select2: (select * from table2 ...)
 
285
   select3: (select * from table3)
 
286
   select1.1.1: (select * from table1_1_1)
 
287
   ...
 
288
 
 
289
     main unit
 
290
     fake0
 
291
     select1 select2 select3
 
292
     |^^     |^
 
293
    s|||     ||master
 
294
    l|||     |+---------------------------------+
 
295
    a|||     +---------------------------------+|
 
296
    v|||master                         slave   ||
 
297
    e||+-------------------------+             ||
 
298
     V|            neighbor      |             V|
 
299
     unit1.1<+==================>unit1.2       unit2.1
 
300
     fake1.1
 
301
     select1.1.1 select 1.1.2    select1.2.1   select2.1.1
 
302
                                               |^
 
303
                                               ||
 
304
                                               V|
 
305
                                               unit2.1.1.1
 
306
                                               select2.1.1.1.1
 
307
 
 
308
 
 
309
   relation in main unit will be following:
 
310
   (bigger picture for:
 
311
      main unit
 
312
      fake0
 
313
      select1 select2 select3
 
314
   in the above picture)
 
315
 
 
316
         main unit
 
317
         |^^^^|fake_select_lex
 
318
         |||||+--------------------------------------------+
 
319
         ||||+--------------------------------------------+|
 
320
         |||+------------------------------+              ||
 
321
         ||+--------------+                |              ||
 
322
    slave||master         |                |              ||
 
323
         V|      neighbor |       neighbor |        master|V
 
324
         select1<========>select2<========>select3        fake0
 
325
 
 
326
    list of all select_lex will be following (as it will be constructed by
 
327
    parser):
 
328
 
 
329
    select1->select2->select3->select2.1.1->select 2.1.2->select2.1.1.1.1-+
 
330
                                                                          |
 
331
    +---------------------------------------------------------------------+
 
332
    |
 
333
    +->select1.1.1->select1.1.2
 
334
 
 
335
*/
 
336
 
 
337
/* 
 
338
    Base class for st_select_lex (SELECT_LEX) & 
 
339
    st_select_lex_unit (SELECT_LEX_UNIT)
 
340
*/
 
341
#endif
 
342
 
 
343
struct st_lex;
 
344
class st_select_lex;
 
345
class st_select_lex_unit;
 
346
 
 
347
#if 0
 
348
class st_select_lex_node {
 
349
protected:
 
350
  st_select_lex_node *next, **prev,   /* neighbor list */
 
351
    *master, *slave,                  /* vertical links */
 
352
    *link_next, **link_prev;          /* list of whole SELECT_LEX */
 
353
public:
 
354
 
 
355
  ulonglong options;
 
356
  /*
 
357
    result of this query can't be cached, bit field, can be :
 
358
      UNCACHEABLE_DEPENDENT
 
359
      UNCACHEABLE_RAND
 
360
      UNCACHEABLE_SIDEEFFECT
 
361
      UNCACHEABLE_EXPLAIN
 
362
      UNCACHEABLE_PREPARE
 
363
  */
 
364
  uint8 uncacheable;
 
365
  enum sub_select_type linkage;
 
366
  bool no_table_names_allowed; /* used for global order by */
 
367
  bool no_error; /* suppress error message (convert it to warnings) */
 
368
 
 
369
  static void *operator new(size_t size)
 
370
  {
 
371
    //return (void*) sql_alloc((uint) size);
 
372
    return malloc((uint) size);
 
373
  }
 
374
  static void *operator new(size_t size, MEM_ROOT *mem_root)
 
375
  { return (void*) alloc_root((uint) size); }
 
376
  static void operator delete(void *ptr,size_t size) { TRASH(ptr, size); }
 
377
  static void operator delete(void *ptr, MEM_ROOT *mem_root) {}
 
378
  st_select_lex_node(): linkage(UNSPECIFIED_TYPE) {}
 
379
  virtual ~st_select_lex_node() {}
 
380
  inline st_select_lex_node* get_master() { return master; }
 
381
  virtual void init_query();
 
382
  virtual void init_select();
 
383
  void include_down(st_select_lex_node *upper);
 
384
  void include_neighbour(st_select_lex_node *before);
 
385
  void include_standalone(st_select_lex_node *sel, st_select_lex_node **ref);
 
386
  void include_global(st_select_lex_node **plink);
 
387
  void exclude();
 
388
 
 
389
  virtual st_select_lex_unit* master_unit()= 0;
 
390
  virtual st_select_lex* outer_select()= 0;
 
391
  virtual st_select_lex* return_after_parsing()= 0;
 
392
 
 
393
  virtual bool set_braces(bool value);
 
394
  virtual bool inc_in_sum_expr();
 
395
  virtual uint get_in_sum_expr();
 
396
  //virtual TABLE_LIST* get_table_list();
 
397
  //virtual List<Item>* get_item_list();
 
398
  //virtual List<String>* get_use_index();
 
399
  //virtual List<String>* get_ignore_index();
 
400
  virtual ulong get_table_join_options();
 
401
  //virtual TABLE_LIST *add_table_to_list(THD *thd, Table_ident *table,
 
402
                //                      LEX_STRING *alias,
 
403
                //                      ulong table_options,
 
404
                //                      thr_lock_type flags= TL_UNLOCK,
 
405
                //                      List<String> *use_index= 0,
 
406
                //                      List<String> *ignore_index= 0,
 
407
  //                                      LEX_STRING *option= 0);
 
408
  virtual void set_lock_for_tables(thr_lock_type lock_type) {}
 
409
 
 
410
  friend class st_select_lex_unit;
 
411
  friend bool mysql_new_select(struct st_lex *lex, bool move_down);
 
412
  //friend bool mysql_make_view(THD *thd, File_parser *parser,
 
413
  //                            TABLE_LIST *table);
 
414
private:
 
415
  void fast_exclude();
 
416
};
 
417
#endif
 
418
 
 
419
typedef class st_select_lex_node SELECT_LEX_NODE;
 
420
 
 
421
/* 
 
422
   SELECT_LEX_UNIT - unit of selects (UNION, INTERSECT, ...) group 
 
423
   SELECT_LEXs
 
424
*/
 
425
class THD;
 
426
class select_result;
 
427
class JOIN;
 
428
class select_union;
 
429
class Procedure;
 
430
 
 
431
#if 0
 
432
class st_select_lex_unit: public st_select_lex_node {
 
433
protected:
 
434
  //TABLE_LIST result_table_list;
 
435
  select_union *union_result;
 
436
  //TABLE *table; /* temporary table using for appending UNION results */
 
437
 
 
438
  select_result *result;
 
439
  ulong found_rows_for_union;
 
440
  bool res;
 
441
public:
 
442
  bool  prepared, // prepare phase already performed for UNION (unit)
 
443
    optimized, // optimize phase already performed for UNION (unit)
 
444
    executed, // already executed
 
445
    cleaned;
 
446
 
 
447
  // list of fields which points to temporary table for union
 
448
  //List<Item> item_list;
 
449
  /*
 
450
    list of types of items inside union (used for union & derived tables)
 
451
    
 
452
    Item_type_holders from which this list consist may have pointers to Field,
 
453
    pointers is valid only after preparing SELECTS of this unit and before
 
454
    any SELECT of this unit execution
 
455
  */
 
456
  //List<Item> types;
 
457
  /*
 
458
    Pointer to 'last' select or pointer to unit where stored
 
459
    global parameters for union
 
460
  */
 
461
  st_select_lex *global_parameters;
 
462
  //node on wich we should return current_select pointer after parsing subquery
 
463
  st_select_lex *return_to;
 
464
  /* LIMIT clause runtime counters */
 
465
  //ha_rows select_limit_cnt, offset_limit_cnt;
 
466
  /* not NULL if unit used in subselect, point to subselect item */
 
467
  //Item_subselect *item;
 
468
  /* thread handler */
 
469
  THD *thd;
 
470
  /*
 
471
    SELECT_LEX for hidden SELECT in onion which process global
 
472
    ORDER BY and LIMIT
 
473
  */
 
474
  st_select_lex *fake_select_lex;
 
475
 
 
476
  st_select_lex *union_distinct; /* pointer to the last UNION DISTINCT */
 
477
  bool describe; /* union exec() called for EXPLAIN */
 
478
  Procedure *last_procedure;     /* Pointer to procedure, if such exists */
 
479
 
 
480
  void init_query();
 
481
  st_select_lex_unit* master_unit();
 
482
  st_select_lex* outer_select();
 
483
  st_select_lex* first_select()
 
484
  {
 
485
    return my_reinterpret_cast(st_select_lex*)(slave);
 
486
  }
 
487
  st_select_lex_unit* next_unit()
 
488
  {
 
489
    return my_reinterpret_cast(st_select_lex_unit*)(next);
 
490
  }
 
491
  st_select_lex* return_after_parsing() { return return_to; }
 
492
  void exclude_level();
 
493
  void exclude_tree();
 
494
 
 
495
  /* UNION methods */
 
496
  bool prepare(THD *thd, select_result *result, ulong additional_options);
 
497
  bool exec();
 
498
  bool cleanup();
 
499
  inline void unclean() { cleaned= 0; }
 
500
  void reinit_exec_mechanism();
 
501
 
 
502
  void print(String *str);
 
503
 
 
504
  void init_prepare_fake_select_lex(THD *thd);
 
505
  inline bool is_prepared() { return prepared; }
 
506
  //bool change_result(select_subselect *result, select_subselect *old_result);
 
507
  void set_limit(st_select_lex *values);
 
508
  void set_thd(THD *thd_arg) { thd= thd_arg; }
 
509
 
 
510
  friend void lex_start(LEX *lex, const uchar *buf, uint length);
 
511
  //friend int subselect_union_engine::exec();
 
512
 
 
513
  //List<Item> *get_unit_column_types();
 
514
};
 
515
 
 
516
typedef class st_select_lex_unit SELECT_LEX_UNIT;
 
517
 
 
518
/*
 
519
  SELECT_LEX - store information of parsed SELECT statment
 
520
*/
 
521
class st_select_lex: public st_select_lex_node
 
522
{
 
523
public:
 
524
  //Name_resolution_context context;
 
525
  char *db;
 
526
  //Item *where, *having;                         /* WHERE & HAVING clauses */
 
527
  //Item *prep_where; /* saved WHERE clause for prepared statement processing */
 
528
  //Item *prep_having;/* saved HAVING clause for prepared statement processing */
 
529
  /* point on lex in which it was created, used in view subquery detection */
 
530
  st_lex *parent_lex;
 
531
  enum olap_type olap;
 
532
  /* FROM clause - points to the beginning of the TABLE_LIST::next_local list. */
 
533
  //SQL_LIST          table_list;
 
534
  //SQL_LIST          group_list; /* GROUP BY clause. */
 
535
  //List<Item>          item_list;  /* list of fields & expressions */
 
536
  //List<String>        interval_list, use_index, *use_index_ptr,
 
537
                //      ignore_index, *ignore_index_ptr;
 
538
  bool                is_item_list_lookup;
 
539
  /* 
 
540
    Usualy it is pointer to ftfunc_list_alloc, but in union used to create fake
 
541
    select_lex for calling mysql_select under results of union
 
542
  */
 
543
  //List<Item_func_match> *ftfunc_list;
 
544
  //List<Item_func_match> ftfunc_list_alloc;
 
545
  JOIN *join; /* after JOIN::prepare it is pointer to corresponding JOIN */
 
546
  //List<TABLE_LIST> top_join_list; /* join list of the top level          */
 
547
  //List<TABLE_LIST> *join_list;    /* list for the currently parsed join  */
 
548
  //TABLE_LIST *embedding;          /* table embedding to the above list   */
 
549
  /*
 
550
    Beginning of the list of leaves in a FROM clause, where the leaves
 
551
    inlcude all base tables including view tables. The tables are connected
 
552
    by TABLE_LIST::next_leaf, so leaf_tables points to the left-most leaf.
 
553
  */
 
554
  //TABLE_LIST *leaf_tables;
 
555
  const char *type;               /* type of select for EXPLAIN          */
 
556
 
 
557
  //SQL_LIST order_list;                /* ORDER clause */
 
558
  //List<List_item>     expr_list;
 
559
  //List<List_item>     when_list;      /* WHEN clause (expression) */
 
560
  //SQL_LIST *gorder_list;
 
561
  //Item *select_limit, *offset_limit;  /* LIMIT clause parameters */
 
562
  // Arrays of pointers to top elements of all_fields list
 
563
  //Item **ref_pointer_array;
 
564
 
 
565
  /*
 
566
    number of items in select_list and HAVING clause used to get number
 
567
    bigger then can be number of entries that will be added to all item
 
568
    list during split_sum_func
 
569
  */
 
570
  uint select_n_having_items;
 
571
  uint cond_count;      /* number of arguments of and/or/xor in where/having */
 
572
  //enum_parsing_place parsing_place; /* where we are parsing expression */
 
573
  bool with_sum_func;   /* sum function indicator */
 
574
  /* 
 
575
    PS or SP cond natural joins was alredy processed with permanent
 
576
    arena and all additional items which we need alredy stored in it
 
577
  */
 
578
  bool conds_processed_with_permanent_arena;
 
579
 
 
580
  ulong table_join_options;
 
581
  uint in_sum_expr;
 
582
  uint select_number; /* number of select (used for EXPLAIN) */
 
583
  int nest_level;     /* nesting level of select */
 
584
  //Item_sum *inner_sum_func_list; /* list of sum func in nested selects */ 
 
585
  uint with_wild; /* item list contain '*' */
 
586
  bool  braces;         /* SELECT ... UNION (SELECT ... ) <- this braces */
 
587
  /* TRUE when having fix field called in processing of this SELECT */
 
588
  bool having_fix_field;
 
589
  /* explicit LIMIT clause was used */
 
590
  bool explicit_limit;
 
591
  /*
 
592
    there are subquery in HAVING clause => we can't close tables before
 
593
    query processing end even if we use temporary table
 
594
  */
 
595
  bool subquery_in_having;
 
596
  /*
 
597
    This variable is required to ensure proper work of subqueries and
 
598
    stored procedures. Generally, one should use the states of
 
599
    Query_arena to determine if it's a statement prepare or first
 
600
    execution of a stored procedure. However, in case when there was an
 
601
    error during the first execution of a stored procedure, the SP body
 
602
    is not expelled from the SP cache. Therefore, a deeply nested
 
603
    subquery might be left unoptimized. So we need this per-subquery
 
604
    variable to inidicate the optimization/execution state of every
 
605
    subquery. Prepared statements work OK in that regard, as in
 
606
    case of an error during prepare the PS is not created.
 
607
  */
 
608
  bool first_execution;
 
609
  bool first_cond_optimization;
 
610
  /* do not wrap view fields with Item_ref */
 
611
  bool no_wrap_view_item;
 
612
  /* exclude this select from check of unique_table() */
 
613
  bool exclude_from_table_unique_test;
 
614
 
 
615
  void init_query();
 
616
  void init_select();
 
617
  st_select_lex_unit* master_unit();
 
618
  st_select_lex_unit* first_inner_unit() 
 
619
  { 
 
620
    return (st_select_lex_unit*) slave; 
 
621
  }
 
622
  st_select_lex* outer_select();
 
623
  st_select_lex* next_select() { return (st_select_lex*) next; }
 
624
  st_select_lex* next_select_in_list() 
 
625
  {
 
626
    return (st_select_lex*) link_next;
 
627
  }
 
628
  st_select_lex_node** next_select_in_list_addr()
 
629
  {
 
630
    return &link_next;
 
631
  }
 
632
  st_select_lex* return_after_parsing()
 
633
  {
 
634
    return master_unit()->return_after_parsing();
 
635
  }
 
636
 
 
637
  void mark_as_dependent(st_select_lex *last);
 
638
 
 
639
  bool set_braces(bool value);
 
640
  bool inc_in_sum_expr();
 
641
  uint get_in_sum_expr();
 
642
 
 
643
  //bool add_item_to_list(THD *thd, Item *item);
 
644
  //bool add_group_to_list(THD *thd, Item *item, bool asc);
 
645
  //bool add_ftfunc_to_list(Item_func_match *func);
 
646
  //bool add_order_to_list(THD *thd, Item *item, bool asc);
 
647
  //TABLE_LIST* add_table_to_list(THD *thd, Table_ident *table,
 
648
                //              LEX_STRING *alias,
 
649
                //              ulong table_options,
 
650
                //              thr_lock_type flags= TL_UNLOCK,
 
651
                //              List<String> *use_index= 0,
 
652
                //              List<String> *ignore_index= 0,
 
653
  //                              LEX_STRING *option= 0);
 
654
  //TABLE_LIST* get_table_list();
 
655
  //bool init_nested_join(THD *thd);
 
656
  //TABLE_LIST *end_nested_join(THD *thd);
 
657
  //TABLE_LIST *nest_last_join(THD *thd);
 
658
  //void add_joined_table(TABLE_LIST *table);
 
659
  //TABLE_LIST *convert_right_join();
 
660
  //List<Item>* get_item_list();
 
661
  //List<String>* get_use_index();
 
662
  //List<String>* get_ignore_index();
 
663
  //ulong get_table_join_options();
 
664
  //void set_lock_for_tables(thr_lock_type lock_type);
 
665
  //inline void init_order()
 
666
  //{
 
667
  //  order_list.elements= 0;
 
668
  //  order_list.first= 0;
 
669
  //  order_list.next= (byte**) &order_list.first;
 
670
  //}
 
671
  /*
 
672
    This method created for reiniting LEX in mysql_admin_table() and can be
 
673
    used only if you are going remove all SELECT_LEX & units except belonger
 
674
    to LEX (LEX::unit & LEX::select, for other purposes there are
 
675
    SELECT_LEX_UNIT::exclude_level & SELECT_LEX_UNIT::exclude_tree
 
676
  */
 
677
  void cut_subtree() { slave= 0; }
 
678
  bool test_limit();
 
679
 
 
680
  friend void lex_start(LEX *lex, const uchar *buf, uint length);
 
681
  st_select_lex() {}
 
682
  void make_empty_select()
 
683
  {
 
684
    init_query();
 
685
    init_select();
 
686
  }
 
687
  bool setup_ref_array(THD *thd, uint order_group_num);
 
688
  void print(THD *thd, String *str);
 
689
  //static void print_order(String *str, ORDER *order);
 
690
  //void print_limit(THD *thd, String *str);
 
691
  //void fix_prepare_information(THD *thd, Item **conds);
 
692
  /*
 
693
    Destroy the used execution plan (JOIN) of this subtree (this
 
694
    SELECT_LEX and all nested SELECT_LEXes and SELECT_LEX_UNITs).
 
695
  */
 
696
  bool cleanup();
 
697
  /*
 
698
    Recursively cleanup the join of this select lex and of all nested
 
699
    select lexes.
 
700
  */
 
701
  void cleanup_all_joins(bool full);
 
702
};
 
703
typedef class st_select_lex SELECT_LEX;
 
704
#endif
 
705
 
 
706
#define ALTER_ADD_COLUMN        (1L << 0)
 
707
#define ALTER_DROP_COLUMN       (1L << 1)
 
708
#define ALTER_CHANGE_COLUMN     (1L << 2)
 
709
#define ALTER_ADD_INDEX         (1L << 3)
 
710
#define ALTER_DROP_INDEX        (1L << 4)
 
711
#define ALTER_RENAME            (1L << 5)
 
712
#define ALTER_ORDER             (1L << 6)
 
713
#define ALTER_OPTIONS           (1L << 7)
 
714
#define ALTER_CHANGE_COLUMN_DEFAULT (1L << 8)
 
715
#define ALTER_KEYS_ONOFF        (1L << 9)
 
716
#define ALTER_CONVERT           (1L << 10)
 
717
#define ALTER_FORCE             (1L << 11)
 
718
#define ALTER_RECREATE          (1L << 12)
 
719
#define ALTER_ADD_PARTITION     (1L << 13)
 
720
#define ALTER_DROP_PARTITION    (1L << 14)
 
721
#define ALTER_COALESCE_PARTITION (1L << 15)
 
722
#define ALTER_REORGANIZE_PARTITION (1L << 16) 
 
723
#define ALTER_PARTITION          (1L << 17)
 
724
#define ALTER_OPTIMIZE_PARTITION (1L << 18)
 
725
#define ALTER_TABLE_REORG        (1L << 19)
 
726
#define ALTER_REBUILD_PARTITION  (1L << 20)
 
727
#define ALTER_ALL_PARTITION      (1L << 21)
 
728
#define ALTER_ANALYZE_PARTITION  (1L << 22)
 
729
#define ALTER_CHECK_PARTITION    (1L << 23)
 
730
#define ALTER_REPAIR_PARTITION   (1L << 24)
 
731
#define ALTER_REMOVE_PARTITIONING (1L << 25)
 
732
 
 
733
#if 0
 
734
typedef struct st_alter_info
 
735
{
 
736
  List<Alter_drop>            drop_list;
 
737
  List<Alter_column>          alter_list;
 
738
  uint                        flags;
 
739
  enum enum_enable_or_disable keys_onoff;
 
740
  enum tablespace_op_type     tablespace_op;
 
741
  List<char>                  partition_names;
 
742
  uint                        no_parts;
 
743
 
 
744
  st_alter_info(){clear();}
 
745
  void clear()
 
746
  {
 
747
    keys_onoff= LEAVE_AS_IS;
 
748
    tablespace_op= NO_TABLESPACE_OP;
 
749
    no_parts= 0;
 
750
    partition_names.empty();
 
751
  }
 
752
  void reset(){drop_list.empty();alter_list.empty();clear();}
 
753
} ALTER_INFO;
 
754
 
 
755
struct st_sp_chistics
 
756
{
 
757
  LEX_STRING comment;
 
758
  enum enum_sp_suid_behaviour suid;
 
759
  bool detistic;
 
760
  enum enum_sp_data_access daccess;
 
761
};
 
762
 
 
763
 
 
764
struct st_trg_chistics
 
765
{
 
766
  enum trg_action_time_type action_time;
 
767
  enum trg_event_type event;
 
768
};
 
769
#endif
 
770
 
 
771
//extern sys_var *trg_new_row_fake_var;
 
772
 
 
773
enum xa_option_words {XA_NONE, XA_JOIN, XA_RESUME, XA_ONE_PHASE,
 
774
                      XA_SUSPEND, XA_FOR_MIGRATE};
 
775
 
 
776
/* The state of the lex parsing. This is saved in the THD struct */
 
777
 
 
778
typedef struct st_lex
 
779
{
 
780
  uint   yylineno,yytoklen;                     /* Simulate lex */
 
781
  SqlAstNode **yylval;
 
782
  SqlAstNode *first_item;
 
783
  SqlAstNode *last_item;
 
784
  //SELECT_LEX_UNIT unit;                         /* most upper unit */
 
785
  //SELECT_LEX select_lex;                        /* first SELECT_LEX */
 
786
  /* current SELECT_LEX in parsing */
 
787
  //SELECT_LEX *current_select;
 
788
  /* list of all SELECT_LEX */
 
789
  //SELECT_LEX *all_selects_list;
 
790
  const uchar *buf;             /* The beginning of string, used by SPs */
 
791
  const uchar *ptr,*tok_start,*tok_end,*end_of_query;
 
792
  
 
793
  /* The values of tok_start/tok_end as they were one call of MYSQLlex before */
 
794
  const uchar *tok_start_prev, *tok_end_prev;
 
795
 
 
796
  char *length,*dec,*change,*name;
 
797
  Table_ident *like_name;
 
798
  char *help_arg;
 
799
  char *backup_dir;                             /* For RESTORE/BACKUP */
 
800
  char* to_log;                                 /* For PURGE MASTER LOGS TO */
 
801
  char* x509_subject,*x509_issuer,*ssl_cipher;
 
802
  char* found_semicolon;                        /* For multi queries - next query */
 
803
  //String *wild;
 
804
  sql_exchange *exchange;
 
805
  select_result *result;
 
806
  //Item *default_value, *on_update_value;
 
807
  LEX_STRING comment, ident;
 
808
  LEX_USER *grant_user;
 
809
  //XID *xid;
 
810
  gptr yacc_yyss,yacc_yyvs;
 
811
  //THD *thd;
 
812
  CHARSET_INFO *charset;
 
813
  //TABLE_LIST *query_tables;   /* global list of all tables in this query */
 
814
  /*
 
815
    last element next_global of previous list (used only for list building
 
816
    during parsing and VIEW processing. This pointer could be invalid during
 
817
    processing of information schema tables(see get_schema_tables_result
 
818
    function)
 
819
  */
 
820
  //TABLE_LIST **query_tables_last;
 
821
  /* store original leaf_tables for INSERT SELECT and PS/SP */
 
822
  //TABLE_LIST *leaf_tables_insert;
 
823
  /* Position (first character index) of SELECT of CREATE VIEW statement */
 
824
  uint create_view_select_start;
 
825
  /* Partition info structure filled in by PARTITION BY parse part */
 
826
  partition_info *part_info;
 
827
 
 
828
  /*
 
829
    The definer of the object being created (view, trigger, stored routine).
 
830
    I.e. the value of DEFINER clause.
 
831
  */
 
832
  LEX_USER *definer;
 
833
 
 
834
  //List<key_part_spec> col_list;
 
835
  //List<key_part_spec> ref_list;
 
836
  //List<String>              interval_list;
 
837
  //List<LEX_USER>      users_list;
 
838
  //List<LEX_COLUMN>    columns;
 
839
  //List<Key>         key_list;
 
840
  //List<create_field>  create_list;
 
841
  //List<Item>        *insert_list,field_list,value_list,update_list;
 
842
  //List<List_item>     many_values;
 
843
  //List<set_var_base>  var_list;
 
844
  //List<Item_param>    param_list;
 
845
  //List<LEX_STRING>    view_list; // view list (list of field names in view)
 
846
  /*
 
847
    A stack of name resolution contexts for the query. This stack is used
 
848
    at parse time to set local name resolution contexts for various parts
 
849
    of a query. For example, in a JOIN ... ON (some_condition) clause the
 
850
    Items in 'some_condition' must be resolved only against the operands
 
851
    of the the join, and not against the whole clause. Similarly, Items in
 
852
    subqueries should be resolved against the subqueries (and outer queries).
 
853
    The stack is used in the following way: when the parser detects that
 
854
    all Items in some clause need a local context, it creates a new context
 
855
    and pushes it on the stack. All newly created Items always store the
 
856
    top-most context in the stack. Once the parser leaves the clause that
 
857
    required a local context, the parser pops the top-most context.
 
858
  */
 
859
  //List<Name_resolution_context> context_stack;
 
860
  //List<LEX_STRING>     db_list;
 
861
 
 
862
  //SQL_LIST          proc_list, auxilliary_table_list, save_list;
 
863
  //create_field              *last_field;
 
864
  //Item_sum *in_sum_func;
 
865
  //udf_func udf;
 
866
  //HA_CHECK_OPT   check_opt;                   // check/repair options
 
867
  //HA_CREATE_INFO create_info;
 
868
  //LEX_MASTER_INFO mi;                         // used by CHANGE MASTER
 
869
  //USER_RESOURCES mqh;
 
870
  //ulong type;
 
871
  /*
 
872
    This variable is used in post-parse stage to declare that sum-functions,
 
873
    or functions which have sense only if GROUP BY is present, are allowed.
 
874
    For example in a query
 
875
    SELECT ... FROM ...WHERE MIN(i) == 1 GROUP BY ... HAVING MIN(i) > 2
 
876
    MIN(i) in the WHERE clause is not allowed in the opposite to MIN(i)
 
877
    in the HAVING clause. Due to possible nesting of select construct
 
878
    the variable can contain 0 or 1 for each nest level.
 
879
  */
 
880
  //nesting_map allow_sum_func;
 
881
  enum_sql_command sql_command, orig_sql_command;
 
882
  //thr_lock_type lock_option;
 
883
  //enum SSL_type ssl_type;                     /* defined in violite.h */
 
884
  enum my_lex_states next_state;
 
885
  //enum enum_duplicates duplicates;
 
886
  //enum enum_tx_isolation tx_isolation;
 
887
  //enum enum_ha_read_modes ha_read_mode;
 
888
  union {
 
889
 //   enum ha_rkey_function ha_rkey_mode;
 
890
    enum xa_option_words xa_opt;
 
891
  };
 
892
  //enum enum_var_type option_type;
 
893
  //enum enum_view_create_mode create_view_mode;
 
894
  //enum enum_drop_mode drop_mode;
 
895
  //uint uint_geom_type;
 
896
  //uint grant, grant_tot_col, which_columns;
 
897
  //uint fk_delete_opt, fk_update_opt, fk_match_option;
 
898
  //uint slave_thd_opt, start_transaction_opt;
 
899
  int nest_level;
 
900
  /*
 
901
    In LEX representing update which were transformed to multi-update
 
902
    stores total number of tables. For LEX representing multi-delete
 
903
    holds number of tables from which we will delete records.
 
904
  */
 
905
  uint table_count;
 
906
  uint8 describe;
 
907
  /*
 
908
    A flag that indicates what kinds of derived tables are present in the
 
909
    query (0 if no derived tables, otherwise a combination of flags
 
910
    DERIVED_SUBQUERY and DERIVED_VIEW).
 
911
  */
 
912
  uint8 derived_tables;
 
913
  uint8 create_view_algorithm;
 
914
  uint8 create_view_check;
 
915
  bool drop_if_exists, drop_temporary, local_file, one_shot_set;
 
916
  bool in_comment, ignore_space, verbose, no_write_to_binlog;
 
917
  /*
 
918
    binlog_row_based_if_mixed tells if the parsing stage detected that some
 
919
    items require row-based binlogging to give a reliable binlog/replication.
 
920
  */
 
921
  bool tx_chain, tx_release, binlog_row_based_if_mixed;
 
922
  /*
 
923
    Special JOIN::prepare mode: changing of query is prohibited.
 
924
    When creating a view, we need to just check its syntax omitting
 
925
    any optimizations: afterwards definition of the view will be
 
926
    reconstructed by means of ::print() methods and written to
 
927
    to an .frm file. We need this definition to stay untouched.
 
928
  */
 
929
  bool view_prepare_mode;
 
930
  /*
 
931
    TRUE if we're parsing a prepared statement: in this mode
 
932
    we should allow placeholders and disallow multistatements.
 
933
  */
 
934
  bool stmt_prepare_mode;
 
935
  bool safe_to_cache_query;
 
936
  bool subqueries, ignore;
 
937
  bool variables_used;
 
938
  //ALTER_INFO alter_info;
 
939
  /* Prepared statements SQL syntax:*/
 
940
  LEX_STRING prepared_stmt_name; /* Statement name (in all queries) */
 
941
  /*
 
942
    Prepared statement query text or name of variable that holds the
 
943
    prepared statement (in PREPARE ... queries)
 
944
  */
 
945
  LEX_STRING prepared_stmt_code;
 
946
  /* If true, prepared_stmt_code is a name of variable that holds the query */
 
947
  bool prepared_stmt_code_is_varref;
 
948
  /* Names of user variables holding parameters (in EXECUTE) */
 
949
  //List<LEX_STRING> prepared_stmt_params;
 
950
  /*
 
951
    Points to part of global table list which contains time zone tables
 
952
    implicitly used by the statement.
 
953
  */
 
954
  //TABLE_LIST *time_zone_tables_used;
 
955
  sp_head *sphead;
 
956
  sp_name *spname;
 
957
  bool sp_lex_in_use;   /* Keep track on lex usage in SPs for error handling */
 
958
  bool all_privileges;
 
959
  sp_pcontext *spcont;
 
960
  /* Set of stored routines called by statement. */
 
961
  //HASH sroutines;
 
962
  /*
 
963
    List linking elements of 'sroutines' set. Allows you to add new elements
 
964
    to this set as you iterate through the list of existing elements.
 
965
    'sroutines_list_own_last' is pointer to ::next member of last element of
 
966
    this list which represents routine which is explicitly used by query.
 
967
    'sroutines_list_own_elements' number of explicitly used routines.
 
968
    We use these two members for restoring of 'sroutines_list' to the state
 
969
    in which it was right after query parsing.
 
970
  */
 
971
  //SQL_LIST sroutines_list;
 
972
  byte     **sroutines_list_own_last;
 
973
  uint     sroutines_list_own_elements;
 
974
 
 
975
  //st_sp_chistics sp_chistics;
 
976
 
 
977
  Event_timed *et;
 
978
  bool et_compile_phase;
 
979
 
 
980
  bool only_view;       /* used for SHOW CREATE TABLE/VIEW */
 
981
  /*
 
982
    field_list was created for view and should be removed before PS/SP
 
983
    rexecuton
 
984
  */
 
985
  bool empty_field_list_on_rset;
 
986
  /*
 
987
    view created to be run from definer (standard behaviour)
 
988
  */
 
989
  bool create_view_suid;
 
990
  /* Characterstics of trigger being created */
 
991
  //st_trg_chistics trg_chistics;
 
992
  /*
 
993
    List of all items (Item_trigger_field objects) representing fields in
 
994
    old/new version of row in trigger. We use this list for checking whenever
 
995
    all such fields are valid at trigger creation time and for binding these
 
996
    fields to TABLE object at table open (altough for latter pointer to table
 
997
    being opened is probably enough).
 
998
  */
 
999
  //SQL_LIST trg_table_fields;
 
1000
 
 
1001
  /*
 
1002
    stmt_definition_begin is intended to point to the next word after
 
1003
    DEFINER-clause in the following statements:
 
1004
      - CREATE TRIGGER (points to "TRIGGER");
 
1005
      - CREATE PROCEDURE (points to "PROCEDURE");
 
1006
      - CREATE FUNCTION (points to "FUNCTION" or "AGGREGATE");
 
1007
 
 
1008
    This pointer is required to add possibly omitted DEFINER-clause to the
 
1009
    DDL-statement before dumping it to the binlog. 
 
1010
  */
 
1011
  const char *stmt_definition_begin;
 
1012
 
 
1013
  /*
 
1014
    If non-0 then indicates that query requires prelocking and points to
 
1015
    next_global member of last own element in query table list (i.e. last
 
1016
    table which was not added to it as part of preparation to prelocking).
 
1017
    0 - indicates that this query does not need prelocking.
 
1018
  */
 
1019
  //TABLE_LIST **query_tables_own_last;
 
1020
 
 
1021
  /*
 
1022
    Pointers to part of LOAD DATA statement that should be rewritten
 
1023
    during replication ("LOCAL 'filename' REPLACE INTO" part).
 
1024
  */
 
1025
  const uchar *fname_start, *fname_end;
 
1026
 
 
1027
  /*
 
1028
    Reference to a struct that contains information in various commands
 
1029
    to add/create/drop/change table spaces.
 
1030
  */
 
1031
  st_alter_tablespace *alter_tablespace_info;
 
1032
  
 
1033
  bool escape_used;
 
1034
 
 
1035
  st_lex();
 
1036
 
 
1037
  ~st_lex()
 
1038
  {
 
1039
    //hash_free(&sroutines);
 
1040
  }
 
1041
 
 
1042
  //inline void uncacheable(uint8 cause)
 
1043
  //{
 
1044
  //  safe_to_cache_query= 0;
 
1045
 
 
1046
  //  /*
 
1047
  //    There are no sense to mark select_lex and union fields of LEX,
 
1048
  //    but we should merk all subselects as uncacheable from current till
 
1049
  //    most upper
 
1050
  //  */
 
1051
  //  SELECT_LEX *sl;
 
1052
  //  SELECT_LEX_UNIT *un;
 
1053
  //  for (sl= current_select, un= sl->master_unit();
 
1054
         //un != &unit;
 
1055
         //sl= sl->outer_select(), un= sl->master_unit())
 
1056
  //  {
 
1057
  //    sl->uncacheable|= cause;
 
1058
  //    un->uncacheable|= cause;
 
1059
  //  }
 
1060
  //}
 
1061
  //TABLE_LIST *unlink_first_table(bool *link_to_local);
 
1062
  //void link_first_table_back(TABLE_LIST *first, bool link_to_local);
 
1063
  void first_lists_tables_same();
 
1064
  //inline void add_to_query_tables(TABLE_LIST *table)
 
1065
  //{
 
1066
  //  *(table->prev_global= query_tables_last)= table;
 
1067
  //  query_tables_last= &table->next_global;
 
1068
  //}
 
1069
  //bool add_time_zone_tables_to_query_tables(THD *thd);
 
1070
 
 
1071
  bool can_be_merged();
 
1072
  bool can_use_merged();
 
1073
  bool can_not_use_merged();
 
1074
  bool only_view_structure();
 
1075
  bool need_correct_ident();
 
1076
  //uint8 get_effective_with_check(st_table_list *view);
 
1077
  /*
 
1078
    Is this update command where 'WHITH CHECK OPTION' clause is important
 
1079
 
 
1080
    SYNOPSIS
 
1081
      st_lex::which_check_option_applicable()
 
1082
 
 
1083
    RETURN
 
1084
      TRUE   have to take 'WHITH CHECK OPTION' clause into account
 
1085
      FALSE  'WHITH CHECK OPTION' clause do not need
 
1086
  */
 
1087
  //inline bool which_check_option_applicable()
 
1088
  //{
 
1089
  //  switch (sql_command) {
 
1090
  //  case SQLCOM_UPDATE:
 
1091
  //  case SQLCOM_UPDATE_MULTI:
 
1092
  //  case SQLCOM_INSERT:
 
1093
  //  case SQLCOM_INSERT_SELECT:
 
1094
  //  case SQLCOM_LOAD:
 
1095
  //    return TRUE;
 
1096
  //  default:
 
1097
  //    return FALSE;
 
1098
  //  }
 
1099
  //}
 
1100
  //inline bool requires_prelocking()
 
1101
  //{
 
1102
  //  return test(query_tables_own_last);
 
1103
  //}
 
1104
  //inline void mark_as_requiring_prelocking(TABLE_LIST **tables_own_last)
 
1105
  //{
 
1106
  //  query_tables_own_last= tables_own_last;
 
1107
  //}
 
1108
  ///* Return pointer to first not-own table in query-tables or 0 */
 
1109
  //TABLE_LIST* first_not_own_table()
 
1110
  //{
 
1111
  //  return ( query_tables_own_last ? *query_tables_own_last : 0);
 
1112
  //}
 
1113
  //void chop_off_not_own_tables()
 
1114
  //{
 
1115
  //  if (query_tables_own_last)
 
1116
  //  {
 
1117
  //    *query_tables_own_last= 0;
 
1118
  //    query_tables_last= query_tables_own_last;
 
1119
  //    query_tables_own_last= 0;
 
1120
  //  }
 
1121
  //}
 
1122
  //void cleanup_after_one_table_open();
 
1123
 
 
1124
  //bool push_context(Name_resolution_context *context)
 
1125
  //{
 
1126
  //  return context_stack.push_front(context);
 
1127
  //}
 
1128
 
 
1129
  //void pop_context()
 
1130
  //{
 
1131
  //  context_stack.pop();
 
1132
  //}
 
1133
 
 
1134
  //Name_resolution_context *current_context()
 
1135
  //{
 
1136
  //  return context_stack.head();
 
1137
  //}
 
1138
 
 
1139
  struct SqlMode
 
1140
  {
 
1141
    SqlMode()
 
1142
      :
 
1143
      MODE_ANSI_QUOTES(false),
 
1144
      MODE_HIGH_NOT_PRECEDENCE(false),
 
1145
      MODE_PIPES_AS_CONCAT(false),
 
1146
      MODE_NO_BACKSLASH_ESCAPES(false),
 
1147
      MODE_IGNORE_SPACE(false)
 
1148
    {}
 
1149
    bool MODE_ANSI_QUOTES;
 
1150
    bool MODE_HIGH_NOT_PRECEDENCE;
 
1151
    bool MODE_PIPES_AS_CONCAT;
 
1152
    bool MODE_NO_BACKSLASH_ESCAPES;
 
1153
    bool MODE_IGNORE_SPACE;
 
1154
  };
 
1155
  SqlMode sql_mode;
 
1156
} LEX;
 
1157
 
 
1158
struct st_lex_local: public st_lex
 
1159
{
 
1160
  static void *operator new(size_t size)
 
1161
  {
 
1162
    //return (void*) sql_alloc((uint) size);
 
1163
    return malloc((uint) size);
 
1164
  }
 
1165
  //static void *operator new(size_t size/*, MEM_ROOT *mem_root*/)
 
1166
  //{
 
1167
  //  return (void*) alloc_root((uint) size);
 
1168
  //}
 
1169
  static void operator delete(void *ptr,size_t size)
 
1170
  { /*TRASH(ptr, size);*/ }
 
1171
  static void operator delete(void *ptr/*, MEM_ROOT *mem_root*/)
 
1172
  { /* Never called */ }
 
1173
};
 
1174
 
 
1175
extern void lex_init(void);
 
1176
extern void lex_free(void);
 
1177
extern void lex_start(LEX *lex, const uchar *buf, uint length);
 
1178
extern void lex_end(LEX *lex);
 
1179
extern int MYSQLlex(void *arg, void *yythd);
 
1180
 
 
1181
extern bool parser_is_stopped;
 
1182
 
 
1183
//extern pthread_key(LEX*,THR_LEX);
 
1184
 
 
1185
#define current_lex (current_thd->lex)
 
1186
 
 
1187
} // namespace mysql_parser