~linuxjedi/drizzle/trunk-bug-667053

« back to all changes in this revision

Viewing changes to storage/innobase/include/que0que.ic

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************
 
2
Query graph
 
3
 
 
4
(c) 1996 Innobase Oy
 
5
 
 
6
Created 5/27/1996 Heikki Tuuri
 
7
*******************************************************/
 
8
 
 
9
#include "usr0sess.h"
 
10
 
 
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 */
 
18
{
 
19
        ut_ad(thr);
 
20
 
 
21
        return(thr->graph->trx);
 
22
}
 
23
 
 
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 */
 
31
{
 
32
        return(UT_LIST_GET_FIRST(fork->thrs));
 
33
}
 
34
 
 
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 */
 
42
{
 
43
        que_thr_t*      thr;
 
44
 
 
45
        thr = UT_LIST_GET_FIRST(fork->thrs);
 
46
 
 
47
        return(thr->child);
 
48
}
 
49
 
 
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 */
 
57
{
 
58
        ut_ad(node);
 
59
 
 
60
        return(((que_common_t*)node)->type);
 
61
}
 
62
 
 
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 */
 
70
{
 
71
        ut_ad(node);
 
72
 
 
73
        return(&(((que_common_t*)node)->val));
 
74
}
 
75
 
 
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 */
 
85
{
 
86
        ut_ad(node);
 
87
 
 
88
        return(((que_common_t*)node)->val_buf_size);
 
89
}
 
90
 
 
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 */
 
99
{
 
100
        ut_ad(node);
 
101
 
 
102
        ((que_common_t*)node)->val_buf_size = size;
 
103
}
 
104
 
 
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 */
 
113
{
 
114
        ut_ad(node);
 
115
 
 
116
        ((que_common_t*)node)->parent = parent;
 
117
}
 
118
 
 
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 */
 
126
{
 
127
        ut_ad(node);
 
128
 
 
129
        return(&(((que_common_t*)node)->val.type));
 
130
}
 
131
 
 
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 */
 
141
{
 
142
        que_common_t*   cnode;
 
143
        que_common_t*   cnode2;
 
144
 
 
145
        cnode = node;
 
146
 
 
147
        cnode->brother = NULL;
 
148
 
 
149
        if (node_list == NULL) {
 
150
 
 
151
                return(node);
 
152
        }
 
153
 
 
154
        cnode2 = node_list;
 
155
 
 
156
        while (cnode2->brother != NULL) {
 
157
                cnode2 = cnode2->brother;
 
158
        }
 
159
 
 
160
        cnode2->brother = node;
 
161
 
 
162
        return(node_list);
 
163
}
 
164
 
 
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 */
 
173
{
 
174
        return(((que_common_t*)node)->brother);
 
175
}
 
176
 
 
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 */
 
185
{
 
186
        que_common_t*   cnode;
 
187
        ulint           len;
 
188
 
 
189
        cnode = node_list;
 
190
        len = 0;
 
191
 
 
192
        while (cnode != NULL) {
 
193
                len++;
 
194
                cnode = cnode->brother;
 
195
        }
 
196
 
 
197
        return(len);
 
198
}
 
199
 
 
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 */
 
208
{
 
209
        return(((que_common_t*)node)->parent);
 
210
}
 
211
 
 
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 */
 
225
{
 
226
        trx_t*  trx;
 
227
        que_t*  graph;
 
228
 
 
229
        graph = thr->graph;
 
230
        trx = graph->trx;
 
231
 
 
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)) {
 
236
 
 
237
                return(TRUE);
 
238
        }
 
239
 
 
240
        return(FALSE);
 
241
}
 
242
 
 
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 */
 
251
{
 
252
        if (graph->fork_type == QUE_FORK_SELECT_SCROLL
 
253
            || graph->fork_type == QUE_FORK_SELECT_NON_SCROLL) {
 
254
 
 
255
                return(TRUE);
 
256
        }
 
257
 
 
258
        return(FALSE);
 
259
}