~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_lex.h

  • Committer: Monty Taylor
  • Date: 2009-09-22 23:50:12 UTC
  • mto: This revision was merged to the branch mainline in revision 1184.
  • Revision ID: mordred@inaugust.com-20090922235012-i0a3bs91f6krqduc
Fixed multi_malloc.h include guard.
Added include guard checking script.

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/slot/function.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
37
#include "drizzled/alter_info.h"
36
 
#include "drizzled/key_part_spec.h"
 
38
#include "drizzled/key.h"
 
39
#include "drizzled/foreign_key.h"
 
40
#include "drizzled/item/param.h"
37
41
#include "drizzled/index_hint.h"
38
42
#include "drizzled/statement.h"
39
 
#include "drizzled/optimizer/explain_plan.h"
40
43
 
41
44
#include <bitset>
42
 
#include <string>
43
 
 
44
 
namespace drizzled
45
 
{
46
45
 
47
46
class select_result_interceptor;
48
47
 
54
53
class Lex_Column;
55
54
class Item_outer_ref;
56
55
 
57
 
} /* namespace drizzled */
58
 
 
59
56
/*
60
57
  The following hack is needed because mysql_yacc.cc does not define
61
58
  YYSTYPE before including this file
62
59
*/
63
60
 
64
61
#ifdef DRIZZLE_SERVER
65
 
/* set_var should change to set_var here ... */
66
 
# include <drizzled/sys_var.h>
 
62
# include <drizzled/set_var.h>
67
63
# include <drizzled/item/func.h>
68
64
# ifdef DRIZZLE_YACC
69
65
#  define LEX_YYSTYPE void *
70
66
# else
71
67
#  if defined(DRIZZLE_LEX)
72
 
#   include <drizzled/foreign_key.h>
73
68
#   include <drizzled/lex_symbol.h>
74
69
#   include <drizzled/sql_yacc.h>
75
70
#   define LEX_YYSTYPE YYSTYPE *
88
83
#define DERIVED_NONE    0
89
84
#define DERIVED_SUBQUERY        1
90
85
 
91
 
namespace drizzled
92
 
{
93
 
 
94
86
typedef List<Item> List_item;
95
87
 
96
88
enum sub_select_type
249
241
      UNCACHEABLE_EXPLAIN
250
242
      UNCACHEABLE_PREPARE
251
243
  */
252
 
  std::bitset<8> uncacheable;
 
244
  uint8_t uncacheable;
253
245
  enum sub_select_type linkage;
254
246
  bool no_table_names_allowed; /* used for global order by */
255
247
  bool no_error; /* suppress error message (convert it to warnings) */
256
248
 
257
249
  static void *operator new(size_t size)
258
250
  {
259
 
    return memory::sql_alloc(size);
 
251
    return sql_alloc(size);
260
252
  }
261
 
  static void *operator new(size_t size, memory::Root *mem_root)
262
 
  { return (void*) mem_root->alloc_root((uint32_t) size); }
 
253
  static void *operator new(size_t size, MEM_ROOT *mem_root)
 
254
  { return (void*) alloc_root(mem_root, (uint32_t) size); }
263
255
  static void operator delete(void *, size_t)
264
 
  {  }
265
 
  static void operator delete(void *, memory::Root *)
 
256
  { TRASH(ptr, size); }
 
257
  static void operator delete(void *, MEM_ROOT *)
266
258
  {}
267
259
  Select_Lex_Node(): linkage(UNSPECIFIED_TYPE) {}
268
260
  virtual ~Select_Lex_Node() {}
284
276
  virtual uint32_t get_in_sum_expr();
285
277
  virtual TableList* get_table_list();
286
278
  virtual List<Item>* get_item_list();
 
279
  virtual uint32_t get_table_join_options();
287
280
  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);
 
281
                                        LEX_STRING *alias,
 
282
                                        uint32_t table_options,
 
283
                                        thr_lock_type flags= TL_UNLOCK,
 
284
                                        List<Index_hint> *hints= 0,
 
285
                                        LEX_STRING *option= 0);
293
286
  virtual void set_lock_for_tables(thr_lock_type)
294
287
  {}
295
288
 
305
298
*/
306
299
class Session;
307
300
class select_result;
308
 
class Join;
 
301
class JOIN;
309
302
class select_union;
310
303
class Select_Lex_Unit: public Select_Lex_Node {
311
304
protected:
404
397
class Select_Lex: public Select_Lex_Node
405
398
{
406
399
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
400
  Name_resolution_context context;
466
401
  char *db;
467
402
  /* An Item representing the WHERE clause */
480
415
  List<Item> item_list;  /* list of fields & expressions */
481
416
  List<String> interval_list;
482
417
  bool is_item_list_lookup;
483
 
  Join *join; /* after Join::prepare it is pointer to corresponding JOIN */
 
418
  JOIN *join; /* after JOIN::prepare it is pointer to corresponding JOIN */
484
419
  List<TableList> top_join_list; /* join list of the top level          */
485
420
  List<TableList> *join_list;    /* list for the currently parsed join  */
486
421
  TableList *embedding;          /* table embedding to the above list   */
491
426
    by TableList::next_leaf, so leaf_tables points to the left-most leaf.
492
427
  */
493
428
  TableList *leaf_tables;
494
 
  enum drizzled::optimizer::select_type type; /* type of select for EXPLAIN */
 
429
  const char *type;               /* type of select for EXPLAIN          */
495
430
 
496
431
  SQL_LIST order_list;                /* ORDER clause */
497
432
  SQL_LIST *gorder_list;
516
451
  enum_parsing_place parsing_place; /* where we are parsing expression */
517
452
  bool with_sum_func;   /* sum function indicator */
518
453
 
 
454
  uint32_t table_join_options;
519
455
  uint32_t in_sum_expr;
520
456
  uint32_t select_number; /* number of select (used for EXPLAIN) */
521
457
  int8_t nest_level;     /* nesting level of select */
571
507
          defined as SUM_FUNC_USED.
572
508
  */
573
509
  std::bitset<2> full_group_by_flag;
574
 
 
575
510
  void init_query();
576
511
  void init_select();
577
512
  Select_Lex_Unit* master_unit();
609
544
  TableList* add_table_to_list(Session *session,
610
545
                               Table_ident *table,
611
546
                               LEX_STRING *alias,
612
 
                               const std::bitset<NUM_OF_TABLE_OPTIONS>& table_options,
 
547
                               uint32_t table_options,
613
548
                               thr_lock_type flags= TL_UNLOCK,
614
549
                               List<Index_hint> *hints= 0,
615
550
                               LEX_STRING *option= 0);
620
555
  void add_joined_table(TableList *table);
621
556
  TableList *convert_right_join();
622
557
  List<Item>* get_item_list();
 
558
  uint32_t get_table_join_options();
623
559
  void set_lock_for_tables(thr_lock_type lock_type);
624
560
  inline void init_order()
625
561
  {
640
576
  bool test_limit();
641
577
 
642
578
  friend void lex_start(Session *session);
 
579
  Select_Lex() : n_sum_items(0), n_child_sum_items(0) {}
643
580
  void make_empty_select()
644
581
  {
645
582
    init_query();
648
585
  bool setup_ref_array(Session *session, uint32_t order_group_num);
649
586
  void print(Session *session, String *str, enum_query_type query_type);
650
587
  static void print_order(String *str,
651
 
                          Order *order,
 
588
                          order_st *order,
652
589
                          enum_query_type query_type);
653
590
  void print_limit(Session *session, String *str, enum_query_type query_type);
654
591
  void fix_prepare_information(Session *session, Item **conds, Item **having_conds);
739
676
    of Query_tables_list instances which are used as backup storage.
740
677
  */
741
678
  Query_tables_list() {}
742
 
  virtual ~Query_tables_list() {}
 
679
  ~Query_tables_list() {}
743
680
 
744
681
  /* Initializes (or resets) Query_tables_list object for "real" use. */
745
682
  void reset_query_tables_list(bool init);
793
730
  DISCARD_COMMENT
794
731
};
795
732
 
796
 
} /* namespace drizzled */
797
 
 
798
733
#include "drizzled/lex_input_stream.h"
799
734
 
800
 
namespace drizzled
801
 
{
802
 
 
803
735
/* The state of the lex parsing. This is saved in the Session struct */
804
736
class LEX : public Query_tables_list
805
737
{
815
747
  char *length;
816
748
  /* This is the decimal precision in DECIMAL(S,P) notation */
817
749
  char *dec;
 
750
  /* The text in a CHANGE COLUMN clause in ALTER TABLE */
 
751
  char *change;
818
752
  
819
753
  /**
820
754
   * This is used kind of like the "ident" member variable below, as 
828
762
  file_exchange *exchange;
829
763
  select_result *result;
830
764
 
 
765
  /* An item representing the DEFAULT clause in CREATE/ALTER TABLE */
 
766
  Item *default_value;
 
767
  /* An item representing the ON UPDATE clause in CREATE/ALTER TABLE */
 
768
  Item *on_update_value;
 
769
  /* Not really sure what exactly goes in here... Comment text at beginning of statement? */
 
770
  LEX_STRING comment;
 
771
 
831
772
  /**
832
773
   * This is current used to store the name of a named key cache
833
774
   * or a named savepoint.  It should probably be refactored out into
851
792
  List<Item>          *insert_list,field_list,value_list,update_list;
852
793
  List<List_item>     many_values;
853
794
  List<set_var_base>  var_list;
 
795
  List<Item_param>    param_list;
854
796
  /*
855
797
    A stack of name resolution contexts for the query. This stack is used
856
798
    at parse time to set local name resolution contexts for various parts
870
812
  SQL_LIST save_list;
871
813
  CreateField *last_field;
872
814
  Item_sum *in_sum_func;
873
 
  plugin::Function *udf;
 
815
  drizzled::plugin::Function *udf;
 
816
  HA_CHECK_OPT check_opt;                       // check/repair options
 
817
  HA_CREATE_INFO create_info;
 
818
  drizzled::message::Table *create_table_proto;
 
819
  StorageEngine *show_engine;
 
820
  KEY_CREATE_INFO key_create_info;
874
821
  uint32_t type;
875
822
  /*
876
823
    This variable is used in post-parse stage to declare that sum-functions,
883
830
  */
884
831
  nesting_map allow_sum_func;
885
832
  enum_sql_command sql_command;
886
 
  statement::Statement *statement;
 
833
  drizzled::statement::Statement *statement;
887
834
  /*
888
835
    Usually `expr` rule of yacc is quite reused but some commands better
889
836
    not support subqueries which comes standard with this rule, like
894
841
 
895
842
  thr_lock_type lock_option;
896
843
  enum enum_duplicates duplicates;
 
844
  enum enum_tx_isolation tx_isolation;
 
845
  enum enum_ha_read_modes ha_read_mode;
897
846
  union {
898
847
    enum ha_rkey_function ha_rkey_mode;
899
848
    enum xa_option_words xa_opt;
900
849
  };
901
 
  sql_var_t option_type;
 
850
  enum enum_var_type option_type;
902
851
 
 
852
  enum column_format_type column_format;
 
853
  enum Foreign_key::fk_match_opt fk_match_option;
 
854
  enum Foreign_key::fk_option fk_update_opt;
 
855
  enum Foreign_key::fk_option fk_delete_opt;
 
856
  /* Options used in START TRANSACTION statement */
 
857
  uint32_t start_transaction_opt;
903
858
  int nest_level;
904
859
  uint8_t describe;
905
860
  /*
908
863
  */
909
864
  uint8_t derived_tables;
910
865
 
 
866
  /* True if "IF EXISTS" used in DROP statement */
 
867
  bool drop_if_exists;
 
868
  /* True if "TEMPORARY" used in DROP/CREATE statement */
 
869
  bool drop_temporary;
 
870
  bool one_shot_set;
 
871
 
 
872
  /* Only true when FULL symbol is found (e.g. SHOW FULL PROCESSLIST) */
 
873
  bool verbose;
 
874
  
 
875
  /* Was the CHAIN option using in COMMIT/ROLLBACK? */
 
876
  bool tx_chain;
 
877
  /* Was the RELEASE option used in COMMIT/ROLLBACK? */
 
878
  bool tx_release;
911
879
  /* Was the IGNORE symbol found in statement */
912
880
  bool ignore;
 
881
  AlterInfo alter_info;
 
882
 
 
883
  /*
 
884
    Pointers to part of LOAD DATA statement that should be rewritten
 
885
    during replication ("LOCAL 'filename' REPLACE INTO" part).
 
886
  */
 
887
  const char *fname_start;
 
888
  const char *fname_end;
913
889
 
914
890
  /**
915
891
    During name resolution search only in the table list given by
938
914
  void link_first_table_back(TableList *first, bool link_to_local);
939
915
  void first_lists_tables_same();
940
916
 
 
917
  bool only_view_structure();
 
918
  bool need_correct_ident();
 
919
 
941
920
  void cleanup_after_one_table_open();
942
921
 
943
922
  bool push_context(Name_resolution_context *context)
982
961
    }
983
962
    return false;
984
963
  }
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
964
};
1017
965
 
1018
966
extern void lex_start(Session *session);
 
967
extern void lex_end(LEX *lex);
1019
968
extern void trim_whitespace(const CHARSET_INFO * const cs, LEX_STRING *str);
1020
969
extern bool is_lex_native_function(const LEX_STRING *name);
1021
970
 
1023
972
  @} (End of group Semantic_Analysis)
1024
973
*/
1025
974
 
1026
 
} /* namespace drizzled */
1027
 
 
1028
975
#endif /* DRIZZLE_SERVER */
1029
976
#endif /* DRIZZLED_SQL_LEX_H */