~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_lex.h

  • Committer: Brian Aker
  • Date: 2008-11-04 15:39:09 UTC
  • mfrom: (575.1.2 devel)
  • Revision ID: brian@tangent.org-20081104153909-c72hn65udxs1ccal
Merge of Monty's work

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
 */
15
19
 
16
20
#ifndef DRIZZLE_SERVER_SQL_LEX_H
17
21
#define DRIZZLE_SERVER_SQL_LEX_H
20
24
  @defgroup Semantic_Analysis Semantic Analysis
21
25
*/
22
26
 
 
27
#include "sql_udf.h"
 
28
 
23
29
/* YACC and LEX Definitions */
24
30
 
25
31
/* These may not be declared yet */
33
39
  YYSTYPE before including this file
34
40
*/
35
41
 
36
 
#include "set_var.h"
 
42
#include <drizzled/set_var.h>
37
43
 
38
44
#ifdef DRIZZLE_YACC
39
45
#define LEX_YYSTYPE void *
66
72
  SQLCOM_SHOW_KEYS, SQLCOM_SHOW_VARIABLES, SQLCOM_SHOW_STATUS,
67
73
  SQLCOM_SHOW_ENGINE_LOGS, SQLCOM_SHOW_ENGINE_STATUS, SQLCOM_SHOW_ENGINE_MUTEX,
68
74
  SQLCOM_SHOW_PROCESSLIST, SQLCOM_SHOW_MASTER_STAT, SQLCOM_SHOW_SLAVE_STAT,
69
 
  SQLCOM_SHOW_CREATE, SQLCOM_SHOW_CHARSETS,
70
 
  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,
71
78
  SQLCOM_LOAD,SQLCOM_SET_OPTION,SQLCOM_LOCK_TABLES,SQLCOM_UNLOCK_TABLES,
72
79
  SQLCOM_CHANGE_DB, SQLCOM_CREATE_DB, SQLCOM_DROP_DB, SQLCOM_ALTER_DB,
73
80
  SQLCOM_REPAIR, SQLCOM_REPLACE, SQLCOM_REPLACE_SELECT,
81
88
  SQLCOM_RENAME_TABLE,  
82
89
  SQLCOM_RESET, SQLCOM_PURGE, SQLCOM_PURGE_BEFORE, SQLCOM_SHOW_BINLOGS,
83
90
  SQLCOM_SHOW_OPEN_TABLES,
84
 
  SQLCOM_SHOW_SLAVE_HOSTS, SQLCOM_DELETE_MULTI, SQLCOM_UPDATE_MULTI,
85
 
  SQLCOM_SHOW_BINLOG_EVENTS,
86
 
  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,
87
95
  SQLCOM_CHECKSUM,
88
96
  SQLCOM_BINLOG_BASE64_EVENT,
89
97
  SQLCOM_SHOW_PLUGINS,
125
133
    Enum is used for making it possible to detect if the user
126
134
    changed variable or if it should be left at old value
127
135
   */
128
 
  enum {LEX_MI_UNCHANGED, LEX_MI_DISABLE, LEX_MI_ENABLE}
129
 
    ssl, ssl_verify_server_cert, heartbeat_opt;
130
 
  char *ssl_key, *ssl_cert, *ssl_ca, *ssl_capath, *ssl_cipher;
 
136
  enum {LEX_MI_UNCHANGED, LEX_MI_DISABLE, LEX_MI_ENABLE} heartbeat_opt;
131
137
  char *relay_log_name;
132
138
  uint32_t relay_log_pos;
133
139
} LEX_MASTER_INFO;
154
160
  Keep in sync with index_hint_type.
155
161
*/
156
162
extern const char * index_hint_type_name[];
157
 
typedef uchar index_clause_map;
 
163
typedef unsigned char index_clause_map;
158
164
 
159
165
/*
160
166
  Bits in index_clause_map : one for each possible FOR clause in
189
195
    key_name.length= length;
190
196
  }
191
197
 
192
 
  void print(THD *thd, String *str);
 
198
  void print(Session *session, String *str);
193
199
}; 
194
200
 
195
201
/* 
368
374
  virtual TableList* get_table_list();
369
375
  virtual List<Item>* get_item_list();
370
376
  virtual uint32_t get_table_join_options();
371
 
  virtual TableList *add_table_to_list(THD *thd, Table_ident *table,
 
377
  virtual TableList *add_table_to_list(Session *session, Table_ident *table,
372
378
                                        LEX_STRING *alias,
373
379
                                        uint32_t table_options,
374
380
                                        thr_lock_type flags= TL_UNLOCK,
388
394
   SELECT_LEX_UNIT - unit of selects (UNION, INTERSECT, ...) group 
389
395
   SELECT_LEXs
390
396
*/
391
 
class THD;
 
397
class Session;
392
398
class select_result;
393
399
class JOIN;
394
400
class select_union;
434
440
  /* not NULL if unit used in subselect, point to subselect item */
435
441
  Item_subselect *item;
436
442
  /* thread handler */
437
 
  THD *thd;
 
443
  Session *session;
438
444
  /*
439
445
    SELECT_LEX for hidden SELECT in onion which process global
440
446
    ORDER BY and LIMIT
449
455
  st_select_lex* outer_select();
450
456
  st_select_lex* first_select()
451
457
  {
452
 
    return my_reinterpret_cast(st_select_lex*)(slave);
 
458
    return reinterpret_cast<st_select_lex*>(slave);
453
459
  }
454
460
  st_select_lex_unit* next_unit()
455
461
  {
456
 
    return my_reinterpret_cast(st_select_lex_unit*)(next);
 
462
    return reinterpret_cast<st_select_lex_unit*>(next);
457
463
  }
458
464
  st_select_lex* return_after_parsing() { return return_to; }
459
465
  void exclude_level();
460
466
  void exclude_tree();
461
467
 
462
468
  /* UNION methods */
463
 
  bool prepare(THD *thd, select_result *result, uint32_t additional_options);
 
469
  bool prepare(Session *session, select_result *result, uint32_t additional_options);
464
470
  bool exec();
465
471
  bool cleanup();
466
472
  inline void unclean() { cleaned= 0; }
468
474
 
469
475
  void print(String *str, enum_query_type query_type);
470
476
 
471
 
  bool add_fake_select_lex(THD *thd);
472
 
  void init_prepare_fake_select_lex(THD *thd);
 
477
  bool add_fake_select_lex(Session *session);
 
478
  void init_prepare_fake_select_lex(Session *session);
473
479
  bool change_result(select_result_interceptor *result,
474
480
                     select_result_interceptor *old_result);
475
481
  void set_limit(st_select_lex *values);
476
 
  void set_thd(THD *thd_arg) { thd= thd_arg; }
 
482
  void set_session(Session *session_arg) { session= session_arg; }
477
483
  inline bool is_union (); 
478
484
 
479
 
  friend void lex_start(THD *thd);
 
485
  friend void lex_start(Session *session);
480
486
  friend int subselect_union_engine::exec();
481
487
 
482
488
  List<Item> *get_unit_column_types();
576
582
  bool subquery_in_having;
577
583
  /* true <=> this SELECT is correlated w.r.t. some ancestor select */
578
584
  bool is_correlated;
579
 
  /*
580
 
    This variable is required to ensure proper work of subqueries and
581
 
    stored procedures. Generally, one should use the states of
582
 
    Query_arena to determine if it's a statement prepare or first
583
 
    execution of a stored procedure. However, in case when there was an
584
 
    error during the first execution of a stored procedure, the SP body
585
 
    is not expelled from the SP cache. Therefore, a deeply nested
586
 
    subquery might be left unoptimized. So we need this per-subquery
587
 
    variable to inidicate the optimization/execution state of every
588
 
    subquery. Prepared statements work OK in that regard, as in
589
 
    case of an error during prepare the PS is not created.
590
 
  */
591
 
  bool first_execution;
592
 
  bool first_cond_optimization;
593
585
  /* exclude this select from check of unique_table() */
594
586
  bool exclude_from_table_unique_test;
595
587
  /* List of fields that aren't under an aggregate function */
650
642
  bool inc_in_sum_expr();
651
643
  uint32_t get_in_sum_expr();
652
644
 
653
 
  bool add_item_to_list(THD *thd, Item *item);
654
 
  bool add_group_to_list(THD *thd, Item *item, bool asc);
655
 
  bool add_order_to_list(THD *thd, Item *item, bool asc);
656
 
  TableList* add_table_to_list(THD *thd, Table_ident *table,
 
645
  bool add_item_to_list(Session *session, Item *item);
 
646
  bool add_group_to_list(Session *session, Item *item, bool asc);
 
647
  bool add_order_to_list(Session *session, Item *item, bool asc);
 
648
  TableList* add_table_to_list(Session *session, Table_ident *table,
657
649
                                LEX_STRING *alias,
658
650
                                uint32_t table_options,
659
651
                                thr_lock_type flags= TL_UNLOCK,
660
652
                                List<Index_hint> *hints= 0,
661
653
                                LEX_STRING *option= 0);
662
654
  TableList* get_table_list();
663
 
  bool init_nested_join(THD *thd);
664
 
  TableList *end_nested_join(THD *thd);
665
 
  TableList *nest_last_join(THD *thd);
 
655
  bool init_nested_join(Session *session);
 
656
  TableList *end_nested_join(Session *session);
 
657
  TableList *nest_last_join(Session *session);
666
658
  void add_joined_table(TableList *table);
667
659
  TableList *convert_right_join();
668
660
  List<Item>* get_item_list();
672
664
  {
673
665
    order_list.elements= 0;
674
666
    order_list.first= 0;
675
 
    order_list.next= (uchar**) &order_list.first;
 
667
    order_list.next= (unsigned char**) &order_list.first;
676
668
  }
677
669
  /*
678
670
    This method created for reiniting LEX in mysql_admin_table() and can be
683
675
  void cut_subtree() { slave= 0; }
684
676
  bool test_limit();
685
677
 
686
 
  friend void lex_start(THD *thd);
 
678
  friend void lex_start(Session *session);
687
679
  st_select_lex() : n_sum_items(0), n_child_sum_items(0) {}
688
680
  void make_empty_select()
689
681
  {
690
682
    init_query();
691
683
    init_select();
692
684
  }
693
 
  bool setup_ref_array(THD *thd, uint32_t order_group_num);
694
 
  void print(THD *thd, String *str, enum_query_type query_type);
 
685
  bool setup_ref_array(Session *session, uint32_t order_group_num);
 
686
  void print(Session *session, String *str, enum_query_type query_type);
695
687
  static void print_order(String *str,
696
688
                          order_st *order,
697
689
                          enum_query_type query_type);
698
 
  void print_limit(THD *thd, String *str, enum_query_type query_type);
699
 
  void fix_prepare_information(THD *thd, Item **conds, Item **having_conds);
 
690
  void print_limit(Session *session, String *str, enum_query_type query_type);
 
691
  void fix_prepare_information(Session *session, Item **conds, Item **having_conds);
700
692
  /*
701
693
    Destroy the used execution plan (JOIN) of this subtree (this
702
694
    SELECT_LEX and all nested SELECT_LEXes and SELECT_LEX_UNITs).
714
706
   Add a index hint to the tagged list of hints. The type and clause of the
715
707
   hint will be the current ones (set by set_index_hint()) 
716
708
  */
717
 
  bool add_index_hint (THD *thd, char *str, uint32_t length);
 
709
  bool add_index_hint (Session *session, char *str, uint32_t length);
718
710
 
719
711
  /* make a list to hold index hints */
720
 
  void alloc_index_hints (THD *thd);
 
712
  void alloc_index_hints (Session *session);
721
713
  /* read and clear the index hints */
722
714
  List<Index_hint>* pop_index_hints(void) 
723
715
  {
864
856
    in which it was right after query parsing.
865
857
  */
866
858
  SQL_LIST sroutines_list;
867
 
  uchar    **sroutines_list_own_last;
 
859
  unsigned char    **sroutines_list_own_last;
868
860
  uint32_t     sroutines_list_own_elements;
869
861
 
870
862
  /*
1009
1001
class Lex_input_stream
1010
1002
{
1011
1003
public:
1012
 
  Lex_input_stream(THD *thd, const char* buff, unsigned int length);
 
1004
  Lex_input_stream(Session *session, const char* buff, unsigned int length);
1013
1005
  ~Lex_input_stream();
1014
1006
 
1015
1007
  /**
1237
1229
    return m_body_utf8_ptr - m_body_utf8;
1238
1230
  }
1239
1231
 
1240
 
  void body_utf8_start(THD *thd, const char *begin_ptr);
 
1232
  void body_utf8_start(Session *session, const char *begin_ptr);
1241
1233
  void body_utf8_append(const char *ptr);
1242
1234
  void body_utf8_append(const char *ptr, const char *end_ptr);
1243
 
  void body_utf8_append_literal(THD *thd,
 
1235
  void body_utf8_append_literal(Session *session,
1244
1236
                                const LEX_STRING *txt,
1245
1237
                                const CHARSET_INFO * const txt_cs,
1246
1238
                                const char *end_ptr);
1247
1239
 
1248
1240
  /** Current thread. */
1249
 
  THD *m_thd;
 
1241
  Session *m_session;
1250
1242
 
1251
1243
  /** Current line number. */
1252
1244
  uint32_t yylineno;
1336
1328
  const char *found_semicolon;
1337
1329
 
1338
1330
  /** Token character bitmaps, to detect 7bit strings. */
1339
 
  uchar tok_bitmap;
 
1331
  unsigned char tok_bitmap;
1340
1332
 
1341
1333
  /** SQL_MODE = IGNORE_SPACE. */
1342
1334
  bool ignore_space;
1348
1340
    Starting position of the TEXT_STRING or IDENT in the pre-processed
1349
1341
    buffer.
1350
1342
 
1351
 
    NOTE: this member must be used within MYSQLlex() function only.
 
1343
    NOTE: this member must be used within DRIZZLElex() function only.
1352
1344
  */
1353
1345
  const char *m_cpp_text_start;
1354
1346
 
1356
1348
    Ending position of the TEXT_STRING or IDENT in the pre-processed
1357
1349
    buffer.
1358
1350
 
1359
 
    NOTE: this member must be used within MYSQLlex() function only.
 
1351
    NOTE: this member must be used within DRIZZLElex() function only.
1360
1352
    */
1361
1353
  const char *m_cpp_text_end;
1362
1354
 
1363
1355
  /**
1364
1356
    Character set specified by the character-set-introducer.
1365
1357
 
1366
 
    NOTE: this member must be used within MYSQLlex() function only.
 
1358
    NOTE: this member must be used within DRIZZLElex() function only.
1367
1359
  */
1368
1360
  const CHARSET_INFO *m_underscore_cs;
1369
1361
};
1370
1362
 
1371
1363
 
1372
 
/* The state of the lex parsing. This is saved in the THD struct */
 
1364
/* The state of the lex parsing. This is saved in the Session struct */
1373
1365
 
1374
1366
typedef struct st_lex : public Query_tables_list
1375
1367
{
1384
1376
  LEX_STRING name;
1385
1377
  char *help_arg;
1386
1378
  char* to_log;                                 /* For PURGE MASTER LOGS TO */
1387
 
  char* x509_subject,*x509_issuer,*ssl_cipher;
1388
1379
  String *wild;
1389
1380
  sql_exchange *exchange;
1390
1381
  select_result *result;
1391
1382
  Item *default_value, *on_update_value;
1392
1383
  LEX_STRING comment, ident;
1393
1384
  XID *xid;
1394
 
  uchar* yacc_yyss, *yacc_yyvs;
1395
 
  THD *thd;
 
1385
  unsigned char* yacc_yyss, *yacc_yyvs;
 
1386
  Session *session;
 
1387
  virtual_column_info *vcol_info;
1396
1388
 
1397
1389
  /* maintain a list of used plugins for this LEX */
1398
1390
  DYNAMIC_ARRAY plugins;
1455
1447
    syntax error back.
1456
1448
  */
1457
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;
1458
1458
 
1459
1459
  thr_lock_type lock_option;
1460
1460
  enum enum_duplicates duplicates;
1474
1474
  enum Foreign_key::fk_match_opt fk_match_option;
1475
1475
  enum Foreign_key::fk_option fk_update_opt;
1476
1476
  enum Foreign_key::fk_option fk_delete_opt;
1477
 
  uint32_t slave_thd_opt, start_transaction_opt;
 
1477
  uint32_t slave_session_opt, start_transaction_opt;
1478
1478
  int nest_level;
1479
1479
  /*
1480
1480
    In LEX representing update which were transformed to multi-update
1559
1559
    return context_stack.head();
1560
1560
  }
1561
1561
  /*
1562
 
    Restore the LEX and THD in case of a parse error.
 
1562
    Restore the LEX and Session in case of a parse error.
1563
1563
  */
1564
 
  static void cleanup_lex_after_parse_error(THD *thd);
 
1564
  static void cleanup_lex_after_parse_error(Session *session);
1565
1565
 
1566
1566
  void reset_n_backup_query_tables_list(Query_tables_list *backup);
1567
1567
  void restore_backup_query_tables_list(Query_tables_list *backup);
1611
1611
 
1612
1612
extern void lex_init(void);
1613
1613
extern void lex_free(void);
1614
 
extern void lex_start(THD *thd);
 
1614
extern void lex_start(Session *session);
1615
1615
extern void lex_end(LEX *lex);
1616
1616
 
1617
1617
extern void trim_whitespace(const CHARSET_INFO * const cs, LEX_STRING *str);