MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Item_in_subselect Class Reference

#include <item_subselect.h>

Inheritance diagram for Item_in_subselect:
Collaboration diagram for Item_in_subselect:

Classes

struct  In2exists_info

Public Member Functions

bool in2exists_added_to_where () const
bool originally_dependent () const
 Is reliable only if IN->EXISTS has been done.
bool * get_cond_guard (int i)
void set_cond_guard_var (int i, bool v)
bool have_guarded_conds ()
 Item_in_subselect (Item *left_expr, st_select_lex *select_lex)
virtual void cleanup ()
subs_type substype ()
virtual void reset ()
trans_res select_transformer (JOIN *join)
trans_res select_in_like_transformer (JOIN *join, Comp_creator *func)
trans_res single_value_transformer (JOIN *join, Comp_creator *func)
trans_res row_value_transformer (JOIN *join)
trans_res single_value_in_to_exists_transformer (JOIN *join, Comp_creator *func)
trans_res row_value_in_to_exists_transformer (JOIN *join)
bool walk (Item_processor processor, bool walk_subquery, uchar *arg)
virtual bool exec ()
longlong val_int ()
double val_real ()
Stringval_str (String *)
my_decimalval_decimal (my_decimal *)
void update_null_value ()
bool val_bool ()
void top_level_item ()
bool is_top_level_item ()
bool test_limit (st_select_lex_unit *unit)
virtual void print (String *str, enum_query_type query_type)
bool fix_fields (THD *thd, Item **ref)
void fix_after_pullout (st_select_lex *parent_select, st_select_lex *removed_select)
bool init_left_expr_cache ()
bool finalize_exists_transform (SELECT_LEX *select_lex)
bool finalize_materialization_transform (JOIN *join)
- Public Member Functions inherited from Item_exists_subselect
 Item_exists_subselect (st_select_lex *select_lex)
enum Item_result result_type () const
bool get_date (MYSQL_TIME *ltime, uint fuzzydate)
bool get_time (MYSQL_TIME *ltime)
void fix_length_and_dec ()
- Public Member Functions inherited from Item_subselect
const subselect_engineget_engine_for_explain () const
 EXPLAIN needs read-only access to the engine.
virtual void init (st_select_lex *select_lex, select_result_interceptor *result)
bool assigned () const
void assigned (bool a)
enum Type type () const
bool is_null ()
table_map used_tables () const
table_map not_null_tables () const
bool const_item () const
table_map get_used_tables_cache ()
bool get_const_item_cache ()
Itemget_tmp_table_item (THD *thd)
void update_used_tables ()
bool change_engine (subselect_engine *eng)
bool is_evaluated () const
bool is_uncacheable () const
virtual void reset_value_registration ()
enum_parsing_place place ()
bool walk_join_condition (List< TABLE_LIST > *tables, Item_processor processor, bool walk_subquery, uchar *argument)
bool walk_body (Item_processor processor, bool walk_subquery, uchar *arg)
virtual bool explain_subquery_checker (uchar **arg)
bool inform_item_in_cond_of_tab (uchar *join_tab_index)
virtual bool clean_up_after_removal (uchar *arg)
const char * func_name () const
- Public Member Functions inherited from Item_result_field
 Item_result_field (THD *thd, Item_result_field *item)
Fieldget_tmp_table_field ()
Fieldtmp_table_field (TABLE *t_arg)
void set_result_field (Field *field)
bool is_result_field ()
void save_in_result_field (bool no_conversions)
- Public Member Functions inherited from Item
 Item (THD *thd, Item *item)
void rename (char *new_name)
void init_make_field (Send_field *tmp_field, enum enum_field_types type)
virtual void make_field (Send_field *field)
virtual Fieldmake_string_field (TABLE *table)
void quick_fix_field ()
type_conversion_status save_in_field_no_warnings (Field *field, bool no_conversions)
virtual type_conversion_status save_in_field (Field *field, bool no_conversions)
virtual void save_org_in_field (Field *field)
virtual type_conversion_status save_safe_in_field (Field *field)
virtual bool send (Protocol *protocol, String *str)
virtual bool eq (const Item *, bool binary_cmp) const
virtual enum Item_result numeric_context_result_type () const
enum Item_result temporal_with_date_as_number_result_type () const
virtual Item_result cast_to_int_type () const
virtual enum_field_types string_field_type () const
virtual enum_field_types field_type () const
virtual enum_monotonicity_info get_monotonicity_info () const
virtual longlong val_int_endpoint (bool left_endp, bool *incl_endp)
virtual longlong val_date_temporal ()
virtual longlong val_time_temporal ()
longlong val_temporal_by_field_type ()
longlong val_temporal_with_round (enum_field_types type, uint8 dec)
ulonglong val_uint ()
virtual Stringval_str_ascii (String *str)
virtual Stringval_nodeset (String *)
type_conversion_status save_time_in_field (Field *field)
type_conversion_status save_date_in_field (Field *field)
type_conversion_status save_str_value_in_field (Field *field, String *result)
virtual const char * full_name () const
virtual double val_result ()
virtual longlong val_int_result ()
virtual longlong val_time_temporal_result ()
virtual longlong val_date_temporal_result ()
virtual Stringstr_result (String *tmp)
virtual my_decimalval_decimal_result (my_decimal *val)
virtual bool val_bool_result ()
virtual bool is_null_result ()
virtual table_map resolved_used_tables () const
virtual bool basic_const_item () const
virtual Itemclone_item ()
virtual cond_result eq_cmp_result () const
uint float_length (uint decimals_par) const
virtual uint decimal_precision () const
int decimal_int_part () const
virtual uint time_precision ()
virtual uint datetime_precision ()
virtual bool const_during_execution () const
void print_item_w_name (String *, enum_query_type query_type)
void print_for_order (String *str, enum_query_type query_type, bool used_alias)
virtual void split_sum_func (THD *thd, Ref_ptr_array ref_pointer_array, List< Item > &fields)
void split_sum_func2 (THD *thd, Ref_ptr_array ref_pointer_array, List< Item > &fields, Item **ref, bool skip_registered)
virtual bool get_timeval (struct timeval *tm, int *warnings)
virtual bool get_date_result (MYSQL_TIME *ltime, uint fuzzydate)
virtual bool is_bool_func ()
virtual void no_rows_in_result ()
virtual Itemcopy_or_same (THD *thd)
virtual Itemcopy_andor_structure (THD *thd, bool real_items=false)
virtual Itemreal_item ()
virtual const CHARSET_INFOcompare_collation ()
virtual const CHARSET_INFOcharset_for_protocol (void) const
virtual Itemtransform (Item_transformer transformer, uchar *arg)
virtual Itemcompile (Item_analyzer analyzer, uchar **arg_p, Item_transformer transformer, uchar *arg_t)
virtual void traverse_cond (Cond_traverser traverser, void *arg, traverse_order order)
virtual bool intro_version (uchar *int_arg)
virtual bool remove_dependence_processor (uchar *arg)
virtual bool remove_fixed (uchar *arg)
virtual bool cleanup_processor (uchar *arg)
virtual bool collect_item_field_processor (uchar *arg)
virtual bool add_field_to_set_processor (uchar *arg)
virtual bool remove_column_from_bitmap (uchar *arg)
virtual bool find_item_in_field_list_processor (uchar *arg)
virtual bool change_context_processor (uchar *context)
virtual bool reset_query_id_processor (uchar *query_id_arg)
virtual bool find_item_processor (uchar *arg)
virtual bool register_field_in_read_map (uchar *arg)
virtual bool cache_const_expr_analyzer (uchar **arg)
virtual Itemcache_const_expr_transformer (uchar *arg)
virtual bool item_field_by_name_analyzer (uchar **arg)
virtual Itemitem_field_by_name_transformer (uchar *arg)
virtual bool equality_substitution_analyzer (uchar **arg)
virtual Itemequality_substitution_transformer (uchar *arg)
virtual bool check_partition_func_processor (uchar *bool_arg)
virtual bool subst_argument_checker (uchar **arg)
virtual Itemexplain_subquery_propagator (uchar *arg)
virtual Itemequal_fields_propagator (uchar *arg)
virtual bool set_no_const_sub (uchar *arg)
virtual Itemreplace_equal_field (uchar *arg)
virtual bool check_valid_arguments_processor (uchar *bool_arg)
virtual bool find_function_processor (uchar *arg)
virtual Itemthis_item ()
virtual const Itemthis_item () const
virtual Item ** this_item_addr (THD *thd, Item **addr_arg)
virtual uint cols ()
virtual Itemelement_index (uint i)
virtual Item ** addr (uint i)
virtual bool check_cols (uint c)
virtual bool null_inside ()
virtual void bring_value ()
Fieldtmp_table_field_from_field_type (TABLE *table, bool fixed_length)
virtual Item_fieldfield_for_view_update ()
virtual Itemneg_transformer (THD *thd)
virtual Itemupdate_value_transformer (uchar *select_arg)
virtual Itemsafe_charset_converter (const CHARSET_INFO *tocs)
void delete_self ()
virtual bool is_splocal ()
virtual
Settable_routine_parameter
get_settable_routine_parameter ()
bool is_temporal_with_date () const
bool is_temporal_with_date_and_time () const
bool is_temporal_with_time () const
bool is_temporal () const
bool has_compatible_context (Item *item) const
virtual Field::geometry_type get_geometry_type () const
Stringcheck_well_formed_result (String *str, bool send_error=0)
bool eq_by_collation (Item *item, bool binary_cmp, const CHARSET_INFO *cs)
virtual bool is_expensive ()
virtual bool can_be_evaluated_now () const
uint32 max_char_length () const
void fix_length_and_charset (uint32 max_char_length_arg, const CHARSET_INFO *cs)
void fix_char_length (uint32 max_char_length_arg)
void fix_char_length_ulonglong (ulonglong max_char_length_arg)
void fix_length_and_charset_datetime (uint32 max_char_length_arg)
void fix_length_and_dec_and_charset_datetime (uint32 max_char_length_arg, uint8 dec_arg)
virtual bool is_outer_field () const
bool is_blob_field () const
virtual bool has_subquery () const
virtual bool has_stored_program () const
virtual bool created_by_in2exists () const
 Whether this Item was created by the IN->EXISTS subquery transformation.

Public Attributes

Itemleft_expr
bool * pushed_cond_guards
Item_func_not_allupper_item
TABLE_LISTexpr_join_nest
- Public Attributes inherited from Item_exists_subselect
enum_exec_method exec_method
int sj_convert_priority
 Priority of this predicate in the convert-to-semi-join-nest process.
bool sj_chosen
 True if this predicate is chosen for semi-join transformation.
TABLE_LISTembedding_join_nest
- Public Attributes inherited from Item_subselect
Itemsubstitution
st_select_lex_unit * unit
int in_cond_of_tab
bool engine_changed
bool changed
- Public Attributes inherited from Item_result_field
Fieldresult_field
- Public Attributes inherited from Item
uint rsize
String str_value
Item_name_string item_name
Item_name_string orig_name
Itemnext
uint32 max_length
int marker
uint8 decimals
my_bool maybe_null
my_bool null_value
my_bool unsigned_flag
my_bool with_sum_func
my_bool fixed
DTCollation collation
Item_result cmp_context

Protected Attributes

List< Cached_item > * left_expr_cache
bool left_expr_cache_filled
 Whether left_expr_cache holds a value.
bool need_expr_cache
Itemexpr
Item_in_optimizeroptimizer
bool was_null
bool abort_on_null
- Protected Attributes inherited from Item_exists_subselect
bool value
- Protected Attributes inherited from Item_subselect
subselect_engineengine
subselect_engineold_engine
table_map used_tables_cache
uint max_columns
enum_parsing_place parsing_place
bool have_to_be_excluded
bool const_item_cache

Friends

class Item_ref_null_helper
class Item_is_not_null_test
class Item_in_optimizer
class subselect_indexsubquery_engine
class subselect_hash_sj_engine

Additional Inherited Members

- Public Types inherited from Item_exists_subselect
enum  enum_exec_method {
  EXEC_UNSPECIFIED, EXEC_SEMI_JOIN, EXEC_EXISTS, EXEC_EXISTS_OR_MAT,
  EXEC_MATERIALIZATION
}
- Static Public Member Functions inherited from Item
static void * operator new (size_t size) throw ()
static void * operator new (size_t size, MEM_ROOT *mem_root) throw ()
static void operator delete (void *ptr, size_t size)
static void operator delete (void *ptr, MEM_ROOT *mem_root)
static const CHARSET_INFOdefault_charset ()
- Protected Member Functions inherited from Item
Stringval_string_from_real (String *str)
Stringval_string_from_int (String *str)
Stringval_string_from_decimal (String *str)
Stringval_string_from_date (String *str)
Stringval_string_from_datetime (String *str)
Stringval_string_from_time (String *str)
my_decimalval_decimal_from_real (my_decimal *decimal_value)
my_decimalval_decimal_from_int (my_decimal *decimal_value)
my_decimalval_decimal_from_string (my_decimal *decimal_value)
my_decimalval_decimal_from_date (my_decimal *decimal_value)
my_decimalval_decimal_from_time (my_decimal *decimal_value)
longlong val_int_from_decimal ()
longlong val_int_from_date ()
longlong val_int_from_time ()
longlong val_int_from_datetime ()
double val_real_from_decimal ()
bool get_date_from_string (MYSQL_TIME *ltime, uint flags)
bool get_date_from_real (MYSQL_TIME *ltime, uint flags)
bool get_date_from_decimal (MYSQL_TIME *ltime, uint flags)
bool get_date_from_int (MYSQL_TIME *ltime, uint flags)
bool get_date_from_time (MYSQL_TIME *ltime)
bool get_date_from_numeric (MYSQL_TIME *ltime, uint fuzzydate)
bool get_date_from_non_temporal (MYSQL_TIME *ltime, uint fuzzydate)
bool get_time_from_string (MYSQL_TIME *ltime)
bool get_time_from_real (MYSQL_TIME *ltime)
bool get_time_from_decimal (MYSQL_TIME *ltime)
bool get_time_from_int (MYSQL_TIME *ltime)
bool get_time_from_date (MYSQL_TIME *ltime)
bool get_time_from_datetime (MYSQL_TIME *ltime)
bool get_time_from_numeric (MYSQL_TIME *ltime)
bool get_time_from_non_temporal (MYSQL_TIME *ltime)

Detailed Description

Representation of IN subquery predicates of the form "left_expr IN (SELECT ...)".

This class has:

  • A "subquery execution engine" (as a subclass of Item_subselect) that allows it to evaluate subqueries. (and this class participates in execution by having was_null variable where part of execution result is stored.
  • Transformation methods (todo: more on this).

This class is not used directly, it is "wrapped" into Item_in_optimizer which provides some small bits of subquery evaluation.

Definition at line 363 of file item_subselect.h.

Member Function Documentation

bool Item_in_subselect::finalize_exists_transform ( SELECT_LEX *  select_lex)

Once the decision to use IN->EXISTS has been taken, performs some last steps of this transformation.

Definition at line 142 of file item_subselect.cc.

Here is the caller graph for this function:

bool Item_in_subselect::finalize_materialization_transform ( JOIN join)

Once the decision to use materialization has been taken, performs some last steps of this transformation.

Definition at line 241 of file item_subselect.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

void Item_in_subselect::fix_after_pullout ( st_select_lex *  parent_select,
st_select_lex *  removed_select 
)
virtual

Fix used tables information for a subquery after query transformations. Common actions for all predicates involving subqueries. Most actions here involve re-resolving information for conditions and items belonging to the subquery. Notice that the usage information from underlying expressions is not propagated to the subquery predicate, as it belongs to inner layers of the query operator structure. However, when underlying expressions contain outer references into a select_lex on this level, the relevant information must be updated when these expressions are resolved.

Reimplemented from Item_subselect.

Definition at line 2394 of file item_subselect.cc.

Here is the call graph for this function:

bool Item_in_subselect::init_left_expr_cache ( )

Initialize the cache of the left operand of the IN predicate.

Note
This method has the same purpose as alloc_group_fields(), but it takes a different kind of collection of items, and the list we push to is dynamically allocated.
Return values
TRUEif a memory allocation error occurred
FALSEif success

Definition at line 2416 of file item_subselect.cc.

Here is the call graph for this function:

void Item_in_subselect::print ( String str,
enum_query_type  query_type 
)
virtual

This method is used for to:

  • to generate a view definition query (SELECT-statement);
  • to generate a SQL-query for EXPLAIN EXTENDED;
  • to generate a SQL-query to be shown in INFORMATION_SCHEMA;
  • debug.

For more information about view definition query, INFORMATION_SCHEMA query and why they should be generated from the Item-tree,

See Also
mysql_register_view().

Reimplemented from Item_exists_subselect.

Reimplemented in Item_allany_subselect.

Definition at line 2366 of file item_subselect.cc.

Here is the call graph for this function:

Item_subselect::trans_res Item_in_subselect::row_value_in_to_exists_transformer ( JOIN join)

Tranform a (possibly non-correlated) IN subquery into a correlated EXISTS.

Todo:
The IF-ELSE below can be refactored so that there is no duplication of the statements that create the new conditions. For this we have to invert the IF and the FOR statements as this: for (each left operand) create the equi-join condition if (is_having_used || !abort_on_null) create the "is null" and is_not_null_test items if (is_having_used) add the equi-join and the null tests to HAVING else add the equi-join and the "is null" to WHERE add the is_not_null_test to HAVING

Definition at line 2010 of file item_subselect.cc.

Here is the call graph for this function:

Item_subselect::trans_res Item_in_subselect::select_in_like_transformer ( JOIN join,
Comp_creator func 
)

Prepare IN/ALL/ANY/SOME subquery transformation and call appropriate transformation function.

To decide which transformation procedure (scalar or row) applicable here we have to call fix_fields() for left expression to be able to call cols() method on it. Also this method make arena management for underlying transformation methods.

Parameters
joinJOIN object of transforming subquery
funccreator of condition function of subquery
Return values
RES_OKOK
RES_REDUCEOK, and current subquery was reduced during transformation
RES_ERRORError

Definition at line 2273 of file item_subselect.cc.

Item_subselect::trans_res Item_in_subselect::single_value_in_to_exists_transformer ( JOIN join,
Comp_creator func 
)

Transofrm an IN predicate into EXISTS via predicate injection.

The transformation injects additional predicates into the subquery (and makes the subquery correlated) as follows.

  • If the subquery has aggregates, GROUP BY, or HAVING, convert to

    SELECT ie FROM ... HAVING subq_having AND trigcond(oe $cmp$ ref_or_null_helper<ie>)

    the addition is wrapped into trigger only when we want to distinguish between NULL and FALSE results.

  • Otherwise (no aggregates/GROUP BY/HAVING) convert it to one of the following:

    = If we don't need to distinguish between NULL and FALSE subquery:

    SELECT 1 FROM ... WHERE (oe $cmp$ ie) AND subq_where

    = If we need to distinguish between those:

    SELECT 1 FROM ... WHERE subq_where AND trigcond((oe $cmp$ ie) OR (ie IS NULL)) HAVING trigcond(<is_not_null_test>(ie))

At JOIN::optimize() we will compare costs of materialization and EXISTS; if the former is cheaper we will switch to it.

Parameters
joinJoin object of the subquery (i.e. 'child' join).
funcSubquery comparison creator
Return values
RES_OKEither subquery was transformed, or appopriate predicates where injected into it.
RES_REDUCEThe subquery was reduced to non-subquery
RES_ERRORError

Definition at line 1712 of file item_subselect.cc.

Here is the call graph for this function:

bool Item_in_subselect::val_bool ( )
virtual
Todo:
Make this functions class dependent

Reimplemented from Item_exists_subselect.

Definition at line 1396 of file item_subselect.cc.

my_decimal * Item_in_subselect::val_decimal ( my_decimal decimal_value)
virtual

Return the result of EXISTS as a decimal value

Converts the true/false result into a decimal value. Note that currently this cannot be NULL, so if the query exection fails it will return 0.

Parameters
decimal_value[out]Buffer to hold the resulting decimal value
Return values
Pointerto the converted decimal. Can't be a NULL pointer, as currently EXISTS cannot return NULL.

Reimplemented from Item_exists_subselect.

Definition at line 1409 of file item_subselect.cc.

String * Item_in_subselect::val_str ( String str)
virtual

Return the result of EXISTS as a string value

Converts the true/false result into a string value. Note that currently this cannot be NULL, so if the query exection fails it will return 0.

Parameters
decimal_value[out]buffer to hold the resulting string value
Return values
Pointerto the converted string. Can't be a NULL pointer, as currently EXISTS cannot return NULL.

Reimplemented from Item_exists_subselect.

Definition at line 1373 of file item_subselect.cc.

Member Data Documentation

bool Item_in_subselect::need_expr_cache
protected

The need for expr cache may be optimized away,

See Also
init_left_expr_cache.

Definition at line 375 of file item_subselect.h.


The documentation for this class was generated from the following files: