~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_lex.h

  • Committer: Monty Taylor
  • Date: 2009-01-01 00:33:21 UTC
  • mto: This revision was merged to the branch mainline in revision 756.
  • Revision ID: mordred@inaugust.com-20090101003321-szs1ertpp0y9fccj
Updated mysql.test for distcheck.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
/**
24
24
  @defgroup Semantic_Analysis Semantic Analysis
25
25
*/
26
 
#include "drizzled/sql_udf.h"
27
 
#include "drizzled/name_resolution_context.h"
28
 
#include "drizzled/item/subselect.h"
29
 
#include "drizzled/item/param.h"
30
 
#include "drizzled/item/outer_ref.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/key.h"
36
 
#include "drizzled/foreign_key.h"
37
 
#include "drizzled/item/param.h"
38
 
#include "drizzled/index_hint.h"
 
26
 
 
27
#include <drizzled/sql_udf.h>
 
28
#include <drizzled/name_resolution_context.h>
 
29
#include <drizzled/item/subselect.h>
 
30
#include <drizzled/item/param.h>
 
31
#include <drizzled/item/outer_ref.h>
 
32
#include <drizzled/table_list.h>
 
33
#include <drizzled/function/math/real.h>
 
34
#include <drizzled/alter_drop.h>
 
35
#include <drizzled/alter_column.h>
 
36
#include <drizzled/key.h>
 
37
#include <drizzled/foreign_key.h>
 
38
#include <drizzled/item/param.h>
39
39
 
40
40
class select_result_interceptor;
41
41
class virtual_column_info;
44
44
 
45
45
/* These may not be declared yet */
46
46
class Table_ident;
47
 
class file_exchange;
48
 
class Lex_Column;
 
47
class sql_exchange;
 
48
class LEX_COLUMN;
49
49
class Item_outer_ref;
50
50
 
51
51
/*
88
88
  char *server_name, *host, *db, *username, *password, *scheme, *owner;
89
89
} LEX_SERVER_OPTIONS;
90
90
 
 
91
typedef struct st_lex_master_info
 
92
{
 
93
  char *host, *user, *password, *log_file_name;
 
94
  uint32_t port, connect_retry;
 
95
  float heartbeat_period;
 
96
  uint64_t pos;
 
97
  uint32_t server_id;
 
98
  /*
 
99
    Enum is used for making it possible to detect if the user
 
100
    changed variable or if it should be left at old value
 
101
   */
 
102
  enum {LEX_MI_UNCHANGED, LEX_MI_DISABLE, LEX_MI_ENABLE} heartbeat_opt;
 
103
  char *relay_log_name;
 
104
  uint32_t relay_log_pos;
 
105
} LEX_MASTER_INFO;
 
106
 
91
107
 
92
108
enum sub_select_type
93
109
{
106
122
};
107
123
 
108
124
/*
 
125
  String names used to print a statement with index hints.
 
126
  Keep in sync with index_hint_type.
 
127
*/
 
128
extern const char * index_hint_type_name[];
 
129
typedef unsigned char index_clause_map;
 
130
 
 
131
/*
 
132
  Bits in index_clause_map : one for each possible FOR clause in
 
133
  USE/FORCE/IGNORE INDEX index hint specification
 
134
*/
 
135
#define INDEX_HINT_MASK_JOIN  (1)
 
136
#define INDEX_HINT_MASK_GROUP (1 << 1)
 
137
#define INDEX_HINT_MASK_ORDER (1 << 2)
 
138
 
 
139
#define INDEX_HINT_MASK_ALL (INDEX_HINT_MASK_JOIN | INDEX_HINT_MASK_GROUP | \
 
140
                             INDEX_HINT_MASK_ORDER)
 
141
 
 
142
/* Single element of an USE/FORCE/IGNORE INDEX list specified as a SQL hint  */
 
143
class Index_hint : public Sql_alloc
 
144
{
 
145
public:
 
146
  /* The type of the hint : USE/FORCE/IGNORE */
 
147
  enum index_hint_type type;
 
148
  /* Where the hit applies to. A bitmask of INDEX_HINT_MASK_<place> values */
 
149
  index_clause_map clause;
 
150
  /*
 
151
    The index name. Empty (str=NULL) name represents an empty list
 
152
    USE INDEX () clause
 
153
  */
 
154
  LEX_STRING key_name;
 
155
 
 
156
  Index_hint (enum index_hint_type type_arg, index_clause_map clause_arg,
 
157
              char *str, uint32_t length) :
 
158
    type(type_arg), clause(clause_arg)
 
159
  {
 
160
    key_name.str= str;
 
161
    key_name.length= length;
 
162
  }
 
163
 
 
164
  void print(Session *session, String *str);
 
165
};
 
166
 
 
167
/*
109
168
  The state of the lex parsing for selects
110
169
 
111
170
   master and slaves are pointers to select_lex.
220
279
*/
221
280
 
222
281
/*
223
 
    Base class for Select_Lex (Select_Lex) &
224
 
    Select_Lex_Unit (Select_Lex_Unit)
 
282
    Base class for st_select_lex (SELECT_LEX) &
 
283
    st_select_lex_unit (SELECT_LEX_UNIT)
225
284
*/
226
285
class LEX;
227
 
class Select_Lex;
228
 
class Select_Lex_Unit;
229
 
class Select_Lex_Node {
 
286
class st_select_lex;
 
287
class st_select_lex_unit;
 
288
class st_select_lex_node {
230
289
protected:
231
 
  Select_Lex_Node *next, **prev,   /* neighbor list */
 
290
  st_select_lex_node *next, **prev,   /* neighbor list */
232
291
    *master, *slave,                  /* vertical links */
233
 
    *link_next, **link_prev;          /* list of whole Select_Lex */
 
292
    *link_next, **link_prev;          /* list of whole SELECT_LEX */
234
293
public:
235
294
 
236
295
  uint64_t options;
258
317
  { TRASH(ptr, size); }
259
318
  static void operator delete(void *, MEM_ROOT *)
260
319
  {}
261
 
  Select_Lex_Node(): linkage(UNSPECIFIED_TYPE) {}
262
 
  virtual ~Select_Lex_Node() {}
263
 
  inline Select_Lex_Node* get_master() { return master; }
 
320
  st_select_lex_node(): linkage(UNSPECIFIED_TYPE) {}
 
321
  virtual ~st_select_lex_node() {}
 
322
  inline st_select_lex_node* get_master() { return master; }
264
323
  virtual void init_query();
265
324
  virtual void init_select();
266
 
  void include_down(Select_Lex_Node *upper);
267
 
  void include_neighbour(Select_Lex_Node *before);
268
 
  void include_standalone(Select_Lex_Node *sel, Select_Lex_Node **ref);
269
 
  void include_global(Select_Lex_Node **plink);
 
325
  void include_down(st_select_lex_node *upper);
 
326
  void include_neighbour(st_select_lex_node *before);
 
327
  void include_standalone(st_select_lex_node *sel, st_select_lex_node **ref);
 
328
  void include_global(st_select_lex_node **plink);
270
329
  void exclude();
271
330
 
272
 
  virtual Select_Lex_Unit* master_unit()= 0;
273
 
  virtual Select_Lex* outer_select()= 0;
274
 
  virtual Select_Lex* return_after_parsing()= 0;
 
331
  virtual st_select_lex_unit* master_unit()= 0;
 
332
  virtual st_select_lex* outer_select()= 0;
 
333
  virtual st_select_lex* return_after_parsing()= 0;
275
334
 
276
335
  virtual bool set_braces(bool value);
277
336
  virtual bool inc_in_sum_expr();
288
347
  virtual void set_lock_for_tables(thr_lock_type)
289
348
  {}
290
349
 
291
 
  friend class Select_Lex_Unit;
 
350
  friend class st_select_lex_unit;
292
351
  friend bool mysql_new_select(LEX *lex, bool move_down);
293
352
private:
294
353
  void fast_exclude();
295
354
};
 
355
typedef class st_select_lex_node SELECT_LEX_NODE;
296
356
 
297
357
/*
298
 
   Select_Lex_Unit - unit of selects (UNION, INTERSECT, ...) group
299
 
   Select_Lexs
 
358
   SELECT_LEX_UNIT - unit of selects (UNION, INTERSECT, ...) group
 
359
   SELECT_LEXs
300
360
*/
301
361
class Session;
302
362
class select_result;
303
363
class JOIN;
304
364
class select_union;
305
 
class Select_Lex_Unit: public Select_Lex_Node {
 
365
class st_select_lex_unit: public st_select_lex_node {
306
366
protected:
307
367
  TableList result_table_list;
308
368
  select_union *union_result;
336
396
    Pointer to 'last' select or pointer to unit where stored
337
397
    global parameters for union
338
398
  */
339
 
  Select_Lex *global_parameters;
 
399
  st_select_lex *global_parameters;
340
400
  //node on wich we should return current_select pointer after parsing subquery
341
 
  Select_Lex *return_to;
 
401
  st_select_lex *return_to;
342
402
  /* LIMIT clause runtime counters */
343
403
  ha_rows select_limit_cnt, offset_limit_cnt;
344
404
  /* not NULL if unit used in subselect, point to subselect item */
346
406
  /* thread handler */
347
407
  Session *session;
348
408
  /*
349
 
    Select_Lex for hidden SELECT in onion which process global
 
409
    SELECT_LEX for hidden SELECT in onion which process global
350
410
    ORDER BY and LIMIT
351
411
  */
352
 
  Select_Lex *fake_select_lex;
 
412
  st_select_lex *fake_select_lex;
353
413
 
354
 
  Select_Lex *union_distinct; /* pointer to the last UNION DISTINCT */
 
414
  st_select_lex *union_distinct; /* pointer to the last UNION DISTINCT */
355
415
  bool describe; /* union exec() called for EXPLAIN */
356
416
 
357
417
  void init_query();
358
 
  Select_Lex_Unit* master_unit();
359
 
  Select_Lex* outer_select();
360
 
  Select_Lex* first_select()
361
 
  {
362
 
    return reinterpret_cast<Select_Lex*>(slave);
363
 
  }
364
 
  Select_Lex_Unit* next_unit()
365
 
  {
366
 
    return reinterpret_cast<Select_Lex_Unit*>(next);
367
 
  }
368
 
  Select_Lex* return_after_parsing() { return return_to; }
 
418
  st_select_lex_unit* master_unit();
 
419
  st_select_lex* outer_select();
 
420
  st_select_lex* first_select()
 
421
  {
 
422
    return reinterpret_cast<st_select_lex*>(slave);
 
423
  }
 
424
  st_select_lex_unit* next_unit()
 
425
  {
 
426
    return reinterpret_cast<st_select_lex_unit*>(next);
 
427
  }
 
428
  st_select_lex* return_after_parsing() { return return_to; }
369
429
  void exclude_level();
370
430
  void exclude_tree();
371
431
 
372
432
  /* UNION methods */
373
 
  bool prepare(Session *session, select_result *result,
374
 
               uint64_t additional_options);
 
433
  bool prepare(Session *session, select_result *result, uint32_t additional_options);
375
434
  bool exec();
376
435
  bool cleanup();
377
436
  inline void unclean() { cleaned= 0; }
383
442
  void init_prepare_fake_select_lex(Session *session);
384
443
  bool change_result(select_result_interceptor *result,
385
444
                     select_result_interceptor *old_result);
386
 
  void set_limit(Select_Lex *values);
 
445
  void set_limit(st_select_lex *values);
387
446
  void set_session(Session *session_arg) { session= session_arg; }
388
447
  inline bool is_union ();
389
448
 
393
452
  List<Item> *get_unit_column_types();
394
453
};
395
454
 
 
455
typedef class st_select_lex_unit SELECT_LEX_UNIT;
 
456
 
396
457
/*
397
 
  Select_Lex - store information of parsed SELECT statment
 
458
  SELECT_LEX - store information of parsed SELECT statment
398
459
*/
399
 
class Select_Lex: public Select_Lex_Node
 
460
class st_select_lex: public st_select_lex_node
400
461
{
401
462
public:
402
463
  Name_resolution_context context;
458
519
  uint32_t table_join_options;
459
520
  uint32_t in_sum_expr;
460
521
  uint32_t select_number; /* number of select (used for EXPLAIN) */
461
 
  int8_t nest_level;     /* nesting level of select */
 
522
  int nest_level;     /* nesting level of select */
462
523
  Item_sum *inner_sum_func_list; /* list of sum func in nested selects */
463
524
  uint32_t with_wild; /* item list contain '*' */
464
525
  bool  braces;         /* SELECT ... UNION (SELECT ... ) <- this braces */
487
548
  /* index in the select list of the expression currently being fixed */
488
549
  int cur_pos_in_select_list;
489
550
 
490
 
  List<Function_builder>     udf_list;                  /* udf function calls stack */
 
551
  List<udf_func>     udf_list;                  /* udf function calls stack */
491
552
  /*
492
553
    This is a copy of the original JOIN USING list that comes from
493
554
    the parser. The parser :
494
555
      1. Sets the natural_join of the second TableList in the join
495
 
         and the Select_Lex::prev_join_using.
 
556
         and the st_select_lex::prev_join_using.
496
557
      2. Makes a parent TableList and sets its is_natural_join/
497
558
       join_using_fields members.
498
559
      3. Uses the wrapper TableList as a table in the upper level.
514
575
  uint8_t full_group_by_flag;
515
576
  void init_query();
516
577
  void init_select();
517
 
  Select_Lex_Unit* master_unit();
518
 
  Select_Lex_Unit* first_inner_unit()
519
 
  {
520
 
    return (Select_Lex_Unit*) slave;
521
 
  }
522
 
  Select_Lex* outer_select();
523
 
  Select_Lex* next_select() { return (Select_Lex*) next; }
524
 
  Select_Lex* next_select_in_list()
525
 
  {
526
 
    return (Select_Lex*) link_next;
527
 
  }
528
 
  Select_Lex_Node** next_select_in_list_addr()
 
578
  st_select_lex_unit* master_unit();
 
579
  st_select_lex_unit* first_inner_unit()
 
580
  {
 
581
    return (st_select_lex_unit*) slave;
 
582
  }
 
583
  st_select_lex* outer_select();
 
584
  st_select_lex* next_select() { return (st_select_lex*) next; }
 
585
  st_select_lex* next_select_in_list()
 
586
  {
 
587
    return (st_select_lex*) link_next;
 
588
  }
 
589
  st_select_lex_node** next_select_in_list_addr()
529
590
  {
530
591
    return &link_next;
531
592
  }
532
 
  Select_Lex* return_after_parsing()
 
593
  st_select_lex* return_after_parsing()
533
594
  {
534
595
    return master_unit()->return_after_parsing();
535
596
  }
536
597
 
537
 
  void mark_as_dependent(Select_Lex *last);
 
598
  void mark_as_dependent(st_select_lex *last);
538
599
 
539
600
  bool set_braces(bool value);
540
601
  bool inc_in_sum_expr();
566
627
  }
567
628
  /*
568
629
    This method created for reiniting LEX in mysql_admin_table() and can be
569
 
    used only if you are going remove all Select_Lex & units except belonger
 
630
    used only if you are going remove all SELECT_LEX & units except belonger
570
631
    to LEX (LEX::unit & LEX::select, for other purposes there are
571
 
    Select_Lex_Unit::exclude_level & Select_Lex_Unit::exclude_tree
 
632
    SELECT_LEX_UNIT::exclude_level & SELECT_LEX_UNIT::exclude_tree
572
633
  */
573
634
  void cut_subtree() { slave= 0; }
574
635
  bool test_limit();
575
636
 
576
637
  friend void lex_start(Session *session);
577
 
  Select_Lex() : n_sum_items(0), n_child_sum_items(0) {}
 
638
  st_select_lex() : n_sum_items(0), n_child_sum_items(0) {}
578
639
  void make_empty_select()
579
640
  {
580
641
    init_query();
589
650
  void fix_prepare_information(Session *session, Item **conds, Item **having_conds);
590
651
  /*
591
652
    Destroy the used execution plan (JOIN) of this subtree (this
592
 
    Select_Lex and all nested Select_Lexes and Select_Lex_Units).
 
653
    SELECT_LEX and all nested SELECT_LEXes and SELECT_LEX_UNITs).
593
654
  */
594
655
  bool cleanup();
595
656
  /*
625
686
  /* a list of USE/FORCE/IGNORE INDEX */
626
687
  List<Index_hint> *index_hints;
627
688
};
 
689
typedef class st_select_lex SELECT_LEX;
628
690
 
629
 
inline bool Select_Lex_Unit::is_union ()
 
691
inline bool st_select_lex_unit::is_union ()
630
692
{
631
693
  return first_select()->next_select() &&
632
694
    first_select()->next_select()->linkage == UNION_TYPE;
1200
1262
class LEX : public Query_tables_list
1201
1263
{
1202
1264
public:
1203
 
  Select_Lex_Unit unit;                         /* most upper unit */
1204
 
  Select_Lex select_lex;                        /* first Select_Lex */
1205
 
  /* current Select_Lex in parsing */
1206
 
  Select_Lex *current_select;
1207
 
  /* list of all Select_Lex */
1208
 
  Select_Lex *all_selects_list;
 
1265
  SELECT_LEX_UNIT unit;                         /* most upper unit */
 
1266
  SELECT_LEX select_lex;                        /* first SELECT_LEX */
 
1267
  /* current SELECT_LEX in parsing */
 
1268
  SELECT_LEX *current_select;
 
1269
  /* list of all SELECT_LEX */
 
1270
  SELECT_LEX *all_selects_list;
1209
1271
 
1210
1272
  char *length,*dec,*change;
1211
1273
  LEX_STRING name;
 
1274
  char *help_arg;
 
1275
  char* to_log;                                 /* For PURGE MASTER LOGS TO */
1212
1276
  String *wild;
1213
 
  file_exchange *exchange;
 
1277
  sql_exchange *exchange;
1214
1278
  select_result *result;
1215
1279
  Item *default_value, *on_update_value;
1216
1280
  LEX_STRING comment, ident;
1227
1291
  List<Key_part_spec> col_list;
1228
1292
  List<Key_part_spec> ref_list;
1229
1293
  List<String>        interval_list;
1230
 
  List<Lex_Column>    columns;
 
1294
  List<LEX_COLUMN>    columns;
1231
1295
  List<Item>          *insert_list,field_list,value_list,update_list;
1232
1296
  List<List_item>     many_values;
1233
1297
  List<set_var_base>  var_list;
1248
1312
  List<Name_resolution_context> context_stack;
1249
1313
  List<LEX_STRING>     db_list;
1250
1314
 
1251
 
  SQL_LIST            auxiliary_table_list, save_list;
 
1315
  SQL_LIST            proc_list, auxiliary_table_list, save_list;
1252
1316
  Create_field        *last_field;
1253
1317
  Item_sum *in_sum_func;
1254
 
  Function_builder *udf;
 
1318
  udf_func udf;
1255
1319
  HA_CHECK_OPT   check_opt;                     // check/repair options
1256
1320
  HA_CREATE_INFO create_info;
1257
1321
  KEY_CREATE_INFO key_create_info;
 
1322
  LEX_MASTER_INFO mi;                           // used by CHANGE MASTER
1258
1323
  uint32_t type;
1259
1324
  /*
1260
1325
    This variable is used in post-parse stage to declare that sum-functions,
1315
1380
    query (0 if no derived tables, otherwise DERIVED_SUBQUERY).
1316
1381
  */
1317
1382
  uint8_t derived_tables;
1318
 
  bool drop_if_exists, drop_temporary, one_shot_set;
 
1383
  bool drop_if_exists, drop_temporary, local_file, one_shot_set;
1319
1384
  bool autocommit;
1320
1385
  bool verbose;
1321
1386
 
1418
1483
  { /* Never called */ }
1419
1484
};
1420
1485
 
 
1486
extern void lex_init(void);
 
1487
extern void lex_free(void);
1421
1488
extern void lex_start(Session *session);
1422
1489
extern void lex_end(LEX *lex);
1423
1490
 
1425
1492
 
1426
1493
extern bool is_lex_native_function(const LEX_STRING *name);
1427
1494
 
 
1495
int lex_casecmp(const char *s, const char *t, uint32_t len);
 
1496
 
1428
1497
/**
1429
1498
  @} (End of group Semantic_Analysis)
1430
1499
*/