~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/subselect.h

  • Committer: Padraig O'Sullivan
  • Date: 2009-09-18 00:22:38 UTC
  • mto: This revision was merged to the branch mainline in revision 1139.
  • Revision ID: osullivan.padraig@gmail.com-20090918002238-zq7mui4r2yzoidz1
Extracted KeyUse into its own header file and placed it within the
drizzled::optimizer namespace.

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
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
 
#include "drizzled/util/test.h"
31
 
 
32
 
namespace drizzled
33
 
{
 
26
#include <drizzled/comp_creator.h>
 
27
#include <drizzled/item/ref.h>
 
28
#include <drizzled/item/field.h>
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;
251
247
  int64_t val_int();
252
248
  double val_real();
253
249
  String *val_str(String*);
254
 
  type::Decimal *val_decimal(type::Decimal *);
 
250
  my_decimal *val_decimal(my_decimal *);
255
251
  bool val_bool();
256
252
  void fix_length_and_dec();
257
253
  virtual void print(String *str, enum_query_type query_type);
336
332
 
337
333
  Item_in_subselect(Item * left_expr, Select_Lex *select_lex);
338
334
  Item_in_subselect()
339
 
    :
340
 
      Item_exists_subselect(),
341
 
      left_expr(NULL),
342
 
      left_expr_cache(NULL),
343
 
      first_execution(true),
344
 
      optimizer(NULL),
345
 
      abort_on_null(false),
346
 
      pushed_cond_guards(NULL),
347
 
      sj_convert_priority(0),
348
 
      expr_join_nest(NULL),
349
 
      exec_method(NOT_TRANSFORMED),
350
 
      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)
351
338
  {}
352
339
  void cleanup();
353
340
  subs_type substype() { return IN_SUBS; }
357
344
    null_value= 0;
358
345
    was_null= 0;
359
346
  }
360
 
  trans_res select_transformer(Join *join);
361
 
  trans_res select_in_like_transformer(Join *join, const Comp_creator *func);
362
 
  trans_res single_value_transformer(Join *join, const Comp_creator *func);
363
 
  trans_res row_value_transformer(Join * join);
364
 
  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,
365
352
                                                  const Comp_creator *func);
366
 
  trans_res row_value_in_to_exists_transformer(Join * join);
 
353
  trans_res row_value_in_to_exists_transformer(JOIN * join);
367
354
  virtual bool exec();
368
355
  int64_t val_int();
369
356
  double val_real();
370
357
  String *val_str(String*);
371
 
  type::Decimal *val_decimal(type::Decimal *);
 
358
  my_decimal *val_decimal(my_decimal *);
372
359
  void update_null_value () { (void) val_bool(); }
373
360
  bool val_bool();
374
361
  void top_level_item() { abort_on_null=1; }
401
388
 
402
389
  // only ALL subquery has upper not
403
390
  subs_type substype() { return all?ALL_SUBS:ANY_SUBS; }
404
 
  trans_res select_transformer(Join *join);
 
391
  trans_res select_transformer(JOIN *join);
405
392
  virtual void print(String *str, enum_query_type query_type);
406
393
};
407
394
 
408
395
 
409
 
class subselect_engine: public memory::SqlAlloc
 
396
class subselect_engine: public Sql_alloc
410
397
{
411
398
protected:
412
399
  select_result_interceptor *result; /* results storage class */
422
409
                         INDEXSUBQUERY_ENGINE, HASH_SJ_ENGINE};
423
410
 
424
411
  subselect_engine(Item_subselect *si, select_result_interceptor *res)
425
 
    :session(NULL)
 
412
    :session(0)
426
413
  {
427
414
    result= res;
428
415
    item= si;
430
417
    res_field_type= DRIZZLE_TYPE_VARCHAR;
431
418
    maybe_null= 0;
432
419
  }
433
 
  virtual ~subselect_engine() {} // to satisfy compiler
 
420
  virtual ~subselect_engine() {}; // to satisfy compiler
434
421
  virtual void cleanup()= 0;
435
422
 
436
423
  /*
463
450
  */
464
451
  virtual int exec()= 0;
465
452
  virtual uint32_t cols()= 0; /* return number of columns in select */
466
 
  virtual bool uncacheable()= 0; /* query is uncacheable */
467
 
  virtual bool uncacheable(uint32_t bit_pos)= 0; /* query is uncacheable */
 
453
  virtual uint8_t uncacheable()= 0; /* query is uncacheable */
468
454
  enum Item_result type() { return res_type; }
469
455
  enum_field_types field_type() { return res_field_type; }
470
456
  virtual void exclude()= 0;
471
 
  virtual bool may_be_null() { return maybe_null; }
 
457
  virtual bool may_be_null() { return maybe_null; };
472
458
  virtual table_map upper_select_const_tables()= 0;
473
459
  static table_map calc_const_tables(TableList *);
474
460
  virtual void print(String *str, enum_query_type query_type)= 0;
491
477
  bool optimized; /* simple subselect is optimized */
492
478
  bool executed; /* simple subselect is executed */
493
479
  Select_Lex *select_lex; /* corresponding select_lex */
494
 
  Join * join; /* corresponding JOIN structure */
 
480
  JOIN * join; /* corresponding JOIN structure */
495
481
public:
496
482
  subselect_single_select_engine(Select_Lex *select,
497
483
                                 select_result_interceptor *result,
501
487
  void fix_length_and_dec(Item_cache** row);
502
488
  int exec();
503
489
  uint32_t cols();
504
 
  bool uncacheable();
505
 
  bool uncacheable(uint32_t bit_pos);
 
490
  uint8_t uncacheable();
506
491
  void exclude();
507
492
  table_map upper_select_const_tables();
508
493
  virtual void print (String *str, enum_query_type query_type);
512
497
  bool is_executed() const { return executed; }
513
498
  bool no_rows();
514
499
  virtual enum_engine_type engine_type() { return SINGLE_SELECT_ENGINE; }
515
 
  bool save_join_if_explain();
516
500
 
517
501
  friend class subselect_hash_sj_engine;
518
502
  friend class Item_in_subselect;
531
515
  void fix_length_and_dec(Item_cache** row);
532
516
  int exec();
533
517
  uint32_t cols();
534
 
  bool uncacheable();
535
 
  bool uncacheable(uint32_t bit_pos);
 
518
  uint8_t uncacheable();
536
519
  void exclude();
537
520
  table_map upper_select_const_tables();
538
521
  virtual void print (String *str, enum_query_type query_type);
577
560
  bool null_keypart; /* TRUE <=> constructed search tuple has a NULL */
578
561
public:
579
562
 
580
 
  // 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
581
564
  subselect_uniquesubquery_engine(Session *session_arg, JoinTable *tab_arg,
582
565
                                  Item_subselect *subs, Item *where)
583
566
    :subselect_engine(subs, 0), tab(tab_arg), cond(where)
589
572
  void fix_length_and_dec(Item_cache** row);
590
573
  int exec();
591
574
  uint32_t cols() { return 1; }
592
 
  bool uncacheable() { return true; }
593
 
  bool uncacheable(uint32_t) { return true; }
 
575
  uint8_t uncacheable() { return UNCACHEABLE_DEPENDENT; }
594
576
  void exclude();
595
577
  table_map upper_select_const_tables() { return 0; }
596
578
  virtual void print (String *str, enum_query_type query_type);
639
621
  Item *having;
640
622
public:
641
623
 
642
 
  // 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
643
625
  subselect_indexsubquery_engine(Session *session_arg, JoinTable *tab_arg,
644
626
                                 Item_subselect *subs, Item *where,
645
627
                                 Item *having_arg, bool chk_null)
687
669
    QEP to execute the subquery and materialize its result into a
688
670
    temporary table. Created during the first call to exec().
689
671
  */
690
 
  Join *materialize_join;
 
672
  JOIN *materialize_join;
691
673
  /* Temp table context of the outer select's JOIN. */
692
674
  Tmp_Table_Param *tmp_param;
693
675
 
713
695
  virtual enum_engine_type engine_type() { return HASH_SJ_ENGINE; }
714
696
};
715
697
 
716
 
} /* namespace drizzled */
717
 
 
718
698
#endif /* DRIZZLED_ITEM_SUBSELECT_H */