InnoDB Plugin  1.0
que0que.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 1996, 2012, Oracle and/or its affiliates. All Rights Reserved.
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 as published by the Free Software
7 Foundation; version 2 of the License.
8 
9 This program is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12 
13 You should have received a copy of the GNU General Public License along with
14 this program; if not, write to the Free Software Foundation, Inc.,
15 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
16 
17 *****************************************************************************/
18 
19 /**************************************************/
26 #ifndef que0que_h
27 #define que0que_h
28 
29 #include "univ.i"
30 #include "data0data.h"
31 #include "dict0types.h"
32 #include "trx0trx.h"
33 #include "trx0roll.h"
34 #include "srv0srv.h"
35 #include "usr0types.h"
36 #include "que0types.h"
37 #include "row0types.h"
38 #include "pars0types.h"
39 
40 /* If the following flag is set TRUE, the module will print trace info
41 of SQL execution in the UNIV_SQL_DEBUG version */
42 extern ibool que_trace_on;
43 
46 
47 /***********************************************************************/
50 UNIV_INTERN
53 /*============*/
54  que_t* graph,
57  que_node_t* parent,
58  ulint fork_type,
59  mem_heap_t* heap);
60 /***********************************************************************/
62 UNIV_INLINE
63 que_thr_t*
65 /*===================*/
66  que_fork_t* fork);
67 /***********************************************************************/
69 UNIV_INLINE
70 que_node_t*
72 /*===============*/
73  que_fork_t* fork);
74 /***********************************************************************/
76 UNIV_INLINE
77 void
79 /*================*/
80  que_node_t* node,
81  que_node_t* parent);
82 /***********************************************************************/
85 UNIV_INTERN
86 que_thr_t*
88 /*===========*/
89  que_fork_t* parent,
90  mem_heap_t* heap);
91 /**********************************************************************/
94 UNIV_INTERN
95 void
97 /*=====================*/
98  que_node_t* node);
99 /**********************************************************************/
101 UNIV_INTERN
102 void
104 /*===========*/
105  que_t* graph);
110 /**********************************************************************/
115 UNIV_INTERN
116 ibool
118 /*=========*/
119  que_thr_t* thr);
120 /**********************************************************************/
123 UNIV_INTERN
124 void
126 /*================================*/
127  que_thr_t* thr,
128  trx_t* trx);
129 /**********************************************************************/
132 UNIV_INTERN
133 void
135 /*============================*/
136  que_thr_t* thr,
137  trx_t* trx);
138 /**********************************************************************/
143 UNIV_INTERN
144 void
146 /*===================*/
147  que_thr_t* thr);
148 /**********************************************************************/
150 UNIV_INTERN
151 void
153 /*============*/
154  que_thr_t* thr);
155 /**********************************************************************/
161 UNIV_INTERN
162 que_thr_t*
164 /*==================*/
165  trx_t* trx);
167 /**********************************************************************/
175 UNIV_INTERN
176 que_thr_t*
178 /*===================*/
179  que_fork_t* fork);
180 /***********************************************************************/
182 UNIV_INLINE
183 trx_t*
185 /*========*/
186  que_thr_t* thr);
187 /*******************************************************************/
192 UNIV_INLINE
193 ibool
195 /*========*/
196  const que_thr_t* thr);
197 /***********************************************************************/
199 UNIV_INLINE
200 ulint
202 /*==============*/
203  que_node_t* node);
204 /***********************************************************************/
206 UNIV_INLINE
207 dtype_t*
209 /*===================*/
210  que_node_t* node);
211 /***********************************************************************/
213 UNIV_INLINE
214 dfield_t*
216 /*=============*/
217  que_node_t* node);
218 /***********************************************************************/
221 UNIV_INLINE
222 ulint
224 /*======================*/
225  que_node_t* node);
226 /***********************************************************************/
228 UNIV_INLINE
229 void
231 /*======================*/
232  que_node_t* node,
233  ulint size);
234 /*********************************************************************/
236 UNIV_INLINE
237 que_node_t*
239 /*==============*/
240  que_node_t* node);
241 /*********************************************************************/
244 UNIV_INLINE
245 que_node_t*
247 /*================*/
248  que_node_t* node);
249 /****************************************************************/
253 UNIV_INTERN
254 que_node_t*
256 /*==============================*/
257  que_node_t* node);
258 /*********************************************************************/
261 UNIV_INLINE
262 que_node_t*
264 /*===================*/
265  que_node_t* node_list,
266  que_node_t* node);
267 /*************************************************************************
268 Get the last node from the list.*/
269 UNIV_INLINE
270 que_node_t*
271 que_node_list_get_last(
272 /*===================*/
273  /* out: node last node from list.*/
274  que_node_t* node_list); /* in: node list, or NULL */
275 /*********************************************************************/
278 UNIV_INLINE
279 ulint
281 /*==================*/
282  que_node_t* node_list);
283 /**********************************************************************/
289 UNIV_INLINE
290 ibool
292 /*==============*/
293  que_thr_t* thr);
294 /***********************************************************************/
297 UNIV_INLINE
298 ibool
300 /*================*/
301  que_t* graph);
302 /**********************************************************************/
304 UNIV_INTERN
305 void
307 /*================*/
308  que_node_t* node);
309 /*********************************************************************/
312 UNIV_INTERN
313 dberr_t
315 /*=========*/
316  pars_info_t* info,
317  const char* sql,
318  ibool reserve_dict_mutex,
321  trx_t* trx);
323 /**********************************************************************/
328 UNIV_INTERN
329 que_thr_t*
331 /*===========================*/
332  que_fork_t* fork,
333  que_thr_t* thr);
335 /*********************************************************************/
337 UNIV_INTERN
338 void
339 que_init(void);
340 /*==========*/
341 
342 /*********************************************************************/
344 UNIV_INTERN
345 void
346 que_close(void);
347 /*===========*/
348 
349 /* Query graph query thread node: the fields are protected by the
350 trx_t::mutex with the exceptions named below */
351 
352 struct que_thr_t{
354  ulint magic_n;
356  que_node_t* child;
358  ulint state;
364  /*------------------------------*/
365  /* The following fields are private to the OS thread executing the
366  query thread, and are not protected by any mutex: */
367 
368  que_node_t* run_node;
371  que_node_t* prev_node;
373  ulint resource;
375  ulint lock_state;
377  struct srv_slot_t*
378  slot; /* The thread slot in the wait
379  array in srv_sys_t */
380  /*------------------------------*/
381  /* The following fields are links for the various lists that
382  this type can be on. */
383  UT_LIST_NODE_T(que_thr_t)
386  UT_LIST_NODE_T(que_thr_t)
389  UT_LIST_NODE_T(que_thr_t)
395 };
396 
397 #define QUE_THR_MAGIC_N 8476583
398 #define QUE_THR_MAGIC_FREED 123461526
399 
400 /* Query graph fork node: its fields are protected by the query thread mutex */
401 struct que_fork_t{
404  ulint fork_type;
405  ulint n_active_thrs;
410  trx_t* trx;
412  ulint state;
413  que_thr_t* caller;
415  UT_LIST_BASE_NODE_T(que_thr_t)
417  /*------------------------------*/
418  /* The fields in this section are defined only in the root node */
419  sym_tab_t* sym_tab;
422  pars_info_t* info;
423  /* The following cur_... fields are relevant only in a select graph */
424 
425  ulint cur_end;
427  ulint cur_pos;
432  ibool cur_on_row;
435  sel_node_t* last_sel_node;
437  UT_LIST_NODE_T(que_fork_t)
438  graphs;
440  /*------------------------------*/
441  mem_heap_t* heap;
444 };
445 
446 /* Query fork (or graph) types */
447 #define QUE_FORK_SELECT_NON_SCROLL 1 /* forward-only cursor */
448 #define QUE_FORK_SELECT_SCROLL 2 /* scrollable cursor */
449 #define QUE_FORK_INSERT 3
450 #define QUE_FORK_UPDATE 4
451 #define QUE_FORK_ROLLBACK 5
452  /* This is really the undo graph used in rollback,
453  no signal-sending roll_node in this graph */
454 #define QUE_FORK_PURGE 6
455 #define QUE_FORK_EXECUTE 7
456 #define QUE_FORK_PROCEDURE 8
457 #define QUE_FORK_PROCEDURE_CALL 9
458 #define QUE_FORK_MYSQL_INTERFACE 10
459 #define QUE_FORK_RECOVERY 11
460 
461 /* Query fork (or graph) states */
462 #define QUE_FORK_ACTIVE 1
463 #define QUE_FORK_COMMAND_WAIT 2
464 #define QUE_FORK_INVALID 3
465 #define QUE_FORK_BEING_FREED 4
466 
467 /* Flag which is ORed to control structure statement node types */
468 #define QUE_NODE_CONTROL_STAT 1024
469 
470 /* Query graph node types */
471 #define QUE_NODE_LOCK 1
472 #define QUE_NODE_INSERT 2
473 #define QUE_NODE_UPDATE 4
474 #define QUE_NODE_CURSOR 5
475 #define QUE_NODE_SELECT 6
476 #define QUE_NODE_AGGREGATE 7
477 #define QUE_NODE_FORK 8
478 #define QUE_NODE_THR 9
479 #define QUE_NODE_UNDO 10
480 #define QUE_NODE_COMMIT 11
481 #define QUE_NODE_ROLLBACK 12
482 #define QUE_NODE_PURGE 13
483 #define QUE_NODE_CREATE_TABLE 14
484 #define QUE_NODE_CREATE_INDEX 15
485 #define QUE_NODE_SYMBOL 16
486 #define QUE_NODE_RES_WORD 17
487 #define QUE_NODE_FUNC 18
488 #define QUE_NODE_ORDER 19
489 #define QUE_NODE_PROC (20 + QUE_NODE_CONTROL_STAT)
490 #define QUE_NODE_IF (21 + QUE_NODE_CONTROL_STAT)
491 #define QUE_NODE_WHILE (22 + QUE_NODE_CONTROL_STAT)
492 #define QUE_NODE_ASSIGNMENT 23
493 #define QUE_NODE_FETCH 24
494 #define QUE_NODE_OPEN 25
495 #define QUE_NODE_COL_ASSIGNMENT 26
496 #define QUE_NODE_FOR (27 + QUE_NODE_CONTROL_STAT)
497 #define QUE_NODE_RETURN 28
498 #define QUE_NODE_ROW_PRINTF 29
499 #define QUE_NODE_ELSIF 30
500 #define QUE_NODE_CALL 31
501 #define QUE_NODE_EXIT 32
502 
503 /* Query thread states */
504 #define QUE_THR_RUNNING 1
505 #define QUE_THR_PROCEDURE_WAIT 2
506 #define QUE_THR_COMPLETED 3 /* in selects this means that the
507  thread is at the end of its result set
508  (or start, in case of a scroll cursor);
509  in other statements, this means the
510  thread has done its task */
511 #define QUE_THR_COMMAND_WAIT 4
512 #define QUE_THR_LOCK_WAIT 5
513 #define QUE_THR_SUSPENDED 7
514 #define QUE_THR_ERROR 8
515 
516 /* Query thread lock states */
517 #define QUE_THR_LOCK_NOLOCK 0
518 #define QUE_THR_LOCK_ROW 1
519 #define QUE_THR_LOCK_TABLE 2
520 
521 /* From where the cursor position is counted */
522 #define QUE_CUR_NOT_DEFINED 1
523 #define QUE_CUR_START 2
524 #define QUE_CUR_END 3
525 
526 #ifndef UNIV_NONINL
527 #include "que0que.ic"
528 #endif
529 
530 #endif