MySQL 9.1.0
Source Code Documentation
nested_join.h
Go to the documentation of this file.
1/* Copyright (c) 2017, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef SQL_NESTED_JOIN_INCLUDED
25#define SQL_NESTED_JOIN_INCLUDED
26
27#include <sys/types.h>
28#include "my_inttypes.h"
29#include "my_table_map.h"
30#include "sql/handler.h"
31#include "sql/sql_list.h"
33
34class Item;
35class Item_field;
36struct POSITION;
37class Table_ref;
38
39/*
40 Used to identify NESTED_JOIN structures within a join (applicable to
41 structures representing outer joins that have not been simplified away).
42*/
44
45/**
46 Semijoin_mat_optimize collects data used when calculating the cost of
47 executing a semijoin operation using a materialization strategy.
48 It is used during optimization phase only.
49*/
50
52 /// Optimal join order calculated for inner tables of this semijoin op.
54 /// True if data types allow the MaterializeLookup semijoin strategy
55 bool lookup_allowed{false};
56 /// True if data types allow the MaterializeScan semijoin strategy
57 bool scan_allowed{false};
58 /// Expected number of rows in the materialized table
59 double expected_rowcount{0.0};
60 /// Materialization cost - execute sub-join and write rows to temp.table
62 /// Cost to make one lookup in the temptable
64 /// Cost of scanning the materialized table
66 /// Array of pointers to fields in the materialized table.
68};
69
70/**
71 Struct NESTED_JOIN is used to represent how tables are connected through
72 outer join operations and semi-join operations to form a query block.
73 Out of the parser, inner joins are also represented by NESTED_JOIN
74 structs, but these are later flattened out by simplify_joins().
75 Some outer join nests are also flattened, when it can be determined that
76 they can be processed as inner joins instead of outer joins.
77*/
83
84 /// list of tables referenced in the nested join
86 table_map used_tables{0}; /* bitmap of tables in the nested join */
87 table_map not_null_tables{0}; /* tables that rejects nulls */
88 /**
89 Used for pointing out the first table in the plan being covered by this
90 join nest. It is used exclusively within make_outerjoin_info().
91 */
93 /**
94 Set to true when natural join or using information has been processed.
95 */
97 /**
98 Number of tables and outer join nests administered by this nested join
99 object for the sake of cost analysis. Includes direct member tables as
100 well as tables included through semi-join nests, but notice that semi-join
101 nests themselves are not counted.
102 */
103 uint nj_total{0};
104 /**
105 Used to count tables in the nested join in 2 isolated places:
106 1. In make_outerjoin_info().
107 2. check_interleaving_with_nj/backout_nj_state (these are called
108 by the join optimizer.
109 Before each use the counters are zeroed by Query_block::reset_nj_counters.
110 */
111 uint nj_counter{0};
112 /**
113 Bit identifying this nested join. Only nested joins representing the
114 outer join structure need this, other nests have bit set to zero.
115 */
117 /**
118 Tables outside the semi-join that are used within the semi-join's
119 ON condition (ie. the subquery WHERE clause and optional IN equalities).
120 Also contains lateral dependencies from materialized derived tables
121 contained inside the semi-join inner tables.
122 */
124 /**
125 Outer non-trivially correlated tables, a true subset of sj_depends_on.
126 Also contains lateral dependencies from materialized derived tables
127 contained inside the semi-join inner tables.
128 */
130 /**
131 Query block id if this struct is generated from a subquery transform.
132 */
134
135 /// Bitmap of which strategies are enabled for this semi-join nest
137
138 /*
139 Lists of trivially-correlated expressions from the outer and inner tables
140 of the semi-join, respectively.
141 */
144};
145
146#endif // SQL_NESTED_JOIN_INCLUDED
Used to store optimizer cost estimates.
Definition: handler.h:3877
Definition: item.h:4385
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:930
Definition: table.h:2900
A (partial) implementation of std::deque allocating its blocks on a MEM_ROOT.
Definition: mem_root_deque.h:111
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:56
uint64_t table_map
Definition: my_table_map.h:30
thread_local MEM_ROOT ** THR_MALLOC
Definition: mysqld.cc:1569
ulonglong nested_join_map
Definition: nested_join.h:37
Common types of the Optimizer, used by optimization and execution.
int plan_idx
This represents the index of a JOIN_TAB/QEP_TAB in an array.
Definition: sql_opt_exec_shared.h:54
Struct NESTED_JOIN is used to represent how tables are connected through outer join operations and se...
Definition: nested_join.h:78
mem_root_deque< Item * > sj_inner_exprs
Definition: nested_join.h:142
mem_root_deque< Table_ref * > m_tables
list of tables referenced in the nested join
Definition: nested_join.h:85
uint sj_enabled_strategies
Bitmap of which strategies are enabled for this semi-join nest.
Definition: nested_join.h:136
Semijoin_mat_optimize sjm
Definition: nested_join.h:143
bool natural_join_processed
Set to true when natural join or using information has been processed.
Definition: nested_join.h:96
nested_join_map nj_map
Bit identifying this nested join.
Definition: nested_join.h:116
table_map sj_corr_tables
Outer non-trivially correlated tables, a true subset of sj_depends_on.
Definition: nested_join.h:129
table_map used_tables
Definition: nested_join.h:86
uint nj_total
Number of tables and outer join nests administered by this nested join object for the sake of cost an...
Definition: nested_join.h:103
uint query_block_id
Query block id if this struct is generated from a subquery transform.
Definition: nested_join.h:133
NESTED_JOIN()
Definition: nested_join.h:79
table_map sj_depends_on
Tables outside the semi-join that are used within the semi-join's ON condition (ie.
Definition: nested_join.h:123
table_map not_null_tables
Definition: nested_join.h:87
uint nj_counter
Used to count tables in the nested join in 2 isolated places:
Definition: nested_join.h:111
plan_idx first_nested
Used for pointing out the first table in the plan being covered by this join nest.
Definition: nested_join.h:92
mem_root_deque< Item * > sj_outer_exprs
Definition: nested_join.h:142
A position of table within a join order.
Definition: sql_select.h:355
Semijoin_mat_optimize collects data used when calculating the cost of executing a semijoin operation ...
Definition: nested_join.h:51
bool scan_allowed
True if data types allow the MaterializeScan semijoin strategy.
Definition: nested_join.h:57
bool lookup_allowed
True if data types allow the MaterializeLookup semijoin strategy.
Definition: nested_join.h:55
POSITION * positions
Optimal join order calculated for inner tables of this semijoin op.
Definition: nested_join.h:53
double expected_rowcount
Expected number of rows in the materialized table.
Definition: nested_join.h:59
Cost_estimate materialization_cost
Materialization cost - execute sub-join and write rows to temp.table.
Definition: nested_join.h:61
Cost_estimate lookup_cost
Cost to make one lookup in the temptable.
Definition: nested_join.h:63
Cost_estimate scan_cost
Cost of scanning the materialized table.
Definition: nested_join.h:65
Item_field ** mat_fields
Array of pointers to fields in the materialized table.
Definition: nested_join.h:67