~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_lex.h

  • Committer: Mark Atwood
  • Date: 2011-08-12 04:08:33 UTC
  • mfrom: (2385.2.17 refactor5)
  • Revision ID: me@mark.atwood.name-20110812040833-u6j85nc6ahuc0dtz
mergeĀ lp:~olafvdspek/drizzle/refactor5

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
 
 
47
 
class st_lex_symbol;
48
 
class select_result_interceptor;
49
 
 
50
 
/* YACC and LEX Definitions */
51
 
 
52
 
/* These may not be declared yet */
53
 
class Table_ident;
54
 
class file_exchange;
55
 
class Lex_Column;
56
 
class Item_outer_ref;
57
 
 
58
 
} /* namespace drizzled */
59
 
 
60
36
/*
61
37
  The following hack is needed because mysql_yacc.cc does not define
62
38
  YYSTYPE before including this file
72
48
#  if defined(DRIZZLE_LEX)
73
49
#   include <drizzled/foreign_key.h>
74
50
#   include <drizzled/lex_symbol.h>
 
51
#   include <drizzled/comp_creator.h>
75
52
#   include <drizzled/sql_yacc.h>
76
53
#   define LEX_YYSTYPE YYSTYPE *
77
54
#  else
230
207
    Base class for Select_Lex (Select_Lex) &
231
208
    Select_Lex_Unit (Select_Lex_Unit)
232
209
*/
233
 
class LEX;
234
 
class Select_Lex;
235
 
class Select_Lex_Unit;
236
210
class Select_Lex_Node {
237
211
protected:
238
212
  Select_Lex_Node *next, **prev,   /* neighbor list */
251
225
      UNCACHEABLE_PREPARE
252
226
  */
253
227
  std::bitset<8> uncacheable;
254
 
  enum sub_select_type linkage;
 
228
  sub_select_type linkage;
255
229
  bool no_table_names_allowed; /* used for global order by */
256
230
  bool no_error; /* suppress error message (convert it to warnings) */
257
231
 
260
234
    return memory::sql_alloc(size);
261
235
  }
262
236
  static void *operator new(size_t size, memory::Root *mem_root)
263
 
  { return (void*) mem_root->alloc_root((uint32_t) size); }
264
 
  static void operator delete(void *, size_t)
 
237
  { return mem_root->alloc(size); }
 
238
  static void operator delete(void*, size_t)
265
239
  {  }
266
 
  static void operator delete(void *, memory::Root *)
 
240
  static void operator delete(void*, memory::Root*)
267
241
  {}
268
242
  Select_Lex_Node(): linkage(UNSPECIFIED_TYPE) {}
269
243
  virtual ~Select_Lex_Node() {}
286
260
  virtual TableList* get_table_list();
287
261
  virtual List<Item>* get_item_list();
288
262
  virtual TableList *add_table_to_list(Session *session, Table_ident *table,
289
 
                                       LEX_STRING *alias,
 
263
                                       lex_string_t *alias,
290
264
                                       const std::bitset<NUM_OF_TABLE_OPTIONS>& table_options,
291
265
                                       thr_lock_type flags= TL_UNLOCK,
292
266
                                       List<Index_hint> *hints= 0,
293
 
                                       LEX_STRING *option= 0);
 
267
                                       lex_string_t *option= 0);
294
268
  virtual void set_lock_for_tables(thr_lock_type)
295
269
  {}
296
270
 
304
278
   Select_Lex_Unit - unit of selects (UNION, INTERSECT, ...) group
305
279
   Select_Lexs
306
280
*/
307
 
class Session;
308
 
class select_result;
309
 
class Join;
310
 
class select_union;
311
281
class Select_Lex_Unit: public Select_Lex_Node {
312
282
protected:
313
283
  TableList result_table_list;
383
353
  inline void unclean() { cleaned= 0; }
384
354
  void reinit_exec_mechanism();
385
355
 
386
 
  void print(String *str, enum_query_type query_type);
 
356
  void print(String *str);
387
357
 
388
358
  bool add_fake_select_lex(Session *session);
389
359
  void init_prepare_fake_select_lex(Session *session);
394
364
  inline bool is_union ();
395
365
 
396
366
  friend void lex_start(Session *session);
397
 
  friend int subselect_union_engine::exec();
398
367
 
399
368
  List<Item> *get_unit_column_types();
400
369
};
475
444
  Item::cond_result having_value;
476
445
  /* point on lex in which it was created, used in view subquery detection */
477
446
  LEX *parent_lex;
478
 
  enum olap_type olap;
 
447
  olap_type olap;
479
448
  /* FROM clause - points to the beginning of the TableList::next_local list. */
480
449
  SQL_LIST table_list;
481
450
  SQL_LIST group_list; /* GROUP BY clause. */
493
462
    by TableList::next_leaf, so leaf_tables points to the left-most leaf.
494
463
  */
495
464
  TableList *leaf_tables;
496
 
  enum drizzled::optimizer::select_type type; /* type of select for EXPLAIN */
 
465
  drizzled::optimizer::select_type type; /* type of select for EXPLAIN */
497
466
 
498
467
  SQL_LIST order_list;                /* ORDER clause */
499
468
  SQL_LIST *gorder_list;
609
578
  bool inc_in_sum_expr();
610
579
  uint32_t get_in_sum_expr();
611
580
 
612
 
  bool add_item_to_list(Session *session, Item *item);
613
 
  bool add_group_to_list(Session *session, Item *item, bool asc);
614
 
  bool add_order_to_list(Session *session, Item *item, bool asc);
 
581
  void add_item_to_list(Session *session, Item *item);
 
582
  void add_group_to_list(Session *session, Item *item, bool asc);
 
583
  void add_order_to_list(Session *session, Item *item, bool asc);
615
584
  TableList* add_table_to_list(Session *session,
616
585
                               Table_ident *table,
617
 
                               LEX_STRING *alias,
 
586
                               lex_string_t *alias,
618
587
                               const std::bitset<NUM_OF_TABLE_OPTIONS>& table_options,
619
588
                               thr_lock_type flags= TL_UNLOCK,
620
589
                               List<Index_hint> *hints= 0,
621
 
                               LEX_STRING *option= 0);
 
590
                               lex_string_t *option= 0);
622
591
  TableList* get_table_list();
623
 
  bool init_nested_join(Session *session);
 
592
  void init_nested_join(Session&);
624
593
  TableList *end_nested_join(Session *session);
625
594
  TableList *nest_last_join(Session *session);
626
595
  void add_joined_table(TableList *table);
651
620
    init_query();
652
621
    init_select();
653
622
  }
654
 
  bool setup_ref_array(Session *session, uint32_t order_group_num);
655
 
  void print(Session *session, String *str, enum_query_type query_type);
656
 
  static void print_order(String *str,
657
 
                          Order *order,
658
 
                          enum_query_type query_type);
659
 
  void print_limit(Session *session, String *str, enum_query_type query_type);
 
623
  void setup_ref_array(Session *session, uint32_t order_group_num);
 
624
  void print(Session *session, String *str);
 
625
  static void print_order(String *str, Order *order);
 
626
 
 
627
  void print_limit(Session *session, String *str);
660
628
  void fix_prepare_information(Session *session, Item **conds, Item **having_conds);
661
629
  /*
662
630
    Destroy the used execution plan (JOIN) of this subtree (this
669
637
  */
670
638
  void cleanup_all_joins(bool full);
671
639
 
672
 
  void set_index_hint_type(enum index_hint_type type, index_clause_map clause);
 
640
  void set_index_hint_type(index_hint_type type, index_clause_map clause);
673
641
 
674
642
  /*
675
643
   Add a index hint to the tagged list of hints. The type and clause of the
676
644
   hint will be the current ones (set by set_index_hint())
677
645
  */
678
 
  bool add_index_hint (Session *session, char *str, uint32_t length);
 
646
  void add_index_hint(Session *session, char *str, uint32_t length);
679
647
 
680
648
  /* make a list to hold index hints */
681
649
  void alloc_index_hints (Session *session);
691
659
 
692
660
private:
693
661
  /* current index hint kind. used in filling up index_hints */
694
 
  enum index_hint_type current_index_hint_type;
 
662
  index_hint_type current_index_hint_type;
695
663
  index_clause_map current_index_hint_clause;
696
664
  /* a list of USE/FORCE/IGNORE INDEX */
697
665
  List<Index_hint> *index_hints;
713
681
, XA_FOR_MIGRATE
714
682
};
715
683
 
716
 
extern const LEX_STRING null_lex_str;
717
 
 
718
684
/*
719
685
  Class representing list of all tables used by statement.
720
686
  It also contains information about stored functions used by statement
801
767
 
802
768
} /* namespace drizzled */
803
769
 
804
 
#include "drizzled/lex_input_stream.h"
805
 
 
806
 
namespace drizzled
807
 
{
 
770
namespace drizzled {
808
771
 
809
772
/* The state of the lex parsing. This is saved in the Session struct */
810
773
class LEX : public Query_tables_list
817
780
  /* list of all Select_Lex */
818
781
  Select_Lex *all_selects_list;
819
782
 
820
 
  /* This is the "scale" for DECIMAL (S,P) notation */ 
821
 
  char *length;
 
783
  /* This is the "scale" for DECIMAL (S,P) notation */
 
784
  const char *length;
822
785
  /* This is the decimal precision in DECIMAL(S,P) notation */
823
 
  char *dec;
824
 
  
 
786
  const char *dec;
 
787
 
825
788
  /**
826
 
   * This is used kind of like the "ident" member variable below, as 
 
789
   * This is used kind of like the "ident" member variable below, as
827
790
   * a place to store certain names of identifiers.  Unfortunately, it
828
791
   * is used differently depending on the Command (SELECT on a derived
829
792
   * table vs CREATE)
830
793
   */
831
 
  LEX_STRING name;
 
794
  lex_string_t name;
832
795
  /* The string literal used in a LIKE expression */
833
796
  String *wild;
834
797
  file_exchange *exchange;
839
802
   * or a named savepoint.  It should probably be refactored out into
840
803
   * the eventual Command class built for the Keycache and Savepoint
841
804
   * commands.
842
 
   */ 
843
 
  LEX_STRING ident;
 
805
   */
 
806
  lex_string_t ident;
844
807
 
845
808
  unsigned char* yacc_yyss, *yacc_yyvs;
846
809
  /* The owning Session of this LEX */
847
810
  Session *session;
848
 
  const CHARSET_INFO *charset;
 
811
  const charset_info_st *charset;
849
812
  bool text_string_is_7bit;
850
813
  /* store original leaf_tables for INSERT SELECT and PS/SP */
851
814
  TableList *leaf_tables_insert;
944
907
 
945
908
  void cleanup_after_one_table_open();
946
909
 
947
 
  bool push_context(Name_resolution_context *context)
 
910
  void push_context(Name_resolution_context *context)
948
911
  {
949
 
    return context_stack.push_front(context);
 
912
    context_stack.push_front(context);
950
913
  }
951
914
 
952
915
  void pop_context()
954
917
    context_stack.pop();
955
918
  }
956
919
 
957
 
  bool copy_db_to(char **p_db, size_t *p_db_length) const;
958
 
 
959
920
  Name_resolution_context *current_context()
960
921
  {
961
 
    return context_stack.head();
 
922
    return &context_stack.front();
962
923
  }
963
924
 
964
925
  /**
1019
980
    return _create_table;
1020
981
  }
1021
982
 
 
983
  message::AlterTable *alter_table();
 
984
 
1022
985
  message::Table::Field *field()
1023
986
  {
1024
987
    return _create_field;
1039
1002
    return _exists;
1040
1003
  }
1041
1004
 
1042
 
private: 
 
1005
private:
1043
1006
  bool cacheable;
1044
1007
  bool sum_expr_used;
1045
1008
  message::Table *_create_table;
 
1009
  message::AlterTable *_alter_table;
1046
1010
  message::Table::Field *_create_field;
1047
1011
  bool _exists;
1048
1012
};
1049
1013
 
1050
1014
extern void lex_start(Session *session);
1051
 
extern void trim_whitespace(const CHARSET_INFO * const cs, LEX_STRING *str);
1052
 
extern bool is_lex_native_function(const LEX_STRING *name);
1053
 
 
1054
 
bool check_for_sql_keyword(drizzled::st_lex_symbol const&);
1055
 
bool check_for_sql_keyword(drizzled::lex_string_t const&);
1056
1015
 
1057
1016
/**
1058
1017
  @} (End of group Semantic_Analysis)
1061
1020
} /* namespace drizzled */
1062
1021
 
1063
1022
#endif /* DRIZZLE_SERVER */
1064
 
#endif /* DRIZZLED_SQL_LEX_H */