1 #ifndef ITEM_SUBSELECT_INCLUDED
2 #define ITEM_SUBSELECT_INCLUDED
22 class st_select_lex_unit;
24 class select_result_interceptor;
31 typedef class st_select_lex SELECT_LEX;
37 typedef Comp_creator* (*chooser_compare_func_creator)(
bool invert);
68 st_select_lex_unit *unit;
84 table_map used_tables_cache;
88 enum_parsing_place parsing_place;
90 bool have_to_be_excluded;
92 bool const_item_cache;
100 enum trans_res {RES_OK, RES_REDUCE, RES_ERROR};
101 enum subs_type {UNKNOWN_SUBS, SINGLEROW_SUBS,
102 EXISTS_SUBS, IN_SUBS, ALL_SUBS, ANY_SUBS};
106 virtual subs_type substype() {
return UNKNOWN_SUBS; }
113 virtual void init (st_select_lex *select_lex,
114 select_result_interceptor *result);
117 virtual void cleanup();
122 virtual trans_res select_transformer(
JOIN *join);
123 bool assigned()
const {
return value_assigned; }
124 void assigned(
bool a) { value_assigned= a; }
125 enum Type type()
const;
131 bool fix_fields(THD *thd,
Item **ref);
133 st_select_lex *removed_select);
135 virtual void fix_length_and_dec();
136 table_map used_tables()
const;
137 table_map not_null_tables()
const {
return 0; }
138 bool const_item()
const;
139 inline table_map get_used_tables_cache() {
return used_tables_cache; }
140 inline bool get_const_item_cache() {
return const_item_cache; }
141 Item *get_tmp_table_item(THD *thd);
142 void update_used_tables();
143 virtual void print(
String *str, enum_query_type query_type);
144 virtual bool have_guarded_conds() {
return FALSE; }
157 bool is_evaluated()
const;
158 bool is_uncacheable()
const;
164 virtual void reset_value_registration() {}
165 enum_parsing_place place() {
return parsing_place; }
167 bool walk_subquery, uchar *argument);
168 bool walk_body(Item_processor processor,
bool walk_subquery, uchar *arg);
169 bool walk(Item_processor processor,
bool walk_subquery, uchar *arg);
174 const char *func_name()
const { DBUG_ASSERT(0);
return "subselect"; }
176 friend class select_result_interceptor;
182 st_select_lex *removed_selec);
183 friend void mark_select_range_as_dependent(THD*,
184 st_select_lex*, st_select_lex*,
201 virtual void cleanup();
202 subs_type substype() {
return SINGLEROW_SUBS; }
204 virtual void reset();
206 void store(uint
i,
Item* item);
211 bool get_date(
MYSQL_TIME *ltime, uint fuzzydate);
214 enum Item_result result_type()
const;
215 enum_field_types field_type()
const;
216 void fix_length_and_dec();
223 virtual void no_rows_in_result();
226 Item* element_index(uint
i) {
return reinterpret_cast<Item*
>(row[
i]); }
227 Item** addr(uint
i) {
return (
Item**)row +
i; }
228 bool check_cols(uint c);
246 friend class select_singlerow_subselect;
250 class select_max_min_finder_subselect;
258 st_select_lex *select_lex,
bool max,
bool ignore_nulls);
259 virtual void print(
String *str, enum_query_type query_type);
260 virtual void cleanup();
261 bool any_value() {
return was_values; }
262 void register_value() { was_values= TRUE; }
263 void reset_value_registration() { was_values= FALSE; }
315 virtual trans_res select_transformer(
JOIN *join)
320 subs_type substype() {
return EXISTS_SUBS; }
326 enum Item_result result_type()
const {
return INT_RESULT;}
332 bool get_date(
MYSQL_TIME *ltime, uint fuzzydate)
340 void fix_length_and_dec();
341 virtual void print(
String *str, enum_query_type query_type);
343 friend class select_exists_subselect;
405 Item *remove_in2exists_conds(
Item* conds);
409 bool *pushed_cond_guards;
420 bool in2exists_added_to_where()
const
421 {
return in2exists_info && in2exists_info->added_to_where; }
425 {
return in2exists_info->originally_dependent; }
427 bool *get_cond_guard(
int i)
429 return pushed_cond_guards ? pushed_cond_guards + i : NULL;
431 void set_cond_guard_var(
int i,
bool v)
433 if ( pushed_cond_guards)
434 pushed_cond_guards[
i]= v;
436 bool have_guarded_conds() {
return test(pushed_cond_guards); }
442 optimizer(NULL), was_null(FALSE), abort_on_null(FALSE),
443 in2exists_info(NULL), pushed_cond_guards(NULL), upper_item(NULL)
445 virtual void cleanup();
446 subs_type substype() {
return IN_SUBS; }
453 trans_res select_transformer(
JOIN *join);
456 trans_res row_value_transformer(
JOIN * join);
460 bool walk(Item_processor processor,
bool walk_subquery, uchar *arg);
466 void update_null_value () { (void)
val_bool(); }
468 void top_level_item() { abort_on_null=1; }
469 inline bool is_top_level_item() {
return abort_on_null; }
470 bool test_limit(st_select_lex_unit *unit);
471 virtual void print(
String *str, enum_query_type query_type);
472 bool fix_fields(THD *thd,
Item **ref);
474 st_select_lex *removed_select);
500 chooser_compare_func_creator func_creator;
505 st_select_lex *select_lex,
bool all);
508 subs_type substype() {
return all?ALL_SUBS:ANY_SUBS; }
509 trans_res select_transformer(
JOIN *join);
510 virtual void print(
String *str, enum_query_type query_type);
517 select_result_interceptor *result;
519 enum Item_result res_type;
520 enum_field_types res_field_type;
524 enum enum_engine_type {ABSTRACT_ENGINE, SINGLE_SELECT_ENGINE,
525 UNION_ENGINE, UNIQUESUBQUERY_ENGINE,
526 INDEXSUBQUERY_ENGINE, HASH_SJ_ENGINE};
529 :result(res), item(si), res_type(STRING_RESULT),
530 res_field_type(MYSQL_TYPE_VAR_STRING), maybe_null(
false)
540 virtual bool prepare()= 0;
541 virtual void fix_length_and_dec(
Item_cache** row)= 0;
558 virtual bool exec()= 0;
559 virtual uint cols()
const = 0;
560 virtual uint8 uncacheable()
const = 0;
561 virtual enum Item_result type()
const {
return res_type; }
562 virtual enum_field_types field_type()
const {
return res_field_type; }
563 virtual void exclude()= 0;
564 virtual bool may_be_null()
const {
return maybe_null; };
565 virtual table_map upper_select_const_tables()
const = 0;
566 static table_map calc_const_tables(
TABLE_LIST *);
567 virtual void print(
String *str, enum_query_type query_type)= 0;
569 select_result_interceptor *result)= 0;
570 virtual bool no_tables()
const = 0;
571 virtual bool is_executed()
const {
return FALSE; }
572 virtual enum_engine_type engine_type()
const {
return ABSTRACT_ENGINE; }
592 st_select_lex *select_lex;
596 select_result_interceptor *result,
600 virtual void fix_length_and_dec(
Item_cache** row);
602 virtual uint cols()
const;
603 virtual uint8 uncacheable()
const;
604 virtual void exclude();
605 virtual table_map upper_select_const_tables()
const;
606 virtual void print (
String *str, enum_query_type query_type);
608 select_result_interceptor *result);
610 virtual bool may_be_null()
const;
611 virtual bool is_executed()
const {
return executed; }
612 virtual enum_engine_type engine_type()
const {
return SINGLE_SELECT_ENGINE; }
623 select_result_interceptor *result,
626 virtual bool prepare();
627 virtual void fix_length_and_dec(
Item_cache** row);
629 virtual uint cols()
const;
630 virtual uint8 uncacheable()
const;
631 virtual void exclude();
632 virtual table_map upper_select_const_tables()
const;
633 virtual void print (
String *str, enum_query_type query_type);
635 select_result_interceptor *result);
637 virtual bool is_executed()
const;
638 virtual enum_engine_type engine_type()
const {
return UNION_ENGINE; }
641 st_select_lex_unit *unit;
693 Item *having_arg,
bool chk_null,
696 check_null(chk_null), having(having_arg), unique(unique_arg)
699 virtual void print (
String *str, enum_query_type query_type);
700 virtual enum_engine_type engine_type()
const
701 {
return unique ? UNIQUESUBQUERY_ENGINE : INDEXSUBQUERY_ENGINE; }
703 virtual bool prepare();
704 virtual void fix_length_and_dec(
Item_cache** row);
705 virtual uint cols()
const {
return 1; }
706 virtual uint8 uncacheable()
const {
return UNCACHEABLE_DEPENDENT; }
707 virtual void exclude();
708 virtual table_map upper_select_const_tables()
const {
return 0; }
710 select_result_interceptor *result);
713 void copy_ref_key(
bool *require_scan,
bool *convert_error);
721 chooser_compare_func_creator cmp,
723 SELECT_LEX *select_lex);
726 inline bool Item_subselect::is_evaluated()
const
728 return engine->is_executed();
732 inline bool Item_subselect::is_uncacheable()
const
734 return engine->uncacheable();
748 bool is_materialized;
757 NEX_IRRELEVANT_OR_FALSE= 0,
763 enum nulls_exist mat_table_has_nulls;
773 TMP_TABLE_PARAM *tmp_param;
780 is_materialized(
false), materialize_engine(old_engine), tmp_param(NULL)
786 virtual bool prepare()
788 return materialize_engine->
prepare();
791 virtual void print (
String *str, enum_query_type query_type);
792 virtual uint cols()
const
794 return materialize_engine->cols();
796 virtual enum_engine_type engine_type()
const {
return HASH_SJ_ENGINE; }
799 Item *get_cond_for_explain()
const {
return cond; }