22 #include <drizzled/comp_creator.h>
23 #include <drizzled/item/ref.h>
24 #include <drizzled/item/field.h>
25 #include <drizzled/item/bin_string.h>
26 #include <drizzled/util/test.h>
39 Select_Lex_Unit *unit;
46 table_map used_tables_cache;
50 enum_parsing_place parsing_place;
52 bool have_to_be_excluded;
54 bool const_item_cache;
65 enum trans_res {RES_OK, RES_REDUCE, RES_ERROR};
66 enum subs_type {UNKNOWN_SUBS, SINGLEROW_SUBS,
67 EXISTS_SUBS, IN_SUBS, ALL_SUBS, ANY_SUBS};
71 virtual subs_type substype() {
return UNKNOWN_SUBS; }
78 virtual void init (Select_Lex *select_lex,
87 virtual trans_res select_transformer(
Join *join);
88 bool assigned() {
return value_assigned; }
89 void assigned(
bool a) { value_assigned= a; }
90 enum Type type()
const;
98 virtual void fix_length_and_dec();
102 inline table_map get_used_tables_cache() {
return used_tables_cache; }
103 inline bool get_const_item_cache() {
return const_item_cache; }
104 Item *get_tmp_table_item(Session *session);
105 void update_used_tables();
106 virtual void print(String *str);
107 virtual bool have_guarded_conds() {
return false; }
108 bool change_engine(subselect_engine *eng)
119 bool is_evaluated()
const;
120 bool is_uncacheable()
const;
126 virtual void reset_value_registration() {}
127 enum_parsing_place place() {
return parsing_place; }
128 bool walk(Item_processor processor,
bool walk_subquery,
unsigned char *arg);
136 friend class select_result_interceptor;
137 friend class Item_in_optimizer;
142 Select_Lex*, Select_Lex*,
143 Field*,
Item*, Item_ident*);
157 subs_type substype() {
return SINGLEROW_SUBS; }
161 void store(uint32_t i,
Item* item);
167 enum Item_result result_type()
const;
168 enum_field_types field_type()
const;
169 void fix_length_and_dec();
172 Item* element_index(uint32_t i) {
return reinterpret_cast<Item*
>(row[i]); }
173 Item** addr(uint32_t i) {
return (
Item**)row + i; }
174 bool check_cols(uint32_t c);
203 Select_Lex *select_lex,
bool max);
206 bool any_value() {
return was_values; }
207 void register_value() { was_values=
true; }
208 void reset_value_registration() { was_values=
false; }
222 subs_type substype() {
return EXISTS_SUBS; }
228 enum Item_result result_type()
const {
return INT_RESULT;}
234 void fix_length_and_dec();
268 bool first_execution;
281 bool *pushed_cond_guards;
284 int sj_convert_priority;
294 enum enum_exec_method {
300 enum_exec_method exec_method;
302 bool *get_cond_guard(
int i)
304 return pushed_cond_guards ? pushed_cond_guards + i : NULL;
306 void set_cond_guard_var(
int i,
bool v)
308 if ( pushed_cond_guards)
309 pushed_cond_guards[i]= v;
311 bool have_guarded_conds() {
return test(pushed_cond_guards); }
320 left_expr_cache(NULL),
321 first_execution(
true),
323 abort_on_null(
false),
324 pushed_cond_guards(NULL),
325 sj_convert_priority(0),
326 expr_join_nest(NULL),
327 exec_method(NOT_TRANSFORMED),
331 subs_type substype() {
return IN_SUBS; }
338 trans_res select_transformer(
Join *join);
341 trans_res row_value_transformer(
Join * join);
353 inline bool is_top_level_item() {
return abort_on_null; }
354 bool test_limit(Select_Lex_Unit *unit);
355 virtual void print(String *str);
356 bool fix_fields(Session *session,
Item **ref);
359 bool is_expensive_processor(
unsigned char *arg);
361 friend class Item_ref_null_helper;
362 friend class Item_is_not_null_test;
363 friend class Item_in_optimizer;
364 friend class subselect_indexsubquery_engine;
365 friend class subselect_hash_sj_engine;
373 chooser_compare_func_creator func_creator;
378 Select_Lex *select_lex,
bool all);
381 subs_type substype() {
return all?ALL_SUBS:ANY_SUBS; }
382 trans_res select_transformer(
Join *join);
393 enum Item_result res_type;
394 enum_field_types res_field_type;
398 enum enum_engine_type {ABSTRACT_ENGINE, SINGLE_SELECT_ENGINE,
399 UNION_ENGINE, UNIQUESUBQUERY_ENGINE,
400 INDEXSUBQUERY_ENGINE, HASH_SJ_ENGINE};
407 res_type= STRING_RESULT;
408 res_field_type= DRIZZLE_TYPE_VARCHAR;
412 virtual void cleanup()= 0;
418 void set_session(
Session *session_arg);
419 Session * get_session() {
return session; }
420 virtual int prepare()= 0;
421 virtual void fix_length_and_dec(
Item_cache** row)= 0;
442 virtual int exec()= 0;
443 virtual uint32_t cols()= 0;
444 virtual bool uncacheable()= 0;
445 virtual bool uncacheable(uint32_t bit_pos)= 0;
446 enum Item_result type() {
return res_type; }
447 enum_field_types field_type() {
return res_field_type; }
448 virtual void exclude()= 0;
449 virtual bool may_be_null() {
return maybe_null; }
450 virtual table_map upper_select_const_tables()= 0;
451 static table_map calc_const_tables(
TableList *);
452 virtual void print(
String *str)= 0;
455 virtual bool no_tables()= 0;
456 virtual bool is_executed()
const {
return false; }
458 virtual bool no_rows() = 0;
459 virtual enum_engine_type engine_type() {
return ABSTRACT_ENGINE; }
471 Select_Lex *select_lex;
483 bool uncacheable(uint32_t bit_pos);
485 table_map upper_select_const_tables();
486 virtual void print (
String *str);
490 bool is_executed()
const {
return executed; }
492 virtual enum_engine_type engine_type() {
return SINGLE_SELECT_ENGINE; }
493 void save_join_if_explain();
502 Select_Lex_Unit *unit;
513 bool uncacheable(uint32_t bit_pos);
515 table_map upper_select_const_tables();
516 virtual void print (
String *str);
519 bool is_executed()
const;
521 virtual enum_engine_type engine_type() {
return UNION_ENGINE; }
551 bool empty_result_set;
560 set_session(session_arg);
566 uint32_t cols() {
return 1; }
567 bool uncacheable() {
return true; }
568 bool uncacheable(uint32_t) {
return true; }
570 table_map upper_select_const_tables() {
return 0; }
571 virtual void print (
String *str);
576 bool no_rows() {
return empty_result_set; }
577 virtual enum_engine_type engine_type() {
return UNIQUESUBQUERY_ENGINE; }
620 Item *having_arg,
bool chk_null)
622 check_null(chk_null),
626 virtual void print (
String *str);
627 virtual enum_engine_type engine_type() {
return INDEXSUBQUERY_ENGINE; }
631 inline bool Item_subselect::is_evaluated()
const
633 return engine->is_executed();
637 inline bool Item_subselect::is_uncacheable()
const
639 return engine->uncacheable();
653 bool is_materialized;
665 Join *materialize_join;
673 is_materialized(
false), materialize_engine(old_engine),
674 materialize_join(NULL), tmp_param(NULL)
681 int prepare() {
return 0; }
686 return materialize_engine->cols();
688 virtual enum_engine_type engine_type() {
return HASH_SJ_ENGINE; }
virtual void print(String *str)
bool change_result(Item_subselect *si, select_result_interceptor *result)
bool change_result(Item_subselect *si, select_result_interceptor *result)
TODO: Rename this file - func.h is stupid.
String * val_str(String *)
bool init_permanent(List< Item > *tmp_columns)
type::Decimal * val_decimal(type::Decimal *)
virtual void print(String *str)
bool fix_fields(Session *, Item **)
table_map used_tables() const
virtual void print(String *str)
table_map not_null_tables() const
virtual void update_null_value()
type::Decimal * val_decimal(type::Decimal *)
bool fix_fields(Session *, Item **)
String * val_str(String *)
trans_res select_transformer(Join *join)
virtual void print(String *str)
String * val_str(String *)
Select_Lex * get_select_lex()
type::Decimal * val_decimal(type::Decimal *)
Select_Lex * invalidate_and_restore_select_lex()
trans_res select_in_like_transformer(Join *join, const Comp_creator *func)
virtual void print(String *str)
trans_res row_value_in_to_exists_transformer(Join *join)
bool init_left_expr_cache()
virtual void print(String *str)
friend void mark_select_range_as_dependent(Session *, Select_Lex *, Select_Lex *, Field *, Item *, Item_ident *)
bool change_result(Item_subselect *si, select_result_interceptor *result)
trans_res single_value_in_to_exists_transformer(Join *join, const Comp_creator *func)
int fix_outer_field(Session *session, Field **field, Item **reference)