drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
sql_lex.h
1/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2008 Sun Microsystems, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#pragma once
21
25#include <drizzled/message/table.pb.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>
32
33#include <bitset>
34#include <string>
35
36/*
37 The following hack is needed because mysql_yacc.cc does not define
38 YYSTYPE before including this file
39*/
40
41#ifdef DRIZZLE_SERVER
42/* set_var should change to set_var here ... */
43# include <drizzled/sys_var.h>
44# include <drizzled/item/func.h>
45# ifdef DRIZZLE_YACC
46# define LEX_YYSTYPE void *
47# else
48# if defined(DRIZZLE_LEX)
49# include <drizzled/foreign_key.h>
50# include <drizzled/lex_symbol.h>
51# include <drizzled/comp_creator.h>
52# include <drizzled/sql_yacc.hh>
53# define LEX_YYSTYPE BASE_SQL_STYPE *
54# else
55# define LEX_YYSTYPE void *
56# endif /* defined(DRIZZLE_LEX) */
57# endif /* DRIZZLE_YACC */
58#endif /* DRIZZLE_SERVER */
59
60// describe/explain types
61#define DESCRIBE_NORMAL 1
62#define DESCRIBE_EXTENDED 2
63
64#ifdef DRIZZLE_SERVER
65
66#define DERIVED_NONE 0
67#define DERIVED_SUBQUERY 1
68
69namespace drizzled
70{
71
72typedef List<Item> List_item;
73
74enum sub_select_type
75{
76 UNSPECIFIED_TYPE,
77 UNION_TYPE,
78 INTERSECT_TYPE,
79 EXCEPT_TYPE,
80 GLOBAL_OPTIONS_TYPE,
81 DERIVED_TABLE_TYPE,
82 OLAP_TYPE
83};
84
85enum olap_type
86{
87 UNSPECIFIED_OLAP_TYPE,
88 CUBE_TYPE,
89 ROLLUP_TYPE
90};
91
92/*
93 The state of the lex parsing for selects
94
95 master and slaves are pointers to select_lex.
96 master is pointer to upper level node.
97 slave is pointer to lower level node
98 select_lex is a SELECT without union
99 unit is container of either
100 - One SELECT
101 - UNION of selects
102 select_lex and unit are both inherited form select_lex_node
103 neighbors are two select_lex or units on the same level
104
105 All select describing structures linked with following pointers:
106 - list of neighbors (next/prev) (prev of first element point to slave
107 pointer of upper structure)
108 - For select this is a list of UNION's (or one element list)
109 - For units this is a list of sub queries for the upper level select
110
111 - pointer to master (master), which is
112 If this is a unit
113 - pointer to outer select_lex
114 If this is a select_lex
115 - pointer to outer unit structure for select
116
117 - pointer to slave (slave), which is either:
118 If this is a unit:
119 - first SELECT that belong to this unit
120 If this is a select_lex
121 - first unit that belong to this SELECT (subquries or derived tables)
122
123 - list of all select_lex (link_next/link_prev)
124 This is to be used for things like derived tables creation, where we
125 go through this list and create the derived tables.
126
127 If unit contain several selects (UNION now, INTERSECT etc later)
128 then it have special select_lex called fake_select_lex. It used for
129 storing global parameters (like ORDER BY, LIMIT) and executing union.
130 Subqueries used in global ORDER BY clause will be attached to this
131 fake_select_lex, which will allow them correctly resolve fields of
132 'upper' UNION and outer selects.
133
134 For example for following query:
135
136 select *
137 from table1
138 where table1.field IN (select * from table1_1_1 union
139 select * from table1_1_2)
140 union
141 select *
142 from table2
143 where table2.field=(select (select f1 from table2_1_1_1_1
144 where table2_1_1_1_1.f2=table2_1_1.f3)
145 from table2_1_1
146 where table2_1_1.f1=table2.f2)
147 union
148 select * from table3;
149
150 we will have following structure:
151
152 select1: (select * from table1 ...)
153 select2: (select * from table2 ...)
154 select3: (select * from table3)
155 select1.1.1: (select * from table1_1_1)
156 ...
157
158 main unit
159 fake0
160 select1 select2 select3
161 |^^ |^
162 s||| ||master
163 l||| |+---------------------------------+
164 a||| +---------------------------------+|
165 v|||master slave ||
166 e||+-------------------------+ ||
167 V| neighbor | V|
168 unit1.1<+==================>unit1.2 unit2.1
169 fake1.1
170 select1.1.1 select 1.1.2 select1.2.1 select2.1.1
171 |^
172 ||
173 V|
174 unit2.1.1.1
175 select2.1.1.1.1
176
177
178 relation in main unit will be following:
179 (bigger picture for:
180 main unit
181 fake0
182 select1 select2 select3
183 in the above picture)
184
185 main unit
186 |^^^^|fake_select_lex
187 |||||+--------------------------------------------+
188 ||||+--------------------------------------------+|
189 |||+------------------------------+ ||
190 ||+--------------+ | ||
191 slave||master | | ||
192 V| neighbor | neighbor | master|V
193 select1<========>select2<========>select3 fake0
194
195 list of all select_lex will be following (as it will be constructed by
196 parser):
197
198 select1->select2->select3->select2.1.1->select 2.1.2->select2.1.1.1.1-+
199 |
200 +---------------------------------------------------------------------+
201 |
202 +->select1.1.1->select1.1.2
203
204*/
205
206/*
207 Base class for Select_Lex (Select_Lex) &
208 Select_Lex_Unit (Select_Lex_Unit)
209*/
210class Select_Lex_Node {
211protected:
212 Select_Lex_Node *next, **prev, /* neighbor list */
213 *master, *slave, /* vertical links */
214 *link_next, **link_prev; /* list of whole Select_Lex */
215public:
216
217 uint64_t options;
218
219 /*
220 result of this query can't be cached, bit field, can be :
221 UNCACHEABLE_DEPENDENT
222 UNCACHEABLE_RAND
223 UNCACHEABLE_SIDEEFFECT
224 UNCACHEABLE_EXPLAIN
225 UNCACHEABLE_PREPARE
226 */
227 std::bitset<8> uncacheable;
228 sub_select_type linkage;
229 bool no_table_names_allowed; /* used for global order by */
230 bool no_error; /* suppress error message (convert it to warnings) */
231
232 static void *operator new(size_t size)
233 {
234 return memory::sql_alloc(size);
235 }
236 static void *operator new(size_t size, memory::Root *mem_root)
237 { return mem_root->alloc(size); }
238 static void operator delete(void*, size_t)
239 { }
240 static void operator delete(void*, memory::Root*)
241 {}
242 Select_Lex_Node(): linkage(UNSPECIFIED_TYPE) {}
243 virtual ~Select_Lex_Node() {}
244 inline Select_Lex_Node* get_master() { return master; }
245 virtual void init_query();
246 virtual void init_select();
247 void include_down(Select_Lex_Node *upper);
248 void include_neighbour(Select_Lex_Node *before);
249 void include_standalone(Select_Lex_Node *sel, Select_Lex_Node **ref);
250 void include_global(Select_Lex_Node **plink);
251 void exclude();
252
253 virtual Select_Lex_Unit* master_unit()= 0;
254 virtual Select_Lex* outer_select()= 0;
255 virtual Select_Lex* return_after_parsing()= 0;
256
257 virtual bool set_braces(bool value);
258 virtual bool inc_in_sum_expr();
259 virtual uint32_t get_in_sum_expr();
260 virtual TableList* get_table_list();
261 virtual List<Item>* get_item_list();
262 virtual TableList *add_table_to_list(Session *session, Table_ident *table,
263 lex_string_t *alias,
264 const std::bitset<NUM_OF_TABLE_OPTIONS>& table_options,
265 thr_lock_type flags= TL_UNLOCK,
266 List<Index_hint> *hints= 0,
267 lex_string_t *option= 0);
268 virtual void set_lock_for_tables(thr_lock_type)
269 {}
270
271 friend class Select_Lex_Unit;
272 friend bool new_select(LEX *lex, bool move_down);
273private:
274 void fast_exclude();
275};
276
277/*
278 Select_Lex_Unit - unit of selects (UNION, INTERSECT, ...) group
279 Select_Lexs
280*/
281class Select_Lex_Unit: public Select_Lex_Node {
282protected:
283 TableList result_table_list;
284 select_union *union_result;
285 Table *table; /* temporary table using for appending UNION results */
286
287 select_result *result;
288 uint64_t found_rows_for_union;
289 bool saved_error;
290
291public:
292 bool prepared, // prepare phase already performed for UNION (unit)
293 optimized, // optimize phase already performed for UNION (unit)
294 executed, // already executed
295 cleaned;
296
297 // list of fields which points to temporary table for union
298 List<Item> item_list;
299 /*
300 list of types of items inside union (used for union & derived tables)
301
302 Item_type_holders from which this list consist may have pointers to Field,
303 pointers is valid only after preparing SELECTS of this unit and before
304 any SELECT of this unit execution
305
306 TODO:
307 Possibly this member should be protected, and its direct use replaced
308 by get_unit_column_types(). Check the places where it is used.
309 */
310 List<Item> types;
311 /*
312 Pointer to 'last' select or pointer to unit where stored
313 global parameters for union
314 */
315 Select_Lex *global_parameters;
316 //node on wich we should return current_select pointer after parsing subquery
317 Select_Lex *return_to;
318 /* LIMIT clause runtime counters */
319 ha_rows select_limit_cnt, offset_limit_cnt;
320 /* not NULL if unit used in subselect, point to subselect item */
321 Item_subselect *item;
322 /* thread handler */
323 Session *session;
324 /*
325 Select_Lex for hidden SELECT in onion which process global
326 ORDER BY and LIMIT
327 */
328 Select_Lex *fake_select_lex;
329
330 Select_Lex *union_distinct; /* pointer to the last UNION DISTINCT */
331 bool describe; /* union exec() called for EXPLAIN */
332
333 void init_query();
334 Select_Lex_Unit* master_unit();
335 Select_Lex* outer_select();
336 Select_Lex* first_select()
337 {
338 return reinterpret_cast<Select_Lex*>(slave);
339 }
340 Select_Lex_Unit* next_unit()
341 {
342 return reinterpret_cast<Select_Lex_Unit*>(next);
343 }
344 Select_Lex* return_after_parsing() { return return_to; }
345 void exclude_level();
346 void exclude_tree();
347
348 /* UNION methods */
349 bool prepare(Session *session, select_result *result,
350 uint64_t additional_options);
351 bool exec();
352 bool cleanup();
353 inline void unclean() { cleaned= 0; }
354 void reinit_exec_mechanism();
355
356 void print(String *str);
357
358 bool add_fake_select_lex(Session *session);
359 void init_prepare_fake_select_lex(Session *session);
360 bool change_result(select_result_interceptor *result,
361 select_result_interceptor *old_result);
362 void set_limit(Select_Lex *values);
363 void set_session(Session *session_arg) { session= session_arg; }
364 inline bool is_union();
365
366 friend void lex_start(Session*);
367
368 List<Item> *get_unit_column_types();
369};
370
371/*
372 Select_Lex - store information of parsed SELECT statment
373*/
374class Select_Lex : public Select_Lex_Node
375{
376public:
377
378 Select_Lex() :
379 context(),
380 db(0),
381 where(0),
382 having(0),
383 cond_value(),
384 having_value(),
385 parent_lex(0),
386 olap(UNSPECIFIED_OLAP_TYPE),
387 table_list(),
388 group_list(),
389 item_list(),
390 interval_list(),
391 is_item_list_lookup(false),
392 join(0),
393 top_join_list(),
394 join_list(0),
395 embedding(0),
396 sj_nests(),
397 leaf_tables(0),
398 type(optimizer::ST_PRIMARY),
399 order_list(),
400 gorder_list(0),
401 select_limit(0),
402 offset_limit(0),
403 ref_pointer_array(0),
404 select_n_having_items(0),
405 cond_count(0),
406 between_count(0),
407 max_equal_elems(0),
408 select_n_where_fields(0),
409 parsing_place(NO_MATTER),
410 with_sum_func(0),
411 in_sum_expr(0),
412 select_number(0),
413 nest_level(0),
414 inner_sum_func_list(0),
415 with_wild(0),
416 braces(0),
417 having_fix_field(0),
418 inner_refs_list(),
419 n_sum_items(0),
420 n_child_sum_items(0),
421 explicit_limit(0),
422 is_cross(false),
423 subquery_in_having(0),
424 is_correlated(0),
425 exclude_from_table_unique_test(0),
426 non_agg_fields(),
427 cur_pos_in_select_list(0),
428 prev_join_using(0),
429 full_group_by_flag(),
430 current_index_hint_type(INDEX_HINT_IGNORE),
431 current_index_hint_clause(),
432 index_hints(0)
433 {
434 }
435
436 Name_resolution_context context;
437 const char *db;
438 /* An Item representing the WHERE clause */
439 Item *where;
440 /* An Item representing the HAVING clause */
441 Item *having;
442 /* Saved values of the WHERE and HAVING clauses*/
443 Item::cond_result cond_value;
444 Item::cond_result having_value;
445 /* point on lex in which it was created, used in view subquery detection */
446 LEX *parent_lex;
447 olap_type olap;
448 /* FROM clause - points to the beginning of the TableList::next_local list. */
449 SQL_LIST table_list;
450 SQL_LIST group_list; /* GROUP BY clause. */
451 List<Item> item_list; /* list of fields & expressions */
452 List<String> interval_list;
453 bool is_item_list_lookup;
454 Join *join; /* after Join::prepare it is pointer to corresponding JOIN */
455 List<TableList> top_join_list; /* join list of the top level */
456 List<TableList> *join_list; /* list for the currently parsed join */
457 TableList *embedding; /* table embedding to the above list */
458 List<TableList> sj_nests;
459 /*
460 Beginning of the list of leaves in a FROM clause, where the leaves
461 inlcude all base tables including view tables. The tables are connected
462 by TableList::next_leaf, so leaf_tables points to the left-most leaf.
463 */
464 TableList *leaf_tables;
465 drizzled::optimizer::select_type type; /* type of select for EXPLAIN */
466
467 SQL_LIST order_list; /* ORDER clause */
468 SQL_LIST *gorder_list;
469 Item *select_limit, *offset_limit; /* LIMIT clause parameters */
470 /* Arrays of pointers to top elements of all_fields list */
471 Item **ref_pointer_array;
472
473 /*
474 number of items in select_list and HAVING clause used to get number
475 bigger then can be number of entries that will be added to all item
476 list during split_sum_func
477 */
478 uint32_t select_n_having_items;
479 uint32_t cond_count; /* number of arguments of and/or/xor in where/having/on */
480 uint32_t between_count; /* number of between predicates in where/having/on */
481 uint32_t max_equal_elems; /* maximal number of elements in multiple equalities */
482 /*
483 Number of fields used in select list or where clause of current select
484 and all inner subselects.
485 */
486 uint32_t select_n_where_fields;
487 enum_parsing_place parsing_place; /* where we are parsing expression */
488 bool with_sum_func; /* sum function indicator */
489
490 uint32_t in_sum_expr;
491 uint32_t select_number; /* number of select (used for EXPLAIN) */
492 int8_t nest_level; /* nesting level of select */
493 Item_sum *inner_sum_func_list; /* list of sum func in nested selects */
494 uint32_t with_wild; /* item list contain '*' */
495 bool braces; /* SELECT ... UNION (SELECT ... ) <- this braces */
496 /* true when having fix field called in processing of this SELECT */
497 bool having_fix_field;
498 /* List of references to fields referenced from inner selects */
499 List<Item_outer_ref> inner_refs_list;
500 /* Number of Item_sum-derived objects in this SELECT */
501 uint32_t n_sum_items;
502 /* Number of Item_sum-derived objects in children and descendant SELECTs */
503 uint32_t n_child_sum_items;
504
505 /* explicit LIMIT clause was used */
506 bool explicit_limit;
507
508 /* explicit CROSS JOIN was used */
509 bool is_cross;
510
511 /*
512 there are subquery in HAVING clause => we can't close tables before
513 query processing end even if we use temporary table
514 */
515 bool subquery_in_having;
516 /* true <=> this SELECT is correlated w.r.t. some ancestor select */
517 bool is_correlated;
518 /* exclude this select from check of unique_table() */
519 bool exclude_from_table_unique_test;
520 /* List of fields that aren't under an aggregate function */
521 List<Item_field> non_agg_fields;
522 /* index in the select list of the expression currently being fixed */
523 int cur_pos_in_select_list;
524
525 /*
526 This is a copy of the original JOIN USING list that comes from
527 the parser. The parser :
528 1. Sets the natural_join of the second TableList in the join
529 and the Select_Lex::prev_join_using.
530 2. Makes a parent TableList and sets its is_natural_join/
531 join_using_fields members.
532 3. Uses the wrapper TableList as a table in the upper level.
533 We cannot assign directly to join_using_fields in the parser because
534 at stage (1.) the parent TableList is not constructed yet and
535 the assignment will override the JOIN USING fields of the lower level
536 joins on the right.
537 */
538 List<String> *prev_join_using;
539 /*
540 Bitmap used in the ONLY_FULL_GROUP_BY_MODE to prevent mixture of aggregate
541 functions and non aggregated fields when GROUP BY list is absent.
542 Bits:
543 0 - non aggregated fields are used in this select,
544 defined as NON_AGG_FIELD_USED.
545 1 - aggregate functions are used in this select,
546 defined as SUM_FUNC_USED.
547 */
548 std::bitset<2> full_group_by_flag;
549
550 void init_query();
551 void init_select();
552 Select_Lex_Unit* master_unit();
553 Select_Lex_Unit* first_inner_unit()
554 {
555 return (Select_Lex_Unit*) slave;
556 }
557 Select_Lex* outer_select();
558 Select_Lex* next_select()
559 {
560 return (Select_Lex*) next;
561 }
562 Select_Lex* next_select_in_list()
563 {
564 return (Select_Lex*) link_next;
565 }
566 Select_Lex_Node** next_select_in_list_addr()
567 {
568 return &link_next;
569 }
570 Select_Lex* return_after_parsing()
571 {
572 return master_unit()->return_after_parsing();
573 }
574
575 void mark_as_dependent(Select_Lex *last);
576
577 bool set_braces(bool value);
578 bool inc_in_sum_expr();
579 uint32_t get_in_sum_expr();
580
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);
584 TableList* add_table_to_list(Session *session,
585 Table_ident *table,
586 lex_string_t *alias,
587 const std::bitset<NUM_OF_TABLE_OPTIONS>& table_options,
588 thr_lock_type flags= TL_UNLOCK,
589 List<Index_hint> *hints= 0,
590 lex_string_t *option= 0);
591 TableList* get_table_list();
592 void init_nested_join(Session&);
593 TableList *end_nested_join();
594 TableList *nest_last_join(Session*);
595 void add_joined_table(TableList *table);
596 TableList *convert_right_join();
597 List<Item>* get_item_list();
598 void set_lock_for_tables(thr_lock_type lock_type);
599 inline void init_order()
600 {
601 order_list.elements= 0;
602 order_list.first= 0;
603 order_list.next= (unsigned char**) &order_list.first;
604 }
605 /*
606 This method created for reiniting LEX in admin_table() and can be
607 used only if you are going remove all Select_Lex & units except belonger
608 to LEX (LEX::unit & LEX::select, for other purposes there are
609 Select_Lex_Unit::exclude_level & Select_Lex_Unit::exclude_tree
610 */
611 void cut_subtree()
612 {
613 slave= 0;
614 }
615 bool test_limit();
616
617 friend void lex_start(Session*);
618 void make_empty_select()
619 {
620 init_query();
621 init_select();
622 }
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);
628 void fix_prepare_information(Session *session, Item **conds, Item **having_conds);
629 /*
630 Destroy the used execution plan (JOIN) of this subtree (this
631 Select_Lex and all nested Select_Lexes and Select_Lex_Units).
632 */
633 bool cleanup();
634 /*
635 Recursively cleanup the join of this select lex and of all nested
636 select lexes.
637 */
638 void cleanup_all_joins(bool full);
639
640 void set_index_hint_type(index_hint_type type, index_clause_map clause);
641
642 /*
643 Add a index hint to the tagged list of hints. The type and clause of the
644 hint will be the current ones (set by set_index_hint())
645 */
646 void add_index_hint(Session*, const char*);
647
648 /* make a list to hold index hints */
649 void alloc_index_hints (Session *session);
650 /* read and clear the index hints */
651 List<Index_hint>* pop_index_hints()
652 {
653 List<Index_hint> *hints= index_hints;
654 index_hints= NULL;
655 return hints;
656 }
657
658 void clear_index_hints() { index_hints= NULL; }
659
660private:
661 /* current index hint kind. used in filling up index_hints */
662 index_hint_type current_index_hint_type;
663 index_clause_map current_index_hint_clause;
664 /* a list of USE/FORCE/IGNORE INDEX */
665 List<Index_hint> *index_hints;
666};
667
668inline bool Select_Lex_Unit::is_union()
669{
670 return first_select()->next_select() && first_select()->next_select()->linkage == UNION_TYPE;
671}
672
673enum xa_option_words
674{
675 XA_NONE,
676 XA_JOIN,
677 XA_RESUME,
678 XA_ONE_PHASE,
679 XA_SUSPEND,
680 XA_FOR_MIGRATE
681};
682
683/*
684 Class representing list of all tables used by statement.
685 It also contains information about stored functions used by statement
686 since during its execution we may have to add all tables used by its
687 stored functions/triggers to this list in order to pre-open and lock
688 them.
689
690 Also used by st_lex::reset_n_backup/restore_backup_query_tables_list()
691 methods to save and restore this information.
692*/
693class Query_tables_list
694{
695public:
696 /* Global list of all tables used by this statement */
697 TableList *query_tables;
698 /* Pointer to next_global member of last element in the previous list. */
699 TableList **query_tables_last;
700 /*
701 If non-0 then indicates that query requires prelocking and points to
702 next_global member of last own element in query table list (i.e. last
703 table which was not added to it as part of preparation to prelocking).
704 0 - indicates that this query does not need prelocking.
705 */
706 TableList **query_tables_own_last;
707
708 /* Initializes (or resets) Query_tables_list object for "real" use. */
709 void reset_query_tables_list(bool init);
710
711 /*
712 Direct addition to the list of query tables.
713 If you are using this function, you must ensure that the table
714 object, in particular table->db member, is initialized.
715 */
716 void add_to_query_tables(TableList *table)
717 {
718 *(table->prev_global= query_tables_last)= table;
719 query_tables_last= &table->next_global;
720 }
721 /* Return pointer to first not-own table in query-tables or 0 */
722 TableList* first_not_own_table()
723 {
724 return ( query_tables_own_last ? *query_tables_own_last : 0);
725 }
726 void chop_off_not_own_tables()
727 {
728 if (query_tables_own_last)
729 {
730 *query_tables_own_last= 0;
731 query_tables_last= query_tables_own_last;
732 query_tables_own_last= 0;
733 }
734 }
735};
736
740enum enum_comment_state
741{
745 NO_COMMENT,
750 PRESERVE_COMMENT,
757 DISCARD_COMMENT
758};
759
760} /* namespace drizzled */
761
762namespace drizzled {
763
764/* The state of the lex parsing. This is saved in the Session struct */
765class LEX : public Query_tables_list
766{
767public:
768 Select_Lex_Unit unit; /* most upper unit */
769 Select_Lex select_lex; /* first Select_Lex */
770 /* current Select_Lex in parsing */
771 Select_Lex *current_select;
772 /* list of all Select_Lex */
773 Select_Lex *all_selects_list;
774
775 /* This is the "scale" for DECIMAL (S,P) notation */
776 const char *length;
777 /* This is the decimal precision in DECIMAL(S,P) notation */
778 const char *dec;
779
786 lex_string_t name;
787 /* The string literal used in a LIKE expression */
788 String *wild;
789 file_exchange *exchange;
790 select_result *result;
791
798 lex_string_t ident;
799
800 unsigned char* yacc_yyss, *yacc_yyvs;
801 /* The owning Session of this LEX */
802 Session *session;
803 const charset_info_st *charset;
804 bool text_string_is_7bit;
805 /* store original leaf_tables for INSERT SELECT and PS/SP */
806 TableList *leaf_tables_insert;
807
808 List<Key_part_spec> col_list;
809 List<Key_part_spec> ref_list;
810 List<String> interval_list;
811 List<Lex_Column> columns;
812 List<Item> *insert_list,field_list,value_list,update_list;
813 List<List_item> many_values;
814 SetVarVector var_list;
815 /*
816 A stack of name resolution contexts for the query. This stack is used
817 at parse time to set local name resolution contexts for various parts
818 of a query. For example, in a JOIN ... ON (some_condition) clause the
819 Items in 'some_condition' must be resolved only against the operands
820 of the the join, and not against the whole clause. Similarly, Items in
821 subqueries should be resolved against the subqueries (and outer queries).
822 The stack is used in the following way: when the parser detects that
823 all Items in some clause need a local context, it creates a new context
824 and pushes it on the stack. All newly created Items always store the
825 top-most context in the stack. Once the parser leaves the clause that
826 required a local context, the parser pops the top-most context.
827 */
828 List<Name_resolution_context> context_stack;
829
830 SQL_LIST auxiliary_table_list;
831 SQL_LIST save_list;
832 CreateField *last_field;
833 Item_sum *in_sum_func;
834 plugin::Function *udf;
835 uint32_t type;
836 /*
837 This variable is used in post-parse stage to declare that sum-functions,
838 or functions which have sense only if GROUP BY is present, are allowed.
839 For example in a query
840 SELECT ... FROM ...WHERE MIN(i) == 1 GROUP BY ... HAVING MIN(i) > 2
841 MIN(i) in the WHERE clause is not allowed in the opposite to MIN(i)
842 in the HAVING clause. Due to possible nesting of select construct
843 the variable can contain 0 or 1 for each nest level.
844 */
845 nesting_map allow_sum_func;
846 enum_sql_command sql_command;
847 statement::Statement *statement;
848 /*
849 Usually `expr` rule of yacc is quite reused but some commands better
850 not support subqueries which comes standard with this rule, like
851 KILL, HA_READ, CREATE/ALTER EVENT etc. Set this to `false` to get
852 syntax error back.
853 */
854 bool expr_allows_subselect;
855
856 thr_lock_type lock_option;
857 enum enum_duplicates duplicates;
858 union {
859 enum ha_rkey_function ha_rkey_mode;
860 enum xa_option_words xa_opt;
861 };
862 sql_var_t option_type;
863
864 int nest_level;
865 uint8_t describe;
866 /*
867 A flag that indicates what kinds of derived tables are present in the
868 query (0 if no derived tables, otherwise DERIVED_SUBQUERY).
869 */
870 uint8_t derived_tables;
871
872 /* Was the IGNORE symbol found in statement */
873 bool ignore;
874
881 bool use_only_table_context;
882
883 /* Was the ESCAPE keyword used? */
884 bool escape_used;
885 bool is_lex_started; /* If lex_start() did run. For debugging. */
886
887 LEX();
888
889 /* Note that init and de-init mostly happen in lex_start and lex_end
890 and not here. This is because LEX isn't delete/new for each new
891 statement in a session. It's re-used by doing lex_end, lex_start
892 in sql_lex.cc
893 */
894 virtual ~LEX();
895
896 TableList *unlink_first_table(bool *link_to_local);
897 void link_first_table_back(TableList *first, bool link_to_local);
898 void first_lists_tables_same();
899
900 void cleanup_after_one_table_open();
901
902 void push_context(Name_resolution_context *context)
903 {
904 context_stack.push_front(context);
905 }
906
907 void pop_context()
908 {
909 context_stack.pop();
910 }
911
912 Name_resolution_context *current_context()
913 {
914 return &context_stack.front();
915 }
916
924 bool is_single_level_stmt()
925 {
926 /*
927 This check exploits the fact that the last added to all_select_list is
928 on its top. So select_lex (as the first added) will be at the tail
929 of the list.
930 */
931 if (&select_lex == all_selects_list)
932 {
933 assert(!all_selects_list->next_select_in_list());
934 return true;
935 }
936 return false;
937 }
938 bool is_cross; // CROSS keyword was used
939 bool isCacheable()
940 {
941 return cacheable;
942 }
943 void setCacheable(bool val)
944 {
945 cacheable= val;
946 }
947
948 void reset()
949 {
950 sum_expr_used= false;
951 _exists= false;
952 }
953
954 void setSumExprUsed()
955 {
956 sum_expr_used= true;
957 }
958
959 bool isSumExprUsed()
960 {
961 return sum_expr_used;
962 }
963
964 void start(Session *session);
965 void end();
966
967 message::Table *table()
968 {
969 if (not _create_table)
970 _create_table= new message::Table;
971
972 return _create_table;
973 }
974
975 message::AlterTable *alter_table();
976
977 message::Table::Field *field()
978 {
979 return _create_field;
980 }
981
982 void setField(message::Table::Field *arg)
983 {
984 _create_field= arg;
985 }
986
987 void setExists()
988 {
989 _exists= true;
990 }
991
992 bool exists() const
993 {
994 return _exists;
995 }
996
997private:
998 bool cacheable;
999 bool sum_expr_used;
1000 message::Table *_create_table;
1001 message::AlterTable *_alter_table;
1002 message::Table::Field *_create_field;
1003 bool _exists;
1004};
1005
1006extern void lex_start(Session *session);
1007
1011
1012} /* namespace drizzled */
1013
1014#endif /* DRIZZLE_SERVER */
TODO: Rename this file - func.h is stupid.
void mark_as_dependent(Session *session, Select_Lex *last, Select_Lex *current, Item_ident *resolved_item, Item_ident *mark_item)
Definition item.cc:772