MySQL 9.1.0
Source Code Documentation
sql_resolver.cc File Reference

Implementation of name resolution stage. More...

#include "sql/sql_resolver.h"
#include <sys/types.h>
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <initializer_list>
#include <utility>
#include <vector>
#include "field_types.h"
#include "lex_string.h"
#include "map_helpers.h"
#include "mem_root_deque.h"
#include "my_alloc.h"
#include "my_bitmap.h"
#include "my_compiler.h"
#include "my_dbug.h"
#include "my_inttypes.h"
#include "my_sqlcommand.h"
#include "my_sys.h"
#include "my_table_map.h"
#include "mysql/components/services/bits/psi_bits.h"
#include "mysql_com.h"
#include "mysqld_error.h"
#include "prealloced_array.h"
#include "sql/aggregate_check.h"
#include "sql/auth/auth_acls.h"
#include "sql/auth/auth_common.h"
#include "sql/check_stack.h"
#include "sql/current_thd.h"
#include "sql/derror.h"
#include "sql/enum_query_type.h"
#include "sql/error_handler.h"
#include "sql/field.h"
#include "sql/item.h"
#include "sql/item_cmpfunc.h"
#include "sql/item_func.h"
#include "sql/item_row.h"
#include "sql/item_subselect.h"
#include "sql/item_sum.h"
#include "sql/join_optimizer/bit_utils.h"
#include "sql/join_optimizer/join_optimizer.h"
#include "sql/key_spec.h"
#include "sql/mdl.h"
#include "sql/mem_root_array.h"
#include "sql/nested_join.h"
#include "sql/opt_hints.h"
#include "sql/opt_trace.h"
#include "sql/opt_trace_context.h"
#include "sql/parse_tree_nodes.h"
#include "sql/parser_yystype.h"
#include "sql/query_options.h"
#include "sql/query_result.h"
#include "sql/query_term.h"
#include "sql/range_optimizer/partition_pruning.h"
#include "sql/range_optimizer/range_optimizer.h"
#include "sql/sql_base.h"
#include "sql/sql_class.h"
#include "sql/sql_cmd.h"
#include "sql/sql_const.h"
#include "sql/sql_derived.h"
#include "sql/sql_error.h"
#include "sql/sql_executor.h"
#include "sql/sql_lex.h"
#include "sql/sql_list.h"
#include "sql/sql_optimizer.h"
#include "sql/sql_select.h"
#include "sql/sql_test.h"
#include "sql/sql_union.h"
#include "sql/system_variables.h"
#include "sql/table.h"
#include "sql/thd_raii.h"
#include "sql/thr_malloc.h"
#include "sql/visible_fields.h"
#include "sql/window.h"
#include "template_utils.h"
#include "thr_lock.h"

Classes

class  Semijoin_decorrelation
 Context object used by semijoin equality decorrelation code. More...
 
struct  Lifted_expressions_map
 Helper singleton class used to track information needed to perform the transform of a correlated scalar subquery in a derived table, as performed by decorrelate_derived_scalar_subquery_pre and decorrelate_derived_scalar_subquery_pre. More...
 

Functions

static bool simplify_const_condition (THD *thd, Item **cond, bool remove_cond, bool *ret_cond_value)
 Try to replace a const condition with a simple constant. More...
 
static Itemcreate_rollup_switcher (THD *thd, Query_block *query_block, Item_sum *item, int send_group_parts)
 
static bool fulltext_uses_rollup_column (const Query_block *query_block)
 Checks if there are any calls to the MATCH function that take a ROLLUP column as argument in the SELECT list, GROUP BY clause, HAVING clause or ORDER BY clause. More...
 
static void update_used_tables_for_join (mem_root_deque< Table_ref * > *tables)
 Update used tables information for a JOIN expression. More...
 
static Table_ref ** make_leaf_tables (Table_ref **list, Table_ref *tables)
 Make list of leaf tables of join table tree. More...
 
static void fix_tables_after_pullout (Query_block *parent_query_block, Query_block *removed_query_block, Table_ref *tr, uint table_adjust, table_map lateral_deps)
 Update table reference information for conditions and expressions due to query blocks having been merged in from derived tables/views and due to semi-join transformation. More...
 
static bool decorrelate_equality (Semijoin_decorrelation &sj_decor, Item_func *func, bool *was_correlated)
 Try to decorrelate an (in)equality node. More...
 
static bool can_decorrelate_operator (Item_func *func, bool only_eq)
 
bool walk_join_list (mem_root_deque< Table_ref * > &list, std::function< bool(Table_ref *)> action)
 
static bool build_sj_exprs (THD *thd, mem_root_deque< Item * > *sj_outer_exprs, mem_root_deque< Item * > *sj_inner_exprs, Item_exists_subselect *subq_pred, Query_block *subq_query_block)
 Builds the list of SJ outer/inner expressions. More...
 
static bool replace_subcondition (THD *thd, Item **tree, Item *old_cond, Item *new_cond, bool do_fix_fields, bool *found_ptr=nullptr)
 Destructively replaces a sub-condition inside a condition tree. More...
 
void propagate_nullability (mem_root_deque< Table_ref * > *tables, bool nullable)
 Propagate nullability into inner tables of outer join operation. More...
 
bool find_order_in_list (THD *thd, Ref_item_array ref_item_array, Table_ref *tables, ORDER *order, mem_root_deque< Item * > *fields, bool is_group_field, bool is_window_order)
 Resolve an ORDER BY or GROUP BY column reference. More...
 
bool setup_order (THD *thd, Ref_item_array ref_item_array, Table_ref *tables, mem_root_deque< Item * > *fields, ORDER *order)
 Resolve and setup list of expressions in ORDER BY clause. More...
 
static ReplaceResult wrap_grouped_expressions_for_rollup (Query_block *select, Item *item, Item *parent, unsigned argument_idx)
 Checks whether an item matches a grouped expression, creates an Item_rollup_group_item around it and replaces the reference to it with that item. More...
 
static bool WalkAndReplaceInner (THD *thd, Item *parent, unsigned argument_idx, const function< ReplaceResult(Item *item, Item *parent, unsigned argument_idx)> &get_new_item, Item **child_ref)
 Helper function for WalkAndReplace() which replaces the Item referenced by "child_ref" if "get_new_item" returns a replacement, or visits the children of "child_ref" otherwise. More...
 
bool WalkAndReplace (THD *thd, Item *item, const function< ReplaceResult(Item *item, Item *parent, unsigned argument_idx)> &get_new_item)
 
static bool refresh_comparators_after_rollup (Item *item)
 Refreshes the comparators after ROLLUP resolving. More...
 
bool validate_gc_assignment (const mem_root_deque< Item * > &fields, const mem_root_deque< Item * > &values, TABLE *table)
 validate_gc_assignment Check whether the other values except DEFAULT are assigned for generated columns. More...
 
static bool baptize_item (THD *thd, Item *item, int *field_no)
 Helper function to make names for columns of a derived table replacing a scalar or table subquery. More...
 
static bool update_context_to_derived (Item *expr, Query_block *new_derived)
 A minion of transform_grouped_to_derived. More...
 
static bool replace_aggregate_in_list (Item::Aggregate_replacement &info, bool was_hidden, mem_root_deque< Item * > *list, Ref_item_array *ref_item_array)
 A minion of transform_grouped_to_derived. More...
 
static bool collect_aggregates (Query_block *select, Item_sum::Collect_grouped_aggregate_info *aggregates)
 A minion of transform_grouped_to_derived. More...
 
static bool query_block_contains_subquery (Query_block *select, Query_expression *slu)
 A minion of transform_scalar_subqueries_to_join_with_derived. More...
 
static bool walk_join_conditions (mem_root_deque< Table_ref * > &list, std::function< bool(Item **expr_p)> action, Item::Collect_scalar_subquery_info *info)
 
static void remember_transform (THD *thd, Query_block *select)
 Remember if this transform was performed. More...
 
static bool add_partition_by_expr (THD *thd, PT_order_list *partition, Query_block *qb, Item *expr)
 Given an expression, create an ORDER expression for that expression and add it to a window's ORDER BY list in preparation for synthesizing a window function, cf. More...
 
static bool replace_inner_function_calls_in_lifted_predicate (THD *thd, Table_ref *derived, Lifted_expressions_map *lifted_exprs, Query_block *qb)
 Function calls in lifted join condition. More...
 
static bool replace_inner_fields_in_lifted_predicate (THD *thd, Table_ref *derived, Lifted_expressions_map *lifted_exprs, Query_block *qb, uint *field_pos_idx)
 Fields in lifted join condition. More...
 
static bool build_reject_if (THD *thd, Table_ref *derived, Lifted_expressions_map *lifted_exprs, uint field_pos_idx)
 
static std::pair< bool, bool > item_containing_non_correlated_field (Item *item)
 WL#15540 check that predicate operand item conforms to our requirements. More...
 
bool is_correlated_predicate_eligible (Item *cor_pred)
 Called to check if the provided correlated predicate is eligible for transformation. More...
 
static bool extract_correlated_condition (THD *thd, Item **cond, Item **correlated_cond)
 Extracts the top level correlated condition in an OR condition. More...
 

Variables

static const enum_walk walk_options
 

Detailed Description

Implementation of name resolution stage.