17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#ifndef DRIZZLED_SQL_LEX_H
21
#define DRIZZLED_SQL_LEX_H
24
23
@defgroup Semantic_Analysis Semantic Analysis
26
25
#include <drizzled/message/table.pb.h>
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>
47
class select_result_interceptor;
49
/* YACC and LEX Definitions */
51
/* These may not be declared yet */
57
} /* namespace drizzled */
60
37
The following hack is needed because mysql_yacc.cc does not define
61
38
YYSTYPE before including this file
71
48
# if defined(DRIZZLE_LEX)
72
49
# include <drizzled/foreign_key.h>
73
50
# include <drizzled/lex_symbol.h>
51
# include <drizzled/comp_creator.h>
74
52
# include <drizzled/sql_yacc.h>
75
53
# define LEX_YYSTYPE YYSTYPE *
259
234
return memory::sql_alloc(size);
261
236
static void *operator new(size_t size, memory::Root *mem_root)
262
{ return (void*) mem_root->alloc_root((uint32_t) size); }
263
static void operator delete(void *, size_t)
237
{ return mem_root->alloc(size); }
238
static void operator delete(void*, size_t)
265
static void operator delete(void *, memory::Root *)
240
static void operator delete(void*, memory::Root*)
267
242
Select_Lex_Node(): linkage(UNSPECIFIED_TYPE) {}
268
243
virtual ~Select_Lex_Node() {}
285
260
virtual TableList* get_table_list();
286
261
virtual List<Item>* get_item_list();
287
262
virtual TableList *add_table_to_list(Session *session, Table_ident *table,
289
264
const std::bitset<NUM_OF_TABLE_OPTIONS>& table_options,
290
265
thr_lock_type flags= TL_UNLOCK,
291
266
List<Index_hint> *hints= 0,
292
LEX_STRING *option= 0);
267
lex_string_t *option= 0);
293
268
virtual void set_lock_for_tables(thr_lock_type)
296
271
friend class Select_Lex_Unit;
297
friend bool mysql_new_select(LEX *lex, bool move_down);
272
friend bool new_select(LEX *lex, bool move_down);
299
274
void fast_exclude();
382
353
inline void unclean() { cleaned= 0; }
383
354
void reinit_exec_mechanism();
385
void print(String *str, enum_query_type query_type);
356
void print(String *str);
387
358
bool add_fake_select_lex(Session *session);
388
359
void init_prepare_fake_select_lex(Session *session);
390
361
select_result_interceptor *old_result);
391
362
void set_limit(Select_Lex *values);
392
363
void set_session(Session *session_arg) { session= session_arg; }
393
inline bool is_union ();
364
inline bool is_union();
395
friend void lex_start(Session *session);
396
friend int subselect_union_engine::exec();
366
friend void lex_start(Session*);
398
368
List<Item> *get_unit_column_types();
473
444
Item::cond_result having_value;
474
445
/* point on lex in which it was created, used in view subquery detection */
477
448
/* FROM clause - points to the beginning of the TableList::next_local list. */
478
449
SQL_LIST table_list;
479
450
SQL_LIST group_list; /* GROUP BY clause. */
491
462
by TableList::next_leaf, so leaf_tables points to the left-most leaf.
493
464
TableList *leaf_tables;
494
enum drizzled::optimizer::select_type type; /* type of select for EXPLAIN */
465
drizzled::optimizer::select_type type; /* type of select for EXPLAIN */
496
467
SQL_LIST order_list; /* ORDER clause */
497
468
SQL_LIST *gorder_list;
603
578
bool inc_in_sum_expr();
604
579
uint32_t get_in_sum_expr();
606
bool add_item_to_list(Session *session, Item *item);
607
bool add_group_to_list(Session *session, Item *item, bool asc);
608
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);
609
584
TableList* add_table_to_list(Session *session,
610
585
Table_ident *table,
612
587
const std::bitset<NUM_OF_TABLE_OPTIONS>& table_options,
613
588
thr_lock_type flags= TL_UNLOCK,
614
589
List<Index_hint> *hints= 0,
615
LEX_STRING *option= 0);
590
lex_string_t *option= 0);
616
591
TableList* get_table_list();
617
bool init_nested_join(Session *session);
592
void init_nested_join(Session&);
618
593
TableList *end_nested_join(Session *session);
619
594
TableList *nest_last_join(Session *session);
620
595
void add_joined_table(TableList *table);
628
603
order_list.next= (unsigned char**) &order_list.first;
631
This method created for reiniting LEX in mysql_admin_table() and can be
606
This method created for reiniting LEX in admin_table() and can be
632
607
used only if you are going remove all Select_Lex & units except belonger
633
608
to LEX (LEX::unit & LEX::select, for other purposes there are
634
609
Select_Lex_Unit::exclude_level & Select_Lex_Unit::exclude_tree
640
615
bool test_limit();
642
friend void lex_start(Session *session);
617
friend void lex_start(Session*);
643
618
void make_empty_select()
648
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,
652
enum_query_type query_type);
653
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);
627
void print_limit(Session *session, String *str);
654
628
void fix_prepare_information(Session *session, Item **conds, Item **having_conds);
656
630
Destroy the used execution plan (JOIN) of this subtree (this
664
638
void cleanup_all_joins(bool full);
666
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);
669
643
Add a index hint to the tagged list of hints. The type and clause of the
670
644
hint will be the current ones (set by set_index_hint())
672
bool add_index_hint (Session *session, char *str, uint32_t length);
646
void add_index_hint(Session*, const char*);
674
648
/* make a list to hold index hints */
675
649
void alloc_index_hints (Session *session);
676
650
/* read and clear the index hints */
677
List<Index_hint>* pop_index_hints(void)
651
List<Index_hint>* pop_index_hints()
679
653
List<Index_hint> *hints= index_hints;
680
654
index_hints= NULL;
684
void clear_index_hints(void) { index_hints= NULL; }
658
void clear_index_hints() { index_hints= NULL; }
687
661
/* current index hint kind. used in filling up index_hints */
688
enum index_hint_type current_index_hint_type;
662
index_hint_type current_index_hint_type;
689
663
index_clause_map current_index_hint_clause;
690
664
/* a list of USE/FORCE/IGNORE INDEX */
691
665
List<Index_hint> *index_hints;
694
inline bool Select_Lex_Unit::is_union ()
668
inline bool Select_Lex_Unit::is_union()
696
return first_select()->next_select() &&
697
first_select()->next_select()->linkage == UNION_TYPE;
670
return first_select()->next_select() && first_select()->next_select()->linkage == UNION_TYPE;
700
673
enum xa_option_words
710
extern const LEX_STRING null_lex_str;
713
684
Class representing list of all tables used by statement.
714
685
It also contains information about stored functions used by statement
735
706
TableList **query_tables_own_last;
738
These constructor and destructor serve for creation/destruction
739
of Query_tables_list instances which are used as backup storage.
741
Query_tables_list() {}
742
virtual ~Query_tables_list() {}
744
708
/* Initializes (or resets) Query_tables_list object for "real" use. */
745
709
void reset_query_tables_list(bool init);
811
772
/* list of all Select_Lex */
812
773
Select_Lex *all_selects_list;
814
/* This is the "scale" for DECIMAL (S,P) notation */
775
/* This is the "scale" for DECIMAL (S,P) notation */
816
777
/* This is the decimal precision in DECIMAL(S,P) notation */
820
* This is used kind of like the "ident" member variable below, as
781
* This is used kind of like the "ident" member variable below, as
821
782
* a place to store certain names of identifiers. Unfortunately, it
822
783
* is used differently depending on the Command (SELECT on a derived
823
784
* table vs CREATE)
826
787
/* The string literal used in a LIKE expression */
828
789
file_exchange *exchange;
833
794
* or a named savepoint. It should probably be refactored out into
834
795
* the eventual Command class built for the Keycache and Savepoint
839
800
unsigned char* yacc_yyss, *yacc_yyvs;
840
801
/* The owning Session of this LEX */
841
802
Session *session;
842
const CHARSET_INFO *charset;
803
const charset_info_st *charset;
843
804
bool text_string_is_7bit;
844
805
/* store original leaf_tables for INSERT SELECT and PS/SP */
845
806
TableList *leaf_tables_insert;
850
811
List<Lex_Column> columns;
851
812
List<Item> *insert_list,field_list,value_list,update_list;
852
813
List<List_item> many_values;
853
List<set_var_base> var_list;
814
SetVarVector var_list;
855
816
A stack of name resolution contexts for the query. This stack is used
856
817
at parse time to set local name resolution contexts for various parts
941
900
void cleanup_after_one_table_open();
943
bool push_context(Name_resolution_context *context)
902
void push_context(Name_resolution_context *context)
945
return context_stack.push_front(context);
904
context_stack.push_front(context);
948
907
void pop_context()
950
909
context_stack.pop();
953
bool copy_db_to(char **p_db, size_t *p_db_length) const;
955
912
Name_resolution_context *current_context()
957
return context_stack.head();
914
return &context_stack.front();
960
Restore the LEX and Session in case of a parse error.
962
static void cleanup_lex_after_parse_error(Session *session);
965
918
@brief check if the statement is a single-level join
1010
964
void start(Session *session);
967
message::Table *table()
969
if (not _create_table)
970
_create_table= new message::Table;
972
return _create_table;
975
message::AlterTable *alter_table();
977
message::Table::Field *field()
979
return _create_field;
982
void setField(message::Table::Field *arg)
1015
999
bool sum_expr_used;
1000
message::Table *_create_table;
1001
message::AlterTable *_alter_table;
1002
message::Table::Field *_create_field;
1018
1006
extern void lex_start(Session *session);
1019
extern void trim_whitespace(const CHARSET_INFO * const cs, LEX_STRING *str);
1020
extern bool is_lex_native_function(const LEX_STRING *name);
1023
1009
@} (End of group Semantic_Analysis)