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