Debian Codegraph @

storage/innobase/include/que0que.ic

raw
1 /*****************************************************************************
2
3 Copyright (c) 1996, 2026, Oracle and/or its affiliates.
4
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License, version 2.0, as published by the
7 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, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20 for more details.
21
22 You should have received a copy of the GNU General Public License along with
23 this program; if not, write to the Free Software Foundation, Inc.,
24 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26 *****************************************************************************/
27
28 /** @file include/que0que.ic
29 Query graph
30
31 Created 5/27/1996 Heikki Tuuri
32 *******************************************************/
33
34 #include "usr0sess.h"
35
36 /** Gets the trx of a query thread. */
37 static inline trx_t *thr_get_trx(que_thr_t *thr) /*!< in: query thread */
38 {
39 ut_ad(thr);
40
41 return (thr->graph->trx);
42 }
43
44 #ifndef UNIV_HOTBACKUP
45 /** Determines if this thread is rolling back an incomplete transaction
46 in crash recovery.
47 @return true if thr is rolling back an incomplete transaction in crash
48 recovery */
49 static inline bool thr_is_recv(const que_thr_t *thr) /*!< in: query thread */
50 {
51 return (trx_is_recv(thr->graph->trx));
52 }
53 #endif /* !UNIV_HOTBACKUP */
54
55 /** Gets the first thr in a fork. */
56 static inline que_thr_t *que_fork_get_first_thr(
57 que_fork_t *fork) /*!< in: query fork */
58 {
59 return (UT_LIST_GET_FIRST(fork->thrs));
60 }
61
62 /** Gets the child node of the first thr in a fork. */
63 static inline que_node_t *que_fork_get_child(
64 que_fork_t *fork) /*!< in: query fork */
65 {
66 que_thr_t *thr;
67
68 thr = UT_LIST_GET_FIRST(fork->thrs);
69
70 return (thr->child);
71 }
72
73 /** Gets the type of a graph node. */
74 static inline ulint que_node_get_type(
75 const que_node_t *node) /*!< in: graph node */
76 {
77 return (reinterpret_cast<const que_common_t *>(node)->type);
78 }
79
80 /** Gets pointer to the value dfield of a graph node. */
81 static inline dfield_t *que_node_get_val(
82 que_node_t *node) /*!< in: graph node */
83 {
84 ut_ad(node);
85
86 return (&(((que_common_t *)node)->val));
87 }
88
89 /** Gets the value buffer size of a graph node.
90 @return val buffer size, not defined if val.data == NULL in node */
91 static inline ulint que_node_get_val_buf_size(
92 que_node_t *node) /*!< in: graph node */
93 {
94 ut_ad(node);
95
96 return (((que_common_t *)node)->val_buf_size);
97 }
98
99 /** Sets the value buffer size of a graph node. */
100 static inline void que_node_set_val_buf_size(
101 que_node_t *node, /*!< in: graph node */
102 ulint size) /*!< in: size */
103 {
104 ut_ad(node);
105
106 ((que_common_t *)node)->val_buf_size = size;
107 }
108
109 /** Sets the parent of a graph node. */
110 static inline void que_node_set_parent(que_node_t *node, /*!< in: graph node */
111 que_node_t *parent) /*!< in: parent */
112 {
113 ut_ad(node);
114
115 ((que_common_t *)node)->parent = parent;
116 }
117
118 /** Gets pointer to the value data type field of a graph node. */
119 static inline dtype_t *que_node_get_data_type(
120 que_node_t *node) /*!< in: graph node */
121 {
122 ut_ad(node);
123
124 return (dfield_get_type(&((que_common_t *)node)->val));
125 }
126
127 /** Catenates a query graph node to a list of them, possible empty list.
128 @return one-way list of nodes */
129 static inline que_node_t *que_node_list_add_last(
130 que_node_t *node_list, /*!< in: node list, or NULL */
131 que_node_t *node) /*!< in: node */
132 {
133 que_common_t *cnode;
134 que_common_t *cnode2;
135
136 cnode = (que_common_t *)node;
137
138 cnode->brother = nullptr;
139
140 if (node_list == nullptr) {
141 return (node);
142 }
143
144 cnode2 = (que_common_t *)node_list;
145
146 while (cnode2->brother != nullptr) {
147 cnode2 = (que_common_t *)cnode2->brother;
148 }
149
150 cnode2->brother = node;
151
152 return (node_list);
153 }
154
155 /*************************************************************************
156 Removes a query graph node from the list.*/
157 static inline que_node_t *que_node_list_get_last(
158 /* out: last node in list.*/
159 que_node_t *node_list) /* in: node list */
160 {
161 que_common_t *node;
162
163 ut_a(node_list != nullptr);
164
165 node = (que_common_t *)node_list;
166
167 /* We need the last element */
168 while (node->brother != nullptr) {
169 node = (que_common_t *)node->brother;
170 }
171
172 return (node);
173 }
174 /** Gets the next list node in a list of query graph nodes.
175 @return next node in a list of nodes */
176 static inline que_node_t *que_node_get_next(
177 que_node_t *node) /*!< in: node in a list */
178 {
179 return (((que_common_t *)node)->brother);
180 }
181
182 /** Gets a query graph node list length.
183 @return length, for NULL list 0 */
184 static inline ulint que_node_list_get_len(
185 que_node_t *node_list) /*!< in: node list, or NULL */
186 {
187 const que_common_t *cnode;
188 ulint len;
189
190 cnode = (const que_common_t *)node_list;
191 len = 0;
192
193 while (cnode != nullptr) {
194 len++;
195 cnode = (const que_common_t *)cnode->brother;
196 }
197
198 return (len);
199 }
200
201 /** Gets the parent node of a query graph node.
202 @return parent node or NULL */
203 static inline que_node_t *que_node_get_parent(que_node_t *node) /*!< in: node */
204 {
205 return (((que_common_t *)node)->parent);
206 }
207
208 /** Checks if graph, trx, or session is in a state where the query thread should
209 be stopped.
210 @return true if should be stopped; NOTE that if the peek is made
211 without reserving the trx mutex, then another peek with the mutex
212 reserved is necessary before deciding the actual stopping */
213 static inline bool que_thr_peek_stop(que_thr_t *thr) /*!< in: query thread */
214 {
215 trx_t *trx;
216 que_t *graph;
217
218 graph = thr->graph;
219 trx = graph->trx;
220
221 if (graph->state != QUE_FORK_ACTIVE ||
222 trx->lock.que_state == TRX_QUE_LOCK_WAIT ||
223 (trx->lock.que_state != TRX_QUE_ROLLING_BACK &&
224 trx->lock.que_state != TRX_QUE_RUNNING)) {
225 return true;
226 }
227
228 return false;
229 }
230
231 /** Returns true if the query graph is for a SELECT statement.
232 @return true if a select */
233 static inline bool que_graph_is_select(que_t *graph) /*!< in: graph */
234 {
235 if (graph->fork_type == QUE_FORK_SELECT_SCROLL ||
236 graph->fork_type == QUE_FORK_SELECT_NON_SCROLL) {
237 return true;
238 }
239
240 return false;
241 }