~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_lex.h

  • Committer: Brian Aker
  • Date: 2009-06-05 23:10:06 UTC
  • mto: This revision was merged to the branch mainline in revision 1055.
  • Revision ID: brian@gaz-20090605231006-01nyw7pfpj2z2v8p
Remove guts in parser for LOCK TABLE.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
*/
26
26
#include <drizzled/message/table.pb.h>
27
27
 
28
 
#include "drizzled/plugin/function.h"
 
28
#include "drizzled/sql_udf.h"
29
29
#include "drizzled/name_resolution_context.h"
30
30
#include "drizzled/item/subselect.h"
 
31
#include "drizzled/item/param.h"
 
32
#include "drizzled/item/outer_ref.h"
31
33
#include "drizzled/table_list.h"
32
34
#include "drizzled/function/math/real.h"
33
35
#include "drizzled/alter_drop.h"
34
36
#include "drizzled/alter_column.h"
35
 
#include "drizzled/alter_info.h"
36
 
#include "drizzled/key_part_spec.h"
 
37
#include "drizzled/key.h"
 
38
#include "drizzled/foreign_key.h"
 
39
#include "drizzled/item/param.h"
37
40
#include "drizzled/index_hint.h"
38
 
#include "drizzled/statement.h"
39
 
#include "drizzled/optimizer/explain_plan.h"
40
 
 
41
 
#include <bitset>
42
 
#include <string>
43
 
 
44
 
namespace drizzled
45
 
{
46
41
 
47
42
class select_result_interceptor;
48
43
 
54
49
class Lex_Column;
55
50
class Item_outer_ref;
56
51
 
57
 
} /* namespace drizzled */
58
 
 
59
52
/*
60
53
  The following hack is needed because mysql_yacc.cc does not define
61
54
  YYSTYPE before including this file
62
55
*/
63
56
 
64
57
#ifdef DRIZZLE_SERVER
65
 
/* set_var should change to set_var here ... */
66
 
# include <drizzled/sys_var.h>
 
58
# include <drizzled/set_var.h>
67
59
# include <drizzled/item/func.h>
68
60
# ifdef DRIZZLE_YACC
69
61
#  define LEX_YYSTYPE void *
70
62
# else
71
63
#  if defined(DRIZZLE_LEX)
72
 
#   include <drizzled/foreign_key.h>
73
64
#   include <drizzled/lex_symbol.h>
74
65
#   include <drizzled/sql_yacc.h>
75
66
#   define LEX_YYSTYPE YYSTYPE *
88
79
#define DERIVED_NONE    0
89
80
#define DERIVED_SUBQUERY        1
90
81
 
91
 
namespace drizzled
92
 
{
93
 
 
94
82
typedef List<Item> List_item;
95
83
 
96
84
enum sub_select_type
111
99
  ROLLUP_TYPE
112
100
};
113
101
 
 
102
enum tablespace_op_type
 
103
{
 
104
  NO_TABLESPACE_OP,
 
105
  DISCARD_TABLESPACE,
 
106
  IMPORT_TABLESPACE
 
107
};
 
108
 
114
109
/*
115
110
  The state of the lex parsing for selects
116
111
 
249
244
      UNCACHEABLE_EXPLAIN
250
245
      UNCACHEABLE_PREPARE
251
246
  */
252
 
  std::bitset<8> uncacheable;
 
247
  uint8_t uncacheable;
253
248
  enum sub_select_type linkage;
254
249
  bool no_table_names_allowed; /* used for global order by */
255
250
  bool no_error; /* suppress error message (convert it to warnings) */
256
251
 
257
252
  static void *operator new(size_t size)
258
253
  {
259
 
    return memory::sql_alloc(size);
 
254
    return sql_alloc(size);
260
255
  }
261
 
  static void *operator new(size_t size, memory::Root *mem_root)
262
 
  { return (void*) mem_root->alloc_root((uint32_t) size); }
 
256
  static void *operator new(size_t size, MEM_ROOT *mem_root)
 
257
  { return (void*) alloc_root(mem_root, (uint32_t) size); }
263
258
  static void operator delete(void *, size_t)
264
 
  {  }
265
 
  static void operator delete(void *, memory::Root *)
 
259
  { TRASH(ptr, size); }
 
260
  static void operator delete(void *, MEM_ROOT *)
266
261
  {}
267
262
  Select_Lex_Node(): linkage(UNSPECIFIED_TYPE) {}
268
263
  virtual ~Select_Lex_Node() {}
284
279
  virtual uint32_t get_in_sum_expr();
285
280
  virtual TableList* get_table_list();
286
281
  virtual List<Item>* get_item_list();
 
282
  virtual uint32_t get_table_join_options();
287
283
  virtual TableList *add_table_to_list(Session *session, Table_ident *table,
288
 
                                       LEX_STRING *alias,
289
 
                                       const std::bitset<NUM_OF_TABLE_OPTIONS>& table_options,
290
 
                                       thr_lock_type flags= TL_UNLOCK,
291
 
                                       List<Index_hint> *hints= 0,
292
 
                                       LEX_STRING *option= 0);
 
284
                                        LEX_STRING *alias,
 
285
                                        uint32_t table_options,
 
286
                                        thr_lock_type flags= TL_UNLOCK,
 
287
                                        List<Index_hint> *hints= 0,
 
288
                                        LEX_STRING *option= 0);
293
289
  virtual void set_lock_for_tables(thr_lock_type)
294
290
  {}
295
291
 
305
301
*/
306
302
class Session;
307
303
class select_result;
308
 
class Join;
 
304
class JOIN;
309
305
class select_union;
310
306
class Select_Lex_Unit: public Select_Lex_Node {
311
307
protected:
404
400
class Select_Lex: public Select_Lex_Node
405
401
{
406
402
public:
407
 
 
408
 
  Select_Lex() :
409
 
    context(),
410
 
    db(0),
411
 
    where(0),
412
 
    having(0),
413
 
    cond_value(),
414
 
    having_value(),
415
 
    parent_lex(0),
416
 
    olap(UNSPECIFIED_OLAP_TYPE),
417
 
    table_list(),
418
 
    group_list(),
419
 
    item_list(),
420
 
    interval_list(),
421
 
    is_item_list_lookup(false),
422
 
    join(0),
423
 
    top_join_list(),
424
 
    join_list(0),
425
 
    embedding(0),
426
 
    sj_nests(),
427
 
    leaf_tables(0),
428
 
    type(optimizer::ST_PRIMARY),
429
 
    order_list(),
430
 
    gorder_list(0),
431
 
    select_limit(0),
432
 
    offset_limit(0),
433
 
    ref_pointer_array(0),
434
 
    select_n_having_items(0),
435
 
    cond_count(0),
436
 
    between_count(0),
437
 
    max_equal_elems(0),
438
 
    select_n_where_fields(0),
439
 
    parsing_place(NO_MATTER),
440
 
    with_sum_func(0),
441
 
    in_sum_expr(0),
442
 
    select_number(0),
443
 
    nest_level(0),
444
 
    inner_sum_func_list(0),
445
 
    with_wild(0),
446
 
    braces(0),
447
 
    having_fix_field(0),
448
 
    inner_refs_list(),
449
 
    n_sum_items(0),
450
 
    n_child_sum_items(0),
451
 
    explicit_limit(0),
452
 
    subquery_in_having(0),
453
 
    is_correlated(0),
454
 
    exclude_from_table_unique_test(0),
455
 
    non_agg_fields(),
456
 
    cur_pos_in_select_list(0),
457
 
    prev_join_using(0),
458
 
    full_group_by_flag(),
459
 
    current_index_hint_type(INDEX_HINT_IGNORE),
460
 
    current_index_hint_clause(),
461
 
    index_hints(0)
462
 
  {
463
 
  }
464
 
 
465
403
  Name_resolution_context context;
466
404
  char *db;
467
405
  /* An Item representing the WHERE clause */
480
418
  List<Item> item_list;  /* list of fields & expressions */
481
419
  List<String> interval_list;
482
420
  bool is_item_list_lookup;
483
 
  Join *join; /* after Join::prepare it is pointer to corresponding JOIN */
 
421
  JOIN *join; /* after JOIN::prepare it is pointer to corresponding JOIN */
484
422
  List<TableList> top_join_list; /* join list of the top level          */
485
423
  List<TableList> *join_list;    /* list for the currently parsed join  */
486
424
  TableList *embedding;          /* table embedding to the above list   */
491
429
    by TableList::next_leaf, so leaf_tables points to the left-most leaf.
492
430
  */
493
431
  TableList *leaf_tables;
494
 
  enum drizzled::optimizer::select_type type; /* type of select for EXPLAIN */
 
432
  const char *type;               /* type of select for EXPLAIN          */
495
433
 
496
434
  SQL_LIST order_list;                /* ORDER clause */
497
435
  SQL_LIST *gorder_list;
516
454
  enum_parsing_place parsing_place; /* where we are parsing expression */
517
455
  bool with_sum_func;   /* sum function indicator */
518
456
 
 
457
  uint32_t table_join_options;
519
458
  uint32_t in_sum_expr;
520
459
  uint32_t select_number; /* number of select (used for EXPLAIN) */
521
460
  int8_t nest_level;     /* nesting level of select */
570
509
      1 - aggregate functions are used in this select,
571
510
          defined as SUM_FUNC_USED.
572
511
  */
573
 
  std::bitset<2> full_group_by_flag;
574
 
 
 
512
  uint8_t full_group_by_flag;
575
513
  void init_query();
576
514
  void init_select();
577
515
  Select_Lex_Unit* master_unit();
609
547
  TableList* add_table_to_list(Session *session,
610
548
                               Table_ident *table,
611
549
                               LEX_STRING *alias,
612
 
                               const std::bitset<NUM_OF_TABLE_OPTIONS>& table_options,
 
550
                               uint32_t table_options,
613
551
                               thr_lock_type flags= TL_UNLOCK,
614
552
                               List<Index_hint> *hints= 0,
615
553
                               LEX_STRING *option= 0);
620
558
  void add_joined_table(TableList *table);
621
559
  TableList *convert_right_join();
622
560
  List<Item>* get_item_list();
 
561
  uint32_t get_table_join_options();
623
562
  void set_lock_for_tables(thr_lock_type lock_type);
624
563
  inline void init_order()
625
564
  {
640
579
  bool test_limit();
641
580
 
642
581
  friend void lex_start(Session *session);
 
582
  Select_Lex() : n_sum_items(0), n_child_sum_items(0) {}
643
583
  void make_empty_select()
644
584
  {
645
585
    init_query();
648
588
  bool setup_ref_array(Session *session, uint32_t order_group_num);
649
589
  void print(Session *session, String *str, enum_query_type query_type);
650
590
  static void print_order(String *str,
651
 
                          Order *order,
 
591
                          order_st *order,
652
592
                          enum_query_type query_type);
653
593
  void print_limit(Session *session, String *str, enum_query_type query_type);
654
594
  void fix_prepare_information(Session *session, Item **conds, Item **having_conds);
697
637
    first_select()->next_select()->linkage == UNION_TYPE;
698
638
}
699
639
 
 
640
#define ALTER_ADD_COLUMN        (1L << 0)
 
641
#define ALTER_DROP_COLUMN       (1L << 1)
 
642
#define ALTER_CHANGE_COLUMN     (1L << 2)
 
643
#define ALTER_COLUMN_STORAGE    (1L << 3)
 
644
#define ALTER_COLUMN_FORMAT     (1L << 4)
 
645
#define ALTER_COLUMN_ORDER      (1L << 5)
 
646
#define ALTER_ADD_INDEX         (1L << 6)
 
647
#define ALTER_DROP_INDEX        (1L << 7)
 
648
#define ALTER_RENAME            (1L << 8)
 
649
#define ALTER_ORDER             (1L << 9)
 
650
#define ALTER_OPTIONS           (1L << 10)
 
651
#define ALTER_COLUMN_DEFAULT    (1L << 11)
 
652
#define ALTER_KEYS_ONOFF        (1L << 12)
 
653
#define ALTER_STORAGE           (1L << 13)
 
654
#define ALTER_ROW_FORMAT        (1L << 14)
 
655
#define ALTER_CONVERT           (1L << 15)
 
656
#define ALTER_FORCE             (1L << 16)
 
657
#define ALTER_RECREATE          (1L << 17)
 
658
#define ALTER_TABLE_REORG        (1L << 24)
 
659
#define ALTER_FOREIGN_KEY         (1L << 31)
 
660
 
 
661
/**
 
662
  @brief Parsing data for CREATE or ALTER Table.
 
663
 
 
664
  This structure contains a list of columns or indexes to be created,
 
665
  altered or dropped.
 
666
*/
 
667
 
 
668
class Alter_info
 
669
{
 
670
public:
 
671
  List<Alter_drop> drop_list;
 
672
  List<Alter_column> alter_list;
 
673
  List<Key> key_list;
 
674
  List<Create_field> create_list;
 
675
  uint32_t flags;
 
676
  enum enum_enable_or_disable keys_onoff;
 
677
  enum tablespace_op_type tablespace_op;
 
678
  uint32_t no_parts;
 
679
  enum ha_build_method build_method;
 
680
  Create_field *datetime_field;
 
681
  bool error_if_not_empty;
 
682
 
 
683
  Alter_info() :
 
684
    flags(0),
 
685
    keys_onoff(LEAVE_AS_IS),
 
686
    tablespace_op(NO_TABLESPACE_OP),
 
687
    no_parts(0),
 
688
    build_method(HA_BUILD_DEFAULT),
 
689
    datetime_field(NULL),
 
690
    error_if_not_empty(false)
 
691
  {}
 
692
 
 
693
  void reset()
 
694
  {
 
695
    drop_list.empty();
 
696
    alter_list.empty();
 
697
    key_list.empty();
 
698
    create_list.empty();
 
699
    flags= 0;
 
700
    keys_onoff= LEAVE_AS_IS;
 
701
    tablespace_op= NO_TABLESPACE_OP;
 
702
    no_parts= 0;
 
703
    build_method= HA_BUILD_DEFAULT;
 
704
    datetime_field= 0;
 
705
    error_if_not_empty= false;
 
706
  }
 
707
  Alter_info(const Alter_info &rhs, MEM_ROOT *mem_root);
 
708
private:
 
709
  Alter_info &operator=(const Alter_info &rhs); // not implemented
 
710
  Alter_info(const Alter_info &rhs);            // not implemented
 
711
};
 
712
 
700
713
enum xa_option_words
701
714
{
702
715
  XA_NONE
739
752
    of Query_tables_list instances which are used as backup storage.
740
753
  */
741
754
  Query_tables_list() {}
742
 
  virtual ~Query_tables_list() {}
 
755
  ~Query_tables_list() {}
743
756
 
744
757
  /* Initializes (or resets) Query_tables_list object for "real" use. */
745
758
  void reset_query_tables_list(bool init);
793
806
  DISCARD_COMMENT
794
807
};
795
808
 
796
 
} /* namespace drizzled */
797
 
 
798
809
#include "drizzled/lex_input_stream.h"
799
810
 
800
 
namespace drizzled
801
 
{
802
 
 
803
811
/* The state of the lex parsing. This is saved in the Session struct */
804
812
class LEX : public Query_tables_list
805
813
{
815
823
  char *length;
816
824
  /* This is the decimal precision in DECIMAL(S,P) notation */
817
825
  char *dec;
 
826
  /* The text in a CHANGE COLUMN clause in ALTER TABLE */
 
827
  char *change;
818
828
  
819
829
  /**
820
830
   * This is used kind of like the "ident" member variable below, as 
828
838
  file_exchange *exchange;
829
839
  select_result *result;
830
840
 
 
841
  /* An item representing the DEFAULT clause in CREATE/ALTER TABLE */
 
842
  Item *default_value;
 
843
  /* An item representing the ON UPDATE clause in CREATE/ALTER TABLE */
 
844
  Item *on_update_value;
 
845
  /* Not really sure what exactly goes in here... Comment text at beginning of statement? */
 
846
  LEX_STRING comment;
 
847
 
831
848
  /**
832
849
   * This is current used to store the name of a named key cache
833
850
   * or a named savepoint.  It should probably be refactored out into
851
868
  List<Item>          *insert_list,field_list,value_list,update_list;
852
869
  List<List_item>     many_values;
853
870
  List<set_var_base>  var_list;
 
871
  List<Item_param>    param_list;
854
872
  /*
855
873
    A stack of name resolution contexts for the query. This stack is used
856
874
    at parse time to set local name resolution contexts for various parts
868
886
 
869
887
  SQL_LIST auxiliary_table_list;
870
888
  SQL_LIST save_list;
871
 
  CreateField *last_field;
 
889
  Create_field *last_field;
872
890
  Item_sum *in_sum_func;
873
 
  plugin::Function *udf;
 
891
  Function_builder *udf;
 
892
  HA_CHECK_OPT check_opt;                       // check/repair options
 
893
  HA_CREATE_INFO create_info;
 
894
  drizzled::message::Table *create_table_proto;
 
895
  KEY_CREATE_INFO key_create_info;
874
896
  uint32_t type;
875
897
  /*
876
898
    This variable is used in post-parse stage to declare that sum-functions,
883
905
  */
884
906
  nesting_map allow_sum_func;
885
907
  enum_sql_command sql_command;
886
 
  statement::Statement *statement;
887
908
  /*
888
909
    Usually `expr` rule of yacc is quite reused but some commands better
889
910
    not support subqueries which comes standard with this rule, like
894
915
 
895
916
  thr_lock_type lock_option;
896
917
  enum enum_duplicates duplicates;
 
918
  enum enum_tx_isolation tx_isolation;
 
919
  enum enum_ha_read_modes ha_read_mode;
897
920
  union {
898
921
    enum ha_rkey_function ha_rkey_mode;
899
922
    enum xa_option_words xa_opt;
 
923
    bool lock_transactional;            /* For LOCK Table ... IN ... MODE */
900
924
  };
901
 
  sql_var_t option_type;
 
925
  enum enum_var_type option_type;
902
926
 
 
927
  enum column_format_type column_format;
 
928
  enum Foreign_key::fk_match_opt fk_match_option;
 
929
  enum Foreign_key::fk_option fk_update_opt;
 
930
  enum Foreign_key::fk_option fk_delete_opt;
 
931
  /* Options used in START TRANSACTION statement */
 
932
  uint32_t start_transaction_opt;
903
933
  int nest_level;
 
934
  /*
 
935
    In LEX representing update which were transformed to multi-update
 
936
    stores total number of tables. For LEX representing multi-delete
 
937
    holds number of tables from which we will delete records.
 
938
  */
 
939
  uint32_t table_count;
904
940
  uint8_t describe;
905
941
  /*
906
942
    A flag that indicates what kinds of derived tables are present in the
908
944
  */
909
945
  uint8_t derived_tables;
910
946
 
 
947
  /* True if "IF EXISTS" used in DROP statement */
 
948
  bool drop_if_exists;
 
949
  /* True if "TEMPORARY" used in DROP/CREATE statement */
 
950
  bool drop_temporary;
 
951
  bool one_shot_set;
 
952
 
 
953
  /* Only true when FULL symbol is found (e.g. SHOW FULL PROCESSLIST) */
 
954
  bool verbose;
 
955
  
 
956
  /* Was the CHAIN option using in COMMIT/ROLLBACK? */
 
957
  bool tx_chain;
 
958
  /* Was the RELEASE option used in COMMIT/ROLLBACK? */
 
959
  bool tx_release;
911
960
  /* Was the IGNORE symbol found in statement */
912
961
  bool ignore;
 
962
  Alter_info alter_info;
 
963
 
 
964
  /*
 
965
    Pointers to part of LOAD DATA statement that should be rewritten
 
966
    during replication ("LOCAL 'filename' REPLACE INTO" part).
 
967
  */
 
968
  const char *fname_start;
 
969
  const char *fname_end;
913
970
 
914
971
  /**
915
972
    During name resolution search only in the table list given by
938
995
  void link_first_table_back(TableList *first, bool link_to_local);
939
996
  void first_lists_tables_same();
940
997
 
 
998
  bool only_view_structure();
 
999
  bool need_correct_ident();
 
1000
 
941
1001
  void cleanup_after_one_table_open();
942
1002
 
943
1003
  bool push_context(Name_resolution_context *context)
982
1042
    }
983
1043
    return false;
984
1044
  }
985
 
  bool is_cross; // CROSS keyword was used
986
 
  bool isCacheable()
987
 
  {
988
 
    return cacheable;
989
 
  }
990
 
  void setCacheable(bool val)
991
 
  {
992
 
    cacheable= val;
993
 
  }
994
 
 
995
 
  void reset()
996
 
  {
997
 
    sum_expr_used= false;
998
 
  }
999
 
 
1000
 
  void setSumExprUsed()
1001
 
  {
1002
 
    sum_expr_used= true;
1003
 
  }
1004
 
 
1005
 
  bool isSumExprUsed()
1006
 
  {
1007
 
    return sum_expr_used;
1008
 
  }
1009
 
 
1010
 
  void start(Session *session);
1011
 
  void end();
1012
 
 
1013
 
private: 
1014
 
  bool cacheable;
1015
 
  bool sum_expr_used;
1016
1045
};
1017
1046
 
1018
1047
extern void lex_start(Session *session);
 
1048
extern void lex_end(LEX *lex);
1019
1049
extern void trim_whitespace(const CHARSET_INFO * const cs, LEX_STRING *str);
1020
1050
extern bool is_lex_native_function(const LEX_STRING *name);
1021
1051
 
1023
1053
  @} (End of group Semantic_Analysis)
1024
1054
*/
1025
1055
 
1026
 
} /* namespace drizzled */
1027
 
 
1028
1056
#endif /* DRIZZLE_SERVER */
1029
1057
#endif /* DRIZZLED_SQL_LEX_H */