~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/item_subselect.h

  • Committer: Brian Aker
  • Date: 2008-07-07 14:25:25 UTC
  • mto: (77.1.25 codestyle)
  • mto: This revision was merged to the branch mainline in revision 82.
  • Revision ID: brian@tangent.org-20080707142525-xzy2nl3ie2ebwfln
LL() cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
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
 
 */
 
1
/* Copyright (C) 2000 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
19
15
 
20
16
/* subselect Item */
21
17
 
 
18
#ifdef USE_PRAGMA_INTERFACE
 
19
#pragma interface                       /* gcc class implementation */
 
20
#endif
22
21
 
23
22
class st_select_lex;
24
23
class st_select_lex_unit;
33
32
 
34
33
class Item_subselect :public Item_result_field
35
34
{
36
 
  bool value_assigned; /* value already assigned to subselect */
 
35
  my_bool value_assigned; /* value already assigned to subselect */
37
36
public:
38
37
  /* thread handler, will be assigned in fix_fields only */
39
38
  THD *thd;
50
49
  /* cache of used external tables */
51
50
  table_map used_tables_cache;
52
51
  /* allowed number of columns (1 for single value subqueries) */
53
 
  uint32_t max_columns;
 
52
  uint max_columns;
54
53
  /* where subquery is placed */
55
54
  enum_parsing_place parsing_place;
56
55
  /* work with 'substitution' */
109
108
  Item *get_tmp_table_item(THD *thd);
110
109
  void update_used_tables();
111
110
  virtual void print(String *str, enum_query_type query_type);
112
 
  virtual bool have_guarded_conds() { return false; }
 
111
  virtual bool have_guarded_conds() { return FALSE; }
113
112
  bool change_engine(subselect_engine *eng)
114
113
  {
115
114
    old_engine= engine;
130
129
  */
131
130
  virtual void reset_value_registration() {}
132
131
  enum_parsing_place place() { return parsing_place; }
133
 
  bool walk(Item_processor processor, bool walk_subquery, unsigned char *arg);
 
132
  bool walk(Item_processor processor, bool walk_subquery, uchar *arg);
134
133
 
135
134
  /**
136
135
    Get the SELECT_LEX structure associated with this Item.
164
163
 
165
164
  void reset();
166
165
  trans_res select_transformer(JOIN *join);
167
 
  void store(uint32_t i, Item* item);
 
166
  void store(uint i, Item* item);
168
167
  double val_real();
169
 
  int64_t val_int ();
 
168
  longlong val_int ();
170
169
  String *val_str (String *);
171
170
  my_decimal *val_decimal(my_decimal *);
172
171
  bool val_bool();
174
173
  enum_field_types field_type() const;
175
174
  void fix_length_and_dec();
176
175
 
177
 
  uint32_t cols();
178
 
  Item* element_index(uint32_t i) { return reinterpret_cast<Item*>(row[i]); }
179
 
  Item** addr(uint32_t i) { return (Item**)row + i; }
180
 
  bool check_cols(uint32_t c);
 
176
  uint cols();
 
177
  Item* element_index(uint i) { return my_reinterpret_cast(Item*)(row[i]); }
 
178
  Item** addr(uint i) { return (Item**)row + i; }
 
179
  bool check_cols(uint c);
181
180
  bool null_inside();
182
181
  void bring_value();
183
182
 
211
210
  virtual void print(String *str, enum_query_type query_type);
212
211
  void cleanup();
213
212
  bool any_value() { return was_values; }
214
 
  void register_value() { was_values= true; }
215
 
  void reset_value_registration() { was_values= false; }
 
213
  void register_value() { was_values= TRUE; }
 
214
  void reset_value_registration() { was_values= FALSE; }
216
215
};
217
216
 
218
217
/* exists subselect */
233
232
  }
234
233
 
235
234
  enum Item_result result_type() const { return INT_RESULT;}
236
 
  int64_t val_int();
 
235
  longlong val_int();
237
236
  double val_real();
238
237
  String *val_str(String*);
239
238
  my_decimal *val_decimal(my_decimal *);
293
292
  /* 
294
293
    Location of the subquery predicate. It is either
295
294
     - pointer to join nest if the subquery predicate is in the ON expression
296
 
     - (TableList*)1 if the predicate is in the WHERE.
 
295
     - (TABLE_LIST*)1 if the predicate is in the WHERE.
297
296
  */
298
 
  TableList *expr_join_nest;
 
297
  TABLE_LIST *expr_join_nest;
299
298
 
300
299
  /* The method chosen to execute the IN predicate.  */
301
300
  enum enum_exec_method {
321
320
 
322
321
  Item_in_subselect(Item * left_expr, st_select_lex *select_lex);
323
322
  Item_in_subselect()
324
 
    :Item_exists_subselect(), left_expr_cache(0), first_execution(true),
 
323
    :Item_exists_subselect(), left_expr_cache(0), first_execution(TRUE),
325
324
    optimizer(0), abort_on_null(0), pushed_cond_guards(NULL),
326
325
    exec_method(NOT_TRANSFORMED), upper_item(0)
327
326
  {}
341
340
                                                  Comp_creator *func);
342
341
  trans_res row_value_in_to_exists_transformer(JOIN * join);
343
342
  virtual bool exec();
344
 
  int64_t val_int();
 
343
  longlong val_int();
345
344
  double val_real();
346
345
  String *val_str(String*);
347
346
  my_decimal *val_decimal(my_decimal *);
354
353
  bool fix_fields(THD *thd, Item **ref);
355
354
  bool setup_engine();
356
355
  bool init_left_expr_cache();
357
 
  bool is_expensive_processor(unsigned char *arg);
 
356
  bool is_expensive_processor(uchar *arg);
358
357
 
359
358
  friend class Item_ref_null_helper;
360
359
  friend class Item_is_not_null_test;
403
402
    result= res;
404
403
    item= si;
405
404
    res_type= STRING_RESULT;
406
 
    res_field_type= DRIZZLE_TYPE_VARCHAR;
 
405
    res_field_type= MYSQL_TYPE_VAR_STRING;
407
406
    maybe_null= 0;
408
407
  }
409
408
  virtual ~subselect_engine() {}; // to satisfy compiler
438
437
          caller should call exec() again for the new engine.
439
438
  */
440
439
  virtual int exec()= 0;
441
 
  virtual uint32_t cols()= 0; /* return number of columns in select */
442
 
  virtual uint8_t uncacheable()= 0; /* query is uncacheable */
 
440
  virtual uint cols()= 0; /* return number of columns in select */
 
441
  virtual uint8 uncacheable()= 0; /* query is uncacheable */
443
442
  enum Item_result type() { return res_type; }
444
443
  enum_field_types field_type() { return res_field_type; }
445
444
  virtual void exclude()= 0;
446
445
  virtual bool may_be_null() { return maybe_null; };
447
446
  virtual table_map upper_select_const_tables()= 0;
448
 
  static table_map calc_const_tables(TableList *);
 
447
  static table_map calc_const_tables(TABLE_LIST *);
449
448
  virtual void print(String *str, enum_query_type query_type)= 0;
450
449
  virtual bool change_result(Item_subselect *si,
451
450
                             select_result_interceptor *result)= 0;
452
451
  virtual bool no_tables()= 0;
453
 
  virtual bool is_executed() const { return false; }
 
452
  virtual bool is_executed() const { return FALSE; }
454
453
  /* Check if subquery produced any rows during last query execution */
455
454
  virtual bool no_rows() = 0;
456
455
  virtual enum_engine_type engine_type() { return ABSTRACT_ENGINE; }
462
461
 
463
462
class subselect_single_select_engine: public subselect_engine
464
463
{
465
 
  bool prepared; /* simple subselect is prepared */
466
 
  bool optimized; /* simple subselect is optimized */
467
 
  bool executed; /* simple subselect is executed */
 
464
  my_bool prepared; /* simple subselect is prepared */
 
465
  my_bool optimized; /* simple subselect is optimized */
 
466
  my_bool executed; /* simple subselect is executed */
468
467
  st_select_lex *select_lex; /* corresponding select_lex */
469
468
  JOIN * join; /* corresponding JOIN structure */
470
469
public:
475
474
  int prepare();
476
475
  void fix_length_and_dec(Item_cache** row);
477
476
  int exec();
478
 
  uint32_t cols();
479
 
  uint8_t uncacheable();
 
477
  uint cols();
 
478
  uint8 uncacheable();
480
479
  void exclude();
481
480
  table_map upper_select_const_tables();
482
481
  virtual void print (String *str, enum_query_type query_type);
503
502
  int prepare();
504
503
  void fix_length_and_dec(Item_cache** row);
505
504
  int exec();
506
 
  uint32_t cols();
507
 
  uint8_t uncacheable();
 
505
  uint cols();
 
506
  uint8 uncacheable();
508
507
  void exclude();
509
508
  table_map upper_select_const_tables();
510
509
  virtual void print (String *str, enum_query_type query_type);
560
559
  int prepare();
561
560
  void fix_length_and_dec(Item_cache** row);
562
561
  int exec();
563
 
  uint32_t cols() { return 1; }
564
 
  uint8_t uncacheable() { return UNCACHEABLE_DEPENDENT; }
 
562
  uint cols() { return 1; }
 
563
  uint8 uncacheable() { return UNCACHEABLE_DEPENDENT; }
565
564
  void exclude();
566
565
  table_map upper_select_const_tables() { return 0; }
567
566
  virtual void print (String *str, enum_query_type query_type);
666
665
  subselect_hash_sj_engine(THD *thd, Item_subselect *in_predicate,
667
666
                               subselect_single_select_engine *old_engine)
668
667
    :subselect_uniquesubquery_engine(thd, NULL, in_predicate, NULL),
669
 
    is_materialized(false), materialize_engine(old_engine),
 
668
    is_materialized(FALSE), materialize_engine(old_engine),
670
669
    materialize_join(NULL), tmp_param(NULL)
671
670
  {}
672
671
  ~subselect_hash_sj_engine();
677
676
  int prepare() { return 0; }
678
677
  int exec();
679
678
  virtual void print (String *str, enum_query_type query_type);
680
 
  uint32_t cols()
 
679
  uint cols()
681
680
  {
682
681
    return materialize_engine->cols();
683
682
  }