~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/subselect.h

  • Committer: Brian Aker
  • Date: 2009-08-18 07:20:29 UTC
  • mfrom: (1117.1.9 merge)
  • Revision ID: brian@gaz-20090818072029-s9ch5lcmltxwidn7
Merge of Brian

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
26
26
#include <drizzled/comp_creator.h>
27
27
#include <drizzled/item/ref.h>
28
28
#include <drizzled/item/field.h>
29
 
#include <drizzled/item/bin_string.h>
30
 
#include <drizzled/util/test.h>
31
 
 
32
 
namespace drizzled
33
 
{
34
29
 
35
30
class Select_Lex;
36
31
class Select_Lex_Unit;
37
 
class Join;
 
32
class JOIN;
38
33
class select_result_interceptor;
39
34
class subselect_engine;
40
35
class subselect_hash_sj_engine;
56
51
  /* substitution instead of subselect in case of optimization */
57
52
  Item *substitution;
58
53
  /* unit of subquery */
 
54
public:
59
55
  Select_Lex_Unit *unit;
60
56
protected:
61
57
  /* engine that perform execution of subselect (single select or union) */
104
100
  {
105
101
    null_value= 1;
106
102
  }
107
 
  virtual trans_res select_transformer(Join *join);
 
103
  virtual trans_res select_transformer(JOIN *join);
108
104
  bool assigned() { return value_assigned; }
109
105
  void assigned(bool a) { value_assigned= a; }
110
106
  enum Type type() const;
178
174
  subs_type substype() { return SINGLEROW_SUBS; }
179
175
 
180
176
  void reset();
181
 
  trans_res select_transformer(Join *join);
 
177
  trans_res select_transformer(JOIN *join);
182
178
  void store(uint32_t i, Item* item);
183
179
  double val_real();
184
180
  int64_t val_int ();
185
181
  String *val_str (String *);
186
 
  type::Decimal *val_decimal(type::Decimal *);
 
182
  my_decimal *val_decimal(my_decimal *);
187
183
  bool val_bool();
188
184
  enum Item_result result_type() const;
189
185
  enum_field_types field_type() const;
214
210
};
215
211
 
216
212
/* used in static ALL/ANY optimization */
 
213
class select_max_min_finder_subselect;
217
214
class Item_maxmin_subselect :public Item_singlerow_subselect
218
215
{
219
216
protected:
250
247
  int64_t val_int();
251
248
  double val_real();
252
249
  String *val_str(String*);
253
 
  type::Decimal *val_decimal(type::Decimal *);
 
250
  my_decimal *val_decimal(my_decimal *);
254
251
  bool val_bool();
255
252
  void fix_length_and_dec();
256
253
  virtual void print(String *str, enum_query_type query_type);
335
332
 
336
333
  Item_in_subselect(Item * left_expr, Select_Lex *select_lex);
337
334
  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)
 
335
    :Item_exists_subselect(), left_expr_cache(0), first_execution(true),
 
336
    optimizer(0), abort_on_null(0), pushed_cond_guards(NULL),
 
337
    exec_method(NOT_TRANSFORMED), upper_item(0)
350
338
  {}
351
339
  void cleanup();
352
340
  subs_type substype() { return IN_SUBS; }
356
344
    null_value= 0;
357
345
    was_null= 0;
358
346
  }
359
 
  trans_res select_transformer(Join *join);
360
 
  trans_res select_in_like_transformer(Join *join, const Comp_creator *func);
361
 
  trans_res single_value_transformer(Join *join, const Comp_creator *func);
362
 
  trans_res row_value_transformer(Join * join);
363
 
  trans_res single_value_in_to_exists_transformer(Join * join,
 
347
  trans_res select_transformer(JOIN *join);
 
348
  trans_res select_in_like_transformer(JOIN *join, const Comp_creator *func);
 
349
  trans_res single_value_transformer(JOIN *join, const Comp_creator *func);
 
350
  trans_res row_value_transformer(JOIN * join);
 
351
  trans_res single_value_in_to_exists_transformer(JOIN * join,
364
352
                                                  const Comp_creator *func);
365
 
  trans_res row_value_in_to_exists_transformer(Join * join);
 
353
  trans_res row_value_in_to_exists_transformer(JOIN * join);
366
354
  virtual bool exec();
367
355
  int64_t val_int();
368
356
  double val_real();
369
357
  String *val_str(String*);
370
 
  type::Decimal *val_decimal(type::Decimal *);
 
358
  my_decimal *val_decimal(my_decimal *);
371
359
  void update_null_value () { (void) val_bool(); }
372
360
  bool val_bool();
373
361
  void top_level_item() { abort_on_null=1; }
400
388
 
401
389
  // only ALL subquery has upper not
402
390
  subs_type substype() { return all?ALL_SUBS:ANY_SUBS; }
403
 
  trans_res select_transformer(Join *join);
 
391
  trans_res select_transformer(JOIN *join);
404
392
  virtual void print(String *str, enum_query_type query_type);
405
393
};
406
394
 
407
395
 
408
 
class subselect_engine: public memory::SqlAlloc
 
396
class subselect_engine: public Sql_alloc
409
397
{
410
398
protected:
411
399
  select_result_interceptor *result; /* results storage class */
421
409
                         INDEXSUBQUERY_ENGINE, HASH_SJ_ENGINE};
422
410
 
423
411
  subselect_engine(Item_subselect *si, select_result_interceptor *res)
424
 
    :session(NULL)
 
412
    :session(0)
425
413
  {
426
414
    result= res;
427
415
    item= si;
429
417
    res_field_type= DRIZZLE_TYPE_VARCHAR;
430
418
    maybe_null= 0;
431
419
  }
432
 
  virtual ~subselect_engine() {} // to satisfy compiler
 
420
  virtual ~subselect_engine() {}; // to satisfy compiler
433
421
  virtual void cleanup()= 0;
434
422
 
435
423
  /*
462
450
  */
463
451
  virtual int exec()= 0;
464
452
  virtual uint32_t cols()= 0; /* return number of columns in select */
465
 
  virtual bool uncacheable()= 0; /* query is uncacheable */
466
 
  virtual bool uncacheable(uint32_t bit_pos)= 0; /* query is uncacheable */
 
453
  virtual uint8_t uncacheable()= 0; /* query is uncacheable */
467
454
  enum Item_result type() { return res_type; }
468
455
  enum_field_types field_type() { return res_field_type; }
469
456
  virtual void exclude()= 0;
470
 
  virtual bool may_be_null() { return maybe_null; }
 
457
  virtual bool may_be_null() { return maybe_null; };
471
458
  virtual table_map upper_select_const_tables()= 0;
472
459
  static table_map calc_const_tables(TableList *);
473
460
  virtual void print(String *str, enum_query_type query_type)= 0;
490
477
  bool optimized; /* simple subselect is optimized */
491
478
  bool executed; /* simple subselect is executed */
492
479
  Select_Lex *select_lex; /* corresponding select_lex */
493
 
  Join * join; /* corresponding JOIN structure */
 
480
  JOIN * join; /* corresponding JOIN structure */
494
481
public:
495
482
  subselect_single_select_engine(Select_Lex *select,
496
483
                                 select_result_interceptor *result,
500
487
  void fix_length_and_dec(Item_cache** row);
501
488
  int exec();
502
489
  uint32_t cols();
503
 
  bool uncacheable();
504
 
  bool uncacheable(uint32_t bit_pos);
 
490
  uint8_t uncacheable();
505
491
  void exclude();
506
492
  table_map upper_select_const_tables();
507
493
  virtual void print (String *str, enum_query_type query_type);
511
497
  bool is_executed() const { return executed; }
512
498
  bool no_rows();
513
499
  virtual enum_engine_type engine_type() { return SINGLE_SELECT_ENGINE; }
514
 
  bool save_join_if_explain();
515
500
 
516
501
  friend class subselect_hash_sj_engine;
517
502
  friend class Item_in_subselect;
530
515
  void fix_length_and_dec(Item_cache** row);
531
516
  int exec();
532
517
  uint32_t cols();
533
 
  bool uncacheable();
534
 
  bool uncacheable(uint32_t bit_pos);
 
518
  uint8_t uncacheable();
535
519
  void exclude();
536
520
  table_map upper_select_const_tables();
537
521
  virtual void print (String *str, enum_query_type query_type);
576
560
  bool null_keypart; /* TRUE <=> constructed search tuple has a NULL */
577
561
public:
578
562
 
579
 
  // constructor can assign Session because it will be called after Join::prepare
 
563
  // constructor can assign Session because it will be called after JOIN::prepare
580
564
  subselect_uniquesubquery_engine(Session *session_arg, JoinTable *tab_arg,
581
565
                                  Item_subselect *subs, Item *where)
582
566
    :subselect_engine(subs, 0), tab(tab_arg), cond(where)
588
572
  void fix_length_and_dec(Item_cache** row);
589
573
  int exec();
590
574
  uint32_t cols() { return 1; }
591
 
  bool uncacheable() { return true; }
592
 
  bool uncacheable(uint32_t) { return true; }
 
575
  uint8_t uncacheable() { return UNCACHEABLE_DEPENDENT; }
593
576
  void exclude();
594
577
  table_map upper_select_const_tables() { return 0; }
595
578
  virtual void print (String *str, enum_query_type query_type);
638
621
  Item *having;
639
622
public:
640
623
 
641
 
  // constructor can assign Session because it will be called after Join::prepare
 
624
  // constructor can assign Session because it will be called after JOIN::prepare
642
625
  subselect_indexsubquery_engine(Session *session_arg, JoinTable *tab_arg,
643
626
                                 Item_subselect *subs, Item *where,
644
627
                                 Item *having_arg, bool chk_null)
686
669
    QEP to execute the subquery and materialize its result into a
687
670
    temporary table. Created during the first call to exec().
688
671
  */
689
 
  Join *materialize_join;
 
672
  JOIN *materialize_join;
690
673
  /* Temp table context of the outer select's JOIN. */
691
674
  Tmp_Table_Param *tmp_param;
692
675
 
712
695
  virtual enum_engine_type engine_type() { return HASH_SJ_ENGINE; }
713
696
};
714
697
 
715
 
} /* namespace drizzled */
716
 
 
717
698
#endif /* DRIZZLED_ITEM_SUBSELECT_H */