mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / storage / innobase / include / que0que.ic
bloba20108a782072e3633c6c3ccf05c5e4d4f54fe97
1 /******************************************************
2 Query graph
4 (c) 1996 Innobase Oy
6 Created 5/27/1996 Heikki Tuuri
7 *******************************************************/
9 #include "usr0sess.h"
11 /***************************************************************************
12 Gets the trx of a query thread. */
13 UNIV_INLINE
14 trx_t*
15 thr_get_trx(
16 /*========*/
17         que_thr_t*      thr)    /* in: query thread */
19         ut_ad(thr);
21         return(thr->graph->trx);
24 /***************************************************************************
25 Gets the first thr in a fork. */
26 UNIV_INLINE
27 que_thr_t*
28 que_fork_get_first_thr(
29 /*===================*/
30         que_fork_t*     fork)   /* in: query fork */
32         return(UT_LIST_GET_FIRST(fork->thrs));
35 /***************************************************************************
36 Gets the child node of the first thr in a fork. */
37 UNIV_INLINE
38 que_node_t*
39 que_fork_get_child(
40 /*===============*/
41         que_fork_t*     fork)   /* in: query fork */
43         que_thr_t*      thr;
45         thr = UT_LIST_GET_FIRST(fork->thrs);
47         return(thr->child);
50 /***************************************************************************
51 Gets the type of a graph node. */
52 UNIV_INLINE
53 ulint
54 que_node_get_type(
55 /*==============*/
56         que_node_t*     node)   /* in: graph node */
58         ut_ad(node);
60         return(((que_common_t*)node)->type);
63 /***************************************************************************
64 Gets pointer to the value dfield of a graph node. */
65 UNIV_INLINE
66 dfield_t*
67 que_node_get_val(
68 /*=============*/
69         que_node_t*     node)   /* in: graph node */
71         ut_ad(node);
73         return(&(((que_common_t*)node)->val));
76 /***************************************************************************
77 Gets the value buffer size of a graph node. */
78 UNIV_INLINE
79 ulint
80 que_node_get_val_buf_size(
81 /*======================*/
82                                 /* out: val buffer size, not defined if
83                                 val.data == NULL in node */
84         que_node_t*     node)   /* in: graph node */
86         ut_ad(node);
88         return(((que_common_t*)node)->val_buf_size);
91 /***************************************************************************
92 Sets the value buffer size of a graph node. */
93 UNIV_INLINE
94 void
95 que_node_set_val_buf_size(
96 /*======================*/
97         que_node_t*     node,   /* in: graph node */
98         ulint           size)   /* in: size */
100         ut_ad(node);
102         ((que_common_t*)node)->val_buf_size = size;
105 /***************************************************************************
106 Sets the parent of a graph node. */
107 UNIV_INLINE
108 void
109 que_node_set_parent(
110 /*================*/
111         que_node_t*     node,   /* in: graph node */
112         que_node_t*     parent) /* in: parent */
114         ut_ad(node);
116         ((que_common_t*)node)->parent = parent;
119 /***************************************************************************
120 Gets pointer to the value data type field of a graph node. */
121 UNIV_INLINE
122 dtype_t*
123 que_node_get_data_type(
124 /*===================*/
125         que_node_t*     node)   /* in: graph node */
127         ut_ad(node);
129         return(&(((que_common_t*)node)->val.type));
132 /*************************************************************************
133 Catenates a query graph node to a list of them, possible empty list. */
134 UNIV_INLINE
135 que_node_t*
136 que_node_list_add_last(
137 /*===================*/
138                                         /* out: one-way list of nodes */
139         que_node_t*     node_list,      /* in: node list, or NULL */
140         que_node_t*     node)           /* in: node */
142         que_common_t*   cnode;
143         que_common_t*   cnode2;
145         cnode = node;
147         cnode->brother = NULL;
149         if (node_list == NULL) {
151                 return(node);
152         }
154         cnode2 = node_list;
156         while (cnode2->brother != NULL) {
157                 cnode2 = cnode2->brother;
158         }
160         cnode2->brother = node;
162         return(node_list);
165 /*************************************************************************
166 Gets the next list node in a list of query graph nodes. */
167 UNIV_INLINE
168 que_node_t*
169 que_node_get_next(
170 /*==============*/
171                                 /* out: next node in a list of nodes */
172         que_node_t*     node)   /* in: node in a list */
174         return(((que_common_t*)node)->brother);
177 /*************************************************************************
178 Gets a query graph node list length. */
179 UNIV_INLINE
180 ulint
181 que_node_list_get_len(
182 /*==================*/
183                                         /* out: length, for NULL list 0 */
184         que_node_t*     node_list)      /* in: node list, or NULL */
186         que_common_t*   cnode;
187         ulint           len;
189         cnode = node_list;
190         len = 0;
192         while (cnode != NULL) {
193                 len++;
194                 cnode = cnode->brother;
195         }
197         return(len);
200 /*************************************************************************
201 Gets the parent node of a query graph node. */
202 UNIV_INLINE
203 que_node_t*
204 que_node_get_parent(
205 /*================*/
206                                 /* out: parent node or NULL */
207         que_node_t*     node)   /* in: node */
209         return(((que_common_t*)node)->parent);
212 /**************************************************************************
213 Checks if graph, trx, or session is in a state where the query thread should
214 be stopped. */
215 UNIV_INLINE
216 ibool
217 que_thr_peek_stop(
218 /*==============*/
219                                 /* out: TRUE if should be stopped; NOTE that
220                                 if the peek is made without reserving the
221                                 kernel mutex, then another peek with the
222                                 mutex reserved is necessary before deciding
223                                 the actual stopping */
224         que_thr_t*      thr)    /* in: query thread */
226         trx_t*  trx;
227         que_t*  graph;
229         graph = thr->graph;
230         trx = graph->trx;
232         if (graph->state != QUE_FORK_ACTIVE
233             || trx->que_state == TRX_QUE_LOCK_WAIT
234             || (UT_LIST_GET_LEN(trx->signals) > 0
235                 && trx->que_state == TRX_QUE_RUNNING)) {
237                 return(TRUE);
238         }
240         return(FALSE);
243 /***************************************************************************
244 Returns TRUE if the query graph is for a SELECT statement. */
245 UNIV_INLINE
246 ibool
247 que_graph_is_select(
248 /*================*/
249                                         /* out: TRUE if a select */
250         que_t*          graph)          /* in: graph */
252         if (graph->fork_type == QUE_FORK_SELECT_SCROLL
253             || graph->fork_type == QUE_FORK_SELECT_NON_SCROLL) {
255                 return(TRUE);
256         }
258         return(FALSE);