24#ifndef SQL_JOIN_OPTIMIZER_MAKE_JOIN_HYPERGRAPH
25#define SQL_JOIN_OPTIMIZER_MAKE_JOIN_HYPERGRAPH 1
35#include <unordered_map>
130 assert(
table !=
nullptr);
137 assert(predicate.
field !=
nullptr);
379 bool *where_is_always_false);
387 const std::array<int, MAX_TABLES> &table_num_to_node_num);
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:929
Definition: sql_optimizer.h:133
Definition: make_join_hypergraph.h:122
void AddSargable(const SargablePredicate &predicate)
Definition: make_join_hypergraph.h:135
const Mem_root_array< SargablePredicate > & sargable_predicates() const
Definition: make_join_hypergraph.h:142
TABLE * m_table
Definition: make_join_hypergraph.h:184
Mem_root_array< SargablePredicate > m_sargable_predicates
Definition: make_join_hypergraph.h:189
int64_t m_read_set_width
Definition: make_join_hypergraph.h:212
hypergraph::NodeMap lateral_dependencies() const
Definition: make_join_hypergraph.h:170
hypergraph::NodeMap m_lateral_dependencies
Definition: make_join_hypergraph.h:207
Node(MEM_ROOT *mem_root, TABLE *table, int64_t read_set_width)
Definition: make_join_hypergraph.h:124
Mem_root_array< PushableJoinCondition > m_pushable_conditions
Definition: make_join_hypergraph.h:201
int64_t read_set_width() const
Definition: make_join_hypergraph.h:178
const Mem_root_array< PushableJoinCondition > & pushable_conditions() const
Definition: make_join_hypergraph.h:166
TABLE * table() const
Definition: make_join_hypergraph.h:133
std::optional< double > cardinality
Definition: make_join_hypergraph.h:181
void AddPushable(Item *cond, const RelationalExpression *from)
Add a join condition that is potentially pushable as a sargable predicate for this node.
Definition: make_join_hypergraph.h:154
void set_lateral_dependencies(hypergraph::NodeMap dependencies)
Definition: make_join_hypergraph.h:174
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:432
Definition: overflow_bitset.h:81
This class represents a query block, aka a query specification, which is a query consisting of a SELE...
Definition: sql_lex.h:1179
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
std::unordered_map, but allocated on a MEM_ROOT.
Definition: map_helpers.h:291
static MEM_ROOT mem_root
Definition: client_plugin.cc:114
Definition of an undirected (join) hypergraph.
bool ItemsAreEqual(const Item *a, const Item *b)
Returns true iff the two items are equal, as in a->eq(b), after unwrapping refs and Item_cache object...
Definition: item.cc:11869
bool MakeJoinHypergraph(THD *thd, JoinHypergraph *graph, bool *where_is_always_false)
Make a join hypergraph from the query block given by “graph->query_block”, converting from MySQL's jo...
Definition: make_join_hypergraph.cc:3826
hypergraph::NodeMap GetNodeMapFromTableMap(table_map table_map, const std::array< int, MAX_TABLES > &table_num_to_node_num)
std::string PrintDottyHypergraph(const JoinHypergraph &graph)
For the given hypergraph, make a textual representation in the form of a dotty graph.
Definition: make_join_hypergraph.cc:2636
void MakeJoinGraphFromRelationalExpression(THD *thd, RelationalExpression *expr, JoinHypergraph *graph)
Convert a join rooted at “expr” into a join hypergraph that encapsulates the constraints given by the...
Definition: make_join_hypergraph.cc:3339
table_map GetVisibleTables(const RelationalExpression *expr)
Definition: make_join_hypergraph.cc:4113
size_t EstimateHashJoinKeyWidth(const RelationalExpression *expr)
Estimates the size of the hash join keys generated from the equi-join predicates in "expr".
Definition: make_join_hypergraph.cc:2735
uint64_t table_map
Definition: my_table_map.h:30
uint64_t NodeMap
Since our graphs can never have more than 61 tables, node sets and edge lists are implemented using 6...
Definition: node_map.h:40
OverflowBitset is a fixed-size (once allocated) bitmap that is optimized for the common case of few e...
For updating an AccessPath's costs by a secondary engine, i.e.
uint64_t SecondaryEngineCostingFlags
Definition: secondary_engine_costing_flags.h:39
File containing constants that can be used throughout the server.
A struct containing a join hypergraph of a single query block, encapsulating the constraints given by...
Definition: make_join_hypergraph.h:99
void set_secondary_engine_nrows_hook(secondary_engine_nrows_hook_t secondary_engine_nrows_hook)
Sets the secondary engine nrows hook (nullptr means unavailable).
Definition: make_join_hypergraph.h:349
secondary_engine_nrows_hook_t m_secondary_engine_nrows_hook
Definition: make_join_hypergraph.h:355
hypergraph::NodeMap nodes_inner_to_outer_join
The set of nodes that are on the inner side of some outer join.
Definition: make_join_hypergraph.h:311
hypergraph::NodeMap nodes_for_table_function
The set of nodes that are represented by table_function.
Definition: make_join_hypergraph.h:321
Mem_root_array< Node > nodes
Definition: make_join_hypergraph.h:214
std::span< Predicate > filter_predicates()
Returns a mutable view of the filter predicates portion of the predicates array.
Definition: make_join_hypergraph.h:278
hypergraph::NodeMap nodes_inner_to_antijoin
The set of nodes that are on the inner side of some antijoin.
Definition: make_join_hypergraph.h:317
bool has_reordered_left_joins
Whether, at any point, we could rewrite (t1 LEFT JOIN t2) LEFT JOIN t3 to t1 LEFT JOIN (t2 LEFT JOIN ...
Definition: make_join_hypergraph.h:303
void AddSargableJoinPredicate(const Item *predicate, int position)
Definition: make_join_hypergraph.h:328
hypergraph::Hypergraph graph
Definition: make_join_hypergraph.h:108
hypergraph::NodeMap nodes_inner_to_semijoin
The set of nodes that are on the inner side of some semijoin.
Definition: make_join_hypergraph.h:314
const Query_block * query_block() const
Returns a pointer to the query block that is being planned.
Definition: make_join_hypergraph.h:287
JoinHypergraph(MEM_ROOT *mem_root, const Query_block *query_block)
Definition: make_join_hypergraph.h:100
const JOIN * join() const
Returns a pointer to the JOIN object of the query block being planned.
Definition: make_join_hypergraph.cc:3824
unsigned num_filter_predicates
Definition: make_join_hypergraph.h:268
const Query_block * m_query_block
A pointer to the query block being planned.
Definition: make_join_hypergraph.h:364
Mem_root_array< Predicate > predicates
Definition: make_join_hypergraph.h:264
int FindSargableJoinPredicate(const Item *predicate) const
Definition: make_join_hypergraph.h:323
OverflowBitset materializable_predicates
Definition: make_join_hypergraph.h:284
SecondaryEngineCostingFlags secondary_engine_costing_flags
Flags set when AccessPaths are proposed to secondary engines for costing.
Definition: make_join_hypergraph.h:115
bool has_secondary_engine_nrows_hook() const
Returns true if the secondary engine nrows hook is available.
Definition: make_join_hypergraph.h:336
bool(*)(const SecondaryEngineNrowsParameters ¶ms) secondary_engine_nrows_hook_t
Definition: make_join_hypergraph.h:333
mem_root_unordered_map< const Item *, int > m_sargable_join_predicates
Definition: make_join_hypergraph.h:361
std::array< int, MAX_TABLES > table_num_to_node_num
Definition: make_join_hypergraph.h:120
bool call_secondary_engine_nrows_hook(const SecondaryEngineNrowsParameters ¶ms) const
Calls the secondary engine nrows hook.
Definition: make_join_hypergraph.h:342
std::span< const Predicate > filter_predicates() const
Returns an immutable view of the filter predicates portion of the predicates array.
Definition: make_join_hypergraph.h:272
bool has_estimates_from_secondary_engine
Definition: make_join_hypergraph.h:308
Mem_root_array< JoinPredicate > edges
Definition: make_join_hypergraph.h:218
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:83
Information about a join condition that can potentially be pushed down as a sargable predicate for a ...
Definition: make_join_hypergraph.h:82
const RelationalExpression * from
The relational expression from which this condition is pushable.
Definition: make_join_hypergraph.h:86
Item * cond
The condition that may be pushed as a sargable predicate.
Definition: make_join_hypergraph.h:84
Represents an expression tree in the relational algebra of joins.
Definition: relational_expression.h:155
A sargable (from “Search ARGument”) predicate is one that we can attempt to push down into an index (...
Definition: make_join_hypergraph.h:64
int predicate_index
Definition: make_join_hypergraph.h:66
Field * field
Definition: make_join_hypergraph.h:71
Item * other_side
Definition: make_join_hypergraph.h:72
bool can_evaluate
True if it is safe to evaluate "other_side" during optimization.
Definition: make_join_hypergraph.h:77
Type for signature generation and for retrieving nrows estimate from secondary engine for current Acc...
Definition: handler.h:2485
Definition: hypergraph.h:92