MySQL 9.6.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
40 DVT_NODELETE = 32
41};
42
43constexpr std::size_t VOID_COLUMN_INDEX =
45
46/**
47 * @brief Class to represent each key and column information from JSON duality
48 * object.
49 */
51 private:
52 /// Base column name.
53 std::string_view m_column_name;
54
55 /// Key in JDV definition.
56 std::string_view m_key;
57
58 /// Field instance of a column.
59 const Field *m_field{nullptr};
60
61 /// Column tags.
63
64 /// Flag to indicate column is projected or not.
66
67 public:
68 /////////////////////////////////////////////////////////////////////////////
69 // Column name.
70 /////////////////////////////////////////////////////////////////////////////
72 const std::string_view &column_name() const { return m_column_name; }
73
74 /////////////////////////////////////////////////////////////////////////////
75 // Key.
76 /////////////////////////////////////////////////////////////////////////////
77 void set_key(const char *key) { m_key = key; }
78 const std::string_view &key() const { return m_key; }
79
80 /////////////////////////////////////////////////////////////////////////////
81 // Field instance of a column.
82 /////////////////////////////////////////////////////////////////////////////
83 void set_field(Field *fld) { m_field = fld; }
84 const Field *field() const;
86 bool is_generated_column() const;
87
88 /////////////////////////////////////////////////////////////////////////////
89 // Column tags.
90 /////////////////////////////////////////////////////////////////////////////
93
94 bool allows_insert() const {
95 return static_cast<bool>(m_column_tags & DVT_INSERT);
96 }
97 bool allows_update() const {
98 return static_cast<bool>(m_column_tags & DVT_UPDATE);
99 }
100 bool allows_delete() const {
101 return static_cast<bool>(m_column_tags & DVT_DELETE);
102 }
103 bool read_only() const {
105 }
106
107 /////////////////////////////////////////////////////////////////////////////
108 // Column projected.
109 /////////////////////////////////////////////////////////////////////////////
110 void set_column_projected(bool col_projected) {
111 m_is_column_projected = col_projected;
112 }
114};
115
116/*
117 * @brief Class to represent each object of JSON duality view in the Content
118 * tree.
119 */
121 public:
122 /// Types of object.
124
125 private:
126 /// Name of this node. Holds "Root Node" for Root and Key name for
127 /// descendents.
128 std::string_view m_name;
129
130 /// Node id. Displayed in I_S.
131 uint m_id{0};
132
133 /// Object query expression.
135
136 /// Table_ref instance of query table.
137 const Table_ref *m_table_ref{nullptr};
138
139 /// Qualified table name.
140 std::string_view m_qualified_table_name;
141
142 /// Qualified table name with quotes.
144
145 /// Table level DV tags.
147
148 /// Node type.
150
151 /// Parent node.
153
154 /// List of children nodes.
156
157 /// List of base columns with tags and key information.
159
160 /// Key to base columns in m_key_column_info_list map.
161 std::map<std::string_view, std::size_t> m_key_column_map;
162
163 /// Index of primary key column in m_key_column_info_list.
165
166 /// Index of join condition column in m_key_column_info_list.
168
169 /// Index of join condition column in Parent's m_key_column_info_list.
171
172 /// Dependency weight to order DML operations.
174
175 public:
176 Content_tree_node() = default;
178
181
182 /////////////////////////////////////////////////////////////////////////////
183 // Name of node.
184 /////////////////////////////////////////////////////////////////////////////
185 void set_name(const char *name) { m_name = name; }
186 const std::string_view &name() const { return m_name; }
187
188 /////////////////////////////////////////////////////////////////////////////
189 // Node id (Table_id in I_S)
190 /////////////////////////////////////////////////////////////////////////////
191 void set_id(uint id) { m_id = id; }
192 uint id() const { return m_id; }
193
194 /////////////////////////////////////////////////////////////////////////////
195 // Query expression.
196 /////////////////////////////////////////////////////////////////////////////
199 return m_query_expression;
200 }
201
202 /////////////////////////////////////////////////////////////////////////////
203 // Table_ref.
204 /////////////////////////////////////////////////////////////////////////////
206 const Table_ref *table_ref() const { return m_table_ref; }
207
208 /////////////////////////////////////////////////////////////////////////////
209 // Qualified table name.
210 /////////////////////////////////////////////////////////////////////////////
211 void set_qualified_table_name(const char *qname) {
213 }
214 const std::string_view &qualified_table_name() const {
216 }
217
218 /////////////////////////////////////////////////////////////////////////////
219 // Quoted qualified table name.
220 /////////////////////////////////////////////////////////////////////////////
221 void set_quoted_qualified_table_name(std::string &&qname) {
223 }
224 const std::string &quoted_qualified_table_name() const {
226 }
227
228 /////////////////////////////////////////////////////////////////////////////
229 // Table tags.
230 /////////////////////////////////////////////////////////////////////////////
232 assert(!((table_tags & DVT_INSERT && table_tags & DVT_NOINSERT) ||
236 }
238 bool allows_insert() const { return (table_tags() & DVT_INSERT) != 0; }
239
240 bool allows_update() const { return (table_tags() & DVT_UPDATE) != 0; }
241
242 bool allows_delete() const { return (table_tags() & DVT_DELETE) != 0; }
243
244 bool read_only() const {
245 return !allows_insert() && !allows_update() && !allows_delete();
246 }
247
248 /////////////////////////////////////////////////////////////////////////////
249 // Node type.
250 /////////////////////////////////////////////////////////////////////////////
252 Type type() const { return m_type; }
253 const char *type_string() const {
254 return (type() == Type::SINGLETON_CHILD ? "singleton" : "nested");
255 }
256 bool is_root_object() const { return type() == Type::ROOT; }
257 bool is_singleton_child() const { return type() == Type::SINGLETON_CHILD; }
258 bool is_nested_child() const { return type() == Type::NESTED_CHILD; }
259
260 /////////////////////////////////////////////////////////////////////////////
261 // Parent node.
262 /////////////////////////////////////////////////////////////////////////////
264 Content_tree_node *parent() const { return m_parent; }
265
266 /////////////////////////////////////////////////////////////////////////////
267 // Children nodes.
268 /////////////////////////////////////////////////////////////////////////////
271 return m_children;
272 }
273
274 /////////////////////////////////////////////////////////////////////////////
275 // Key columns info list.
276 /////////////////////////////////////////////////////////////////////////////
279 }
282 }
283
284 /////////////////////////////////////////////////////////////////////////////
285 // Key to column map.
286 /////////////////////////////////////////////////////////////////////////////
287 std::map<std::string_view, std::size_t> *key_column_map() {
288 return &m_key_column_map;
289 }
290 const std::map<std::string_view, std::size_t> &key_column_map() const {
291 return m_key_column_map;
292 }
293
294 /////////////////////////////////////////////////////////////////////////////
295 // Primary key column index in key columns info list.
296 /////////////////////////////////////////////////////////////////////////////
297 void set_primary_key_column_index(std::size_t key_col_idx) {
298 m_primary_key_column = key_col_idx;
299 }
300 std::size_t primary_key_column_index() const { return m_primary_key_column; }
301
304 }
305
308 }
309
310 /////////////////////////////////////////////////////////////////////////////
311 // Join column index in key columns info list.
312 /////////////////////////////////////////////////////////////////////////////
313 void set_join_column_index(std::size_t join_col_idx) {
314 m_join_column_index = join_col_idx;
315 }
316 std::size_t join_column_index() const { return m_join_column_index; }
317
318 bool has_join_condition() const {
320 }
321
324 }
325
326 /////////////////////////////////////////////////////////////////////////////
327 // Join column index in parent node's key columns info list.
328 /////////////////////////////////////////////////////////////////////////////
329 void set_parent_join_column_index(std::size_t join_col_idx) {
330 m_parent_join_column_index = join_col_idx;
331 }
332 std::size_t parent_join_column_index() const {
334 }
335
337 assert(!is_root_object() && m_parent != nullptr);
339 }
340
341 /////////////////////////////////////////////////////////////////////////////
342 // Join column index in current node and parent node's key columns info list.
343 /////////////////////////////////////////////////////////////////////////////
344 void set_join_column_index(std::size_t join_col_idx, bool is_parent) {
345 if (is_parent)
346 set_parent_join_column_index(join_col_idx);
347 else
348 set_join_column_index(join_col_idx);
349 }
350
351 std::size_t join_column_index(bool is_parent) const {
352 return is_parent ? parent_join_column_index() : join_column_index();
353 }
354
355 /////////////////////////////////////////////////////////////////////////////
356 // Dependency weight of a node.
357 /////////////////////////////////////////////////////////////////////////////
360};
361
362/**
363 Constructs the content tree for given JSON duality view.
364
365 @param [in] thd THD context.
366 @param [in] view_lex LEX* object for the current query
367
368 @returns Content_tree on success, nullptr otherwise.
369*/
370Content_tree_node *prepare_content_tree(THD *thd, LEX *view_lex);
371
372/**
373 Deletes the content tree for given JSON duality view.
374
375 @param [in] root Root object of content tree
376*/
377void destroy_content_tree(Content_tree_node *root);
378} // namespace jdv
Definition: field.h:570
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:2952
Definition: content_tree.h:120
const Key_column_info & parent_join_column_info() const
Definition: content_tree.h:336
Type type() const
Definition: content_tree.h:252
std::size_t primary_key_column_index() const
Definition: content_tree.h:300
Content_tree_node(MEM_ROOT *mem_root)
Definition: content_tree.h:179
bool is_root_object() const
Definition: content_tree.h:256
bool allows_delete() const
Definition: content_tree.h:242
Content_tree_node * parent() const
Definition: content_tree.h:264
Mem_root_array< Content_tree_node * > m_children
List of children nodes.
Definition: content_tree.h:155
bool read_only() const
Definition: content_tree.h:244
Duality_view_tags m_table_tags
Table level DV tags.
Definition: content_tree.h:146
std::map< std::string_view, std::size_t > * key_column_map()
Definition: content_tree.h:287
void set_qualified_table_name(const char *qname)
Definition: content_tree.h:211
void set_table_ref(Table_ref *table_ref)
Definition: content_tree.h:205
Type m_type
Node type.
Definition: content_tree.h:149
const std::string & quoted_qualified_table_name() const
Definition: content_tree.h:224
uint m_id
Node id. Displayed in I_S.
Definition: content_tree.h:131
bool is_nested_child() const
Definition: content_tree.h:258
void set_table_tags(Duality_view_tags table_tags)
Definition: content_tree.h:231
void set_name(const char *name)
Definition: content_tree.h:185
void set_parent_join_column_index(std::size_t join_col_idx)
Definition: content_tree.h:329
const std::string_view & name() const
Definition: content_tree.h:186
std::string_view m_qualified_table_name
Qualified table name.
Definition: content_tree.h:140
const Mem_root_array< Content_tree_node * > & children() const
Definition: content_tree.h:270
~Content_tree_node()=default
Type
Types of object.
Definition: content_tree.h:123
const Key_column_info & join_column_info() const
Definition: content_tree.h:322
bool allows_update() const
Definition: content_tree.h:240
void set_join_column_index(std::size_t join_col_idx, bool is_parent)
Definition: content_tree.h:344
Mem_root_array< Key_column_info > m_key_column_info_list
List of base columns with tags and key information.
Definition: content_tree.h:158
Duality_view_tags table_tags() const
Definition: content_tree.h:237
void set_join_column_index(std::size_t join_col_idx)
Definition: content_tree.h:313
uint id() const
Definition: content_tree.h:192
std::size_t m_primary_key_column
Index of primary key column in m_key_column_info_list.
Definition: content_tree.h:164
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:161
const Mem_root_array< Key_column_info > & key_column_info_list() const
Definition: content_tree.h:280
std::string m_quoted_qualified_table_name
Qualified table name with quotes.
Definition: content_tree.h:143
std::size_t join_column_index() const
Definition: content_tree.h:316
bool has_join_condition() const
Definition: content_tree.h:318
void set_quoted_qualified_table_name(std::string &&qname)
Definition: content_tree.h:221
void set_parent(Content_tree_node *parent)
Definition: content_tree.h:263
std::size_t m_join_column_index
Index of join condition column in m_key_column_info_list.
Definition: content_tree.h:167
void set_primary_key_column_index(std::size_t key_col_idx)
Definition: content_tree.h:297
int m_dependency_weight
Dependency weight to order DML operations.
Definition: content_tree.h:173
Mem_root_array< Key_column_info > * key_column_info_list()
Definition: content_tree.h:277
const std::map< std::string_view, std::size_t > & key_column_map() const
Definition: content_tree.h:290
const std::string_view & qualified_table_name() const
Definition: content_tree.h:214
std::size_t parent_join_column_index() const
Definition: content_tree.h:332
Content_tree_node * m_parent
Parent node.
Definition: content_tree.h:152
const Table_ref * m_table_ref
Table_ref instance of query table.
Definition: content_tree.h:137
void set_query_expression(Query_expression *qe)
Definition: content_tree.h:197
void set_type(Type type)
Definition: content_tree.h:251
int dependency_weight() const
Definition: content_tree.h:359
const Query_expression * m_query_expression
Object query expression.
Definition: content_tree.h:134
void set_id(uint id)
Definition: content_tree.h:191
const Table_ref * table_ref() const
Definition: content_tree.h:206
void set_dependency_weight(int weight)
Definition: content_tree.h:358
std::string_view m_name
Name of this node.
Definition: content_tree.h:128
bool allows_insert() const
Definition: content_tree.h:238
const Query_expression * query_expression() const
Definition: content_tree.h:198
Mem_root_array< Content_tree_node * > * children()
Definition: content_tree.h:269
const Key_column_info & primary_key_column() const
Definition: content_tree.h:306
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:170
bool is_singleton_child() const
Definition: content_tree.h:257
const char * type_string() const
Definition: content_tree.h:253
std::size_t join_column_index(bool is_parent) const
Definition: content_tree.h:351
bool is_primary_key_column_projected()
Definition: content_tree.h:302
Class to represent each key and column information from JSON duality object.
Definition: content_tree.h:50
Duality_view_tags m_column_tags
Column tags.
Definition: content_tree.h:62
bool allows_delete() const
Definition: content_tree.h:100
const Field * m_field
Field instance of a column.
Definition: content_tree.h:59
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:65
const std::string_view & key() const
Definition: content_tree.h:78
void set_column_tags(Duality_view_tags tags)
Definition: content_tree.h:91
bool read_only() const
Definition: content_tree.h:103
std::string_view m_key
Key in JDV definition.
Definition: content_tree.h:56
void set_column_name(const char *column_name)
Definition: content_tree.h:71
void set_key(const char *key)
Definition: content_tree.h:77
void set_column_projected(bool col_projected)
Definition: content_tree.h:110
bool is_column_projected() const
Definition: content_tree.h:113
bool allows_update() const
Definition: content_tree.h:97
bool allows_insert() const
Definition: content_tree.h:94
enum_field_types field_type() const
Definition: content_tree.cc:43
Duality_view_tags column_tags() const
Definition: content_tree.h:92
const std::string_view & column_name() const
Definition: content_tree.h:72
std::string_view m_column_name
Base column name.
Definition: content_tree.h:53
void set_field(Field *fld)
Definition: content_tree.h:83
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_NOINSERT
Definition: content_tree.h:38
@ DVT_NOUPDATE
Definition: content_tree.h:39
@ 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
@ DVT_NODELETE
Definition: content_tree.h:40
constexpr std::size_t VOID_COLUMN_INDEX
Definition: content_tree.h:43
void destroy_content_tree(Content_tree_node *root)
Deletes the content tree for given JSON duality view.
Definition: content_tree.cc:389
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:3995
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:83