MySQL 8.0.40
Source Code Documentation
Item_in_subselect Class Reference

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

#include <item_subselect.h>

Inheritance diagram for Item_in_subselect:
[legend]

Classes

struct  In2exists_info
 This bundles several pieces of information useful when doing the IN->EXISTS transform. More...
 

Public Member Functions

bool in2exists_added_to_where () const
 
bool dependent_before_in2exists () const
 Is reliable only if IN->EXISTS has been done. More...
 
bool * get_cond_guard (int i)
 
void set_cond_guard_var (int i, bool v)
 
 Item_in_subselect (Item *left_expr, Query_block *query_block)
 
 Item_in_subselect (const POS &pos, Item *left_expr, PT_subquery *pt_subquery_arg)
 
 Item_in_subselect ()
 
bool itemize (Parse_context *pc, Item **res) override
 The same as contextualize() but with additional parameter. More...
 
void cleanup () override
 Called for every Item after use (preparation and execution). More...
 
subs_type substype () const override
 
void reset () override
 
bool select_transformer (THD *thd, Query_block *select) override
 
bool select_in_like_transformer (THD *thd, Query_block *select, Comp_creator *func)
 Prepare IN/ALL/ANY/SOME subquery transformation and call appropriate transformation function. More...
 
bool single_value_transformer (THD *thd, Query_block *select, Comp_creator *func)
 Rewrite a single-column IN/ALL/ANY subselect. More...
 
bool row_value_transformer (THD *thd, Query_block *select)
 
bool single_value_in_to_exists_transformer (THD *thd, Query_block *select, Comp_creator *func)
 Transform an IN predicate into EXISTS via predicate injection. More...
 
bool row_value_in_to_exists_transformer (THD *thd, Query_block *select)
 Transform a (possibly non-correlated) IN subquery into a correlated EXISTS. More...
 
bool subquery_allows_materialization (THD *thd, Query_block *query_block, const Query_block *outer)
 Check if the subquery predicate can be executed via materialization. More...
 
bool walk (Item_processor processor, enum_walk walk, uchar *arg) override
 Traverses a tree of Items in prefix and/or postfix order. More...
 
Itemtransform (Item_transformer transformer, uchar *arg) override
 Perform a generic transformation of the Item tree, by adding zero or more additional Item objects to it. More...
 
Itemcompile (Item_analyzer analyzer, uchar **arg_p, Item_transformer transformer, uchar *arg_t) override
 Perform a generic "compilation" of the Item tree, ie transform the Item tree by adding zero or more Item objects to it. More...
 
bool exec (THD *thd) override
 
longlong val_int () override
 
double val_real () override
 
Stringval_str (String *) override
 Return the result of EXISTS as a string value. More...
 
my_decimalval_decimal (my_decimal *) override
 Return the result of EXISTS as a decimal value. More...
 
bool val_bool () override
 
bool test_limit ()
 
void print (const THD *thd, String *str, enum_query_type query_type) const override
 This method is used for to: More...
 
bool fix_fields (THD *thd, Item **ref) override
 An object of class Item_in_subselect is always substituted with another object of class Item_in_optimizer, and the substitution object contains a pointer to the original Item_in_subselect. More...
 
void fix_after_pullout (Query_block *parent_query_block, Query_block *removed_query_block) override
 
void update_used_tables () override
 Updates used tables, not null tables information and accumulates properties up the item tree, cf. More...
 
bool init_left_expr_cache (THD *thd)
 Initialize the cache of the left operand of the IN predicate. More...
 
bool finalize_exists_transform (THD *thd, Query_block *select)
 Once the decision to use IN->EXISTS has been taken, performs some last steps of this transformation. More...
 
bool finalize_materialization_transform (THD *thd, JOIN *join)
 Once the decision to use materialization has been taken, performs some last steps of this transformation. More...
 
AccessPathroot_access_path () const override
 
std::optional< ContainedSubqueryget_contained_subquery (const Query_block *outer_query_block) override
 If this item represents a IN/ALL/ANY/comparison_operator subquery, return that (along with data on how it will be executed). More...
 
- Public Member Functions inherited from Item_exists_subselect
 Item_exists_subselect (Query_block *select)
 
 Item_exists_subselect ()
 
 Item_exists_subselect (const POS &pos)
 
void notify_removal () override
 Called when an item has been removed, can be used to notify external objects about the removal, e.g subquery predicates that are part of the sj_candidates container. More...
 
bool is_bool_func () const override
 
enum Item_result result_type () const override
 
bool with_is_op () const
 
Itemtruth_transformer (THD *, enum Bool_test test) override
 Informs an item that it is wrapped in a truth test, in case it wants to transforms itself to implement this test by itself. More...
 
bool translate (bool &null_v, bool v)
 Translates the value of the naked EXISTS to a value taking into account the optional NULL and IS [NOT] TRUE/FALSE. More...
 
void apply_is_true () override
 Apply the IS TRUE truth property, meaning that an UNKNOWN result and a FALSE result are treated the same. More...
 
bool choose_semijoin_or_antijoin ()
 Helper for resolve_subquery(). More...
 
bool get_date (MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
 
bool get_time (MYSQL_TIME *ltime) override
 
bool resolve_type (THD *thd) override
 Resolve type-related information for this item, such as result field type, maximum size, precision, signedness, character set and collation. More...
 
- Public Member Functions inherited from Item_subselect
enum_engine_type engine_type () const
 
const TABLEget_table () const
 
const Index_lookupindex_lookup () const
 
join_type get_join_type () const
 
void create_iterators (THD *thd)
 
 Item_subselect ()
 
 Item_subselect (const POS &pos)
 
void accumulate_used_tables (table_map add_tables)
 Accumulate used tables. More...
 
bool assigned () const
 
void assigned (bool a)
 
enum Type type () const override
 
bool is_null () override
 The method allows to determine nullness of a complex expression without fully evaluating it, instead of calling val*() then checking null_value. More...
 
table_map used_tables () const override
 
table_map not_null_tables () const override
 Return table map of tables that can't be NULL tables (tables that are used in a context where if they would contain a NULL row generated by a LEFT or RIGHT join, the item would not be true). More...
 
Itemget_tmp_table_item (THD *thd) override
 If an Item is materialized in a temporary table, a different Item may have to be used in the part of the query that runs after the materialization. More...
 
void set_indexsubquery_engine (subselect_indexsubquery_engine *eng)
 
bool is_evaluated () const
 
bool is_uncacheable () const
 
virtual void reset_value_registration ()
 
enum_parsing_context place ()
 
bool explain_subquery_checker (uchar **arg) override
 Register subquery to the table where it is used within a condition. More...
 
bool inform_item_in_cond_of_tab (uchar *arg) override
 Tells an Item that it is in the condition of a JOIN_TAB of a query block. More...
 
bool clean_up_after_removal (uchar *arg) override
 Clean up after removing the subquery from the item tree. More...
 
const char * func_name () const override
 
bool check_function_as_value_generator (uchar *args) override
 Check if this item is allowed for a virtual column or inside a default expression. More...
 
bool collect_subqueries (uchar *) override
 
Itemreplace_item_field (uchar *arg) override
 Transform processor. More...
 
Itemreplace_item_view_ref (uchar *arg) override
 Transform processor. More...
 
Itemreplace_item (Item_transformer t, uchar *arg)
 
- Public Member Functions inherited from Item_result_field
 Item_result_field ()=default
 
 Item_result_field (const POS &pos)
 
 Item_result_field (THD *thd, const Item_result_field *item)
 
Fieldget_tmp_table_field () override
 If this Item is being materialized into a temporary table, returns the field that is being materialized into. More...
 
Fieldtmp_table_field (TABLE *) override
 
void set_result_field (Field *field) override
 
bool is_result_field () const override
 
Fieldget_result_field () const override
 
bool mark_field_in_map (uchar *arg) override
 Mark underlying field in read or write map of a table. More...
 
longlong llrint_with_overflow_check (double realval)
 
void raise_numeric_overflow (const char *type_name)
 
double raise_float_overflow ()
 
longlong raise_integer_overflow ()
 
int raise_decimal_overflow ()
 
- Public Member Functions inherited from Item
 Item (const Item &)=delete
 
void operator= (Item &)=delete
 
 Item ()
 Item constructor for general use. More...
 
 Item (THD *thd, const Item *item)
 Constructor used by Item_field, Item_ref & aggregate functions. More...
 
 Item (const POS &)
 Parse-time context-independent constructor. More...
 
 ~Item () override=default
 
void rename (char *new_name)
 rename item (used for views, cleanup() return original name). More...
 
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) const
 Create a field to hold a string value from an item. More...
 
void quick_fix_field ()
 
virtual void set_can_use_prefix_key ()
 
virtual bool propagate_type (THD *thd, const Type_properties &type)
 Propagate data type specifications into parameters and user variables. More...
 
bool propagate_type (THD *thd, enum_field_types def=MYSQL_TYPE_VARCHAR, bool pin=false, bool inherit=false)
 Wrapper for easier calling of propagate_type(const Type_properties &). More...
 
virtual void mark_json_as_scalar ()
 For Items with data type JSON, mark that a string argument is treated as a scalar JSON value. More...
 
type_conversion_status save_in_field_no_warnings (Field *field, bool no_conversions)
 Save the item into a field but do not emit any warnings. More...
 
type_conversion_status save_in_field (Field *field, bool no_conversions)
 Save a temporal value in packed longlong format into a Field. More...
 
void save_in_field_no_error_check (Field *field, bool no_conversions)
 A slightly faster value of save_in_field() that returns no error value (you will need to check thd->is_error() yourself), and does not support saving into hidden fields for functional indexes. More...
 
virtual void save_org_in_field (Field *field)
 
virtual bool send (Protocol *protocol, String *str)
 This is only called from items that is not of type item_field. More...
 
bool evaluate (THD *thd, String *str)
 Evaluate item, possibly using the supplied buffer. More...
 
virtual bool eq (const Item *, bool binary_cmp) const
 
virtual Item_result numeric_context_result_type () const
 Result type when an item appear in a numeric context. More...
 
Item_result temporal_with_date_as_number_result_type () const
 Similar to result_type() but makes DATE, DATETIME, TIMESTAMP pretend to be numbers rather than strings. More...
 
virtual void set_data_type_inherited ()
 Set data type for item as inherited. More...
 
virtual void pin_data_type ()
 Pin the data type for the item. More...
 
enum_field_types data_type () const
 Retrieve the derived data type of the Item. More...
 
virtual enum_field_types actual_data_type () const
 Retrieve actual data type for an item. More...
 
virtual enum_field_types default_data_type () const
 Get the default data (output) type for the specific item. More...
 
void set_data_type (enum_field_types data_type)
 Set the data type of the current Item. More...
 
void set_data_type_null ()
 
void set_data_type_bool ()
 
void set_data_type_longlong ()
 Set the data type of the Item to be longlong. More...
 
void set_data_type_decimal (uint8 precision, uint8 scale)
 Set the data type of the Item to be decimal. More...
 
void set_data_type_double ()
 Set the data type of the Item to be double precision floating point. More...
 
void set_data_type_float ()
 Set the data type of the Item to be single precision floating point. More...
 
void set_data_type_string (uint32 max_l)
 Set the Item to be variable length string. More...
 
void set_data_type_string (ulonglong max_char_length_arg)
 Set the Item to be variable length string. More...
 
void set_data_type_string (uint32 max_l, const CHARSET_INFO *cs)
 Set the Item to be variable length string. More...
 
void set_data_type_string (uint32 max_l, const DTCollation &coll)
 Set the Item to be variable length string. More...
 
void set_data_type_char (uint32 max_l)
 Set the Item to be fixed length string. More...
 
void set_data_type_char (uint32 max_l, const CHARSET_INFO *cs)
 Set the Item to be fixed length string. More...
 
void set_data_type_blob (uint32 max_l)
 Set the Item to be of BLOB type. More...
 
void set_data_type_date ()
 Set all type properties for Item of DATE type. More...
 
void set_data_type_time (uint8 fsp)
 Set all type properties for Item of TIME type. More...
 
void set_data_type_datetime (uint8 fsp)
 Set all properties for Item of DATETIME type. More...
 
void set_data_type_timestamp (uint8 fsp)
 Set all properties for Item of TIMESTAMP type. More...
 
void set_data_type_geometry ()
 Set the data type of the Item to be GEOMETRY. More...
 
void set_data_type_json ()
 Set the data type of the Item to be JSON. More...
 
void set_data_type_year ()
 Set the data type of the Item to be YEAR. More...
 
void set_data_type_bit ()
 Set the data type of the Item to be bit. More...
 
void set_data_type_from_item (const Item *item)
 Set data type properties of the item from the properties of another item. More...
 
virtual TYPELIBget_typelib () const
 Get the typelib information for an item of type set or enum. More...
 
virtual Item_result cast_to_int_type () const
 
void aggregate_type (Bounds_checked_array< Item * > items)
 Aggregates data types from array of items into current item. More...
 
virtual enum_monotonicity_info get_monotonicity_info () const
 
virtual longlong val_int_endpoint (bool left_endp, bool *incl_endp)
 
virtual longlong val_date_temporal ()
 Return date value of item in packed longlong format. More...
 
virtual longlong val_time_temporal ()
 Return time value of item in packed longlong format. More...
 
longlong val_temporal_by_field_type ()
 Return date or time value of item in packed longlong format, depending on item field type. More...
 
longlong int_sort_key ()
 Produces a key suitable for filesort. More...
 
longlong val_temporal_with_round (enum_field_types type, uint8 dec)
 Get date or time value in packed longlong format. More...
 
ulonglong val_uint ()
 
virtual Stringval_str_ascii (String *str)
 
virtual bool val_json (Json_wrapper *result)
 Get a JSON value from an Item. More...
 
virtual float get_filtering_effect (THD *thd, table_map filter_for_table, table_map read_tables, const MY_BITMAP *fields_to_ignore, double rows_in_table)
 Calculate the filter contribution that is relevant for table 'filter_for_table' for this item. More...
 
bool error_json ()
 Get the value to return from val_json() in case of errors. More...
 
bool get_date_from_non_temporal (MYSQL_TIME *ltime, my_time_flags_t fuzzydate)
 Convert a non-temporal type to date. More...
 
bool get_time_from_non_temporal (MYSQL_TIME *ltime)
 Convert a non-temporal type to time. More...
 
my_decimalerror_decimal (my_decimal *decimal_value)
 Get the value to return from val_decimal() in case of errors. More...
 
Stringerror_str ()
 Get the value to return from val_str() in case of errors. More...
 
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 bool basic_const_item () const
 Returns true if this is a simple constant item like an integer, not a constant expression. More...
 
bool may_eval_const_item (const THD *thd) const
 
virtual Itemclone_item () const
 
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 ()
 TIME precision of the item: 0..6. More...
 
virtual uint datetime_precision ()
 DATETIME precision of the item: 0..6. More...
 
bool const_item () const
 Returns true if item is constant, regardless of query evaluation state. More...
 
bool const_for_execution () const
 Returns true if item is constant during one query execution. More...
 
bool may_evaluate_const (const THD *thd) const
 Return true if this is a const item that may be evaluated in the current phase of statement processing. More...
 
bool is_non_deterministic () const
 
bool is_outer_reference () const
 
void print_item_w_name (const THD *thd, String *, enum_query_type query_type) const
 
void print_for_order (const THD *thd, String *str, enum_query_type query_type, bool used_alias) const
 Prints the item when it's part of ORDER BY and GROUP BY. More...
 
virtual void split_sum_func (THD *, Ref_item_array, mem_root_deque< Item * > *)
 
void split_sum_func2 (THD *thd, Ref_item_array ref_item_array, mem_root_deque< Item * > *fields, Item **ref, bool skip_registered)
 
virtual bool get_timeval (my_timeval *tm, int *warnings)
 Get timestamp in "struct timeval" format. More...
 
bool update_null_value ()
 Make sure the null_value member has a correct value. More...
 
virtual void no_rows_in_result ()
 
virtual Itemcopy_or_same (THD *)
 
virtual Itemcopy_andor_structure (THD *)
 
virtual Itemreal_item ()
 
virtual const Itemreal_item () const
 
virtual const CHARSET_INFOcompare_collation () const
 
virtual const CHARSET_INFOcharset_for_protocol ()
 
template<class T >
auto walk_helper_thunk (uchar *arg)
 
template<class T >
auto analyze_helper_thunk (uchar **arg)
 See CompileItem. More...
 
virtual void traverse_cond (Cond_traverser traverser, void *arg, traverse_order)
 
virtual bool intro_version (uchar *)
 
bool cleanup_processor (uchar *)
 cleanup() item if it is resolved ('fixed'). More...
 
virtual bool collect_item_field_processor (uchar *)
 
virtual bool collect_item_field_or_ref_processor (uchar *)
 
virtual bool collect_item_field_or_view_ref_processor (uchar *)
 Collects fields and view references that have the qualifying table in the specified query block. More...
 
virtual bool add_field_to_set_processor (uchar *)
 Item::walk function. More...
 
virtual bool visitor_processor (uchar *arg)
 A processor to handle the select lex visitor framework. More...
 
virtual bool add_field_to_cond_set_processor (uchar *)
 Item::walk function. More...
 
virtual bool remove_column_from_bitmap (uchar *arg)
 Visitor interface for removing all column expressions (Item_field) in this expression tree from a bitmap. More...
 
virtual bool find_item_in_field_list_processor (uchar *)
 
virtual bool change_context_processor (uchar *)
 
virtual bool find_item_processor (uchar *arg)
 
virtual bool is_non_const_over_literals (uchar *)
 
virtual bool find_field_processor (uchar *)
 Is this an Item_field which references the given Field argument? More...
 
virtual bool cast_incompatible_args (uchar *)
 Wrap incompatible arguments in CAST nodes to the expected data types. More...
 
virtual bool reset_wf_state (uchar *arg)
 Reset execution state for such window function types as determined by arg. More...
 
virtual bool used_tables_for_level (uchar *arg)
 Return used table information for the specified query block (level). More...
 
virtual bool check_column_privileges (uchar *thd)
 Check privileges. More...
 
virtual void bind_fields ()
 Bind objects from the current execution context to field objects in item trees. More...
 
virtual bool aggregate_check_distinct (uchar *)
 
virtual bool aggregate_check_group (uchar *)
 
virtual bool is_strong_side_column_not_in_fd (uchar *)
 
virtual bool is_column_not_in_fd (uchar *)
 
virtual Bool3 local_column (const Query_block *) const
 
virtual bool collect_scalar_subqueries (uchar *)
 
virtual bool collect_grouped_aggregates (uchar *)
 
virtual bool update_depended_from (uchar *)
 
virtual bool has_aggregate_ref_in_group_by (uchar *)
 Check if an aggregate is referenced from within the GROUP BY clause of the query block in which it is aggregated. More...
 
bool visit_all_analyzer (uchar **)
 
virtual bool cache_const_expr_analyzer (uchar **cache_item)
 Check if an item is a constant one and can be cached. More...
 
Itemcache_const_expr_transformer (uchar *item)
 Cache item if needed. More...
 
virtual bool equality_substitution_analyzer (uchar **)
 
virtual Itemequality_substitution_transformer (uchar *)
 
virtual bool check_partition_func_processor (uchar *)
 Check if a partition function is allowed. More...
 
virtual bool subst_argument_checker (uchar **arg)
 
virtual Itemexplain_subquery_propagator (uchar *)
 
virtual Itemequal_fields_propagator (uchar *)
 
virtual bool disable_constant_propagation (uchar *)
 
virtual Itemreplace_equal_field (uchar *)
 
virtual bool check_valid_arguments_processor (uchar *)
 
virtual bool check_gcol_depend_default_processor (uchar *args)
 Check if a generated expression depends on DEFAULT function with specific column name as argument. More...
 
virtual bool is_valid_for_pushdown (uchar *arg)
 Check if all the columns present in this expression are from the derived table. More...
 
virtual bool check_column_in_window_functions (uchar *arg)
 Check if all the columns present in this expression are present in PARTITION clause of window functions of the derived table. More...
 
virtual bool check_column_in_group_by (uchar *arg)
 Check if all the columns present in this expression are present in GROUP BY clause of the derived table. More...
 
virtual Itemreplace_with_derived_expr (uchar *arg)
 Assuming this expression is part of a condition that would be pushed to the WHERE clause of a materialized derived table, replace, in this expression, each derived table's column with a clone of the expression lying under it in the derived table's definition. More...
 
virtual Itemreplace_with_derived_expr_ref (uchar *arg)
 Assuming this expression is part of a condition that would be pushed to the HAVING clause of a materialized derived table, replace, in this expression, each derived table's column with a reference to the expression lying under it in the derived table's definition. More...
 
virtual Itemreplace_view_refs_with_clone (uchar *arg)
 Assuming this expression is part of a condition that would be pushed to a materialized derived table, replace, in this expression, each view reference with a clone of the expression in merged derived table's definition. More...
 
virtual Itemthis_item ()
 
virtual const Itemthis_item () const
 
virtual Item ** this_item_addr (THD *, Item **addr_arg)
 
virtual uint cols () const
 
virtual Itemelement_index (uint)
 
virtual Item ** addr (uint)
 
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) const
 Create a field based on field_type of argument. More...
 
virtual Item_fieldfield_for_view_update ()
 
virtual Itemupdate_value_transformer (uchar *)
 
virtual Itemreplace_scalar_subquery (uchar *)
 When walking the item tree seeing an Item_singlerow_subselect matching a target, replace it with a substitute field used when transforming scalar subqueries into derived tables. More...
 
virtual Itemreplace_aggregate (uchar *)
 
virtual Itemreplace_outer_ref (uchar *)
 
virtual bool update_aggr_refs (uchar *)
 A walker processor overridden by Item_aggregate_ref, q.v. More...
 
virtual Itemsafe_charset_converter (THD *thd, const CHARSET_INFO *tocs)
 
void delete_self ()
 Delete this item. More...
 
virtual bool is_splocal () const
 
virtual Settable_routine_parameterget_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
 Check whether this and the given item has compatible comparison context. More...
 
virtual Field::geometry_type get_geometry_type () const
 
Stringcheck_well_formed_result (String *str, bool send_error, bool truncate)
 Verifies that the input string is well-formed according to its character set. More...
 
bool eq_by_collation (Item *item, bool binary_cmp, const CHARSET_INFO *cs)
 
virtual bool is_expensive ()
 
uint32 max_char_length () const
 
uint32 max_char_length (const CHARSET_INFO *cs) const
 
void fix_char_length (uint32 max_char_length_arg)
 
virtual bool is_outer_field () const
 
bool is_blob_field () const
 Check if an item either is a blob field, or will be represented as a BLOB field if a field is created based on this item. More...
 
uint reference_count () const
 
void increment_ref_count ()
 Increment reference count. More...
 
uint decrement_ref_count ()
 Decrement reference count. More...
 
bool has_subquery () const
 
bool has_stored_program () const
 
bool has_aggregation () const
 
void set_aggregation ()
 Set the "has aggregation" property. More...
 
void reset_aggregation ()
 Reset the "has aggregation" property. More...
 
bool has_wf () const
 
void set_wf ()
 Set the "has window function" property. More...
 
bool has_rollup_expr () const
 
void set_rollup_expr ()
 Set the property: this item (tree) contains a reference to a ROLLUP expr. More...
 
bool has_grouping_func () const
 
void set_grouping_func ()
 Set the property: this item is a call to GROUPING. More...
 
virtual bool created_by_in2exists () const
 Whether this Item was created by the IN->EXISTS subquery transformation. More...
 
void mark_subqueries_optimized_away ()
 
virtual bool gc_subst_analyzer (uchar **)
 Analyzer function for GC substitution. More...
 
virtual Itemgc_subst_transformer (uchar *)
 Transformer function for GC substitution. More...
 
virtual bool replace_field_processor (uchar *)
 A processor that replaces any Fields with a Create_field_wrapper. More...
 
bool can_be_substituted_for_gc (bool array=false) const
 Check if this item is of a type that is eligible for GC substitution. More...
 
void aggregate_decimal_properties (Item **item, uint nitems)
 Set precision and decimals of function when this depends on arguments' values for these quantities. More...
 
void aggregate_float_properties (Item **item, uint nitems)
 Set max_length and decimals of function if function is floating point and result length/precision depends on argument ones. More...
 
void aggregate_char_length (Item **args, uint nitems)
 Set the maximum number of characters required by any of the items in args. More...
 
void aggregate_temporal_properties (Item **item, uint nitems)
 Set fractional seconds precision for temporal functions. More...
 
bool aggregate_string_properties (const char *name, Item **item, uint nitems)
 Aggregate string properties (character set, collation and maximum length) for string function. More...
 
void aggregate_num_type (Item_result result_type, Item **item, uint nitems)
 This function is used to resolve type for numeric result type of CASE, COALESCE, IF and LEAD/LAG. More...
 
virtual bool repoint_const_outer_ref (uchar *arg)
 This function applies only to Item_field objects referred to by an Item_ref object that has been marked as a const_item. More...
 
virtual bool strip_db_table_name_processor (uchar *)
 
bool is_abandoned () const
 
bool is_nullable () const
 
void set_nullable (bool nullable)
 
virtual bool supports_partial_update (const Field_json *field) const
 Check if this expression can be used for partial update of a given JSON column. More...
 
virtual bool returns_array () const
 Whether the item returns array of its data type. More...
 
virtual void allow_array_cast ()
 A helper function to ensure proper usage of CAST(. More...
 
- Public Member Functions inherited from Parse_tree_node_tmpl< Context >
virtual ~Parse_tree_node_tmpl ()=default
 
bool is_contextualized () const
 
virtual bool contextualize (Context *pc)
 Do all context-sensitive things and mark the node as contextualized. More...
 
void error (Context *pc, const POS &pos) const
 syntax_error() function replacement for deferred reporting of syntax errors More...
 
void error (Context *pc, const POS &pos, const char *msg) const
 syntax_error() function replacement for deferred reporting of syntax errors More...
 
void errorf (Context *pc, const POS &pos, const char *format,...) const
 syntax_error() function replacement for deferred reporting of syntax errors More...
 

Public Attributes

Itemleft_expr
 
bool * pushed_cond_guards
 
Item_func_not_allupper_item
 
- Public Attributes inherited from Item_exists_subselect
int sj_convert_priority {0}
 Priority of this predicate in the convert-to-semi-join-nest process. More...
 
Subquery_strategy strategy {Subquery_strategy::UNSPECIFIED}
 Execution strategy chosen for this Item. More...
 
enum_condition_context outer_condition_context {enum_condition_context::ANDS}
 Used by the transformation to derived table. More...
 
Table_refembedding_join_nest {nullptr}
 Used by subquery optimizations to keep track about where this subquery predicate is located, and whether it is a candidate for transformation. More...
 
enum Bool_test value_transform = BOOL_IDENTITY
 
bool implicit_is_op = false
 True if the IS TRUE/FALSE wasn't explicit in the query. More...
 
bool can_do_aj = false
 True if the Item has decided that it can do antijoin. More...
 
- Public Attributes inherited from Item_subselect
Itemsubstitution
 
Query_expressionunit
 
int in_cond_of_tab
 If !=NO_PLAN_IDX: this Item is in the condition attached to the JOIN_TAB having this index in the parent JOIN. More...
 
table_map m_subquery_used_tables {0}
 cache of used tables, used to identify tables added for IN subquery More...
 
bool changed
 subquery is transformed More...
 
- Public Attributes inherited from Item
Itemnext_free
 Intrusive list pointer for free list. More...
 
DTCollation collation
 Character set and collation properties assigned for this Item. More...
 
Item_name_string item_name
 Name from query. More...
 
Item_name_string orig_name
 Original item name (if it was renamed) More...
 
uint32 max_length
 Maximum length of result of evaluating this item, in number of bytes. More...
 
item_marker marker
 This member has several successive meanings, depending on the phase we're in (. More...
 
Item_result cmp_context
 Comparison context. More...
 
bool fixed
 True if item has been resolved. More...
 
uint8 decimals
 Number of decimals in result when evaluating this item. More...
 
bool null_value
 True if item is null. More...
 
bool unsigned_flag
 
bool m_is_window_function
 True if item represents window func. More...
 
bool hidden {false}
 If the item is in a SELECT list (Query_block::fields) and hidden is true, the item wasn't actually in the list as given by the user (it was added by the optimizer, to e.g. More...
 
bool m_in_check_constraint_exec_ctx {false}
 True if item is a top most element in the expression being evaluated for a check constraint. More...
 

Protected Attributes

List< Cached_item > * left_expr_cache
 Cache of the left operand of the subquery predicate. More...
 
bool left_expr_cache_filled
 Whether left_expr_cache holds a value. More...
 
bool need_expr_cache
 The need for expr cache may be optimized away,. More...
 
bool abort_on_null
 True if naked IN is allowed to exchange FALSE for UNKNOWN. More...
 
- Protected Attributes inherited from Item_exists_subselect
bool value {false}
 value of this item (boolean: exists/not-exists) More...
 
- Protected Attributes inherited from Item_subselect
unique_ptr_destroy_only< SubqueryWithResultsubquery
 The inner part of the subquery. More...
 
subselect_indexsubquery_engineindexsubquery_engine = nullptr
 Only relevant for Item_in_subselect; optimized structure used for execution in place of running the entire subquery. More...
 
table_map used_tables_cache
 cache of used tables More...
 
uint max_columns
 allowed number of columns (1 for scalar subqueries) More...
 
enum_parsing_context parsing_place
 where subquery is placed More...
 
bool have_to_be_excluded
 work with 'substitution' More...
 
- Protected Attributes inherited from Item_result_field
Fieldresult_field {nullptr}
 
- Protected Attributes inherited from Item
String str_value
 str_values's main purpose is to cache the value in save_in_field More...
 
uint8 m_accum_properties
 

Private Types

typedef Item_exists_subselect super
 

Private Member Functions

bool mark_as_outer (Item *left_row, size_t col)
 Decide whether to mark the injected left expression "outer" relative to the subquery. More...
 
bool val_bool_naked ()
 

Private Attributes

Item_refm_injected_left_expr
 In the case of. More...
 
Item_in_optimizeroptimizer
 Pointer to the created Item_in_optimizer; it is stored for the same reasons as 'm_injected_left_expr'. More...
 
bool was_null
 
struct Item_in_subselect::In2exists_infoin2exists_info
 
PT_subquerypt_subselect
 

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_subselect
enum  enum_engine_type { OTHER_ENGINE , INDEXSUBQUERY_ENGINE , HASH_SJ_ENGINE }
 
enum  subs_type {
  UNKNOWN_SUBS , SINGLEROW_SUBS , EXISTS_SUBS , IN_SUBS ,
  ALL_SUBS , ANY_SUBS
}
 
- Public Types inherited from Item
enum  Type {
  INVALID_ITEM = 0 , FIELD_ITEM , FUNC_ITEM , SUM_FUNC_ITEM ,
  STRING_ITEM , INT_ITEM , REAL_ITEM , NULL_ITEM ,
  VARBIN_ITEM , METADATA_COPY_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 , TRIGGER_FIELD_ITEM ,
  DECIMAL_ITEM , XPATH_NODESET , XPATH_NODESET_CMP , VIEW_FIXER_ITEM ,
  FIELD_BIT_ITEM , VALUES_COLUMN_ITEM
}
 
enum  cond_result { COND_UNDEF , COND_OK , COND_TRUE , COND_FALSE }
 
enum  traverse_order { POSTFIX , PREFIX }
 
enum  enum_const_item_cache { CACHE_NONE = 0 , CACHE_JSON_VALUE , CACHE_JSON_ATOM }
 How to cache constant JSON data. More...
 
enum  Bool_test {
  BOOL_IS_TRUE = 0x00 , BOOL_IS_FALSE = 0x01 , BOOL_IS_UNKNOWN = 0x02 , BOOL_NOT_TRUE = 0x03 ,
  BOOL_NOT_FALSE = 0x04 , BOOL_NOT_UNKNOWN = 0x05 , BOOL_IDENTITY = 0x06 , BOOL_NEGATED = 0x07 ,
  BOOL_ALWAYS_TRUE = 0x08 , BOOL_ALWAYS_FALSE = 0x09
}
 < Modifier for result transformation More...
 
enum  item_marker {
  MARKER_NONE = 0 , MARKER_IMPLICIT_NE_ZERO = 1 , MARKER_CONST_PROPAG = 2 , MARKER_BIT = 4 ,
  MARKER_FUNC_DEP_NOT_NULL = 5 , MARKER_DISTINCT_GROUP = 6 , MARKER_COND_DERIVED_TABLE = 7 , MARKER_TRAVERSAL = 8 ,
  MARKER_ICP_COND_USES_INDEX_ONLY = 10
}
 < Values for member 'marker' More...
 
- Public Types inherited from Parse_tree_node_tmpl< Context >
typedef Context context_t
 
- Static Public Member Functions inherited from Item
static void * operator new (size_t size) noexcept
 
static void * operator new (size_t size, MEM_ROOT *mem_root, const std::nothrow_t &arg=std::nothrow) noexcept
 
static void operator delete (void *ptr, size_t size)
 
static void operator delete (void *, MEM_ROOT *, const std::nothrow_t &) noexcept
 
static enum_field_types result_to_type (Item_result result)
 
static Item_result type_to_result (enum_field_types type)
 
static enum_field_types type_for_variable (enum_field_types src_type)
 Provide data type for a user or system variable, based on the type of the item that is assigned to the variable. More...
 
static enum_field_types string_field_type (uint32 max_bytes)
 Determine correct string field type, based on string length. More...
 
static const CHARSET_INFOdefault_charset ()
 
- Static Public Member Functions inherited from Parse_tree_node_tmpl< Context >
static void * operator new (size_t size, MEM_ROOT *mem_root, const std::nothrow_t &arg=std::nothrow) noexcept
 
static void operator delete (void *ptr, size_t size)
 
static void operator delete (void *, MEM_ROOT *, const std::nothrow_t &) noexcept
 
- Protected Member Functions inherited from Item_subselect
void init (Query_block *select, Query_result_subquery *result)
 We need this method, because some compilers do not allow 'this' pointer in constructor initialization list, but we need to pass a pointer to subselect Item class to Query_result_interceptor's constructor. More...
 
uint unit_cols () const
 
- Protected Member Functions inherited from Item
Stringmake_empty_result ()
 Sets the result value of the function an empty string, using the current character set. More...
 
bool skip_itemize (Item **res)
 Helper function to skip itemize() for grammar-allocated items. More...
 
virtual type_conversion_status save_in_field_inner (Field *field, bool no_conversions)
 Helper function which does all of the work for save_in_field(Field*, bool), except some error checking common to all subclasses, which is performed by save_in_field() itself. More...
 
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 ()
 
longlong val_int_from_string ()
 
double val_real_from_decimal ()
 
double val_real_from_string ()
 
bool error_bool ()
 Get the value to return from val_bool() in case of errors. More...
 
int error_int ()
 Get the value to return from val_int() in case of errors. More...
 
double error_real ()
 Get the value to return from val_real() in case of errors. More...
 
bool error_date ()
 Get the value to return from get_date() in case of errors. More...
 
bool error_time ()
 Get the value to return from get_time() in case of errors. More...
 
Stringnull_return_str ()
 Gets the value to return from val_str() when returning a NULL value. More...
 
bool get_date_from_string (MYSQL_TIME *ltime, my_time_flags_t flags)
 Convert val_str() to date in MYSQL_TIME. More...
 
bool get_date_from_real (MYSQL_TIME *ltime, my_time_flags_t flags)
 Convert val_real() to date in MYSQL_TIME. More...
 
bool get_date_from_decimal (MYSQL_TIME *ltime, my_time_flags_t flags)
 Convert val_decimal() to date in MYSQL_TIME. More...
 
bool get_date_from_int (MYSQL_TIME *ltime, my_time_flags_t flags)
 Convert val_int() to date in MYSQL_TIME. More...
 
bool get_date_from_time (MYSQL_TIME *ltime)
 Convert get_time() from time to date in MYSQL_TIME. More...
 
bool get_date_from_numeric (MYSQL_TIME *ltime, my_time_flags_t fuzzydate)
 Convert a numeric type to date. More...
 
bool get_time_from_string (MYSQL_TIME *ltime)
 Convert val_str() to time in MYSQL_TIME. More...
 
bool get_time_from_real (MYSQL_TIME *ltime)
 Convert val_real() to time in MYSQL_TIME. More...
 
bool get_time_from_decimal (MYSQL_TIME *ltime)
 Convert val_decimal() to time in MYSQL_TIME. More...
 
bool get_time_from_int (MYSQL_TIME *ltime)
 Convert val_int() to time in MYSQL_TIME. More...
 
bool get_time_from_date (MYSQL_TIME *ltime)
 Convert date to time. More...
 
bool get_time_from_datetime (MYSQL_TIME *ltime)
 Convert datetime to time. More...
 
bool get_time_from_numeric (MYSQL_TIME *ltime)
 Convert a numeric type to time. More...
 
virtual longlong val_date_temporal_at_utc ()
 
virtual longlong val_time_temporal_at_utc ()
 
void set_accum_properties (const Item *item)
 Set accumulated properties for an Item. More...
 
void add_accum_properties (const Item *item)
 Add more accumulated properties to an Item. More...
 
void set_subquery ()
 Set the "has subquery" property. More...
 
void set_stored_program ()
 Set the "has stored program" property. More...
 
- Protected Member Functions inherited from Parse_tree_node_tmpl< Context >
 Parse_tree_node_tmpl ()
 
- Static Protected Member Functions inherited from Item
static bool bit_func_returns_binary (const Item *a, const Item *b)
 
static bool mark_field_in_map (Mark_field *mark_field, Field *field)
 Helper function for mark_field_in_map(uchar *arg). More...
 
- Static Protected Attributes inherited from Item
static constexpr uint8 PROP_SUBQUERY = 0x01
 Set of properties that are calculated by accumulation from underlying items. More...
 
static constexpr uint8 PROP_STORED_PROGRAM = 0x02
 
static constexpr uint8 PROP_AGGREGATION = 0x04
 
static constexpr uint8 PROP_WINDOW_FUNCTION = 0x08
 
static constexpr uint8 PROP_ROLLUP_EXPR = 0x10
 Set if the item or one or more of the underlying items contains a ROLLUP expression. More...
 
static constexpr uint8 PROP_GROUPING_FUNC = 0x20
 Set if the item or one or more of the underlying items is a GROUPING function. More...
 

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.

Member Typedef Documentation

◆ super

Constructor & Destructor Documentation

◆ Item_in_subselect() [1/3]

Item_in_subselect::Item_in_subselect ( Item left_expr,
Query_block query_block 
)

◆ Item_in_subselect() [2/3]

Item_in_subselect::Item_in_subselect ( const POS pos,
Item left_expr,
PT_subquery pt_subquery_arg 
)

◆ Item_in_subselect() [3/3]

Item_in_subselect::Item_in_subselect ( )
inline

Member Function Documentation

◆ cleanup()

void Item_in_subselect::cleanup ( )
overridevirtual

Called for every Item after use (preparation and execution).

Release all allocated resources, such as dynamic memory. Prepare for new execution by clearing cached values. Do not remove values allocated during preparation, destructor handles this.

Reimplemented from Item_subselect.

◆ compile()

Item * Item_in_subselect::compile ( Item_analyzer  analyzer,
uchar **  arg_p,
Item_transformer  transformer,
uchar arg_t 
)
overridevirtual

Perform a generic "compilation" of the Item tree, ie transform the Item tree by adding zero or more Item objects to it.

Parameters
analyzerAnalyzer function, see details section
[in,out]arg_pPointer to struct used by analyzer function
transformerTransformer function, see details section
[in,out]arg_tPointer to struct used by transformer function
Returns
Returned item tree after transformation, NULL if error

The process of this transformation is assumed to be as follows:

{
if (this->*some_analyzer(...))
{
compile children if any;
return this->*some_transformer(...);
}
else
return this;
}
Item * compile(Item_analyzer analyzer, uchar **arg_p, Item_transformer transformer, uchar *arg_t) override
Perform a generic "compilation" of the Item tree, ie transform the Item tree by adding zero or more I...
Definition: item_subselect.cc:736

i.e. analysis is performed top-down while transformation is done bottom-up. If no transformation is applied, the item is returned unchanged. A transformation error is indicated by returning a NULL pointer. Notice that the analyzer function should never cause an error.

The function is supposed to be used during the optimization stage of query execution. All new allocations are recorded using THD::change_item_tree() so that they can be rolled back after execution.

Reimplemented from Item.

◆ dependent_before_in2exists()

bool Item_in_subselect::dependent_before_in2exists ( ) const
inline

Is reliable only if IN->EXISTS has been done.

◆ exec()

bool Item_in_subselect::exec ( THD thd)
overridevirtual

Reimplemented from Item_subselect.

◆ finalize_exists_transform()

bool Item_in_subselect::finalize_exists_transform ( THD thd,
Query_block select 
)

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

◆ finalize_materialization_transform()

bool Item_in_subselect::finalize_materialization_transform ( THD thd,
JOIN join 
)

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

◆ fix_after_pullout()

void Item_in_subselect::fix_after_pullout ( Query_block parent_query_block,
Query_block removed_query_block 
)
overridevirtual
See also
Query_expression::fix_after_pullout()

Reimplemented from Item_subselect.

◆ fix_fields()

bool Item_in_subselect::fix_fields ( THD thd,
Item **  ref 
)
overridevirtual

An object of class Item_in_subselect is always substituted with another object of class Item_in_optimizer, and the substitution object contains a pointer to the original Item_in_subselect.

This substitution is currently handled by calling fix_fields() twice: The first call will resolve the underlying query expression and create the Item_in_optimizer substitution object. The second call is performed from Item_in_optimizer::fix_fields() and will complete the resolving of the object. Notice also that this process is partly managed by Item_subselect::fix_fields().

Reimplemented from Item_subselect.

◆ get_cond_guard()

bool * Item_in_subselect::get_cond_guard ( int  i)
inline

◆ get_contained_subquery()

std::optional< ContainedSubquery > Item_in_subselect::get_contained_subquery ( const Query_block outer_query_block)
overridevirtual

If this item represents a IN/ALL/ANY/comparison_operator subquery, return that (along with data on how it will be executed).

(These subqueries correspond to

See also
Item_in_subselect and
Item_singlerow_subselect .) Also,
FindContainedSubqueries() for context.
Parameters
outer_query_blockthe Query_block to which 'this' belongs.
Returns
The subquery that 'this' represents, if there is one.

Reimplemented from Item.

◆ in2exists_added_to_where()

bool Item_in_subselect::in2exists_added_to_where ( ) const
inline

◆ init_left_expr_cache()

bool Item_in_subselect::init_left_expr_cache ( THD thd)

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

◆ itemize()

bool Item_in_subselect::itemize ( Parse_context pc,
Item **  res 
)
overridevirtual

The same as contextualize() but with additional parameter.

This function finalize the construction of Item objects (see the Item(POS) constructor): we can access/change parser contexts from the itemize() function.

Parameters
pccurrent parse context
[out]respointer to "this" or to a newly allocated replacement object to use in the Item tree instead
Return values
falsesuccess
truesyntax/OOM/etc error

Reimplemented from Item.

◆ mark_as_outer()

bool Item_in_subselect::mark_as_outer ( Item left_row,
size_t  col 
)
private

Decide whether to mark the injected left expression "outer" relative to the subquery.

It should be marked as outer in the following cases:

1) If the left expression is not constant.

2) If the left expression could be a constant NULL and we care about the difference between UNKNOWN and FALSE. In this case, JOIN::optimize() for the subquery must be prevented from evaluating any triggered condition, as the triggers for such conditions have not yet been properly set by Item_in_optimizer::val_int(). By marking the left expression as outer, a triggered condition using it will not be considered constant, will not be evaluated by JOIN::optimize(); it will only be evaluated by JOIN::exec() which is called from Item_in_optimizer::val_int()

3) If the left expression comes from a subquery and is not a basic constant. In this case, the value cannot be read until after the subquery has been evaluated. By marking it as outer, we prevent it from being read when JOIN::optimize() attempts to evaluate constant conditions.

Parameters
[in]left_rowThe item that represents the left operand of the IN operator
[in]colThe column number of the expression in the left operand to possibly mark as dependent of the outer select
Returns
true if we should mark the injected left expression "outer" relative to the subquery

◆ print()

void Item_in_subselect::print ( const THD ,
String str,
enum_query_type   
) const
overridevirtual

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;
  • to generate a SQL-query that looks like a prepared statement for query_rewrite
  • 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.

◆ reset()

void Item_in_subselect::reset ( void  )
inlineoverridevirtual

Reimplemented from Item_exists_subselect.

◆ root_access_path()

AccessPath * Item_in_subselect::root_access_path ( ) const
overridevirtual

Reimplemented from Item_subselect.

◆ row_value_in_to_exists_transformer()

bool Item_in_subselect::row_value_in_to_exists_transformer ( THD thd,
Query_block select 
)

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

◆ row_value_transformer()

bool Item_in_subselect::row_value_transformer ( THD thd,
Query_block select 
)

◆ select_in_like_transformer()

bool Item_in_subselect::select_in_like_transformer ( THD thd,
Query_block select,
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
thdThread handle
selectQuery block of subquery being transformed
funccreator of condition function of subquery
Returns
false if success, true if error

◆ select_transformer()

bool Item_in_subselect::select_transformer ( THD thd,
Query_block select 
)
overridevirtual

Reimplemented from Item_exists_subselect.

Reimplemented in Item_allany_subselect.

◆ set_cond_guard_var()

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

◆ single_value_in_to_exists_transformer()

bool Item_in_subselect::single_value_in_to_exists_transformer ( THD thd,
Query_block select,
Comp_creator func 
)

Transform 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
thdThread handle
selectQuery block of the subquery
funcSubquery comparison creator
Returns
false if success, true if error Success means that appropriate predicates were injected into the query block of the subquery predicate, or the subquery predicate was reduced to a simple predicate.

◆ single_value_transformer()

bool Item_in_subselect::single_value_transformer ( THD thd,
Query_block select,
Comp_creator func 
)

Rewrite a single-column IN/ALL/ANY subselect.

DESCRIPTION Rewrite a single-column subquery using rule-based approach. The subquery

oe $cmp$ (SELECT ie FROM ... WHERE subq_where ... HAVING subq_having)

First, try to convert the subquery to scalar-result subquery in one of the forms:

  • oe $cmp$ (SELECT MAX(...) ) // handled by Item_singlerow_subselect
  • oe $cmp$ <max>(SELECT ...) // handled by Item_maxmin_subselect

If that fails, the subquery will be handled with class Item_in_optimizer. There are two possibilities:

  • If the subquery execution method is materialization, then the subquery is not transformed any further.
  • Otherwise the IN predicates is transformed into EXISTS by injecting equi-join predicates and possibly other helper predicates. For details see method single_value_in_like_transformer().
Parameters
thdThread handle
selectQuery block of the subquery
funcSubquery comparison creator
Returns
false if success, true if error

◆ substype()

subs_type Item_in_subselect::substype ( ) const
inlineoverridevirtual

Reimplemented from Item_exists_subselect.

Reimplemented in Item_allany_subselect.

◆ test_limit()

bool Item_in_subselect::test_limit ( )

◆ transform()

Item * Item_in_subselect::transform ( Item_transformer  transformer,
uchar arg 
)
overridevirtual

Perform a generic transformation of the Item tree, by adding zero or more additional Item objects to it.

Parameters
transformerTransformer function
[in,out]argPointer to struct used by transformer function
Returns
Returned item tree after transformation, NULL if error

Transformation is performed as follows:

{
transform children if any;
return this->*some_transformer(...);
}
Item * transform(Item_transformer transformer, uchar *arg) override
Perform a generic transformation of the Item tree, by adding zero or more additional Item objects to ...
Definition: item_subselect.cc:729

Note that unlike Item::compile(), transform() does not support an analyzer function, ie. all children are unconditionally invoked.

Item::transform() should handle all transformations during preparation. Notice that all transformations are permanent; they are not rolled back.

Use Item::compile() to perform transformations during optimization.

Reimplemented from Item.

◆ update_used_tables()

void Item_in_subselect::update_used_tables ( )
overridevirtual

Updates used tables, not null tables information and accumulates properties up the item tree, cf.

used_tables_cache, not_null_tables_cache and m_accum_properties.

TODO(sgunders): Consider just removing these caches; it causes a lot of bugs (cache invalidation is known to be a complex problem), and the performance benefits are dubious.

Reimplemented from Item_subselect.

◆ val_bool()

bool Item_in_subselect::val_bool ( )
overridevirtual

Reimplemented from Item_exists_subselect.

◆ val_bool_naked()

bool Item_in_subselect::val_bool_naked ( )
private

◆ val_decimal()

my_decimal * Item_in_subselect::val_decimal ( my_decimal decimal_value)
overridevirtual

Return the result of EXISTS as a decimal value.

Converts the true/false result into a decimal value.

Parameters
[out]decimal_valueBuffer to hold the resulting decimal value
Return values
Pointerto the converted decimal. NULL if execution returns in error

Reimplemented from Item_exists_subselect.

◆ val_int()

longlong Item_in_subselect::val_int ( void  )
overridevirtual

Reimplemented from Item_exists_subselect.

◆ val_real()

double Item_in_subselect::val_real ( void  )
overridevirtual

Reimplemented from Item_exists_subselect.

◆ val_str()

String * Item_in_subselect::val_str ( String str)
overridevirtual

Return the result of EXISTS as a string value.

Converts the true/false result into a string value.

Parameters
[out]strbuffer to hold the resulting string value
Return values
Pointerto the converted string. NULL if execution returns in error

Reimplemented from Item_exists_subselect.

◆ walk()

bool Item_in_subselect::walk ( Item_processor  processor,
enum_walk  walk,
uchar arg 
)
overridevirtual

Traverses a tree of Items in prefix and/or postfix order.

Optionally walks into subqueries.

Parameters
processorprocessor function to be invoked per item returns true to abort traversal, false to continue
walkcontrols how to traverse the item tree enum_walk::PREFIX: call processor before invoking children enum_walk::POSTFIX: call processor after invoking children enum_walk::SUBQUERY go down into subqueries walk values are bit-coded and may be combined. Omitting both enum_walk::PREFIX and enum_walk::POSTFIX is undefined behaviour.
argOptional pointer to a walk-specific object
Return values
falsewalk succeeded
truewalk aborted by agreement, an error may have been reported

Reimplemented from Item_subselect.

Friends And Related Function Documentation

◆ Item_in_optimizer

friend class Item_in_optimizer
friend

◆ Item_is_not_null_test

friend class Item_is_not_null_test
friend

◆ Item_ref_null_helper

friend class Item_ref_null_helper
friend

◆ subselect_hash_sj_engine

friend class subselect_hash_sj_engine
friend

◆ subselect_indexsubquery_engine

friend class subselect_indexsubquery_engine
friend

Member Data Documentation

◆ abort_on_null

bool Item_in_subselect::abort_on_null
protected

True if naked IN is allowed to exchange FALSE for UNKNOWN.

Because this is about the naked IN, there is no public ignore_unknown(), intentionally, so that callers don't get it wrong.

◆ in2exists_info

struct Item_in_subselect::In2exists_info * Item_in_subselect::in2exists_info
private

◆ left_expr

Item* Item_in_subselect::left_expr

◆ left_expr_cache

List<Cached_item>* Item_in_subselect::left_expr_cache
protected

Cache of the left operand of the subquery predicate.

Allocated in the runtime memory root, for each execution, thus need not be freed.

◆ left_expr_cache_filled

bool Item_in_subselect::left_expr_cache_filled
protected

Whether left_expr_cache holds a value.

◆ m_injected_left_expr

Item_ref* Item_in_subselect::m_injected_left_expr
private

In the case of.

x COMP_OP (SELECT1 UNION SELECT2 ...)

  • the subquery transformation is done on SELECT1; this requires wrapping 'x' with more Item layers, and injecting that in a condition in SELECT1.
  • the same transformation is done on SELECT2; but the wrapped 'x' doesn't need to be created again, the one created for SELECT1 could be reused
  • to achieve this, the wrapped 'x' is stored in member 'm_injected_left_expr' when it is created for SELECT1, and is later reused for SELECT2.

This will refer to a cached value which is reevaluated once for each candidate row, cf. setup in single_value_transformer.

◆ need_expr_cache

bool Item_in_subselect::need_expr_cache
protected

The need for expr cache may be optimized away,.

See also
init_left_expr_cache.

◆ optimizer

Item_in_optimizer* Item_in_subselect::optimizer
private

Pointer to the created Item_in_optimizer; it is stored for the same reasons as 'm_injected_left_expr'.

◆ pt_subselect

PT_subquery* Item_in_subselect::pt_subselect
private

◆ pushed_cond_guards

bool* Item_in_subselect::pushed_cond_guards

◆ upper_item

Item_func_not_all* Item_in_subselect::upper_item

◆ was_null

bool Item_in_subselect::was_null
private

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