~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_lex.h

  • Committer: Olaf van der Spek
  • Date: 2011-03-28 14:32:36 UTC
  • mto: (2257.1.1 build) (2276.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 2258.
  • Revision ID: olafvdspek@gmail.com-20110328143236-4ge1d793iqaktfq0
Common fwd

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#ifndef DRIZZLED_SQL_LEX_H
21
 
#define DRIZZLED_SQL_LEX_H
 
20
#pragma once
22
21
 
23
22
/**
24
23
  @defgroup Semantic_Analysis Semantic Analysis
25
24
*/
26
25
#include <drizzled/message/table.pb.h>
27
 
 
28
 
#include "drizzled/plugin/function.h"
29
 
#include "drizzled/name_resolution_context.h"
30
 
#include "drizzled/item/subselect.h"
31
 
#include "drizzled/table_list.h"
32
 
#include "drizzled/function/math/real.h"
33
 
#include "drizzled/alter_drop.h"
34
 
#include "drizzled/alter_column.h"
35
 
#include "drizzled/alter_info.h"
36
 
#include "drizzled/key_part_spec.h"
37
 
#include "drizzled/index_hint.h"
38
 
#include "drizzled/statement.h"
39
 
#include "drizzled/optimizer/explain_plan.h"
 
26
#include <drizzled/name_resolution_context.h>
 
27
#include <drizzled/table_list.h>
 
28
#include <drizzled/function/math/real.h>
 
29
#include <drizzled/key_part_spec.h>
 
30
#include <drizzled/index_hint.h>
 
31
#include <drizzled/optimizer/explain_plan.h>
40
32
 
41
33
#include <bitset>
42
34
#include <string>
43
35
 
44
 
namespace drizzled
45
 
{
46
 
 
 
36
namespace drizzled {
 
37
 
 
38
namespace plugin { class Function; }
 
39
namespace statement { class Statement; }
 
40
 
 
41
  namespace message
 
42
  {
 
43
    class AlterTable;
 
44
  }
 
45
 
 
46
class st_lex_symbol;
47
47
class select_result_interceptor;
48
48
 
49
49
/* YACC and LEX Definitions */
71
71
#  if defined(DRIZZLE_LEX)
72
72
#   include <drizzled/foreign_key.h>
73
73
#   include <drizzled/lex_symbol.h>
 
74
#   include <drizzled/comp_creator.h>
74
75
#   include <drizzled/sql_yacc.h>
75
76
#   define LEX_YYSTYPE YYSTYPE *
76
77
#  else
250
251
      UNCACHEABLE_PREPARE
251
252
  */
252
253
  std::bitset<8> uncacheable;
253
 
  enum sub_select_type linkage;
 
254
  sub_select_type linkage;
254
255
  bool no_table_names_allowed; /* used for global order by */
255
256
  bool no_error; /* suppress error message (convert it to warnings) */
256
257
 
294
295
  {}
295
296
 
296
297
  friend class Select_Lex_Unit;
297
 
  friend bool mysql_new_select(LEX *lex, bool move_down);
 
298
  friend bool new_select(LEX *lex, bool move_down);
298
299
private:
299
300
  void fast_exclude();
300
301
};
382
383
  inline void unclean() { cleaned= 0; }
383
384
  void reinit_exec_mechanism();
384
385
 
385
 
  void print(String *str, enum_query_type query_type);
 
386
  void print(String *str);
386
387
 
387
388
  bool add_fake_select_lex(Session *session);
388
389
  void init_prepare_fake_select_lex(Session *session);
393
394
  inline bool is_union ();
394
395
 
395
396
  friend void lex_start(Session *session);
396
 
  friend int subselect_union_engine::exec();
397
397
 
398
398
  List<Item> *get_unit_column_types();
399
399
};
449
449
    n_sum_items(0),
450
450
    n_child_sum_items(0),
451
451
    explicit_limit(0),
 
452
    is_cross(false),
452
453
    subquery_in_having(0),
453
454
    is_correlated(0),
454
455
    exclude_from_table_unique_test(0),
473
474
  Item::cond_result having_value;
474
475
  /* point on lex in which it was created, used in view subquery detection */
475
476
  LEX *parent_lex;
476
 
  enum olap_type olap;
 
477
  olap_type olap;
477
478
  /* FROM clause - points to the beginning of the TableList::next_local list. */
478
479
  SQL_LIST table_list;
479
480
  SQL_LIST group_list; /* GROUP BY clause. */
491
492
    by TableList::next_leaf, so leaf_tables points to the left-most leaf.
492
493
  */
493
494
  TableList *leaf_tables;
494
 
  enum drizzled::optimizer::select_type type; /* type of select for EXPLAIN */
 
495
  drizzled::optimizer::select_type type; /* type of select for EXPLAIN */
495
496
 
496
497
  SQL_LIST order_list;                /* ORDER clause */
497
498
  SQL_LIST *gorder_list;
533
534
 
534
535
  /* explicit LIMIT clause was used */
535
536
  bool explicit_limit;
 
537
 
 
538
  /* explicit CROSS JOIN was used */
 
539
  bool is_cross;
 
540
 
536
541
  /*
537
542
    there are subquery in HAVING clause => we can't close tables before
538
543
    query processing end even if we use temporary table
628
633
    order_list.next= (unsigned char**) &order_list.first;
629
634
  }
630
635
  /*
631
 
    This method created for reiniting LEX in mysql_admin_table() and can be
 
636
    This method created for reiniting LEX in admin_table() and can be
632
637
    used only if you are going remove all Select_Lex & units except belonger
633
638
    to LEX (LEX::unit & LEX::select, for other purposes there are
634
639
    Select_Lex_Unit::exclude_level & Select_Lex_Unit::exclude_tree
646
651
    init_select();
647
652
  }
648
653
  bool setup_ref_array(Session *session, uint32_t order_group_num);
649
 
  void print(Session *session, String *str, enum_query_type query_type);
650
 
  static void print_order(String *str,
651
 
                          Order *order,
652
 
                          enum_query_type query_type);
653
 
  void print_limit(Session *session, String *str, enum_query_type query_type);
 
654
  void print(Session *session, String *str);
 
655
  static void print_order(String *str, Order *order);
 
656
 
 
657
  void print_limit(Session *session, String *str);
654
658
  void fix_prepare_information(Session *session, Item **conds, Item **having_conds);
655
659
  /*
656
660
    Destroy the used execution plan (JOIN) of this subtree (this
663
667
  */
664
668
  void cleanup_all_joins(bool full);
665
669
 
666
 
  void set_index_hint_type(enum index_hint_type type, index_clause_map clause);
 
670
  void set_index_hint_type(index_hint_type type, index_clause_map clause);
667
671
 
668
672
  /*
669
673
   Add a index hint to the tagged list of hints. The type and clause of the
670
674
   hint will be the current ones (set by set_index_hint())
671
675
  */
672
 
  bool add_index_hint (Session *session, char *str, uint32_t length);
 
676
  void add_index_hint(Session *session, char *str, uint32_t length);
673
677
 
674
678
  /* make a list to hold index hints */
675
679
  void alloc_index_hints (Session *session);
685
689
 
686
690
private:
687
691
  /* current index hint kind. used in filling up index_hints */
688
 
  enum index_hint_type current_index_hint_type;
 
692
  index_hint_type current_index_hint_type;
689
693
  index_clause_map current_index_hint_clause;
690
694
  /* a list of USE/FORCE/IGNORE INDEX */
691
695
  List<Index_hint> *index_hints;
795
799
 
796
800
} /* namespace drizzled */
797
801
 
798
 
#include "drizzled/lex_input_stream.h"
 
802
#include <drizzled/lex_input_stream.h>
799
803
 
800
804
namespace drizzled
801
805
{
811
815
  /* list of all Select_Lex */
812
816
  Select_Lex *all_selects_list;
813
817
 
814
 
  /* This is the "scale" for DECIMAL (S,P) notation */ 
 
818
  /* This is the "scale" for DECIMAL (S,P) notation */
815
819
  char *length;
816
820
  /* This is the decimal precision in DECIMAL(S,P) notation */
817
821
  char *dec;
818
 
  
 
822
 
819
823
  /**
820
 
   * This is used kind of like the "ident" member variable below, as 
 
824
   * This is used kind of like the "ident" member variable below, as
821
825
   * a place to store certain names of identifiers.  Unfortunately, it
822
826
   * is used differently depending on the Command (SELECT on a derived
823
827
   * table vs CREATE)
833
837
   * or a named savepoint.  It should probably be refactored out into
834
838
   * the eventual Command class built for the Keycache and Savepoint
835
839
   * commands.
836
 
   */ 
 
840
   */
837
841
  LEX_STRING ident;
838
842
 
839
843
  unsigned char* yacc_yyss, *yacc_yyvs;
840
844
  /* The owning Session of this LEX */
841
845
  Session *session;
842
 
  const CHARSET_INFO *charset;
 
846
  const charset_info_st *charset;
843
847
  bool text_string_is_7bit;
844
848
  /* store original leaf_tables for INSERT SELECT and PS/SP */
845
849
  TableList *leaf_tables_insert;
850
854
  List<Lex_Column>    columns;
851
855
  List<Item>          *insert_list,field_list,value_list,update_list;
852
856
  List<List_item>     many_values;
853
 
  List<set_var_base>  var_list;
 
857
  SetVarVector  var_list;
854
858
  /*
855
859
    A stack of name resolution contexts for the query. This stack is used
856
860
    at parse time to set local name resolution contexts for various parts
930
934
     statement in a session. It's re-used by doing lex_end, lex_start
931
935
     in sql_lex.cc
932
936
  */
933
 
  virtual ~LEX()
934
 
  {
935
 
  }
 
937
  virtual ~LEX();
936
938
 
937
939
  TableList *unlink_first_table(bool *link_to_local);
938
940
  void link_first_table_back(TableList *first, bool link_to_local);
940
942
 
941
943
  void cleanup_after_one_table_open();
942
944
 
943
 
  bool push_context(Name_resolution_context *context)
 
945
  void push_context(Name_resolution_context *context)
944
946
  {
945
 
    return context_stack.push_front(context);
 
947
    context_stack.push_front(context);
946
948
  }
947
949
 
948
950
  void pop_context()
954
956
 
955
957
  Name_resolution_context *current_context()
956
958
  {
957
 
    return context_stack.head();
 
959
    return &context_stack.front();
958
960
  }
959
 
  /*
960
 
    Restore the LEX and Session in case of a parse error.
961
 
  */
962
 
  static void cleanup_lex_after_parse_error(Session *session);
963
961
 
964
962
  /**
965
963
    @brief check if the statement is a single-level join
995
993
  void reset()
996
994
  {
997
995
    sum_expr_used= false;
 
996
    _exists= false;
998
997
  }
999
998
 
1000
999
  void setSumExprUsed()
1010
1009
  void start(Session *session);
1011
1010
  void end();
1012
1011
 
1013
 
private: 
 
1012
  message::Table *table()
 
1013
  {
 
1014
    if (not _create_table)
 
1015
      _create_table= new message::Table;
 
1016
 
 
1017
    return _create_table;
 
1018
  }
 
1019
 
 
1020
  message::AlterTable *alter_table();
 
1021
 
 
1022
  message::Table::Field *field()
 
1023
  {
 
1024
    return _create_field;
 
1025
  }
 
1026
 
 
1027
  void setField(message::Table::Field *arg)
 
1028
  {
 
1029
    _create_field= arg;
 
1030
  }
 
1031
 
 
1032
  void setExists()
 
1033
  {
 
1034
    _exists= true;
 
1035
  }
 
1036
 
 
1037
  bool exists() const
 
1038
  {
 
1039
    return _exists;
 
1040
  }
 
1041
 
 
1042
private:
1014
1043
  bool cacheable;
1015
1044
  bool sum_expr_used;
 
1045
  message::Table *_create_table;
 
1046
  message::AlterTable *_alter_table;
 
1047
  message::Table::Field *_create_field;
 
1048
  bool _exists;
1016
1049
};
1017
1050
 
1018
1051
extern void lex_start(Session *session);
1019
 
extern void trim_whitespace(const CHARSET_INFO * const cs, LEX_STRING *str);
 
1052
extern void trim_whitespace(const charset_info_st * const cs, LEX_STRING *str);
1020
1053
extern bool is_lex_native_function(const LEX_STRING *name);
1021
1054
 
 
1055
bool check_for_sql_keyword(drizzled::st_lex_symbol const&);
 
1056
bool check_for_sql_keyword(drizzled::lex_string_t const&);
 
1057
 
1022
1058
/**
1023
1059
  @} (End of group Semantic_Analysis)
1024
1060
*/
1026
1062
} /* namespace drizzled */
1027
1063
 
1028
1064
#endif /* DRIZZLE_SERVER */
1029
 
#endif /* DRIZZLED_SQL_LEX_H */