MySQL 8.4.3
Source Code Documentation
Group_check Class Reference

Checks for queries which have GROUP BY or aggregate functions. More...

#include <aggregate_check.h>

Inheritance diagram for Group_check:
[legend]

Public Member Functions

 Group_check (Query_block *select_arg, MEM_ROOT *root)
 
 ~Group_check ()
 
 Group_check (const Group_check &)=delete
 
Group_checkoperator= (const Group_check &)=delete
 
bool check_query (THD *thd)
 Rejects the query if it does aggregation or grouping, and expressions in its SELECT list, ORDER BY clause, HAVING condition, or window functions may vary inside a group (are not "group-invariant"). More...
 
void to_opt_trace (THD *thd)
 Writes "check information" to the optimizer trace. More...
 

Private Types

enum  enum_ident_check { CHECK_GROUP , CHECK_STRONG_SIDE_COLUMN , CHECK_COLUMN }
 Enum for argument of do_ident_check() More...
 

Private Member Functions

bool is_fd_on_source (Item *item)
 Tells if 'item' is functionally dependent ("FD") on source columns. More...
 
bool is_child () const
 
 Group_check (Query_block *select_arg, MEM_ROOT *root, Table_ref *table_arg)
 Private ctor, for a Group_check to build a child Group_check. More...
 
bool check_expression (THD *thd, Item *expr, bool in_select_list)
 Validates one expression (this forms one step of check_query()). More...
 
bool local_column (Item *item) const
 Shortcut for common use of Item::local_column() More...
 
void add_to_fd (Item *item, bool local_column, bool add_to_mat_table=true)
 
void add_to_fd (table_map m)
 
void add_to_source_of_mat_table (Item_field *item_field, Table_ref *tl)
 If we just added a column of a materialized table to 'fd', we record this fact in a new Group_check (mat_gc) for the query expression underlying that table. More...
 
bool is_in_fd (Item *item)
 is_in_fd() is low-level compared to is_fd_on_source(). More...
 
bool is_in_fd_of_underlying (Item_ident *item)
 See if we can derive a FD from a column which has an underlying expression. More...
 
Itemget_fd_equal (Item *item)
 
void analyze_conjunct (Item *cond, Item *conjunct, table_map weak_tables, bool weak_side_upwards)
 Searches for equality-based functional dependences in an AND-ed part of a condition (a conjunct). More...
 
void analyze_scalar_eq (Item *cond, Item *left_item, Item *right_item, table_map weak_tables, bool weak_side_upwards)
 Helper function. More...
 
void find_fd_in_cond (Item *cond, table_map weak_tables, bool weak_side_upwards)
 Searches for equality-based functional dependencies in a condition. More...
 
void find_fd_in_joined_table (mem_root_deque< Table_ref * > *join_list)
 Searches for equality-based functional dependencies in the condition of a join nest, and recursively in all contained join nests. More...
 
void to_opt_trace2 (Opt_trace_context *ctx, Opt_trace_object *parent)
 Utility function for to_opt_trace(), as we need recursion in children Group_checks. More...
 
void find_group_in_fd (Item *item)
 This function must be called every time we discover an item which is FD on source columns, or add a bit to whole_tables_fd; it maintains group_in_fd. More...
 
Itemselect_expression (uint idx)
 
bool do_ident_check (Item_ident *i, table_map tm, enum enum_ident_check type)
 Does one low-level check on one Item_ident. More...
 

Private Attributes

Query_block *const select
 Query block which we are validating. More...
 
bool search_in_underlying
 "Underlying" == expressions which are underlying in an identifier. More...
 
bool non_null_in_source
 This member is readable only if this is a child Group_check. More...
 
Table_ref *const table
 The Group_check employed to validate one query block, the one on which check_query() runs, is named the "master". More...
 
ulonglong group_in_fd
 Bit N is set if the N-th expression of GROUP BY is functionally dependent on source columns. More...
 
MEM_ROOT *const m_root
 Memory for allocations (like of 'fd') More...
 
Mem_root_array< Item_ident * > fd
 Columns which are local to 'select' and functionally dependent on an initial set of "source" columns defined like this: More...
 
table_map whole_tables_fd
 Map of tables for which all columns can be considered part of 'fd'. More...
 
table_map recheck_nullable_keys
 Map of tables for which we discovered known-not-nullable columns. More...
 
Mem_root_array< Group_check * > mat_tables
 Children Group_checks of 'this'. More...
 
Item_identfailed_ident
 Identifier which triggered an error. More...
 
SQL_I_List< ORDERm_added_by_transform
 GROUP BY list non single column expressions entries added by transform. More...
 

Friends

bool Item_ident::aggregate_check_group (uchar *arg)
 Just because we need to go through Item::walk() to reach all items to validate, some work must be delegated to "Item processors" (members of Item); this work conceptually belongs to Group_check, and needs privileged access to it. More...
 
bool Item_sum::aggregate_check_group (uchar *arg)
 
bool Item_func_any_value::aggregate_check_group (uchar *arg)
 
bool Item_ident::is_strong_side_column_not_in_fd (uchar *arg)
 
bool Item_ident::is_column_not_in_fd (uchar *arg)
 
bool Item_func_grouping::aggregate_check_group (uchar *arg)
 

Additional Inherited Members

- Protected Member Functions inherited from Item_tree_walker
 Item_tree_walker ()
 
 ~Item_tree_walker ()
 
 Item_tree_walker (const Item_tree_walker &)=delete
 
Item_tree_walkeroperator= (const Item_tree_walker &)=delete
 
void stop_at (const Item *i)
 Stops walking children of this item. More...
 
bool is_stopped (const Item *i)
 

Detailed Description

Checks for queries which have GROUP BY or aggregate functions.

Member Enumeration Documentation

◆ enum_ident_check

Enum for argument of do_ident_check()

Enumerator
CHECK_GROUP 
CHECK_STRONG_SIDE_COLUMN 
CHECK_COLUMN 

Constructor & Destructor Documentation

◆ Group_check() [1/3]

Group_check::Group_check ( Query_block select_arg,
MEM_ROOT root 
)
inline

◆ ~Group_check()

Group_check::~Group_check ( )
inline

◆ Group_check() [2/3]

Group_check::Group_check ( const Group_check )
delete

◆ Group_check() [3/3]

Group_check::Group_check ( Query_block select_arg,
MEM_ROOT root,
Table_ref table_arg 
)
inlineprivate

Private ctor, for a Group_check to build a child Group_check.

Member Function Documentation

◆ add_to_fd()

void Group_check::add_to_fd ( table_map  m)
inlineprivate

◆ is_child()

bool Group_check::is_child ( ) const
inlineprivate

◆ local_column()

bool Group_check::local_column ( Item item) const
inlineprivate

Shortcut for common use of Item::local_column()

◆ operator=()

Group_check & Group_check::operator= ( const Group_check )
delete

Friends And Related Function Documentation

◆ Item_func_any_value::aggregate_check_group

◆ Item_func_grouping::aggregate_check_group

◆ Item_ident::aggregate_check_group

bool Item_ident::aggregate_check_group ( uchar arg)
friend

Just because we need to go through Item::walk() to reach all items to validate, some work must be delegated to "Item processors" (members of Item); this work conceptually belongs to Group_check, and needs privileged access to it.

◆ Item_ident::is_column_not_in_fd

bool Item_ident::is_column_not_in_fd ( uchar arg)
friend

◆ Item_ident::is_strong_side_column_not_in_fd

◆ Item_sum::aggregate_check_group

bool Item_sum::aggregate_check_group ( uchar arg)
friend

Member Data Documentation

◆ failed_ident

Item_ident* Group_check::failed_ident
private

Identifier which triggered an error.

◆ fd

Mem_root_array<Item_ident *> Group_check::fd
private

Columns which are local to 'select' and functionally dependent on an initial set of "source" columns defined like this:

  • if !is_child(), the GROUP BY columns
  • if is_child(), columns of the result of the query expression under 'table' which are themselves part of 'fd' of the parent Group_check.

◆ group_in_fd

ulonglong Group_check::group_in_fd
private

Bit N is set if the N-th expression of GROUP BY is functionally dependent on source columns.

It serves to find FDs in the query expression of a materialized table having GROUP BY. For a non-child Group-check, all bits are turned on from the start. Currently limited to 64 bits => max 64 GROUP expressions; should probably be MY_BITMAP.

◆ m_added_by_transform

SQL_I_List<ORDER> Group_check::m_added_by_transform
private

GROUP BY list non single column expressions entries added by transform.

◆ m_root

MEM_ROOT* const Group_check::m_root
private

Memory for allocations (like of 'fd')

◆ mat_tables

Mem_root_array<Group_check *> Group_check::mat_tables
private

Children Group_checks of 'this'.

◆ non_null_in_source

bool Group_check::non_null_in_source
private

This member is readable only if this is a child Group_check.

Is true if one expression of the SELECT list of this->select is non-nullable.

◆ recheck_nullable_keys

table_map Group_check::recheck_nullable_keys
private

Map of tables for which we discovered known-not-nullable columns.

◆ search_in_underlying

bool Group_check::search_in_underlying
private

"Underlying" == expressions which are underlying in an identifier.

The identifier can be a column of a view or derived table, both merged or materialized, or a generated column: all of those have an underlying expression. "Materialized table (mat table)" == view or derived table, materialized. If this is true, is_in_fd() will look for FDs in underlying expressions of columns.

◆ select

Query_block* const Group_check::select
private

Query block which we are validating.

◆ table

Table_ref* const Group_check::table
private

The Group_check employed to validate one query block, the one on which check_query() runs, is named the "master".

If the query block references a materialized table, the master may create a child Group_check, whose job is to discover FDs in the query expression of the mat table (with the ultimate goal of deducing from them some FDs in the mat table and thus in the parent Group_check). A child may have children itself. If this Group_check is a child, 'table' points to the materialized table, otherwise it is NULL.

◆ whole_tables_fd

table_map Group_check::whole_tables_fd
private

Map of tables for which all columns can be considered part of 'fd'.


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