MySQL 8.4.0
Source Code Documentation
item_subselect.cc File Reference

Implements the subselect Item, used when there is a subselect in a SELECT list, WHERE, etc. More...

#include "sql/item_subselect.h"
#include <climits>
#include <cstdio>
#include <cstring>
#include <initializer_list>
#include <memory>
#include <string>
#include <utility>
#include "decimal.h"
#include "lex_string.h"
#include "my_alloc.h"
#include "my_base.h"
#include "my_compiler.h"
#include "my_dbug.h"
#include "my_pointer_arithmetic.h"
#include "my_sys.h"
#include "mysql/strings/m_ctype.h"
#include "mysql_com.h"
#include "mysqld_error.h"
#include "scope_guard.h"
#include "sql-common/my_decimal.h"
#include "sql/check_stack.h"
#include "sql/current_thd.h"
#include "sql/debug_sync.h"
#include "sql/derror.h"
#include "sql/field.h"
#include "sql/handler.h"
#include "sql/item_cmpfunc.h"
#include "sql/item_func.h"
#include "sql/item_sum.h"
#include "sql/iterators/basic_row_iterators.h"
#include "sql/iterators/composite_iterators.h"
#include "sql/iterators/ref_row_iterators.h"
#include "sql/iterators/row_iterator.h"
#include "sql/iterators/timing_iterator.h"
#include "sql/join_optimizer/access_path.h"
#include "sql/join_optimizer/cost_model.h"
#include "sql/join_optimizer/join_optimizer.h"
#include "sql/key.h"
#include "sql/mysqld.h"
#include "sql/opt_explain_format.h"
#include "sql/opt_trace.h"
#include "sql/opt_trace_context.h"
#include "sql/parse_tree_nodes.h"
#include "sql/query_options.h"
#include "sql/query_result.h"
#include "sql/sql_class.h"
#include "sql/sql_const.h"
#include "sql/sql_error.h"
#include "sql/sql_executor.h"
#include "sql/sql_lex.h"
#include "sql/sql_list.h"
#include "sql/sql_opt_exec_shared.h"
#include "sql/sql_optimizer.h"
#include "sql/sql_select.h"
#include "sql/sql_test.h"
#include "sql/sql_tmp_table.h"
#include "sql/sql_union.h"
#include "sql/system_variables.h"
#include "sql/table.h"
#include "sql/temp_table_param.h"
#include "sql/thd_raii.h"
#include "sql/window.h"
#include "sql_string.h"
#include "string_with_len.h"
#include "template_utils.h"

Classes

class  Query_result_scalar_subquery
 Query result class for scalar and row subqueries. More...
 
class  Query_result_max_min_subquery
 
class  Query_result_exists_subquery
 

Functions

static bool guaranteed_one_row (const Query_block *qb)
 Check if a query block is guaranteed to return one row. More...
 
static bool wrapped_in_intersect_except (Query_term *qb)
 Check if a query block is part of an INTERSECT or EXCEPT set operation. More...
 
Itemremove_in2exists_conds (Item *conds)
 Removes every predicate injected by IN->EXISTS. More...
 
bool is_quantified_comp_predicate (Item *item)
 
static Item ** find_subquery_in_select_list (Query_block *select, Item_singlerow_subselect *subquery)
 Find the scalar subquery in Query_block::fields if directly present, i.e., not inside an expression. More...
 
bool ExecuteExistsQuery (THD *thd, Query_expression *qe, RowIterator *iterator, bool *found)
 Run a query to see if it returns at least one row (stops after the first has been found, or on error). More...
 
static int safe_index_read (TABLE *table, const Index_lookup &ref)
 

Variables

static const enum_walk walk_options
 

Detailed Description

Implements the subselect Item, used when there is a subselect in a SELECT list, WHERE, etc.

Function Documentation

◆ ExecuteExistsQuery()

bool ExecuteExistsQuery ( THD thd,
Query_expression qe,
RowIterator iterator,
bool *  found 
)

Run a query to see if it returns at least one row (stops after the first has been found, or on error).

Unless there was an error, whether the row was found in "found".

Return values
trueon error

◆ find_subquery_in_select_list()

static Item ** find_subquery_in_select_list ( Query_block select,
Item_singlerow_subselect subquery 
)
static

Find the scalar subquery in Query_block::fields if directly present, i.e., not inside an expression.

Parameters
selectThe query block owning the transformation.
subqueryThe scalar subquery to look for.
Returns
the corresponding ref in Query_block::base_ref_items, or nullptr if not found.

◆ guaranteed_one_row()

static bool guaranteed_one_row ( const Query_block qb)
static

Check if a query block is guaranteed to return one row.

We know that this is the case if it has no tables and is not filtered with WHERE, HAVING or LIMIT clauses.

Parameters
qbthe Query_block to check
Returns
true if we are certain that the query block always returns one row, false otherwise

◆ is_quantified_comp_predicate()

bool is_quantified_comp_predicate ( Item item)
Returns
whether the item is a quantified comparison predicate

◆ remove_in2exists_conds()

Item * remove_in2exists_conds ( Item conds)

Removes every predicate injected by IN->EXISTS.

This function is different from others:

  • it wants to remove all traces of IN->EXISTS (for materialization)
  • remove_subq_pushed_predicates() and remove_additional_cond() want to remove only the conditions of IN->EXISTS which index lookup already satisfies (they are just an optimization).

If there are no in2exists conditions, it will return the exact same pointer. If it returns a new Item, the old Item is left alone, so it can be reused in other settings.

Parameters
condsCondition; may be nullptr.
Returns
new condition

◆ safe_index_read()

static int safe_index_read ( TABLE table,
const Index_lookup ref 
)
static

◆ wrapped_in_intersect_except()

static bool wrapped_in_intersect_except ( Query_term qb)
static

Check if a query block is part of an INTERSECT or EXCEPT set operation.

Parameters
qbQuery block to check
Returns
true if query block is part of INTERSECT/EXCEPT, false otherwise.

Variable Documentation

◆ walk_options

const enum_walk walk_options
static