MySQL 9.4.0
Source Code Documentation
content_tree.h
Go to the documentation of this file.
1#pragma once
2
3/* Copyright (c) 2025, Oracle and/or its affiliates.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License, version 2.0,
7 as published by the Free Software Foundation.
8
9 This program is designed to work with certain software (including
10 but not limited to OpenSSL) that is licensed under separate terms,
11 as designated in a particular file or component or in included license
12 documentation. The authors of MySQL hereby grant you an additional
13 permission to link the program and your derivative works with the
14 separately licensed software that they have either included with
15 the program or referenced in the documentation.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License, version 2.0, for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
25
26#include "sql/sql_class.h"
27#include "sql/table.h"
28
29class Field;
30
31namespace jdv {
32
38 DVT_NOUPDATE = 8
39};
40
41constexpr std::size_t VOID_COLUMN_INDEX =
43
44/**
45 * @brief Class to represent each key and column information from JSON duality
46 * object.
47 */
49 private:
50 /// Base column name.
51 std::string_view m_column_name;
52
53 /// Key in JDV definition.
54 std::string_view m_key;
55
56 /// Field instance of a column.
57 const Field *m_field{nullptr};
58
59 /// Column tags.
61
62 /// Flag to indicate column is projected or not.
64
65 public:
66 /////////////////////////////////////////////////////////////////////////////
67 // Column name.
68 /////////////////////////////////////////////////////////////////////////////
70 const std::string_view &column_name() const { return m_column_name; }
71
72 /////////////////////////////////////////////////////////////////////////////
73 // Key.
74 /////////////////////////////////////////////////////////////////////////////
75 void set_key(const char *key) { m_key = key; }
76 const std::string_view &key() const { return m_key; }
77
78 /////////////////////////////////////////////////////////////////////////////
79 // Field instance of a column.
80 /////////////////////////////////////////////////////////////////////////////
81 void set_field(Field *fld) { m_field = fld; }
82 const Field *field() const;
84 bool is_generated_column() const;
85
86 /////////////////////////////////////////////////////////////////////////////
87 // Column tags.
88 /////////////////////////////////////////////////////////////////////////////
91
92 bool allows_insert() const {
93 return static_cast<bool>(m_column_tags & DVT_INSERT);
94 }
95 bool allows_update() const {
96 return static_cast<bool>(m_column_tags & DVT_UPDATE);
97 }
98 bool allows_delete() const {
99 return static_cast<bool>(m_column_tags & DVT_DELETE);
100 }
101 bool read_only() const {
103 }
104
105 /////////////////////////////////////////////////////////////////////////////
106 // Column projected.
107 /////////////////////////////////////////////////////////////////////////////
108 void set_column_projected(bool col_projected) {
109 m_is_column_projected = col_projected;
110 }
112};
113
114/*
115 * @brief Class to represent each object of JSON duality view in the Content
116 * tree.
117 */
119 public:
120 /// Types of object.
122
123 private:
124 /// Name of this node. Holds "Root Node" for Root and Key name for
125 /// descendents.
126 std::string_view m_name;
127
128 /// Temporary id created for I_S.
130
131 /// Object query expression.
133
134 /// Table_ref instance of query table.
135 const Table_ref *m_table_ref{nullptr};
136
137 /// Qualified table name.
138 std::string_view m_qualified_table_name;
139
140 /// Qualified table name with quotes.
142
143 /// Table level DV tags.
145
146 /// Node type.
148
149 /// Parent node.
151
152 /// List of children nodes.
154
155 /// List of base columns with tags and key information.
157
158 /// Key to base columns in m_key_column_info_list map.
159 std::map<std::string_view, std::size_t> m_key_column_map;
160
161 /// Index of primary key column in m_key_column_info_list.
163
164 /// Index of join condition column in m_key_column_info_list.
166
167 /// Index of join condition column in Parent's m_key_column_info_list.
169
170 /// Dependency weight to order DML operations.
172
173 public:
174 Content_tree_node() = default;
176
179
180 /////////////////////////////////////////////////////////////////////////////
181 // Name of node.
182 /////////////////////////////////////////////////////////////////////////////
183 void set_name(const char *name) { m_name = name; }
184 const std::string_view &name() const { return m_name; }
185
186 /////////////////////////////////////////////////////////////////////////////
187 // Table id.
188 /////////////////////////////////////////////////////////////////////////////
189 void set_tmp_table_id(uint id) { m_tmp_table_id = id; }
190 uint tmp_table_id() const { return m_tmp_table_id; }
191
192 /////////////////////////////////////////////////////////////////////////////
193 // Query expression.
194 /////////////////////////////////////////////////////////////////////////////
197 return m_query_expression;
198 }
199
200 /////////////////////////////////////////////////////////////////////////////
201 // Table_ref.
202 /////////////////////////////////////////////////////////////////////////////
204 const Table_ref *table_ref() const { return m_table_ref; }
205
206 /////////////////////////////////////////////////////////////////////////////
207 // Qualified table name.
208 /////////////////////////////////////////////////////////////////////////////
209 void set_qualified_table_name(const char *qname) {
211 }
212 const std::string_view &qualified_table_name() const {
214 }
215
216 /////////////////////////////////////////////////////////////////////////////
217 // Quoted qualified table name.
218 /////////////////////////////////////////////////////////////////////////////
219 void set_quoted_qualified_table_name(std::string &&qname) {
221 }
222 const std::string &quoted_qualified_table_name() const {
224 }
225
226 /////////////////////////////////////////////////////////////////////////////
227 // Table tags.
228 /////////////////////////////////////////////////////////////////////////////
231 }
233 bool allows_insert() const {
234 return static_cast<bool>(table_tags() & DVT_INSERT);
235 }
236 bool allows_update() const {
237 return static_cast<bool>(table_tags() & DVT_UPDATE);
238 }
239 bool allows_delete() const {
240 return static_cast<bool>(table_tags() & DVT_DELETE);
241 }
242 bool read_only() const {
243 return (!(table_tags() & (DVT_INSERT | DVT_UPDATE | DVT_DELETE)));
244 }
245
246 /////////////////////////////////////////////////////////////////////////////
247 // Node type.
248 /////////////////////////////////////////////////////////////////////////////
250 Type type() const { return m_type; }
251 const char *type_string() const {
252 return (type() == Type::SINGLETON_CHILD ? "singleton" : "nested");
253 }
254 bool is_root_object() const { return type() == Type::ROOT; }
255 bool is_singleton_child() const { return type() == Type::SINGLETON_CHILD; }
256 bool is_nested_child() const { return type() == Type::NESTED_CHILD; }
257
258 /////////////////////////////////////////////////////////////////////////////
259 // Parent node.
260 /////////////////////////////////////////////////////////////////////////////
262 Content_tree_node *parent() const { return m_parent; }
263
264 /////////////////////////////////////////////////////////////////////////////
265 // Children nodes.
266 /////////////////////////////////////////////////////////////////////////////
269 return m_children;
270 }
271
272 /////////////////////////////////////////////////////////////////////////////
273 // Key columns info list.
274 /////////////////////////////////////////////////////////////////////////////
277 }
280 }
281
282 /////////////////////////////////////////////////////////////////////////////
283 // Key to column map.
284 /////////////////////////////////////////////////////////////////////////////
285 std::map<std::string_view, std::size_t> *key_column_map() {
286 return &m_key_column_map;
287 }
288 const std::map<std::string_view, std::size_t> &key_column_map() const {
289 return m_key_column_map;
290 }
291
292 /////////////////////////////////////////////////////////////////////////////
293 // Primary key column index in key columns info list.
294 /////////////////////////////////////////////////////////////////////////////
295 void set_primary_key_column_index(std::size_t key_col_idx) {
296 m_primary_key_column = key_col_idx;
297 }
298 std::size_t primary_key_column_index() const { return m_primary_key_column; }
299
302 }
303
306 }
307
308 /////////////////////////////////////////////////////////////////////////////
309 // Join column index in key columns info list.
310 /////////////////////////////////////////////////////////////////////////////
311 void set_join_column_index(std::size_t join_col_idx) {
312 m_join_column_index = join_col_idx;
313 }
314 std::size_t join_column_index() const { return m_join_column_index; }
315
316 bool has_join_condition() const {
318 }
319
322 }
323
324 /////////////////////////////////////////////////////////////////////////////
325 // Join column index in parent node's key columns info list.
326 /////////////////////////////////////////////////////////////////////////////
327 void set_parent_join_column_index(std::size_t join_col_idx) {
328 m_parent_join_column_index = join_col_idx;
329 }
330 std::size_t parent_join_column_index() const {
332 }
333
335 assert(!is_root_object() && m_parent != nullptr);
337 }
338
339 /////////////////////////////////////////////////////////////////////////////
340 // Join column index in current node and parent node's key columns info list.
341 /////////////////////////////////////////////////////////////////////////////
342 void set_join_column_index(std::size_t join_col_idx, bool is_parent) {
343 if (is_parent)
344 set_parent_join_column_index(join_col_idx);
345 else
346 set_join_column_index(join_col_idx);
347 }
348
349 std::size_t join_column_index(bool is_parent) const {
350 return is_parent ? parent_join_column_index() : join_column_index();
351 }
352
353 /////////////////////////////////////////////////////////////////////////////
354 // Dependency weight of a node.
355 /////////////////////////////////////////////////////////////////////////////
358};
359
360/**
361 Constructs the content tree for given JSON duality view.
362
363 @param [in] thd THD context.
364 @param [in] view_lex LEX* object for the current query
365
366 @returns Content_tree on success, nullptr otherwise.
367*/
368Content_tree_node *prepare_content_tree(THD *thd, LEX *view_lex);
369
370/**
371 Deletes the content tree for given JSON duality view.
372
373 @param [in] root Root object of content tree
374*/
375void destroy_content_tree(Content_tree_node *root);
376} // namespace jdv
Definition: field.h:569
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:432
This class represents a query expression (one query block or several query blocks combined with UNION...
Definition: sql_lex.h:643
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
Definition: table.h:2931
Definition: content_tree.h:118
const Key_column_info & parent_join_column_info() const
Definition: content_tree.h:334
Type type() const
Definition: content_tree.h:250
std::size_t primary_key_column_index() const
Definition: content_tree.h:298
void set_tmp_table_id(uint id)
Definition: content_tree.h:189
Content_tree_node(MEM_ROOT *mem_root)
Definition: content_tree.h:177
bool is_root_object() const
Definition: content_tree.h:254
bool allows_delete() const
Definition: content_tree.h:239
Content_tree_node * parent() const
Definition: content_tree.h:262
Mem_root_array< Content_tree_node * > m_children
List of children nodes.
Definition: content_tree.h:153
bool read_only() const
Definition: content_tree.h:242
Duality_view_tags m_table_tags
Table level DV tags.
Definition: content_tree.h:144
std::map< std::string_view, std::size_t > * key_column_map()
Definition: content_tree.h:285
void set_qualified_table_name(const char *qname)
Definition: content_tree.h:209
void set_table_ref(Table_ref *table_ref)
Definition: content_tree.h:203
Type m_type
Node type.
Definition: content_tree.h:147
const std::string & quoted_qualified_table_name() const
Definition: content_tree.h:222
bool is_nested_child() const
Definition: content_tree.h:256
void set_table_tags(Duality_view_tags table_tags)
Definition: content_tree.h:229
void set_name(const char *name)
Definition: content_tree.h:183
void set_parent_join_column_index(std::size_t join_col_idx)
Definition: content_tree.h:327
const std::string_view & name() const
Definition: content_tree.h:184
std::string_view m_qualified_table_name
Qualified table name.
Definition: content_tree.h:138
const Mem_root_array< Content_tree_node * > & children() const
Definition: content_tree.h:268
~Content_tree_node()=default
Type
Types of object.
Definition: content_tree.h:121
const Key_column_info & join_column_info() const
Definition: content_tree.h:320
bool allows_update() const
Definition: content_tree.h:236
void set_join_column_index(std::size_t join_col_idx, bool is_parent)
Definition: content_tree.h:342
Mem_root_array< Key_column_info > m_key_column_info_list
List of base columns with tags and key information.
Definition: content_tree.h:156
Duality_view_tags table_tags() const
Definition: content_tree.h:232
void set_join_column_index(std::size_t join_col_idx)
Definition: content_tree.h:311
std::size_t m_primary_key_column
Index of primary key column in m_key_column_info_list.
Definition: content_tree.h:162
std::map< std::string_view, std::size_t > m_key_column_map
Key to base columns in m_key_column_info_list map.
Definition: content_tree.h:159
uint tmp_table_id() const
Definition: content_tree.h:190
const Mem_root_array< Key_column_info > & key_column_info_list() const
Definition: content_tree.h:278
std::string m_quoted_qualified_table_name
Qualified table name with quotes.
Definition: content_tree.h:141
std::size_t join_column_index() const
Definition: content_tree.h:314
bool has_join_condition() const
Definition: content_tree.h:316
void set_quoted_qualified_table_name(std::string &&qname)
Definition: content_tree.h:219
void set_parent(Content_tree_node *parent)
Definition: content_tree.h:261
std::size_t m_join_column_index
Index of join condition column in m_key_column_info_list.
Definition: content_tree.h:165
void set_primary_key_column_index(std::size_t key_col_idx)
Definition: content_tree.h:295
int m_dependency_weight
Dependency weight to order DML operations.
Definition: content_tree.h:171
Mem_root_array< Key_column_info > * key_column_info_list()
Definition: content_tree.h:275
const std::map< std::string_view, std::size_t > & key_column_map() const
Definition: content_tree.h:288
const std::string_view & qualified_table_name() const
Definition: content_tree.h:212
std::size_t parent_join_column_index() const
Definition: content_tree.h:330
Content_tree_node * m_parent
Parent node.
Definition: content_tree.h:150
const Table_ref * m_table_ref
Table_ref instance of query table.
Definition: content_tree.h:135
void set_query_expression(Query_expression *qe)
Definition: content_tree.h:195
void set_type(Type type)
Definition: content_tree.h:249
int dependency_weight() const
Definition: content_tree.h:357
const Query_expression * m_query_expression
Object query expression.
Definition: content_tree.h:132
const Table_ref * table_ref() const
Definition: content_tree.h:204
void set_dependency_weight(int weight)
Definition: content_tree.h:356
std::string_view m_name
Name of this node.
Definition: content_tree.h:126
bool allows_insert() const
Definition: content_tree.h:233
const Query_expression * query_expression() const
Definition: content_tree.h:196
uint m_tmp_table_id
Temporary id created for I_S.
Definition: content_tree.h:129
Mem_root_array< Content_tree_node * > * children()
Definition: content_tree.h:267
const Key_column_info & primary_key_column() const
Definition: content_tree.h:304
std::size_t m_parent_join_column_index
Index of join condition column in Parent's m_key_column_info_list.
Definition: content_tree.h:168
bool is_singleton_child() const
Definition: content_tree.h:255
const char * type_string() const
Definition: content_tree.h:251
std::size_t join_column_index(bool is_parent) const
Definition: content_tree.h:349
bool is_primary_key_column_projected()
Definition: content_tree.h:300
Class to represent each key and column information from JSON duality object.
Definition: content_tree.h:48
Duality_view_tags m_column_tags
Column tags.
Definition: content_tree.h:60
bool allows_delete() const
Definition: content_tree.h:98
const Field * m_field
Field instance of a column.
Definition: content_tree.h:57
bool is_generated_column() const
Definition: content_tree.cc:48
bool m_is_column_projected
Flag to indicate column is projected or not.
Definition: content_tree.h:63
const std::string_view & key() const
Definition: content_tree.h:76
void set_column_tags(Duality_view_tags tags)
Definition: content_tree.h:89
bool read_only() const
Definition: content_tree.h:101
std::string_view m_key
Key in JDV definition.
Definition: content_tree.h:54
void set_column_name(const char *column_name)
Definition: content_tree.h:69
void set_key(const char *key)
Definition: content_tree.h:75
void set_column_projected(bool col_projected)
Definition: content_tree.h:108
bool is_column_projected() const
Definition: content_tree.h:111
bool allows_update() const
Definition: content_tree.h:95
bool allows_insert() const
Definition: content_tree.h:92
enum_field_types field_type() const
Definition: content_tree.cc:43
Duality_view_tags column_tags() const
Definition: content_tree.h:90
const std::string_view & column_name() const
Definition: content_tree.h:70
std::string_view m_column_name
Base column name.
Definition: content_tree.h:51
void set_field(Field *fld)
Definition: content_tree.h:81
const Field * field() const
Definition: content_tree.cc:41
static MEM_ROOT mem_root
Definition: client_plugin.cc:114
enum_field_types
Column types for MySQL Note: Keep include/mysql/components/services/bits/stored_program_bits....
Definition: field_types.h:55
Definition: content_tree.cc:39
Content_tree_node * prepare_content_tree(THD *thd, LEX *view_lex)
Constructs the content tree for given JSON duality view.
Definition: content_tree.cc:372
Duality_view_tags
Definition: content_tree.h:33
@ DVT_NOUPDATE
Definition: content_tree.h:38
@ DVT_UPDATE
Definition: content_tree.h:36
@ DVT_INSERT
Definition: content_tree.h:35
@ DVT_DELETE
Definition: content_tree.h:37
@ DVT_INVALID
Definition: content_tree.h:34
constexpr std::size_t VOID_COLUMN_INDEX
Definition: content_tree.h:41
void destroy_content_tree(Content_tree_node *root)
Deletes the content tree for given JSON duality view.
Definition: content_tree.cc:388
ValueType max(X &&first)
Definition: gtid.h:103
required uint64 weight
Definition: replication_asynchronous_connection_failover.proto:35
The LEX object currently serves three different purposes:
Definition: sql_lex.h:3994
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:83
unsigned long id[MAX_DEAD]
Definition: xcom_base.cc:510