File: nested_join.h

package info (click to toggle)
mysql-8.0 8.0.44-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,272,892 kB
  • sloc: cpp: 4,685,345; ansic: 412,712; pascal: 108,395; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; python: 21,816; sh: 17,285; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,083; makefile: 1,793; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (146 lines) | stat: -rw-r--r-- 5,582 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/* Copyright (c) 2017, 2025, Oracle and/or its affiliates.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License, version 2.0,
   as published by the Free Software Foundation.

   This program is designed to work with certain software (including
   but not limited to OpenSSL) that is licensed under separate terms,
   as designated in a particular file or component or in included license
   documentation.  The authors of MySQL hereby grant you an additional
   permission to link the program and your derivative works with the
   separately licensed software that they have either included with
   the program or referenced in the documentation.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License, version 2.0, for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */

#ifndef SQL_NESTED_JOIN_INCLUDED
#define SQL_NESTED_JOIN_INCLUDED

#include <sys/types.h>
#include "my_inttypes.h"
#include "my_table_map.h"
#include "sql/handler.h"
#include "sql/sql_list.h"
#include "sql/sql_opt_exec_shared.h"

class Item;
class Item_field;
struct POSITION;
class Table_ref;

/*
  Used to identify NESTED_JOIN structures within a join (applicable to
  structures representing outer joins that have not been simplified away).
*/
typedef ulonglong nested_join_map;

/**
  Semijoin_mat_optimize collects data used when calculating the cost of
  executing a semijoin operation using a materialization strategy.
  It is used during optimization phase only.
*/

struct Semijoin_mat_optimize {
  /// Optimal join order calculated for inner tables of this semijoin op.
  POSITION *positions{nullptr};
  /// True if data types allow the MaterializeLookup semijoin strategy
  bool lookup_allowed{false};
  /// True if data types allow the MaterializeScan semijoin strategy
  bool scan_allowed{false};
  /// Expected number of rows in the materialized table
  double expected_rowcount{0.0};
  /// Materialization cost - execute sub-join and write rows to temp.table
  Cost_estimate materialization_cost;
  /// Cost to make one lookup in the temptable
  Cost_estimate lookup_cost;
  /// Cost of scanning the materialized table
  Cost_estimate scan_cost;
  /// Array of pointers to fields in the materialized table.
  Item_field **mat_fields{nullptr};
};

/**
  Struct NESTED_JOIN is used to represent how tables are connected through
  outer join operations and semi-join operations to form a query block.
  Out of the parser, inner joins are also represented by NESTED_JOIN
  structs, but these are later flattened out by simplify_joins().
  Some outer join nests are also flattened, when it can be determined that
  they can be processed as inner joins instead of outer joins.
*/
struct NESTED_JOIN {
  NESTED_JOIN()
      : m_tables(*THR_MALLOC),
        sj_outer_exprs(*THR_MALLOC),
        sj_inner_exprs(*THR_MALLOC) {}

  /// list of tables referenced in the nested join
  mem_root_deque<Table_ref *> m_tables;
  table_map used_tables{0};     /* bitmap of tables in the nested join */
  table_map not_null_tables{0}; /* tables that rejects nulls           */
  /**
    Used for pointing out the first table in the plan being covered by this
    join nest. It is used exclusively within make_outerjoin_info().
  */
  plan_idx first_nested{0};
  /**
    Set to true when natural join or using information has been processed.
  */
  bool natural_join_processed{false};
  /**
    Number of tables and outer join nests administered by this nested join
    object for the sake of cost analysis. Includes direct member tables as
    well as tables included through semi-join nests, but notice that semi-join
    nests themselves are not counted.
  */
  uint nj_total{0};
  /**
    Used to count tables in the nested join in 2 isolated places:
    1. In make_outerjoin_info().
    2. check_interleaving_with_nj/backout_nj_state (these are called
       by the join optimizer.
    Before each use the counters are zeroed by Query_block::reset_nj_counters.
  */
  uint nj_counter{0};
  /**
    Bit identifying this nested join. Only nested joins representing the
    outer join structure need this, other nests have bit set to zero.
  */
  nested_join_map nj_map{0};
  /**
    Tables outside the semi-join that are used within the semi-join's
    ON condition (ie. the subquery WHERE clause and optional IN equalities).
    Also contains lateral dependencies from materialized derived tables
    contained inside the semi-join inner tables.
  */
  table_map sj_depends_on{0};
  /**
    Outer non-trivially correlated tables, a true subset of sj_depends_on.
    Also contains lateral dependencies from materialized derived tables
    contained inside the semi-join inner tables.
  */
  table_map sj_corr_tables{0};
  /**
    Query block id if this struct is generated from a subquery transform.
  */
  uint query_block_id{0};

  /// Bitmap of which strategies are enabled for this semi-join nest
  uint sj_enabled_strategies{0};

  /*
    Lists of trivially-correlated expressions from the outer and inner tables
    of the semi-join, respectively.
  */
  mem_root_deque<Item *> sj_outer_exprs, sj_inner_exprs;
  Semijoin_mat_optimize sjm;
};

#endif  // SQL_NESTED_JOIN_INCLUDED