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

#include <item_subselect.h>

Inheritance diagram for subselect_indexsubquery_engine:
Collaboration diagram for subselect_indexsubquery_engine:

Public Member Functions

 subselect_indexsubquery_engine (THD *thd_arg, st_join_table *tab_arg, Item_subselect *subs, Item *where, Item *having_arg, bool chk_null, bool unique_arg)
virtual bool exec ()
virtual void print (String *str, enum_query_type query_type)
virtual enum_engine_type engine_type () const
virtual void cleanup ()
virtual bool prepare ()
virtual void fix_length_and_dec (Item_cache **row)
virtual uint cols () const
virtual uint8 uncacheable () const
virtual void exclude ()
virtual table_map upper_select_const_tables () const
virtual bool change_result (Item_subselect *si, select_result_interceptor *result)
virtual bool no_tables () const
bool scan_table ()
void copy_ref_key (bool *require_scan, bool *convert_error)
- Public Member Functions inherited from subselect_engine
 subselect_engine (Item_subselect *si, select_result_interceptor *res)
void set_thd_for_result ()
 Sets "thd" for 'result'. Should be called before prepare()
virtual enum Item_result type () const
virtual enum_field_types field_type () const
virtual bool may_be_null () const
virtual bool is_executed () const
const Item_subselectget_item () const

Protected Attributes

st_join_tabletab
Itemcond
- Protected Attributes inherited from subselect_engine
select_result_interceptor * result
Item_subselectitem
enum Item_result res_type
enum_field_types res_field_type
bool maybe_null

Additional Inherited Members

- Public Types inherited from subselect_engine
enum  enum_engine_type {
  ABSTRACT_ENGINE, SINGLE_SELECT_ENGINE, UNION_ENGINE, UNIQUESUBQUERY_ENGINE,
  INDEXSUBQUERY_ENGINE, HASH_SJ_ENGINE
}
- Static Public Member Functions inherited from subselect_engine
static table_map calc_const_tables (TABLE_LIST *)
- Protected Member Functions inherited from subselect_engine
void set_row (List< Item > &item_list, Item_cache **row)

Detailed Description

A subquery execution engine that evaluates the subquery by doing index lookups in a single table's index.

This engine is used to resolve subqueries in forms

outer_expr IN (SELECT tbl.key FROM tbl WHERE subq_where)

or, row-based:

(oe1, .. oeN) IN (SELECT key_part1, ... key_partK FROM tbl WHERE subqwhere)

i.e. the subquery is a single table SELECT without GROUP BY, aggregate functions, etc.

Definition at line 664 of file item_subselect.h.

Member Function Documentation

bool subselect_indexsubquery_engine::change_result ( Item_subselect si,
select_result_interceptor *  res 
)
virtual

change select_result emulation, never should be called.

Parameters
sinew subselect Item
resnew select_result object
Return values
FALSEOK
TRUEerror

Implements subselect_engine.

Definition at line 3392 of file item_subselect.cc.

virtual void subselect_indexsubquery_engine::cleanup ( )
inlinevirtual

Cleanup engine after complete query execution, free all resources.

Implements subselect_engine.

Reimplemented in subselect_hash_sj_engine.

Definition at line 702 of file item_subselect.h.

void subselect_indexsubquery_engine::copy_ref_key ( bool *  require_scan,
bool *  convert_error 
)

Copy ref key and check for null parts in it

Construct a search tuple to be used for index lookup. If one of the key parts have a NULL value, the following logic applies:

For top level items, e.g.

"WHERE <outer_value_list> IN (SELECT <inner_value_list>...)"

where one of the outer values are NULL, the IN predicate evaluates to false/UNKNOWN (we don't care) and it's not necessary to evaluate the subquery. That shortcut is taken in Item_in_optimizer::val_int(). Thus, if a key part with a NULL value is found here, the NULL is either not outer or this subquery is not top level. Therefore we cannot shortcut subquery execution if a NULL is found here.

Thus, if one of the key parts have a NULL value there are two possibilities:

a) The NULL is from the outer_value_list. Since this is not a top level item (see above) we need to check whether this predicate evaluates to NULL or false. That is done by checking if the subquery has a row if the conditions based on outer NULL values are disabled. Index lookup cannot be used for this, so a table scan must be done.

b) The NULL is local to the subquery, e.g.:

  "WHERE ... IN (SELECT ... WHERE inner_col IS NULL)"

In this case we're looking for rows with the exact inner_col value of NULL, not rows that match if the "inner_col IS NULL" condition is disabled. Index lookup can be used for this.

See Also
subselect_indexsubquery_engine::exec()
Item_in_optimizer::val_int()
Parameters
[out]require_scantrue if a NULL value is found that falls into category a) above, false if index lookup can be used.
[out]convert_errortrue if an error occured during conversion of values from one type to another, false otherwise.

Definition at line 2952 of file item_subselect.cc.

Here is the call graph for this function:

bool subselect_indexsubquery_engine::no_tables ( ) const
virtual

Report about presence of tables in subquery.

Return values
TRUEthere are not tables used in subquery
FALSEthere are some tables in subquery

Implements subselect_engine.

Definition at line 3458 of file item_subselect.cc.

bool subselect_indexsubquery_engine::scan_table ( )

Search, using a table scan, for at least one row satisfying select condition.

The caller must set item's 'value' to 'false' before calling this function. This function will set it to 'true' if it finds a matching row.

Returns
false if ok, true if read error.

Definition at line 2861 of file item_subselect.cc.

Here is the call graph for this function:


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