~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_lex.h

  • Committer: Monty Taylor
  • Date: 2008-10-16 06:32:30 UTC
  • mto: (511.1.5 codestyle)
  • mto: This revision was merged to the branch mainline in revision 521.
  • Revision ID: monty@inaugust.com-20081016063230-4brxsra0qsmsg84q
Added -Wunused-macros.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000-2006 MySQL 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; version 2 of the License.
6
 
 
7
 
   This program is distributed in the hope that it will be useful,
8
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 
   GNU General Public License for more details.
11
 
 
12
 
   You should have received a copy of the GNU General Public License
13
 
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2008 Sun Microsystems
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; version 2 of the License.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 */
 
19
 
 
20
#ifndef DRIZZLE_SERVER_SQL_LEX_H
 
21
#define DRIZZLE_SERVER_SQL_LEX_H
15
22
 
16
23
/**
17
24
  @defgroup Semantic_Analysis Semantic Analysis
18
25
*/
19
26
 
 
27
#include "sql_udf.h"
 
28
 
20
29
/* YACC and LEX Definitions */
21
30
 
22
31
/* These may not be declared yet */
23
32
class Table_ident;
24
33
class sql_exchange;
25
34
class LEX_COLUMN;
26
 
class st_alter_tablespace;
27
35
 
28
 
#ifdef MYSQL_SERVER
 
36
#ifdef DRIZZLE_SERVER
29
37
/*
30
38
  The following hack is needed because mysql_yacc.cc does not define
31
39
  YYSTYPE before including this file
33
41
 
34
42
#include "set_var.h"
35
43
 
36
 
#ifdef MYSQL_YACC
 
44
#ifdef DRIZZLE_YACC
37
45
#define LEX_YYSTYPE void *
38
46
#else
39
 
#if MYSQL_LEX
 
47
#if defined(DRIZZLE_LEX)
40
48
#include "lex_symbol.h"
41
49
#include "sql_yacc.h"
42
50
#define LEX_YYSTYPE YYSTYPE *
64
72
  SQLCOM_SHOW_KEYS, SQLCOM_SHOW_VARIABLES, SQLCOM_SHOW_STATUS,
65
73
  SQLCOM_SHOW_ENGINE_LOGS, SQLCOM_SHOW_ENGINE_STATUS, SQLCOM_SHOW_ENGINE_MUTEX,
66
74
  SQLCOM_SHOW_PROCESSLIST, SQLCOM_SHOW_MASTER_STAT, SQLCOM_SHOW_SLAVE_STAT,
67
 
  SQLCOM_SHOW_CREATE, SQLCOM_SHOW_CHARSETS,
68
 
  SQLCOM_SHOW_COLLATIONS, SQLCOM_SHOW_CREATE_DB, SQLCOM_SHOW_TABLE_STATUS,
 
75
  SQLCOM_SHOW_CREATE,
 
76
  SQLCOM_SHOW_CREATE_DB,
 
77
  SQLCOM_SHOW_TABLE_STATUS,
69
78
  SQLCOM_LOAD,SQLCOM_SET_OPTION,SQLCOM_LOCK_TABLES,SQLCOM_UNLOCK_TABLES,
70
79
  SQLCOM_CHANGE_DB, SQLCOM_CREATE_DB, SQLCOM_DROP_DB, SQLCOM_ALTER_DB,
71
80
  SQLCOM_REPAIR, SQLCOM_REPLACE, SQLCOM_REPLACE_SELECT,
72
81
  SQLCOM_OPTIMIZE, SQLCOM_CHECK,
73
 
  SQLCOM_ASSIGN_TO_KEYCACHE, SQLCOM_PRELOAD_KEYS,
 
82
  SQLCOM_ASSIGN_TO_KEYCACHE,
74
83
  SQLCOM_FLUSH, SQLCOM_KILL, SQLCOM_ANALYZE,
75
84
  SQLCOM_ROLLBACK, SQLCOM_ROLLBACK_TO_SAVEPOINT,
76
85
  SQLCOM_COMMIT, SQLCOM_SAVEPOINT, SQLCOM_RELEASE_SAVEPOINT,
79
88
  SQLCOM_RENAME_TABLE,  
80
89
  SQLCOM_RESET, SQLCOM_PURGE, SQLCOM_PURGE_BEFORE, SQLCOM_SHOW_BINLOGS,
81
90
  SQLCOM_SHOW_OPEN_TABLES,
82
 
  SQLCOM_SHOW_SLAVE_HOSTS, SQLCOM_DELETE_MULTI, SQLCOM_UPDATE_MULTI,
83
 
  SQLCOM_SHOW_BINLOG_EVENTS,
84
 
  SQLCOM_SHOW_WARNS, SQLCOM_EMPTY_QUERY, SQLCOM_SHOW_ERRORS,
 
91
  SQLCOM_DELETE_MULTI, SQLCOM_UPDATE_MULTI,
 
92
  SQLCOM_SHOW_WARNS,
 
93
  SQLCOM_EMPTY_QUERY,
 
94
  SQLCOM_SHOW_ERRORS,
85
95
  SQLCOM_CHECKSUM,
86
 
  SQLCOM_ALTER_TABLESPACE,
87
96
  SQLCOM_BINLOG_BASE64_EVENT,
88
97
  SQLCOM_SHOW_PLUGINS,
89
 
  SQLCOM_ALTER_DB_UPGRADE,
90
98
  /*
91
99
    When a command is added here, be sure it's also added in mysqld.cc
92
100
    in "struct show_var_st status_vars[]= {" ...
99
107
#define DESCRIBE_NORMAL         1
100
108
#define DESCRIBE_EXTENDED       2
101
109
 
102
 
#ifdef MYSQL_SERVER
103
 
 
104
 
enum enum_sp_data_access
105
 
{
106
 
  SP_DEFAULT_ACCESS= 0,
107
 
  SP_CONTAINS_SQL,
108
 
  SP_NO_SQL,
109
 
  SP_READS_SQL_DATA,
110
 
  SP_MODIFIES_SQL_DATA
111
 
};
112
 
 
113
 
const LEX_STRING sp_data_access_name[]=
114
 
{
115
 
  { C_STRING_WITH_LEN("") },
116
 
  { C_STRING_WITH_LEN("CONTAINS SQL") },
117
 
  { C_STRING_WITH_LEN("NO SQL") },
118
 
  { C_STRING_WITH_LEN("READS SQL DATA") },
119
 
  { C_STRING_WITH_LEN("MODIFIES SQL DATA") }
120
 
};
 
110
#ifdef DRIZZLE_SERVER
121
111
 
122
112
#define DERIVED_NONE    0
123
113
#define DERIVED_SUBQUERY        1
124
114
 
125
 
enum enum_drop_mode
126
 
{
127
 
  DROP_DEFAULT, // mode is not specified
128
 
  DROP_CASCADE, // CASCADE option
129
 
  DROP_RESTRICT // RESTRICT option
130
 
};
131
 
 
132
115
typedef List<Item> List_item;
133
116
 
134
117
/* SERVERS CACHE CHANGES */
135
118
typedef struct st_lex_server_options
136
119
{
137
 
  long port;
138
 
  uint server_name_length;
139
 
  char *server_name, *host, *db, *username, *password, *scheme, *socket, *owner;
 
120
  int32_t port;
 
121
  uint32_t server_name_length;
 
122
  char *server_name, *host, *db, *username, *password, *scheme, *owner;
140
123
} LEX_SERVER_OPTIONS;
141
124
 
142
125
typedef struct st_lex_master_info
143
126
{
144
127
  char *host, *user, *password, *log_file_name;
145
 
  uint port, connect_retry;
 
128
  uint32_t port, connect_retry;
146
129
  float heartbeat_period;
147
 
  ulonglong pos;
148
 
  ulong server_id;
 
130
  uint64_t pos;
 
131
  uint32_t server_id;
149
132
  /*
150
133
    Enum is used for making it possible to detect if the user
151
134
    changed variable or if it should be left at old value
152
135
   */
153
 
  enum {LEX_MI_UNCHANGED, LEX_MI_DISABLE, LEX_MI_ENABLE}
154
 
    ssl, ssl_verify_server_cert, heartbeat_opt;
155
 
  char *ssl_key, *ssl_cert, *ssl_ca, *ssl_capath, *ssl_cipher;
 
136
  enum {LEX_MI_UNCHANGED, LEX_MI_DISABLE, LEX_MI_ENABLE} heartbeat_opt;
156
137
  char *relay_log_name;
157
 
  ulong relay_log_pos;
 
138
  uint32_t relay_log_pos;
158
139
} LEX_MASTER_INFO;
159
140
 
160
141
 
179
160
  Keep in sync with index_hint_type.
180
161
*/
181
162
extern const char * index_hint_type_name[];
182
 
typedef uchar index_clause_map;
 
163
typedef unsigned char index_clause_map;
183
164
 
184
165
/*
185
166
  Bits in index_clause_map : one for each possible FOR clause in
207
188
  LEX_STRING key_name;
208
189
 
209
190
  Index_hint (enum index_hint_type type_arg, index_clause_map clause_arg,
210
 
              char *str, uint length) :
 
191
              char *str, uint32_t length) :
211
192
    type(type_arg), clause(clause_arg)
212
193
  {
213
194
    key_name.str= str;
345
326
    *link_next, **link_prev;          /* list of whole SELECT_LEX */
346
327
public:
347
328
 
348
 
  ulonglong options;
 
329
  uint64_t options;
349
330
 
350
331
  /*
351
332
    result of this query can't be cached, bit field, can be :
355
336
      UNCACHEABLE_EXPLAIN
356
337
      UNCACHEABLE_PREPARE
357
338
  */
358
 
  uint8 uncacheable;
 
339
  uint8_t uncacheable;
359
340
  enum sub_select_type linkage;
360
341
  bool no_table_names_allowed; /* used for global order by */
361
342
  bool no_error; /* suppress error message (convert it to warnings) */
365
346
    return sql_alloc(size);
366
347
  }
367
348
  static void *operator new(size_t size, MEM_ROOT *mem_root)
368
 
  { return (void*) alloc_root(mem_root, (uint) size); }
369
 
  static void operator delete(void *ptr,size_t size) { TRASH(ptr, size); }
370
 
  static void operator delete(void *ptr, MEM_ROOT *mem_root) {}
 
349
  { return (void*) alloc_root(mem_root, (uint32_t) size); }
 
350
  static void operator delete(void *ptr __attribute__((unused)),
 
351
                              size_t size __attribute__((unused)))
 
352
  { TRASH(ptr, size); }
 
353
  static void operator delete(void *ptr __attribute__((unused)),
 
354
                              MEM_ROOT *mem_root __attribute__((unused)))
 
355
  {}
371
356
  st_select_lex_node(): linkage(UNSPECIFIED_TYPE) {}
372
357
  virtual ~st_select_lex_node() {}
373
358
  inline st_select_lex_node* get_master() { return master; }
385
370
 
386
371
  virtual bool set_braces(bool value);
387
372
  virtual bool inc_in_sum_expr();
388
 
  virtual uint get_in_sum_expr();
389
 
  virtual TABLE_LIST* get_table_list();
 
373
  virtual uint32_t get_in_sum_expr();
 
374
  virtual TableList* get_table_list();
390
375
  virtual List<Item>* get_item_list();
391
 
  virtual ulong get_table_join_options();
392
 
  virtual TABLE_LIST *add_table_to_list(THD *thd, Table_ident *table,
393
 
                                        LEX_STRING *alias,
394
 
                                        ulong table_options,
395
 
                                        thr_lock_type flags= TL_UNLOCK,
396
 
                                        List<Index_hint> *hints= 0,
 
376
  virtual uint32_t get_table_join_options();
 
377
  virtual TableList *add_table_to_list(THD *thd, Table_ident *table,
 
378
                                        LEX_STRING *alias,
 
379
                                        uint32_t table_options,
 
380
                                        thr_lock_type flags= TL_UNLOCK,
 
381
                                        List<Index_hint> *hints= 0,
397
382
                                        LEX_STRING *option= 0);
398
 
  virtual void set_lock_for_tables(thr_lock_type lock_type) {}
 
383
  virtual void set_lock_for_tables(thr_lock_type lock_type __attribute__((unused)))
 
384
  {}
399
385
 
400
386
  friend class st_select_lex_unit;
401
387
  friend bool mysql_new_select(struct st_lex *lex, bool move_down);
414
400
class select_union;
415
401
class st_select_lex_unit: public st_select_lex_node {
416
402
protected:
417
 
  TABLE_LIST result_table_list;
 
403
  TableList result_table_list;
418
404
  select_union *union_result;
419
 
  TABLE *table; /* temporary table using for appending UNION results */
 
405
  Table *table; /* temporary table using for appending UNION results */
420
406
 
421
407
  select_result *result;
422
 
  ulonglong found_rows_for_union;
 
408
  uint64_t found_rows_for_union;
423
409
  bool saved_error;
424
410
 
425
411
public:
469
455
  st_select_lex* outer_select();
470
456
  st_select_lex* first_select()
471
457
  {
472
 
    return my_reinterpret_cast(st_select_lex*)(slave);
 
458
    return reinterpret_cast<st_select_lex*>(slave);
473
459
  }
474
460
  st_select_lex_unit* next_unit()
475
461
  {
476
 
    return my_reinterpret_cast(st_select_lex_unit*)(next);
 
462
    return reinterpret_cast<st_select_lex_unit*>(next);
477
463
  }
478
464
  st_select_lex* return_after_parsing() { return return_to; }
479
465
  void exclude_level();
480
466
  void exclude_tree();
481
467
 
482
468
  /* UNION methods */
483
 
  bool prepare(THD *thd, select_result *result, ulong additional_options);
 
469
  bool prepare(THD *thd, select_result *result, uint32_t additional_options);
484
470
  bool exec();
485
471
  bool cleanup();
486
472
  inline void unclean() { cleaned= 0; }
513
499
  Name_resolution_context context;
514
500
  char *db;
515
501
  Item *where, *having;                         /* WHERE & HAVING clauses */
516
 
  Item *prep_where; /* saved WHERE clause for prepared statement processing */
517
 
  Item *prep_having;/* saved HAVING clause for prepared statement processing */
518
502
  /* Saved values of the WHERE and HAVING clauses*/
519
503
  Item::cond_result cond_value, having_value;
520
504
  /* point on lex in which it was created, used in view subquery detection */
521
505
  st_lex *parent_lex;
522
506
  enum olap_type olap;
523
 
  /* FROM clause - points to the beginning of the TABLE_LIST::next_local list. */
 
507
  /* FROM clause - points to the beginning of the TableList::next_local list. */
524
508
  SQL_LIST            table_list;
525
509
  SQL_LIST            group_list; /* GROUP BY clause. */
526
510
  List<Item>          item_list;  /* list of fields & expressions */
533
517
  List<Item_real_func> *ftfunc_list;
534
518
  List<Item_real_func> ftfunc_list_alloc;
535
519
  JOIN *join; /* after JOIN::prepare it is pointer to corresponding JOIN */
536
 
  List<TABLE_LIST> top_join_list; /* join list of the top level          */
537
 
  List<TABLE_LIST> *join_list;    /* list for the currently parsed join  */
538
 
  TABLE_LIST *embedding;          /* table embedding to the above list   */
539
 
  List<TABLE_LIST> sj_nests;
 
520
  List<TableList> top_join_list; /* join list of the top level          */
 
521
  List<TableList> *join_list;    /* list for the currently parsed join  */
 
522
  TableList *embedding;          /* table embedding to the above list   */
 
523
  List<TableList> sj_nests;
540
524
  /*
541
525
    Beginning of the list of leaves in a FROM clause, where the leaves
542
526
    inlcude all base tables including view tables. The tables are connected
543
 
    by TABLE_LIST::next_leaf, so leaf_tables points to the left-most leaf.
 
527
    by TableList::next_leaf, so leaf_tables points to the left-most leaf.
544
528
  */
545
 
  TABLE_LIST *leaf_tables;
 
529
  TableList *leaf_tables;
546
530
  const char *type;               /* type of select for EXPLAIN          */
547
531
 
548
532
  SQL_LIST order_list;                /* ORDER clause */
556
540
    bigger then can be number of entries that will be added to all item
557
541
    list during split_sum_func
558
542
  */
559
 
  uint select_n_having_items;
560
 
  uint cond_count;    /* number of arguments of and/or/xor in where/having/on */
561
 
  uint between_count; /* number of between predicates in where/having/on      */
562
 
  uint max_equal_elems; /* maximal number of elements in multiple equalities  */   
 
543
  uint32_t select_n_having_items;
 
544
  uint32_t cond_count;    /* number of arguments of and/or/xor in where/having/on */
 
545
  uint32_t between_count; /* number of between predicates in where/having/on      */
 
546
  uint32_t max_equal_elems; /* maximal number of elements in multiple equalities  */   
563
547
  /*
564
548
    Number of fields used in select list or where clause of current select
565
549
    and all inner subselects.
566
550
  */
567
 
  uint select_n_where_fields;
 
551
  uint32_t select_n_where_fields;
568
552
  enum_parsing_place parsing_place; /* where we are parsing expression */
569
553
  bool with_sum_func;   /* sum function indicator */
570
554
  /* 
573
557
  */
574
558
  bool conds_processed_with_permanent_arena;
575
559
 
576
 
  ulong table_join_options;
577
 
  uint in_sum_expr;
578
 
  uint select_number; /* number of select (used for EXPLAIN) */
 
560
  uint32_t table_join_options;
 
561
  uint32_t in_sum_expr;
 
562
  uint32_t select_number; /* number of select (used for EXPLAIN) */
579
563
  int nest_level;     /* nesting level of select */
580
564
  Item_sum *inner_sum_func_list; /* list of sum func in nested selects */ 
581
 
  uint with_wild; /* item list contain '*' */
 
565
  uint32_t with_wild; /* item list contain '*' */
582
566
  bool  braces;         /* SELECT ... UNION (SELECT ... ) <- this braces */
583
 
  /* TRUE when having fix field called in processing of this SELECT */
 
567
  /* true when having fix field called in processing of this SELECT */
584
568
  bool having_fix_field;
585
569
  /* List of references to fields referenced from inner selects */
586
570
  List<Item_outer_ref> inner_refs_list;
587
571
  /* Number of Item_sum-derived objects in this SELECT */
588
 
  uint n_sum_items;
 
572
  uint32_t n_sum_items;
589
573
  /* Number of Item_sum-derived objects in children and descendant SELECTs */
590
 
  uint n_child_sum_items;
 
574
  uint32_t n_child_sum_items;
591
575
 
592
576
  /* explicit LIMIT clause was used */
593
577
  bool explicit_limit;
596
580
    query processing end even if we use temporary table
597
581
  */
598
582
  bool subquery_in_having;
599
 
  /* TRUE <=> this SELECT is correlated w.r.t. some ancestor select */
 
583
  /* true <=> this SELECT is correlated w.r.t. some ancestor select */
600
584
  bool is_correlated;
601
 
  /*
602
 
    This variable is required to ensure proper work of subqueries and
603
 
    stored procedures. Generally, one should use the states of
604
 
    Query_arena to determine if it's a statement prepare or first
605
 
    execution of a stored procedure. However, in case when there was an
606
 
    error during the first execution of a stored procedure, the SP body
607
 
    is not expelled from the SP cache. Therefore, a deeply nested
608
 
    subquery might be left unoptimized. So we need this per-subquery
609
 
    variable to inidicate the optimization/execution state of every
610
 
    subquery. Prepared statements work OK in that regard, as in
611
 
    case of an error during prepare the PS is not created.
612
 
  */
613
 
  bool first_execution;
614
 
  bool first_cond_optimization;
615
 
  /* do not wrap view fields with Item_ref */
616
 
  bool no_wrap_view_item;
617
585
  /* exclude this select from check of unique_table() */
618
586
  bool exclude_from_table_unique_test;
619
587
  /* List of fields that aren't under an aggregate function */
625
593
  /* 
626
594
    This is a copy of the original JOIN USING list that comes from
627
595
    the parser. The parser :
628
 
      1. Sets the natural_join of the second TABLE_LIST in the join
 
596
      1. Sets the natural_join of the second TableList in the join
629
597
         and the st_select_lex::prev_join_using.
630
 
      2. Makes a parent TABLE_LIST and sets its is_natural_join/
 
598
      2. Makes a parent TableList and sets its is_natural_join/
631
599
       join_using_fields members.
632
 
      3. Uses the wrapper TABLE_LIST as a table in the upper level.
 
600
      3. Uses the wrapper TableList as a table in the upper level.
633
601
    We cannot assign directly to join_using_fields in the parser because
634
 
    at stage (1.) the parent TABLE_LIST is not constructed yet and
 
602
    at stage (1.) the parent TableList is not constructed yet and
635
603
    the assignment will override the JOIN USING fields of the lower level
636
604
    joins on the right.
637
605
  */
645
613
      1 - aggregate functions are used in this select,
646
614
          defined as SUM_FUNC_USED.
647
615
  */
648
 
  uint8 full_group_by_flag;
 
616
  uint8_t full_group_by_flag;
649
617
  void init_query();
650
618
  void init_select();
651
619
  st_select_lex_unit* master_unit();
672
640
 
673
641
  bool set_braces(bool value);
674
642
  bool inc_in_sum_expr();
675
 
  uint get_in_sum_expr();
 
643
  uint32_t get_in_sum_expr();
676
644
 
677
645
  bool add_item_to_list(THD *thd, Item *item);
678
646
  bool add_group_to_list(THD *thd, Item *item, bool asc);
679
647
  bool add_order_to_list(THD *thd, Item *item, bool asc);
680
 
  TABLE_LIST* add_table_to_list(THD *thd, Table_ident *table,
 
648
  TableList* add_table_to_list(THD *thd, Table_ident *table,
681
649
                                LEX_STRING *alias,
682
 
                                ulong table_options,
 
650
                                uint32_t table_options,
683
651
                                thr_lock_type flags= TL_UNLOCK,
684
652
                                List<Index_hint> *hints= 0,
685
653
                                LEX_STRING *option= 0);
686
 
  TABLE_LIST* get_table_list();
 
654
  TableList* get_table_list();
687
655
  bool init_nested_join(THD *thd);
688
 
  TABLE_LIST *end_nested_join(THD *thd);
689
 
  TABLE_LIST *nest_last_join(THD *thd);
690
 
  void add_joined_table(TABLE_LIST *table);
691
 
  TABLE_LIST *convert_right_join();
 
656
  TableList *end_nested_join(THD *thd);
 
657
  TableList *nest_last_join(THD *thd);
 
658
  void add_joined_table(TableList *table);
 
659
  TableList *convert_right_join();
692
660
  List<Item>* get_item_list();
693
 
  ulong get_table_join_options();
 
661
  uint32_t get_table_join_options();
694
662
  void set_lock_for_tables(thr_lock_type lock_type);
695
663
  inline void init_order()
696
664
  {
697
665
    order_list.elements= 0;
698
666
    order_list.first= 0;
699
 
    order_list.next= (uchar**) &order_list.first;
 
667
    order_list.next= (unsigned char**) &order_list.first;
700
668
  }
701
669
  /*
702
670
    This method created for reiniting LEX in mysql_admin_table() and can be
714
682
    init_query();
715
683
    init_select();
716
684
  }
717
 
  bool setup_ref_array(THD *thd, uint order_group_num);
 
685
  bool setup_ref_array(THD *thd, uint32_t order_group_num);
718
686
  void print(THD *thd, String *str, enum_query_type query_type);
719
687
  static void print_order(String *str,
720
 
                          ORDER *order,
 
688
                          order_st *order,
721
689
                          enum_query_type query_type);
722
690
  void print_limit(THD *thd, String *str, enum_query_type query_type);
723
691
  void fix_prepare_information(THD *thd, Item **conds, Item **having_conds);
738
706
   Add a index hint to the tagged list of hints. The type and clause of the
739
707
   hint will be the current ones (set by set_index_hint()) 
740
708
  */
741
 
  bool add_index_hint (THD *thd, char *str, uint length);
 
709
  bool add_index_hint (THD *thd, char *str, uint32_t length);
742
710
 
743
711
  /* make a list to hold index hints */
744
712
  void alloc_index_hints (THD *thd);
789
757
#define ALTER_FOREIGN_KEY         (1L << 31)
790
758
 
791
759
/**
792
 
  @brief Parsing data for CREATE or ALTER TABLE.
 
760
  @brief Parsing data for CREATE or ALTER Table.
793
761
 
794
762
  This structure contains a list of columns or indexes to be created,
795
763
  altered or dropped.
802
770
  List<Alter_column>            alter_list;
803
771
  List<Key>                     key_list;
804
772
  List<Create_field>            create_list;
805
 
  uint                          flags;
 
773
  uint32_t                          flags;
806
774
  enum enum_enable_or_disable   keys_onoff;
807
775
  enum tablespace_op_type       tablespace_op;
808
 
  uint                          no_parts;
 
776
  uint32_t                          no_parts;
809
777
  enum ha_build_method          build_method;
810
778
  Create_field                 *datetime_field;
811
779
  bool                          error_if_not_empty;
818
786
    no_parts(0),
819
787
    build_method(HA_BUILD_DEFAULT),
820
788
    datetime_field(NULL),
821
 
    error_if_not_empty(FALSE)
 
789
    error_if_not_empty(false)
822
790
  {}
823
791
 
824
792
  void reset()
833
801
    no_parts= 0;
834
802
    build_method= HA_BUILD_DEFAULT;
835
803
    datetime_field= 0;
836
 
    error_if_not_empty= FALSE;
 
804
    error_if_not_empty= false;
837
805
  }
838
806
  Alter_info(const Alter_info &rhs, MEM_ROOT *mem_root);
839
807
private:
862
830
{
863
831
public:
864
832
  /* Global list of all tables used by this statement */
865
 
  TABLE_LIST *query_tables;
 
833
  TableList *query_tables;
866
834
  /* Pointer to next_global member of last element in the previous list. */
867
 
  TABLE_LIST **query_tables_last;
 
835
  TableList **query_tables_last;
868
836
  /*
869
837
    If non-0 then indicates that query requires prelocking and points to
870
838
    next_global member of last own element in query table list (i.e. last
871
839
    table which was not added to it as part of preparation to prelocking).
872
840
    0 - indicates that this query does not need prelocking.
873
841
  */
874
 
  TABLE_LIST **query_tables_own_last;
 
842
  TableList **query_tables_own_last;
875
843
  /*
876
844
    Set of stored routines called by statement.
877
845
    (Note that we use lazy-initialization for this hash).
888
856
    in which it was right after query parsing.
889
857
  */
890
858
  SQL_LIST sroutines_list;
891
 
  uchar    **sroutines_list_own_last;
892
 
  uint     sroutines_list_own_elements;
 
859
  unsigned char    **sroutines_list_own_last;
 
860
  uint32_t     sroutines_list_own_elements;
893
861
 
894
862
  /*
895
863
    These constructor and destructor serve for creation/destruction
911
879
    If you are using this function, you must ensure that the table
912
880
    object, in particular table->db member, is initialized.
913
881
  */
914
 
  void add_to_query_tables(TABLE_LIST *table)
 
882
  void add_to_query_tables(TableList *table)
915
883
  {
916
884
    *(table->prev_global= query_tables_last)= table;
917
885
    query_tables_last= &table->next_global;
918
886
  }
919
887
  /* Return pointer to first not-own table in query-tables or 0 */
920
 
  TABLE_LIST* first_not_own_table()
 
888
  TableList* first_not_own_table()
921
889
  {
922
890
    return ( query_tables_own_last ? *query_tables_own_last : 0);
923
891
  }
971
939
    a reliable binlog/replication, or if we will use stored functions
972
940
    or triggers which themselves need require row-based binlogging.
973
941
  */
974
 
  uint32 binlog_stmt_flags;
 
942
  uint32_t binlog_stmt_flags;
975
943
};
976
944
 
977
945
 
1239
1207
  }
1240
1208
 
1241
1209
  /** Get the length of the current token, in the raw buffer. */
1242
 
  uint yyLength()
 
1210
  uint32_t yyLength()
1243
1211
  {
1244
1212
    /*
1245
1213
      The assumption is that the lexical analyser is always 1 character ahead,
1246
1214
      which the -1 account for.
1247
1215
    */
1248
 
    DBUG_ASSERT(m_ptr > m_tok_start);
1249
 
    return (uint) ((m_ptr - m_tok_start) - 1);
 
1216
    assert(m_ptr > m_tok_start);
 
1217
    return (uint32_t) ((m_ptr - m_tok_start) - 1);
1250
1218
  }
1251
1219
 
1252
1220
  /** Get the utf8-body string. */
1256
1224
  }
1257
1225
 
1258
1226
  /** Get the utf8-body length. */
1259
 
  uint get_body_utf8_length()
 
1227
  uint32_t get_body_utf8_length()
1260
1228
  {
1261
1229
    return m_body_utf8_ptr - m_body_utf8;
1262
1230
  }
1266
1234
  void body_utf8_append(const char *ptr, const char *end_ptr);
1267
1235
  void body_utf8_append_literal(THD *thd,
1268
1236
                                const LEX_STRING *txt,
1269
 
                                CHARSET_INFO *txt_cs,
 
1237
                                const CHARSET_INFO * const txt_cs,
1270
1238
                                const char *end_ptr);
1271
1239
 
1272
1240
  /** Current thread. */
1273
1241
  THD *m_thd;
1274
1242
 
1275
1243
  /** Current line number. */
1276
 
  uint yylineno;
 
1244
  uint32_t yylineno;
1277
1245
 
1278
1246
  /** Length of the last token parsed. */
1279
 
  uint yytoklen;
 
1247
  uint32_t yytoklen;
1280
1248
 
1281
1249
  /** Interface with bison, value of the last token parsed. */
1282
1250
  LEX_YYSTYPE yylval;
1307
1275
  const char *m_buf;
1308
1276
 
1309
1277
  /** Length of the raw buffer. */
1310
 
  uint m_buf_length;
 
1278
  uint32_t m_buf_length;
1311
1279
 
1312
1280
  /** Echo the parsed stream to the pre-processed buffer. */
1313
1281
  bool m_echo;
1360
1328
  const char *found_semicolon;
1361
1329
 
1362
1330
  /** Token character bitmaps, to detect 7bit strings. */
1363
 
  uchar tok_bitmap;
 
1331
  unsigned char tok_bitmap;
1364
1332
 
1365
1333
  /** SQL_MODE = IGNORE_SPACE. */
1366
1334
  bool ignore_space;
1367
1335
 
1368
 
  /**
1369
 
    TRUE if we're parsing a prepared statement: in this mode
1370
 
    we should allow placeholders and disallow multi-statements.
1371
 
  */
1372
 
  bool stmt_prepare_mode;
1373
 
 
1374
1336
  /** State of the lexical analyser for comments. */
1375
1337
  enum_comment_state in_comment;
1376
1338
 
1395
1357
 
1396
1358
    NOTE: this member must be used within MYSQLlex() function only.
1397
1359
  */
1398
 
  CHARSET_INFO *m_underscore_cs;
 
1360
  const CHARSET_INFO *m_underscore_cs;
1399
1361
};
1400
1362
 
1401
1363
 
1413
1375
  char *length,*dec,*change;
1414
1376
  LEX_STRING name;
1415
1377
  char *help_arg;
1416
 
  LEX_STRING backup_dir;                                /* For RESTORE/BACKUP */
1417
1378
  char* to_log;                                 /* For PURGE MASTER LOGS TO */
1418
 
  char* x509_subject,*x509_issuer,*ssl_cipher;
1419
1379
  String *wild;
1420
1380
  sql_exchange *exchange;
1421
1381
  select_result *result;
1422
1382
  Item *default_value, *on_update_value;
1423
1383
  LEX_STRING comment, ident;
1424
1384
  XID *xid;
1425
 
  uchar* yacc_yyss, *yacc_yyvs;
 
1385
  unsigned char* yacc_yyss, *yacc_yyvs;
1426
1386
  THD *thd;
 
1387
  virtual_column_info *vcol_info;
1427
1388
 
1428
1389
  /* maintain a list of used plugins for this LEX */
1429
1390
  DYNAMIC_ARRAY plugins;
1430
1391
  plugin_ref plugins_static_buffer[INITIAL_LEX_PLUGIN_LIST_SIZE];
1431
1392
 
1432
 
  CHARSET_INFO *charset;
 
1393
  const CHARSET_INFO *charset;
1433
1394
  bool text_string_is_7bit;
1434
1395
  /* store original leaf_tables for INSERT SELECT and PS/SP */
1435
 
  TABLE_LIST *leaf_tables_insert;
 
1396
  TableList *leaf_tables_insert;
1436
1397
 
1437
1398
  List<Key_part_spec> col_list;
1438
1399
  List<Key_part_spec> ref_list;
1439
1400
  List<String>        interval_list;
1440
 
  List<LEX_USER>      users_list;
1441
1401
  List<LEX_COLUMN>    columns;
1442
1402
  List<Item>          *insert_list,field_list,value_list,update_list;
1443
1403
  List<List_item>     many_values;
1444
1404
  List<set_var_base>  var_list;
1445
1405
  List<Item_param>    param_list;
1446
 
  List<LEX_STRING>    view_list; // view list (list of field names in view)
1447
1406
  /*
1448
1407
    A stack of name resolution contexts for the query. This stack is used
1449
1408
    at parse time to set local name resolution contexts for various parts
1469
1428
  KEY_CREATE_INFO key_create_info;
1470
1429
  LEX_MASTER_INFO mi;                           // used by CHANGE MASTER
1471
1430
  LEX_SERVER_OPTIONS server_options;
1472
 
  USER_RESOURCES mqh;
1473
 
  ulong type;
 
1431
  uint32_t type;
1474
1432
  /*
1475
1433
    This variable is used in post-parse stage to declare that sum-functions,
1476
1434
    or functions which have sense only if GROUP BY is present, are allowed.
1489
1447
    syntax error back.
1490
1448
  */
1491
1449
  bool expr_allows_subselect;
 
1450
  /*
 
1451
    A special command "PARSE_VCOL_EXPR" is defined for the parser 
 
1452
    to translate an expression statement of a virtual column \
 
1453
    (stored in the *.frm file as a string) into an Item object.
 
1454
    The following flag is used to prevent other applications to use 
 
1455
    this command.
 
1456
  */
 
1457
  bool parse_vcol_expr;
1492
1458
 
1493
1459
  thr_lock_type lock_option;
1494
1460
  enum enum_duplicates duplicates;
1497
1463
  union {
1498
1464
    enum ha_rkey_function ha_rkey_mode;
1499
1465
    enum xa_option_words xa_opt;
1500
 
    bool lock_transactional;            /* For LOCK TABLE ... IN ... MODE */
 
1466
    bool lock_transactional;            /* For LOCK Table ... IN ... MODE */
1501
1467
  };
1502
1468
  enum enum_var_type option_type;
1503
 
  enum enum_drop_mode drop_mode;
1504
1469
 
1505
 
  uint profile_query_id;
1506
 
  uint profile_options;
1507
 
  enum ha_storage_media storage_type;
 
1470
  uint32_t profile_query_id;
 
1471
  uint32_t profile_options;
1508
1472
  enum column_format_type column_format;
1509
 
  uint which_columns;
 
1473
  uint32_t which_columns;
1510
1474
  enum Foreign_key::fk_match_opt fk_match_option;
1511
1475
  enum Foreign_key::fk_option fk_update_opt;
1512
1476
  enum Foreign_key::fk_option fk_delete_opt;
1513
 
  uint slave_thd_opt, start_transaction_opt;
 
1477
  uint32_t slave_thd_opt, start_transaction_opt;
1514
1478
  int nest_level;
1515
1479
  /*
1516
1480
    In LEX representing update which were transformed to multi-update
1517
1481
    stores total number of tables. For LEX representing multi-delete
1518
1482
    holds number of tables from which we will delete records.
1519
1483
  */
1520
 
  uint table_count;
1521
 
  uint8 describe;
 
1484
  uint32_t table_count;
 
1485
  uint8_t describe;
1522
1486
  /*
1523
1487
    A flag that indicates what kinds of derived tables are present in the
1524
1488
    query (0 if no derived tables, otherwise DERIVED_SUBQUERY).
1525
1489
  */
1526
 
  uint8 derived_tables;
 
1490
  uint8_t derived_tables;
1527
1491
  bool drop_if_exists, drop_temporary, local_file, one_shot_set;
1528
1492
  bool autocommit;
1529
 
  bool verbose, no_write_to_binlog;
 
1493
  bool verbose;
1530
1494
 
1531
1495
  bool tx_chain, tx_release;
1532
 
  /*
1533
 
    Special JOIN::prepare mode: changing of query is prohibited.
1534
 
    When creating a view, we need to just check its syntax omitting
1535
 
    any optimizations: afterwards definition of the view will be
1536
 
    reconstructed by means of ::print() methods and written to
1537
 
    to an .frm file. We need this definition to stay untouched.
1538
 
  */
1539
 
  bool view_prepare_mode;
1540
1496
  bool subqueries, ignore;
1541
1497
  st_parsing_options parsing_options;
1542
1498
  Alter_info alter_info;
1561
1517
    (see Item_field::fix_fields()). 
1562
1518
  */
1563
1519
  bool use_only_table_context;
1564
 
 
1565
 
  /*
1566
 
    Reference to a struct that contains information in various commands
1567
 
    to add/create/drop/change table spaces.
1568
 
  */
1569
 
  st_alter_tablespace *alter_tablespace_info;
1570
1520
  
1571
1521
  bool escape_used;
1572
1522
  bool is_lex_started; /* If lex_start() did run. For debugging. */
1580
1530
    delete_dynamic(&plugins);
1581
1531
  }
1582
1532
 
1583
 
  TABLE_LIST *unlink_first_table(bool *link_to_local);
1584
 
  void link_first_table_back(TABLE_LIST *first, bool link_to_local);
 
1533
  TableList *unlink_first_table(bool *link_to_local);
 
1534
  void link_first_table_back(TableList *first, bool link_to_local);
1585
1535
  void first_lists_tables_same();
1586
1536
 
1587
1537
  bool can_be_merged();
1589
1539
  bool can_not_use_merged();
1590
1540
  bool only_view_structure();
1591
1541
  bool need_correct_ident();
1592
 
  uint8 get_effective_with_check(TABLE_LIST *view);
1593
 
  /*
1594
 
    Is this update command where 'WHITH CHECK OPTION' clause is important
1595
 
 
1596
 
    SYNOPSIS
1597
 
      st_lex::which_check_option_applicable()
1598
 
 
1599
 
    RETURN
1600
 
      TRUE   have to take 'WHITH CHECK OPTION' clause into account
1601
 
      FALSE  'WHITH CHECK OPTION' clause do not need
1602
 
  */
1603
 
  inline bool which_check_option_applicable()
1604
 
  {
1605
 
    switch (sql_command) {
1606
 
    case SQLCOM_UPDATE:
1607
 
    case SQLCOM_UPDATE_MULTI:
1608
 
    case SQLCOM_INSERT:
1609
 
    case SQLCOM_INSERT_SELECT:
1610
 
    case SQLCOM_REPLACE:
1611
 
    case SQLCOM_REPLACE_SELECT:
1612
 
    case SQLCOM_LOAD:
1613
 
      return TRUE;
1614
 
    default:
1615
 
      return FALSE;
1616
 
    }
1617
 
  }
1618
1542
 
1619
1543
  void cleanup_after_one_table_open();
1620
1544
 
1647
1571
  /**
1648
1572
    @brief check if the statement is a single-level join
1649
1573
    @return result of the check
1650
 
      @retval TRUE  The statement doesn't contain subqueries, unions and 
 
1574
      @retval true  The statement doesn't contain subqueries, unions and 
1651
1575
                    stored procedure calls.
1652
 
      @retval FALSE There are subqueries, UNIONs or stored procedure calls.
 
1576
      @retval false There are subqueries, UNIONs or stored procedure calls.
1653
1577
  */
1654
1578
  bool is_single_level_stmt() 
1655
1579
  { 
1660
1584
    */ 
1661
1585
    if (&select_lex == all_selects_list && !sroutines.records)
1662
1586
    {
1663
 
      DBUG_ASSERT(!all_selects_list->next_select_in_list());
1664
 
      return TRUE;
 
1587
      assert(!all_selects_list->next_select_in_list());
 
1588
      return true;
1665
1589
    }
1666
 
    return FALSE;
 
1590
    return false;
1667
1591
  }
1668
1592
} LEX;
1669
1593
 
1675
1599
  }
1676
1600
  static void *operator new(size_t size, MEM_ROOT *mem_root) throw()
1677
1601
  {
1678
 
    return (void*) alloc_root(mem_root, (uint) size);
 
1602
    return (void*) alloc_root(mem_root, (uint32_t) size);
1679
1603
  }
1680
 
  static void operator delete(void *ptr,size_t size)
 
1604
  static void operator delete(void *ptr __attribute__((unused)),
 
1605
                              size_t size __attribute__((unused)))
1681
1606
  { TRASH(ptr, size); }
1682
 
  static void operator delete(void *ptr, MEM_ROOT *mem_root)
 
1607
  static void operator delete(void *ptr __attribute__((unused)),
 
1608
                              MEM_ROOT *mem_root __attribute__((unused)))
1683
1609
  { /* Never called */ }
1684
1610
};
1685
1611
 
1687
1613
extern void lex_free(void);
1688
1614
extern void lex_start(THD *thd);
1689
1615
extern void lex_end(LEX *lex);
1690
 
extern int MYSQLlex(void *arg, void *yythd);
1691
1616
 
1692
 
extern void trim_whitespace(CHARSET_INFO *cs, LEX_STRING *str);
 
1617
extern void trim_whitespace(const CHARSET_INFO * const cs, LEX_STRING *str);
1693
1618
 
1694
1619
extern bool is_lex_native_function(const LEX_STRING *name);
1695
1620
 
1697
1622
  @} (End of group Semantic_Analysis)
1698
1623
*/
1699
1624
 
1700
 
#endif /* MYSQL_SERVER */
 
1625
#endif /* DRIZZLE_SERVER */
 
1626
#endif /* DRIZZLE_SERVER_SQL_LEX_H */