summaryrefslogtreecommitdiff
path: root/storage/xtradb/include/que0que.ic
blob: e9a6b00b9ab3299069a897073ca3e556fbc66308 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/*****************************************************************************

Copyright (c) 1996, 2009, Innobase Oy. All Rights Reserved.

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; version 2 of the License.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA

*****************************************************************************/

/******************************************************
Query graph

Created 5/27/1996 Heikki Tuuri
*******************************************************/

#include "usr0sess.h"

/***************************************************************************
Gets the trx of a query thread. */
UNIV_INLINE
trx_t*
thr_get_trx(
/*========*/
	que_thr_t*	thr)	/* in: query thread */
{
	ut_ad(thr);

	return(thr->graph->trx);
}

/***************************************************************************
Gets the first thr in a fork. */
UNIV_INLINE
que_thr_t*
que_fork_get_first_thr(
/*===================*/
	que_fork_t*	fork)	/* in: query fork */
{
	return(UT_LIST_GET_FIRST(fork->thrs));
}

/***************************************************************************
Gets the child node of the first thr in a fork. */
UNIV_INLINE
que_node_t*
que_fork_get_child(
/*===============*/
	que_fork_t*	fork)	/* in: query fork */
{
	que_thr_t*	thr;

	thr = UT_LIST_GET_FIRST(fork->thrs);

	return(thr->child);
}

/***************************************************************************
Gets the type of a graph node. */
UNIV_INLINE
ulint
que_node_get_type(
/*==============*/
	que_node_t*	node)	/* in: graph node */
{
	ut_ad(node);

	return(((que_common_t*)node)->type);
}

/***************************************************************************
Gets pointer to the value dfield of a graph node. */
UNIV_INLINE
dfield_t*
que_node_get_val(
/*=============*/
	que_node_t*	node)	/* in: graph node */
{
	ut_ad(node);

	return(&(((que_common_t*)node)->val));
}

/***************************************************************************
Gets the value buffer size of a graph node. */
UNIV_INLINE
ulint
que_node_get_val_buf_size(
/*======================*/
				/* out: val buffer size, not defined if
				val.data == NULL in node */
	que_node_t*	node)	/* in: graph node */
{
	ut_ad(node);

	return(((que_common_t*)node)->val_buf_size);
}

/***************************************************************************
Sets the value buffer size of a graph node. */
UNIV_INLINE
void
que_node_set_val_buf_size(
/*======================*/
	que_node_t*	node,	/* in: graph node */
	ulint		size)	/* in: size */
{
	ut_ad(node);

	((que_common_t*)node)->val_buf_size = size;
}

/***************************************************************************
Sets the parent of a graph node. */
UNIV_INLINE
void
que_node_set_parent(
/*================*/
	que_node_t*	node,	/* in: graph node */
	que_node_t*	parent)	/* in: parent */
{
	ut_ad(node);

	((que_common_t*)node)->parent = parent;
}

/***************************************************************************
Gets pointer to the value data type field of a graph node. */
UNIV_INLINE
dtype_t*
que_node_get_data_type(
/*===================*/
	que_node_t*	node)	/* in: graph node */
{
	ut_ad(node);

	return(dfield_get_type(&((que_common_t*) node)->val));
}

/*************************************************************************
Catenates a query graph node to a list of them, possible empty list. */
UNIV_INLINE
que_node_t*
que_node_list_add_last(
/*===================*/
					/* out: one-way list of nodes */
	que_node_t*	node_list,	/* in: node list, or NULL */
	que_node_t*	node)		/* in: node */
{
	que_common_t*	cnode;
	que_common_t*	cnode2;

	cnode = (que_common_t*) node;

	cnode->brother = NULL;

	if (node_list == NULL) {

		return(node);
	}

	cnode2 = (que_common_t*) node_list;

	while (cnode2->brother != NULL) {
		cnode2 = (que_common_t*) cnode2->brother;
	}

	cnode2->brother = node;

	return(node_list);
}

/*************************************************************************
Gets the next list node in a list of query graph nodes. */
UNIV_INLINE
que_node_t*
que_node_get_next(
/*==============*/
				/* out: next node in a list of nodes */
	que_node_t*	node)	/* in: node in a list */
{
	return(((que_common_t*)node)->brother);
}

/*************************************************************************
Gets a query graph node list length. */
UNIV_INLINE
ulint
que_node_list_get_len(
/*==================*/
					/* out: length, for NULL list 0 */
	que_node_t*	node_list)	/* in: node list, or NULL */
{
	const que_common_t*	cnode;
	ulint			len;

	cnode = (const que_common_t*) node_list;
	len = 0;

	while (cnode != NULL) {
		len++;
		cnode = (const que_common_t*) cnode->brother;
	}

	return(len);
}

/*************************************************************************
Gets the parent node of a query graph node. */
UNIV_INLINE
que_node_t*
que_node_get_parent(
/*================*/
				/* out: parent node or NULL */
	que_node_t*	node)	/* in: node */
{
	return(((que_common_t*)node)->parent);
}

/**************************************************************************
Checks if graph, trx, or session is in a state where the query thread should
be stopped. */
UNIV_INLINE
ibool
que_thr_peek_stop(
/*==============*/
				/* out: TRUE if should be stopped; NOTE that
				if the peek is made without reserving the
				kernel mutex, then another peek with the
				mutex reserved is necessary before deciding
				the actual stopping */
	que_thr_t*	thr)	/* in: query thread */
{
	trx_t*	trx;
	que_t*	graph;

	graph = thr->graph;
	trx = graph->trx;

	if (graph->state != QUE_FORK_ACTIVE
	    || trx->que_state == TRX_QUE_LOCK_WAIT
	    || (UT_LIST_GET_LEN(trx->signals) > 0
		&& trx->que_state == TRX_QUE_RUNNING)) {

		return(TRUE);
	}

	return(FALSE);
}

/***************************************************************************
Returns TRUE if the query graph is for a SELECT statement. */
UNIV_INLINE
ibool
que_graph_is_select(
/*================*/
					/* out: TRUE if a select */
	que_t*		graph)		/* in: graph */
{
	if (graph->fork_type == QUE_FORK_SELECT_SCROLL
	    || graph->fork_type == QUE_FORK_SELECT_NON_SCROLL) {

		return(TRUE);
	}

	return(FALSE);
}