My Project
Classes | Public Member Functions | Public Attributes | Protected Attributes | Friends
Item_in_subselect Class Reference

#include <item_subselect.h>

Inheritance diagram for Item_in_subselect:
Item_exists_subselect Item_subselect Item_result_field Item Item_allany_subselect

List of all members.


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 Attributes

bool * pushed_cond_guards

Protected Attributes

List< Cached_item > * left_expr_cache
bool left_expr_cache_filled
 Whether left_expr_cache holds a value.
bool need_expr_cache
bool was_null
bool abort_on_null


class Item_ref_null_helper
class Item_is_not_null_test
class Item_in_optimizer
class subselect_indexsubquery_engine
class subselect_hash_sj_engine

Detailed Description

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

This class has:

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

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.

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

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.

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

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
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:

Reimplemented from Item_exists_subselect.

Reimplemented in Item_allany_subselect.

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.

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
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.

joinJOIN object of transforming subquery
funccreator of condition function of subquery
Return values:
RES_REDUCEOK, and current subquery was reduced during transformation
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.

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
bool Item_in_subselect::val_bool ( ) [virtual]
Make this functions class dependent

Reimplemented from Item_exists_subselect.

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.

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.

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.

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.

Member Data Documentation

The need for expr cache may be optimized away,

See also:

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines