1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
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.
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.
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
1
/* Copyright (C) 2000 MySQL AB
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.
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.
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 */
20
16
/* subselect Item */
18
#ifdef USE_PRAGMA_INTERFACE
19
#pragma interface /* gcc class implementation */
23
22
class st_select_lex;
24
23
class st_select_lex_unit;
34
33
class Item_subselect :public Item_result_field
36
bool value_assigned; /* value already assigned to subselect */
35
my_bool value_assigned; /* value already assigned to subselect */
38
37
/* thread handler, will be assigned in fix_fields only */
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) */
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)
115
114
old_engine= engine;
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);
136
135
Get the SELECT_LEX structure associated with this Item.
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();
170
169
String *val_str (String *);
171
170
my_decimal *val_decimal(my_decimal *);
174
173
enum_field_types field_type() const;
175
174
void fix_length_and_dec();
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);
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();
211
210
virtual void print(String *str, enum_query_type query_type);
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; }
218
217
/* exists subselect */
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.
298
TableList *expr_join_nest;
297
TABLE_LIST *expr_join_nest;
300
299
/* The method chosen to execute the IN predicate. */
301
300
enum enum_exec_method {
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)
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);
359
358
friend class Item_ref_null_helper;
360
359
friend class Item_is_not_null_test;
438
437
caller should call exec() again for the new engine.
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; }
463
462
class subselect_single_select_engine: public subselect_engine
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 */
561
560
void fix_length_and_dec(Item_cache** row);
563
uint32_t cols() { return 1; }
564
uint8_t uncacheable() { return UNCACHEABLE_DEPENDENT; }
562
uint cols() { return 1; }
563
uint8 uncacheable() { return UNCACHEABLE_DEPENDENT; }
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)
672
671
~subselect_hash_sj_engine();