~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/subselect.h

  • Committer: Brian Aker
  • Date: 2008-12-19 07:02:38 UTC
  • Revision ID: brian@tangent.org-20081219070238-569uxp3vsr6r37v1
Updated/fix to foreign key test.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
/* subselect Item */
24
24
 
25
25
 
26
 
#include "drizzled/comp_creator.h"
27
 
#include "drizzled/item/ref.h"
28
 
#include "drizzled/item/field.h"
29
 
#include "drizzled/item/bin_string.h"
30
 
 
31
 
namespace drizzled
32
 
{
33
 
 
34
 
class Select_Lex;
35
 
class Select_Lex_Unit;
 
26
#include <drizzled/comp_creator.h>
 
27
#include <drizzled/item/ref.h>
 
28
 
 
29
class st_select_lex;
 
30
class st_select_lex_unit;
36
31
class JOIN;
37
32
class select_result_interceptor;
38
33
class subselect_engine;
41
36
class Cached_item;
42
37
class Item_in_optimizer;
43
38
class Item_func_not_all;
44
 
class Tmp_Table_Param;
 
39
class TMP_TABLE_PARAM;
45
40
 
46
41
 
47
42
/* base class for subselects */
55
50
  /* substitution instead of subselect in case of optimization */
56
51
  Item *substitution;
57
52
  /* unit of subquery */
58
 
  Select_Lex_Unit *unit;
 
53
public:
 
54
  st_select_lex_unit *unit;
59
55
protected:
60
56
  /* engine that perform execution of subselect (single select or union) */
61
57
  subselect_engine *engine;
94
90
    pointer in constructor initialization list, but we need to pass a pointer
95
91
    to subselect Item class to select_result_interceptor's constructor.
96
92
  */
97
 
  virtual void init (Select_Lex *select_lex,
 
93
  virtual void init (st_select_lex *select_lex,
98
94
                     select_result_interceptor *result);
99
95
 
100
96
  ~Item_subselect();
147
143
  bool walk(Item_processor processor, bool walk_subquery, unsigned char *arg);
148
144
 
149
145
  /**
150
 
    Get the Select_Lex structure associated with this Item.
151
 
    @return the Select_Lex structure associated with this Item
 
146
    Get the SELECT_LEX structure associated with this Item.
 
147
    @return the SELECT_LEX structure associated with this Item
152
148
  */
153
 
  Select_Lex* get_select_lex();
 
149
  st_select_lex* get_select_lex();
154
150
 
155
151
  friend class select_result_interceptor;
156
152
  friend class Item_in_optimizer;
158
154
  friend int  Item_field::fix_outer_field(Session *, Field **, Item **);
159
155
  friend bool Item_ref::fix_fields(Session *, Item **);
160
156
  friend void mark_select_range_as_dependent(Session*,
161
 
                                             Select_Lex*, Select_Lex*,
 
157
                                             st_select_lex*, st_select_lex*,
162
158
                                             Field*, Item*, Item_ident*);
163
159
};
164
160
 
170
166
protected:
171
167
  Item_cache *value, **row;
172
168
public:
173
 
  Item_singlerow_subselect(Select_Lex *select_lex);
 
169
  Item_singlerow_subselect(st_select_lex *select_lex);
174
170
  Item_singlerow_subselect() :Item_subselect(), value(0), row (0) {}
175
171
 
176
172
  void cleanup();
201
197
    The only caller of this method is handle_sql2003_note184_exception(),
202
198
    see the code there for more details.
203
199
    Note that this method breaks the object internal integrity, by
204
 
    removing it's association with the corresponding Select_Lex,
 
200
    removing it's association with the corresponding SELECT_LEX,
205
201
    making this object orphan from the parse tree.
206
202
    No other method, beside the destructor, should be called on this
207
203
    object, as it is now invalid.
208
 
    @return the Select_Lex structure that was given in the constructor.
 
204
    @return the SELECT_LEX structure that was given in the constructor.
209
205
  */
210
 
  Select_Lex* invalidate_and_restore_select_lex();
 
206
  st_select_lex* invalidate_and_restore_select_lex();
211
207
 
212
208
  friend class select_singlerow_subselect;
213
209
};
221
217
  bool was_values;  // Set if we have found at least one row
222
218
public:
223
219
  Item_maxmin_subselect(Session *session, Item_subselect *parent,
224
 
                        Select_Lex *select_lex, bool max);
 
220
                        st_select_lex *select_lex, bool max);
225
221
  virtual void print(String *str, enum_query_type query_type);
226
222
  void cleanup();
227
223
  bool any_value() { return was_values; }
237
233
  bool value; /* value of this item (boolean: exists/not-exists) */
238
234
 
239
235
public:
240
 
  Item_exists_subselect(Select_Lex *select_lex);
 
236
  Item_exists_subselect(st_select_lex *select_lex);
241
237
  Item_exists_subselect(): Item_subselect() {}
242
238
 
243
239
  subs_type substype() { return EXISTS_SUBS; }
333
329
 
334
330
  Item_func_not_all *upper_item; // point on NOT/NOP before ALL/SOME subquery
335
331
 
336
 
  Item_in_subselect(Item * left_expr, Select_Lex *select_lex);
 
332
  Item_in_subselect(Item * left_expr, st_select_lex *select_lex);
337
333
  Item_in_subselect()
338
 
    :
339
 
      Item_exists_subselect(),
340
 
      left_expr(NULL),
341
 
      left_expr_cache(NULL),
342
 
      first_execution(true),
343
 
      optimizer(NULL),
344
 
      abort_on_null(false),
345
 
      pushed_cond_guards(NULL),
346
 
      sj_convert_priority(0),
347
 
      expr_join_nest(NULL),
348
 
      exec_method(NOT_TRANSFORMED),
349
 
      upper_item(NULL)
 
334
    :Item_exists_subselect(), left_expr_cache(0), first_execution(true),
 
335
    optimizer(0), abort_on_null(0), pushed_cond_guards(NULL),
 
336
    exec_method(NOT_TRANSFORMED), upper_item(0)
350
337
  {}
351
338
  void cleanup();
352
339
  subs_type substype() { return IN_SUBS; }
372
359
  bool val_bool();
373
360
  void top_level_item() { abort_on_null=1; }
374
361
  inline bool is_top_level_item() { return abort_on_null; }
375
 
  bool test_limit(Select_Lex_Unit *unit);
 
362
  bool test_limit(st_select_lex_unit *unit);
376
363
  virtual void print(String *str, enum_query_type query_type);
377
364
  bool fix_fields(Session *session, Item **ref);
378
365
  bool setup_engine();
396
383
  bool all;
397
384
 
398
385
  Item_allany_subselect(Item * left_expr, chooser_compare_func_creator fc,
399
 
                        Select_Lex *select_lex, bool all);
 
386
                        st_select_lex *select_lex, bool all);
400
387
 
401
388
  // only ALL subquery has upper not
402
389
  subs_type substype() { return all?ALL_SUBS:ANY_SUBS; }
405
392
};
406
393
 
407
394
 
408
 
class subselect_engine: public memory::SqlAlloc
 
395
class subselect_engine: public Sql_alloc
409
396
{
410
397
protected:
411
398
  select_result_interceptor *result; /* results storage class */
421
408
                         INDEXSUBQUERY_ENGINE, HASH_SJ_ENGINE};
422
409
 
423
410
  subselect_engine(Item_subselect *si, select_result_interceptor *res)
424
 
    :session(NULL)
 
411
    :session(0)
425
412
  {
426
413
    result= res;
427
414
    item= si;
488
475
  bool prepared; /* simple subselect is prepared */
489
476
  bool optimized; /* simple subselect is optimized */
490
477
  bool executed; /* simple subselect is executed */
491
 
  Select_Lex *select_lex; /* corresponding select_lex */
 
478
  st_select_lex *select_lex; /* corresponding select_lex */
492
479
  JOIN * join; /* corresponding JOIN structure */
493
480
public:
494
 
  subselect_single_select_engine(Select_Lex *select,
 
481
  subselect_single_select_engine(st_select_lex *select,
495
482
                                 select_result_interceptor *result,
496
483
                                 Item_subselect *item);
497
484
  void cleanup();
517
504
 
518
505
class subselect_union_engine: public subselect_engine
519
506
{
520
 
  Select_Lex_Unit *unit;  /* corresponding unit structure */
 
507
  st_select_lex_unit *unit;  /* corresponding unit structure */
521
508
public:
522
 
  subselect_union_engine(Select_Lex_Unit *u,
 
509
  subselect_union_engine(st_select_lex_unit *u,
523
510
                         select_result_interceptor *result,
524
511
                         Item_subselect *item);
525
512
  void cleanup();
539
526
};
540
527
 
541
528
 
542
 
class JoinTable;
 
529
struct st_join_table;
543
530
 
544
531
 
545
532
/*
562
549
class subselect_uniquesubquery_engine: public subselect_engine
563
550
{
564
551
protected:
565
 
  JoinTable *tab;
 
552
  st_join_table *tab;
566
553
  Item *cond; /* The WHERE condition of subselect */
567
554
  /*
568
555
    TRUE<=> last execution produced empty set. Valid only when left
573
560
public:
574
561
 
575
562
  // constructor can assign Session because it will be called after JOIN::prepare
576
 
  subselect_uniquesubquery_engine(Session *session_arg, JoinTable *tab_arg,
 
563
  subselect_uniquesubquery_engine(Session *session_arg, st_join_table *tab_arg,
577
564
                                  Item_subselect *subs, Item *where)
578
565
    :subselect_engine(subs, 0), tab(tab_arg), cond(where)
579
566
  {
634
621
public:
635
622
 
636
623
  // constructor can assign Session because it will be called after JOIN::prepare
637
 
  subselect_indexsubquery_engine(Session *session_arg, JoinTable *tab_arg,
 
624
  subselect_indexsubquery_engine(Session *session_arg, st_join_table *tab_arg,
638
625
                                 Item_subselect *subs, Item *where,
639
626
                                 Item *having_arg, bool chk_null)
640
627
    :subselect_uniquesubquery_engine(session_arg, tab_arg, subs, where),
683
670
  */
684
671
  JOIN *materialize_join;
685
672
  /* Temp table context of the outer select's JOIN. */
686
 
  Tmp_Table_Param *tmp_param;
 
673
  TMP_TABLE_PARAM *tmp_param;
687
674
 
688
675
public:
689
 
  subselect_hash_sj_engine(Session *session_in, Item_subselect *in_predicate,
 
676
  subselect_hash_sj_engine(Session *session, Item_subselect *in_predicate,
690
677
                               subselect_single_select_engine *old_engine)
691
 
    :subselect_uniquesubquery_engine(session_in, NULL, in_predicate, NULL),
 
678
    :subselect_uniquesubquery_engine(session, NULL, in_predicate, NULL),
692
679
    is_materialized(false), materialize_engine(old_engine),
693
680
    materialize_join(NULL), tmp_param(NULL)
694
681
  {}
707
694
  virtual enum_engine_type engine_type() { return HASH_SJ_ENGINE; }
708
695
};
709
696
 
710
 
} /* namespace drizzled */
711
 
 
712
697
#endif /* DRIZZLED_ITEM_SUBSELECT_H */