drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
drizzled::Item_in_subselect Class Reference

#include <subselect.h>

Inheritance diagram for drizzled::Item_in_subselect:
[legend]
Collaboration diagram for drizzled::Item_in_subselect:
[legend]

Public Types

enum  enum_exec_method { NOT_TRANSFORMED , SEMI_JOIN , IN_TO_EXISTS , MATERIALIZATION }
Public Types inherited from drizzled::Item_subselect
enum  trans_res { RES_OK , RES_REDUCE , RES_ERROR }
enum  subs_type {
  UNKNOWN_SUBS , SINGLEROW_SUBS , EXISTS_SUBS , IN_SUBS ,
  ALL_SUBS , ANY_SUBS
}
Public Types inherited from drizzled::Item
enum  Type {
  FIELD_ITEM = 0 , FUNC_ITEM , SUM_FUNC_ITEM , STRING_ITEM ,
  INT_ITEM , REAL_ITEM , NULL_ITEM , VARBIN_ITEM ,
  COPY_STR_ITEM , FIELD_AVG_ITEM , DEFAULT_VALUE_ITEM , PROC_ITEM ,
  COND_ITEM , REF_ITEM , FIELD_STD_ITEM , FIELD_VARIANCE_ITEM ,
  INSERT_VALUE_ITEM , SUBSELECT_ITEM , ROW_ITEM , CACHE_ITEM ,
  TYPE_HOLDER , PARAM_ITEM , BOOLEAN_ITEM , DECIMAL_ITEM
}
enum  traverse_order { T_POSTFIX , T_PREFIX }
enum  cond_result { COND_UNDEF , COND_OK , COND_TRUE , COND_FALSE }

Public Member Functions

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, Select_Lex *select_lex)
void cleanup ()
subs_type substype ()
void reset ()
trans_res select_transformer (Join *join)
trans_res select_in_like_transformer (Join *join, const Comp_creator *func)
trans_res single_value_transformer (Join *join, const Comp_creator *func)
trans_res row_value_transformer (Join *join)
trans_res single_value_in_to_exists_transformer (Join *join, const Comp_creator *func)
trans_res row_value_in_to_exists_transformer (Join *join)
virtual bool exec ()
int64_t val_int ()
double val_real ()
String * val_str (String *)
type::Decimal * val_decimal (type::Decimal *)
void update_null_value ()
bool val_bool ()
void top_level_item ()
bool is_top_level_item ()
bool test_limit (Select_Lex_Unit *unit)
virtual void print (String *str)
bool fix_fields (Session *session, Item **ref)
bool setup_engine ()
bool init_left_expr_cache ()
bool is_expensive_processor (unsigned char *arg)
Public Member Functions inherited from drizzled::Item_exists_subselect
 Item_exists_subselect (Select_Lex *select_lex)
enum Item_result result_type () const
void fix_length_and_dec ()
Public Member Functions inherited from drizzled::Item_subselect
virtual void init (Select_Lex *select_lex, select_result_interceptor *result)
void cleanup ()
bool assigned ()
void assigned (bool a)
enum Type type () const
bool is_null ()
bool fix_fields (Session *session, Item **ref)
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 ()
Item * get_tmp_table_item (Session *session)
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 (Item_processor processor, bool walk_subquery, unsigned char *arg)
Select_Lex * get_select_lex ()
Public Member Functions inherited from drizzled::Item_result_field
 Item_result_field (Session *session, Item_result_field *item)
Field * get_tmp_table_field ()
Field * tmp_table_field (Table *)
void set_result_field (Field *field)
bool is_result_field ()
void save_in_result_field (bool no_conversions)
Public Member Functions inherited from drizzled::Item
bool is_unsigned () const
virtual bool negative () const
 Item ()
 Item (Session *session, Item *item)
void set_name (str_ref arg)
void set_name (const char *arg)
void set_name (const char *str, uint32_t length, const charset_info_st *cs=system_charset_info)
void init_make_field (SendField *tmp_field, enum_field_types type)
virtual void make_field (SendField *field)
Field * make_string_field (Table *table)
virtual void fix_after_pullout (Select_Lex *new_parent, Item **ref)
void quick_fix_field ()
virtual int save_in_field (Field *field, bool no_conversions)
virtual void save_org_in_field (Field *field)
virtual int save_safe_in_field (Field *field)
virtual void send (plugin::Client *client, String *str)
virtual bool eq (const Item *, bool binary_cmp) 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 int64_t val_int_endpoint (bool left_endp, bool *incl_endp)
uint64_t val_uint ()
String * val_string_from_real (String *str)
String * val_string_from_int (String *str)
String * val_string_from_decimal (String *str)
type::Decimal * val_decimal_from_real (type::Decimal *decimal_value)
type::Decimal * val_decimal_from_int (type::Decimal *decimal_value)
type::Decimal * val_decimal_from_string (type::Decimal *decimal_value)
type::Decimal * val_decimal_from_date (type::Decimal *decimal_value)
type::Decimal * val_decimal_from_time (type::Decimal *decimal_value)
int64_t val_int_from_decimal ()
double val_real_from_decimal ()
bool save_time_in_field (Field *field)
bool save_date_in_field (Field *field)
int save_str_value_in_field (Field *field, String *result)
virtual const char * full_name (void) const
virtual double val_result ()
virtual int64_t val_int_result ()
virtual String * str_result (String *tmp)
virtual type::Decimal * val_decimal_result (type::Decimal *val)
virtual bool val_bool_result ()
virtual bool basic_const_item () const
virtual Item * clone_item ()
virtual cond_result eq_cmp_result () const
uint32_t float_length (uint32_t decimals_par) const
virtual uint32_t decimal_precision () const
int decimal_int_part () const
virtual bool const_during_execution () const
void print_item_w_name (String *)
virtual void split_sum_func (Session *session, Item **ref_pointer_array, List< Item > &fields)
void split_sum_func (Session *session, Item **ref_pointer_array, List< Item > &fields, Item **ref, bool skip_registered)
virtual bool get_date (type::Time &ltime, uint32_t fuzzydate)
virtual bool get_time (type::Time &ltime)
virtual bool get_date_result (type::Time &ltime, uint32_t fuzzydate)
virtual bool is_bool_func (void)
virtual void no_rows_in_result (void)
virtual Item * copy_or_same (Session *session)
virtual Item * copy_andor_structure (Session *session)
virtual Item * real_item (void)
virtual const Item * real_item (void) const
virtual const charset_info_st * compare_collation ()
virtual Item * transform (Item_transformer transformer, unsigned char *arg)
virtual Item * compile (Item_analyzer analyzer, unsigned char **arg_p, Item_transformer transformer, unsigned char *arg_t)
virtual void traverse_cond (Cond_traverser traverser, void *arg, traverse_order order)
virtual bool remove_dependence_processor (unsigned char *arg)
virtual bool collect_item_field_processor (unsigned char *arg)
virtual bool find_item_in_field_list_processor (unsigned char *arg)
virtual bool change_context_processor (unsigned char *context)
virtual bool register_field_in_read_map (unsigned char *arg)
virtual bool subst_argument_checker (unsigned char **arg)
virtual bool cache_const_expr_analyzer (unsigned char **arg)
virtual Item * cache_const_expr_transformer (unsigned char *arg)
virtual Item * equal_fields_propagator (unsigned char *arg)
virtual bool set_no_const_sub (unsigned char *arg)
virtual Item * replace_equal_field (unsigned char *arg)
virtual uint32_t cols ()
virtual Item * element_index (uint32_t i)
virtual Item ** addr (uint32_t i)
virtual bool check_cols (uint32_t c)
virtual bool null_inside ()
virtual void bring_value ()
Field * tmp_table_field_from_field_type (Table *table, bool fixed_length)
virtual Item * neg_transformer (Session *session)
virtual Item * update_value_transformer (unsigned char *select_arg)
virtual Item * safe_charset_converter (const charset_info_st *const tocs)
void delete_self ()
virtual bool result_as_int64_t ()
bool is_datetime ()
virtual bool is_expensive ()
String * check_well_formed_result (String *str, bool send_error=0)
bool eq_by_collation (Item *item, bool binary_cmp, const charset_info_st *const cs)
uint32_t char_to_byte_length_safe (uint32_t char_length_arg, uint32_t mbmaxlen_arg)
uint32_t max_char_length () const
void fix_char_length (uint32_t max_char_length_arg)

Public Attributes

Item * left_expr
bool * pushed_cond_guards
int sj_convert_priority
TableList * expr_join_nest
enum_exec_method exec_method
Item_func_not_all * upper_item
Public Attributes inherited from drizzled::Item_subselect
Session * session
Item * substitution
Select_Lex_Unit * unit
bool engine_changed
bool changed
bool is_correlated
Public Attributes inherited from drizzled::Item_result_field
Field * result_field
Public Attributes inherited from drizzled::Item
String str_value
const char * name
uint32_t name_length
Item * next
uint32_t max_length
int8_t marker
uint8_t decimals
bool fixed
bool maybe_null
bool null_value
bool unsigned_flag
bool with_sum_func
bool is_autogenerated_name
bool with_subselect
DTCollation collation
Item_result cmp_context

Protected Attributes

List< Cached_item > * left_expr_cache
bool first_execution
Item * expr
Item_in_optimizer * optimizer
bool was_null
bool abort_on_null
Protected Attributes inherited from drizzled::Item_exists_subselect
bool value
Protected Attributes inherited from drizzled::Item_subselect
subselect_engine * engine
subselect_engine * old_engine
table_map used_tables_cache
uint32_t 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

Static Public Member Functions inherited from drizzled::Item
static const charset_info_st * default_charset ()
Static Public Member Functions inherited from drizzled::memory::SqlAlloc
static void * operator new (size_t size)
static void * operator new[] (size_t size)
static void * operator new (size_t size, Root &root)
static void * operator new[] (size_t size, Root &root)
static void * operator new (size_t size, Root *root)
static void * operator new[] (size_t size, Root *root)
static void operator delete (void *)
static void operator delete[] (void *)
static void operator delete (void *, Root &)
static void operator delete[] (void *, Root &)
static void operator delete (void *, Root *)
static void operator delete[] (void *, Root *)
Protected Member Functions inherited from drizzled::Item
Session & getSession ()

Detailed Description

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

@detail 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 258 of file subselect.h.

Member Enumeration Documentation

◆ enum_exec_method

enum drizzled::Item_in_subselect::enum_exec_method

Definition at line 294 of file subselect.h.

Constructor & Destructor Documentation

◆ Item_in_subselect() [1/2]

drizzled::Item_in_subselect::Item_in_subselect ( Item * left_expr,
Select_Lex * select_lex )

Definition at line 737 of file subselect.cc.

◆ Item_in_subselect() [2/2]

drizzled::Item_in_subselect::Item_in_subselect ( )
inline

Definition at line 316 of file subselect.h.

Member Function Documentation

◆ cleanup()

void drizzled::Item_in_subselect::cleanup ( )
virtual

Reimplemented from drizzled::Item.

Definition at line 162 of file subselect.cc.

◆ exec()

bool drizzled::Item_in_subselect::exec ( )
virtual

Reimplemented from drizzled::Item_subselect.

Definition at line 329 of file subselect.cc.

◆ fix_fields()

bool drizzled::Item_in_subselect::fix_fields ( Session * session,
Item ** ref )
virtual

Reimplemented from drizzled::Item.

Definition at line 1705 of file subselect.cc.

◆ get_cond_guard()

bool * drizzled::Item_in_subselect::get_cond_guard ( int i)
inline

Definition at line 302 of file subselect.h.

◆ have_guarded_conds()

bool drizzled::Item_in_subselect::have_guarded_conds ( )
inlinevirtual

Reimplemented from drizzled::Item_subselect.

Definition at line 311 of file subselect.h.

◆ init_left_expr_cache()

bool drizzled::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 or the cache is not applicable to the current query
falseif success

Definition at line 1809 of file subselect.cc.

◆ is_expensive_processor()

bool drizzled::Item_in_subselect::is_expensive_processor ( unsigned char * arg)
virtual

Reimplemented from drizzled::Item.

Definition at line 1843 of file subselect.cc.

◆ is_top_level_item()

bool drizzled::Item_in_subselect::is_top_level_item ( )
inline

Definition at line 353 of file subselect.h.

◆ print()

void drizzled::Item_in_subselect::print ( String * str)
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
register_view().

Reimplemented from drizzled::Item_exists_subselect.

Reimplemented in drizzled::Item_allany_subselect.

Definition at line 1692 of file subselect.cc.

◆ reset()

void drizzled::Item_in_subselect::reset ( )
inlinevirtual

Reimplemented from drizzled::Item_exists_subselect.

Definition at line 332 of file subselect.h.

◆ row_value_in_to_exists_transformer()

Item_subselect::trans_res drizzled::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 1395 of file subselect.cc.

◆ row_value_transformer()

Item_subselect::trans_res drizzled::Item_in_subselect::row_value_transformer ( Join * join)

Definition at line 1320 of file subselect.cc.

◆ select_in_like_transformer()

Item_subselect::trans_res drizzled::Item_in_subselect::select_in_like_transformer ( Join * join,
const 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 1613 of file subselect.cc.

◆ select_transformer()

Item_subselect::trans_res drizzled::Item_in_subselect::select_transformer ( Join * join)
virtual

Reimplemented from drizzled::Item_subselect.

Definition at line 1585 of file subselect.cc.

◆ set_cond_guard_var()

void drizzled::Item_in_subselect::set_cond_guard_var ( int i,
bool v )
inline

Definition at line 306 of file subselect.h.

◆ setup_engine()

bool drizzled::Item_in_subselect::setup_engine ( )

Try to create an engine to compute the subselect via materialization, and if this fails, revert to execution via the IN=>EXISTS transformation.

The purpose of this method is to hide the implementation details of this Item's execution. The method creates a new engine for materialized execution, and initializes the engine.

If this initialization fails

  • either because it wasn't possible to create the needed temporary table and its index,
  • or because of a memory allocation error, then we revert back to execution via the IN=>EXISTS tranformation.

The initialization of the new engine is divided in two parts - a permanent one that lives across prepared statements, and one that is repeated for each execution.

Returns
Return values
truememory allocation error occurred
falsean execution method was chosen successfully

Definition at line 1740 of file subselect.cc.

◆ single_value_in_to_exists_transformer()

Item_subselect::trans_res drizzled::Item_in_subselect::single_value_in_to_exists_transformer ( Join * join,
const 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))

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 1168 of file subselect.cc.

◆ single_value_transformer()

Item_subselect::trans_res drizzled::Item_in_subselect::single_value_transformer ( Join * join,
const Comp_creator * func )

Definition at line 990 of file subselect.cc.

◆ substype()

subs_type drizzled::Item_in_subselect::substype ( )
inlinevirtual

Reimplemented from drizzled::Item_exists_subselect.

Definition at line 331 of file subselect.h.

◆ test_limit()

bool drizzled::Item_in_subselect::test_limit ( Select_Lex_Unit * unit)

Definition at line 722 of file subselect.cc.

◆ top_level_item()

void drizzled::Item_in_subselect::top_level_item ( void )
inlinevirtual

Inform the item that there will be no distinction between its result being false or NULL.

Note

This function will be called for eg. Items that are top-level AND-parts of the WHERE clause. Items implementing this function (currently Item_cond_and and subquery-related item) enable special optimizations when they are "top level".

Reimplemented from drizzled::Item.

Definition at line 352 of file subselect.h.

◆ update_null_value()

void drizzled::Item_in_subselect::update_null_value ( )
inlinevirtual

Make sure the null_value member has a correct value.

Reimplemented from drizzled::Item.

Definition at line 350 of file subselect.h.

◆ val_bool()

bool drizzled::Item_in_subselect::val_bool ( )
virtual

Return boolean value of item.

Return values
falsevalue is false or NULL true value is true (not equal to 0)
Todo
Make this functions class dependent

Reimplemented from drizzled::Item_exists_subselect.

Definition at line 913 of file subselect.cc.

◆ val_decimal()

type::Decimal * drizzled::Item_in_subselect::val_decimal ( type::Decimal * decimal_buffer)
virtual

Return decimal representation of item with fixed point.

Parameters
bufferwhich can be used by Item for returning value (but can be not)
Note

Returned value should not be changed if it is not the same which was passed via argument.

Return values
Returnpointer on type::Decimal (it can be other then passed via argument) if value is not NULL (null_value flag will be reset to false). In case of NULL value it return 0 pointer and set null_value flag to true.

Reimplemented from drizzled::Item_exists_subselect.

Definition at line 933 of file subselect.cc.

◆ val_int()

int64_t drizzled::Item_in_subselect::val_int ( )
virtual

Returns integer representation of item.

Return values
Incase of NULL value return 0 and set null_value flag to true. If value is not null null_value flag will be reset to false.

Reimplemented from drizzled::Item_exists_subselect.

Definition at line 868 of file subselect.cc.

◆ val_real()

double drizzled::Item_in_subselect::val_real ( )
virtual

Returns double precision floating point representation of item.

Return values
Incase of NULL value return 0.0 and set null_value flag to true. If value is not null null_value flag will be reset to false.

Reimplemented from drizzled::Item_exists_subselect.

Definition at line 847 of file subselect.cc.

◆ val_str()

String * drizzled::Item_in_subselect::val_str ( String * str)
virtual

Return string representation of this item object.

Parameters
anallocated buffer this or any nested Item object can use to store return value of this method.
Note

Buffer passed via argument should only be used if the item itself doesn't have an own String buffer. In case when the item maintains it's own string buffer, it's preferable to return it instead to minimize number of mallocs/memcpys.

The caller of this method can modify returned string, but only in case when it was allocated on heap, (is_alloced() is true). This allows the caller to efficiently use a buffer allocated by a child without having to allocate a buffer of it's own. The buffer, given to val_str() as argument, belongs to the caller and is later used by the caller at it's own choosing.

A few implications from the above:

  • unless you return a string object which only points to your buffer but doesn't manages it you should be ready that it will be modified.
  • even for not allocated strings (is_alloced() == false) the caller can change charset (see Item_func_{typecast/binary}. XXX: is this a bug?
  • still you should try to minimize data copying and return internal object whenever possible.
Return values
Incase of NULL value return 0 (NULL pointer) and set null_value flag to true. If value is not null null_value flag will be reset to false.

Reimplemented from drizzled::Item_exists_subselect.

Definition at line 888 of file subselect.cc.

◆ Item_in_optimizer

friend class Item_in_optimizer
friend

Definition at line 363 of file subselect.h.

◆ Item_is_not_null_test

friend class Item_is_not_null_test
friend

Definition at line 362 of file subselect.h.

◆ Item_ref_null_helper

friend class Item_ref_null_helper
friend

Definition at line 361 of file subselect.h.

◆ subselect_hash_sj_engine

friend class subselect_hash_sj_engine
friend

Definition at line 365 of file subselect.h.

◆ subselect_indexsubquery_engine

friend class subselect_indexsubquery_engine
friend

Definition at line 364 of file subselect.h.

Member Data Documentation

◆ abort_on_null

bool drizzled::Item_in_subselect::abort_on_null
protected

Definition at line 277 of file subselect.h.

◆ exec_method

enum_exec_method drizzled::Item_in_subselect::exec_method

Definition at line 300 of file subselect.h.

◆ expr

Item* drizzled::Item_in_subselect::expr
protected

Definition at line 274 of file subselect.h.

◆ expr_join_nest

TableList* drizzled::Item_in_subselect::expr_join_nest

Definition at line 291 of file subselect.h.

◆ first_execution

bool drizzled::Item_in_subselect::first_execution
protected

Definition at line 268 of file subselect.h.

◆ left_expr

Item* drizzled::Item_in_subselect::left_expr

Definition at line 261 of file subselect.h.

◆ left_expr_cache

List<Cached_item>* drizzled::Item_in_subselect::left_expr_cache
protected

Definition at line 267 of file subselect.h.

◆ optimizer

Item_in_optimizer* drizzled::Item_in_subselect::optimizer
protected

Definition at line 275 of file subselect.h.

◆ pushed_cond_guards

bool* drizzled::Item_in_subselect::pushed_cond_guards

Definition at line 281 of file subselect.h.

◆ sj_convert_priority

int drizzled::Item_in_subselect::sj_convert_priority

Definition at line 284 of file subselect.h.

◆ upper_item

Item_func_not_all* drizzled::Item_in_subselect::upper_item

Definition at line 313 of file subselect.h.

◆ was_null

bool drizzled::Item_in_subselect::was_null
protected

Definition at line 276 of file subselect.h.


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