MySQL 9.3.0
Source Code Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
anonymous_namespace{finalize_plan.cc} Namespace Reference

Functions

bool IsMaterializePathForDeduplication (AccessPath *path)
 
bool IsMaterializePathForDistinct (AccessPath *path)
 
bool IsMaterializePathForGroupBy (AccessPath *path)
 
bool HasVisibleBitItems (bool is_distinct, mem_root_deque< Item * > *distinct_items, bool is_group_by, ORDER *group)
 Search for visible BIT items, and return true if found. More...
 
void ReplaceUpdateValuesWithTempTableFields (Sql_cmd_insert_select *sql_cmd, Query_block *query_block, const mem_root_deque< Item * > &original_fields, const mem_root_deque< Item * > &temp_table_fields)
 Replaces field references in an ON DUPLICATE KEY UPDATE clause with references to corresponding fields in a temporary table. More...
 
void CollectItemsWithoutRollup (Item *root, mem_root_deque< Item * > *items)
 Collects the set of items in the item tree that satisfy the following: More...
 
TABLECreateTemporaryTableFromSelectList (THD *thd, Query_block *query_block, Window *window, Temp_table_param **temp_table_param_arg, bool after_aggregation, bool is_group_by=false, bool is_distinct=false)
 Creates a temporary table with columns matching the SELECT list of the given query block. More...
 
void ReplaceSelectListWithTempTableFields (THD *thd, JOIN *join, const Func_ptr_array &items_to_copy, Mem_root_array< const Func_ptr_array * > *applied_replacements)
 Replaces the items in the SELECT list with items that point to fields in a temporary table. More...
 
bool InitTmpTableSliceRefs (THD *thd, AccessPath *path, JOIN *join)
 In hypergraph optimizer, slices are currently used only for temp tables created for GROUP BY; i.e. More...
 
table_map GetUsedTableMap (const ORDER *order)
 
bool OrderItemsReferenceUnavailableTables (const AccessPath *sort_path, table_map used_tables_before_replacement)
 Checks if the order items in a SORT access path reference any column that is not available to it. More...
 
Temp_table_paramGetItemsToCopy (AccessPath *path)
 
bool UpdateReferencesToMaterializedItems (THD *thd, Query_block *query_block, AccessPath *path, bool after_aggregation, Mem_root_array< const Func_ptr_array * > *applied_replacements)
 See FinalizePlanForQueryBlock(). More...
 
bool DelayedCreateTemporaryTable (THD *thd, Query_block *query_block, AccessPath *path, bool after_aggregation, TABLE **last_window_temp_table, unsigned *num_windows_seen)
 If the given access path needs a temporary table, it instantiates said table (we cannot do this until we have a final access path list, where we know which temporary tables are created and in which order). More...
 
void FinalizeWindowPath (THD *thd, Query_block *query_block, const mem_root_deque< Item * > &original_fields, const Mem_root_array< const Func_ptr_array * > &applied_replacements, AccessPath *path)
 See FinalizePlanForQueryBlock(). More...
 
ItemAddCachesAroundConstantConditions (Item *item)
 
bool AddCachesAroundConstantConditionsInPath (AccessPath *path)
 
void FinalizeUpdateOrDelete (AccessPath *root_path, table_map target_tables)
 Perform finalization specific to UPDATE and DELETE access paths. More...
 
void FinalizeSortPaths (THD *thd, AccessPath *root_path, JOIN *join)
 Create Filesort objects for all SORT access paths in a query block. More...
 

Function Documentation

◆ AddCachesAroundConstantConditions()

Item * anonymous_namespace{finalize_plan.cc}::AddCachesAroundConstantConditions ( Item item)

◆ AddCachesAroundConstantConditionsInPath()

bool anonymous_namespace{finalize_plan.cc}::AddCachesAroundConstantConditionsInPath ( AccessPath path)

◆ CollectItemsWithoutRollup()

void anonymous_namespace{finalize_plan.cc}::CollectItemsWithoutRollup ( Item root,
mem_root_deque< Item * > *  items 
)

Collects the set of items in the item tree that satisfy the following:

1) Neither the item itself nor any of its descendants have a reference to a ROLLUP expression (item->has_grouping_set_dep() evaluates to false). 2) The item is either the root item or its parent item does not satisfy 1).

In other words, we do not collect every item without rollup in the tree. Instead we collect the root item of every largest possible subtree where none of the items in the subtree have rollup.

Parameters
rootThe root item of the tree to search.
itemsA collection of items. We add items that satisfy the search criteria to this collection.

◆ CreateTemporaryTableFromSelectList()

TABLE * anonymous_namespace{finalize_plan.cc}::CreateTemporaryTableFromSelectList ( THD thd,
Query_block query_block,
Window window,
Temp_table_param **  temp_table_param_arg,
bool  after_aggregation,
bool  is_group_by = false,
bool  is_distinct = false 
)

Creates a temporary table with columns matching the SELECT list of the given query block.

(In FinalizePlanForQueryBlock(), the SELECT list of the query block is updated to point to the fields in the temporary table, but not here.)

This function is used for materializing the query result, either as an intermediate step before sorting the final result if the sort requires the rows to come from a single table instead of a join, or as the last step if the SQL_BUFFER_RESULT query option has been specified. It is also used for setting up the output temporary table for window functions.

NOTE: If after_aggregation = true, it is impossible to call this function again later with after_aggregation = false, as count_field_types() will remove item->has_aggregation() once called. Thus, we need to set up all these temporary tables in FinalizePlanForQueryBlock(), in the right order. 'is_group_by'=true indicates that the temp table is to be created with rows grouped using GROUP BY items. 'is_distinct'=true indicates that the temp table is to be created with distinct rows. (corresponds to SELECT DISTINCT ...)

◆ DelayedCreateTemporaryTable()

bool anonymous_namespace{finalize_plan.cc}::DelayedCreateTemporaryTable ( THD thd,
Query_block query_block,
AccessPath path,
bool  after_aggregation,
TABLE **  last_window_temp_table,
unsigned *  num_windows_seen 
)

If the given access path needs a temporary table, it instantiates said table (we cannot do this until we have a final access path list, where we know which temporary tables are created and in which order).

For window functions, it also needs to forward this information to the materialization access path coming right after this window, if any, so it uses last_window_temp_table as a buffer to hold this.

◆ FinalizeSortPaths()

void anonymous_namespace{finalize_plan.cc}::FinalizeSortPaths ( THD thd,
AccessPath root_path,
JOIN join 
)

Create Filesort objects for all SORT access paths in a query block.

This is done in a top-down fashion, in contrast to the bottom-up processing in FinalizePlanForQueryBlock(). It is done top-down because a Filesort that requires row IDs may need to enable row IDs on SORT paths further down in the tree, so it is not known whether a SORT path should use row IDs or not until the SORT paths above it has had their Filesort objects created.

◆ FinalizeUpdateOrDelete()

void anonymous_namespace{finalize_plan.cc}::FinalizeUpdateOrDelete ( AccessPath root_path,
table_map  target_tables 
)

Perform finalization specific to UPDATE and DELETE access paths.

Make sure that rows in the target tables can be deleted using the information that comes up through the access paths. In particular, paths that potentially reorder the rows returned by the underlying scans, specifically SORT and HASH_JOIN, must be told to preserve row IDs, so that the correct row can be updated or deleted.

◆ FinalizeWindowPath()

void anonymous_namespace{finalize_plan.cc}::FinalizeWindowPath ( THD thd,
Query_block query_block,
const mem_root_deque< Item * > &  original_fields,
const Mem_root_array< const Func_ptr_array * > &  applied_replacements,
AccessPath path 
)

See FinalizePlanForQueryBlock().

◆ GetItemsToCopy()

Temp_table_param * anonymous_namespace{finalize_plan.cc}::GetItemsToCopy ( AccessPath path)

◆ GetUsedTableMap()

table_map anonymous_namespace{finalize_plan.cc}::GetUsedTableMap ( const ORDER order)
Returns
The tables used by the order items.

◆ HasVisibleBitItems()

bool anonymous_namespace{finalize_plan.cc}::HasVisibleBitItems ( bool  is_distinct,
mem_root_deque< Item * > *  distinct_items,
bool  is_group_by,
ORDER group 
)

Search for visible BIT items, and return true if found.

Used specifically for avoiding bit-to-long type conversion of visible join fields.

◆ InitTmpTableSliceRefs()

bool anonymous_namespace{finalize_plan.cc}::InitTmpTableSliceRefs ( THD thd,
AccessPath path,
JOIN join 
)

In hypergraph optimizer, slices are currently used only for temp tables created for GROUP BY; i.e.

temp table aggregation and materialization with deduplication (not for DISTINCT deduplication or UNION deduplication).

For GROUP BY, we require slices to handle subqueries in HAVING clause.

For DISTINCT, we don't require slices. ORDER BY clause is the only clause that is appled after DISTINCT. And the ORDER BY expression is always added as a hidden select item, and the temp table always has this item as one of its columns. This means that the expression is already evaluated and materialized in the temp table; there is no further evaluation. If it were not materialized, any Item refs (e.g. if the expression is a subquery) would have required a temp table slice for evaluation, but because it is already materialized, we don't require slices.

(Note: The temp-table item replacement infrastructure doesn't support items inside subqueries, hence slices).

◆ IsMaterializePathForDeduplication()

bool anonymous_namespace{finalize_plan.cc}::IsMaterializePathForDeduplication ( AccessPath path)

◆ IsMaterializePathForDistinct()

bool anonymous_namespace{finalize_plan.cc}::IsMaterializePathForDistinct ( AccessPath path)

◆ IsMaterializePathForGroupBy()

bool anonymous_namespace{finalize_plan.cc}::IsMaterializePathForGroupBy ( AccessPath path)

◆ OrderItemsReferenceUnavailableTables()

bool anonymous_namespace{finalize_plan.cc}::OrderItemsReferenceUnavailableTables ( const AccessPath sort_path,
table_map  used_tables_before_replacement 
)

Checks if the order items in a SORT access path reference any column that is not available to it.

Specifically, it tests that all columns referenced in the order items belong to tables that are available from a child of "sort_path", without any intermediate materialization step between the child and "sort_path".

Say we have an access path tree such as this:

-> Sort
    -> Nested loop join
        -> Table scan on t1
        -> Materialize
            -> Table scan on t2

Here, the ordering elements in the sort node may reference columns from t1 or from the materialize node, but not from t2. If they reference columns from t2 directly, it means that something is missing from the set of expressions to materialize from t2. Or that something has gone wrong when rewriting the expressions in the ordering elements to point into the temporary table.

◆ ReplaceSelectListWithTempTableFields()

void anonymous_namespace{finalize_plan.cc}::ReplaceSelectListWithTempTableFields ( THD thd,
JOIN join,
const Func_ptr_array items_to_copy,
Mem_root_array< const Func_ptr_array * > *  applied_replacements 
)

Replaces the items in the SELECT list with items that point to fields in a temporary table.

See FinalizePlanForQueryBlock() for more information. Also creates a new items_to_copy list made up of aggregate items that were not found while finding replacement. These items need to be added in 'applied_replacements' so that further items get a direct match for subsequent occurences of these items, rather than generating a new replacement. Without this, the replacement does not propagate from the bottom to the top plan node.

◆ ReplaceUpdateValuesWithTempTableFields()

void anonymous_namespace{finalize_plan.cc}::ReplaceUpdateValuesWithTempTableFields ( Sql_cmd_insert_select sql_cmd,
Query_block query_block,
const mem_root_deque< Item * > &  original_fields,
const mem_root_deque< Item * > &  temp_table_fields 
)

Replaces field references in an ON DUPLICATE KEY UPDATE clause with references to corresponding fields in a temporary table.

The changes will be rolled back at the end of execution and will have to be redone during optimization in the next execution.

◆ UpdateReferencesToMaterializedItems()

bool anonymous_namespace{finalize_plan.cc}::UpdateReferencesToMaterializedItems ( THD thd,
Query_block query_block,
AccessPath path,
bool  after_aggregation,
Mem_root_array< const Func_ptr_array * > *  applied_replacements 
)

See FinalizePlanForQueryBlock().