Drizzled Public API Documentation

que0que.h
Go to the documentation of this file.
00001 /*****************************************************************************
00002 
00003 Copyright (C) 1996, 2010, Innobase Oy. All Rights Reserved.
00004 
00005 This program is free software; you can redistribute it and/or modify it under
00006 the terms of the GNU General Public License as published by the Free Software
00007 Foundation; version 2 of the License.
00008 
00009 This program is distributed in the hope that it will be useful, but WITHOUT
00010 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00011 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
00012 
00013 You should have received a copy of the GNU General Public License along with
00014 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
00015 St, Fifth Floor, Boston, MA 02110-1301 USA
00016 
00017 *****************************************************************************/
00018 
00019 /**************************************************/
00026 #pragma once
00027 #ifndef que0que_h
00028 #define que0que_h
00029 
00030 #include "univ.i"
00031 #include "data0data.h"
00032 #include "dict0types.h"
00033 #include "trx0trx.h"
00034 #include "trx0roll.h"
00035 #include "srv0srv.h"
00036 #include "usr0types.h"
00037 #include "que0types.h"
00038 #include "row0types.h"
00039 #include "pars0types.h"
00040 
00041 /* If the following flag is set TRUE, the module will print trace info
00042 of SQL execution in the UNIV_SQL_DEBUG version */
00043 extern ibool  que_trace_on;
00044 
00045 /***********************************************************************/
00047 UNIV_INTERN
00048 void
00049 que_graph_publish(
00050 /*==============*/
00051   que_t*  graph,  
00052   sess_t* sess);  
00053 /***********************************************************************/
00056 UNIV_INTERN
00057 que_fork_t*
00058 que_fork_create(
00059 /*============*/
00060   que_t*    graph,    
00063   que_node_t* parent,   
00064   ulint   fork_type,  
00065   mem_heap_t* heap);    
00066 /***********************************************************************/
00068 UNIV_INLINE
00069 que_thr_t*
00070 que_fork_get_first_thr(
00071 /*===================*/
00072   que_fork_t* fork);  
00073 /***********************************************************************/
00075 UNIV_INLINE
00076 que_node_t*
00077 que_fork_get_child(
00078 /*===============*/
00079   que_fork_t* fork);  
00080 /***********************************************************************/
00082 UNIV_INLINE
00083 void
00084 que_node_set_parent(
00085 /*================*/
00086   que_node_t* node, 
00087   que_node_t* parent);
00088 /***********************************************************************/
00091 UNIV_INTERN
00092 que_thr_t*
00093 que_thr_create(
00094 /*===========*/
00095   que_fork_t* parent, 
00096   mem_heap_t* heap);  
00097 /**********************************************************************/
00100 UNIV_INTERN
00101 void
00102 que_graph_free_recursive(
00103 /*=====================*/
00104   que_node_t* node);  
00105 /**********************************************************************/
00107 UNIV_INTERN
00108 void
00109 que_graph_free(
00110 /*===========*/
00111   que_t*  graph); 
00116 /**********************************************************************/
00121 UNIV_INTERN
00122 ibool
00123 que_thr_stop(
00124 /*=========*/
00125   que_thr_t*  thr); 
00126 /**********************************************************************/
00129 UNIV_INTERN
00130 void
00131 que_thr_move_to_run_state_for_mysql(
00132 /*================================*/
00133   que_thr_t*  thr,  
00134   trx_t*    trx); 
00135 /**********************************************************************/
00138 UNIV_INTERN
00139 void
00140 que_thr_stop_for_mysql_no_error(
00141 /*============================*/
00142   que_thr_t*  thr,  
00143   trx_t*    trx); 
00144 /**********************************************************************/
00149 UNIV_INTERN
00150 void
00151 que_thr_stop_for_mysql(
00152 /*===================*/
00153   que_thr_t*  thr); 
00154 /**********************************************************************/
00156 UNIV_INTERN
00157 void
00158 que_run_threads(
00159 /*============*/
00160   que_thr_t*  thr); 
00161 /**********************************************************************/
00165 UNIV_INTERN
00166 void
00167 que_fork_error_handle(
00168 /*==================*/
00169   trx_t*  trx,  
00170   que_t*  fork);  
00172 /**********************************************************************/
00177 UNIV_INTERN
00178 void
00179 que_thr_end_wait(
00180 /*=============*/
00181   que_thr_t*  thr,    
00185   que_thr_t** next_thr);  
00190 /**********************************************************************/
00192 UNIV_INTERN
00193 void
00194 que_thr_end_wait_no_next_thr(
00195 /*=========================*/
00196   que_thr_t*  thr);   
00200 /**********************************************************************/
00208 UNIV_INTERN
00209 que_thr_t*
00210 que_fork_start_command(
00211 /*===================*/
00212   que_fork_t* fork);  
00213 /***********************************************************************/
00215 UNIV_INLINE
00216 trx_t*
00217 thr_get_trx(
00218 /*========*/
00219   que_thr_t*  thr); 
00220 /*******************************************************************/
00225 UNIV_INLINE
00226 ibool
00227 thr_is_recv(
00228 /*========*/
00229   const que_thr_t*  thr); 
00230 /***********************************************************************/
00232 UNIV_INLINE
00233 ulint
00234 que_node_get_type(
00235 /*==============*/
00236   que_node_t* node);  
00237 /***********************************************************************/
00239 UNIV_INLINE
00240 dtype_t*
00241 que_node_get_data_type(
00242 /*===================*/
00243   que_node_t* node);  
00244 /***********************************************************************/
00246 UNIV_INLINE
00247 dfield_t*
00248 que_node_get_val(
00249 /*=============*/
00250   que_node_t* node);  
00251 /***********************************************************************/
00254 UNIV_INLINE
00255 ulint
00256 que_node_get_val_buf_size(
00257 /*======================*/
00258   que_node_t* node);  
00259 /***********************************************************************/
00261 UNIV_INLINE
00262 void
00263 que_node_set_val_buf_size(
00264 /*======================*/
00265   que_node_t* node, 
00266   ulint   size);  
00267 /*********************************************************************/
00269 UNIV_INLINE
00270 que_node_t*
00271 que_node_get_next(
00272 /*==============*/
00273   que_node_t* node);  
00274 /*********************************************************************/
00277 UNIV_INLINE
00278 que_node_t*
00279 que_node_get_parent(
00280 /*================*/
00281   que_node_t* node);  
00282 /****************************************************************/
00286 UNIV_INTERN
00287 que_node_t*
00288 que_node_get_containing_loop_node(
00289 /*==============================*/
00290   que_node_t* node);  
00291 /*********************************************************************/
00294 UNIV_INLINE
00295 que_node_t*
00296 que_node_list_add_last(
00297 /*===================*/
00298   que_node_t* node_list,  
00299   que_node_t* node);    
00300 /*********************************************************************/
00303 UNIV_INLINE
00304 ulint
00305 que_node_list_get_len(
00306 /*==================*/
00307   que_node_t* node_list); 
00308 /**********************************************************************/
00314 UNIV_INLINE
00315 ibool
00316 que_thr_peek_stop(
00317 /*==============*/
00318   que_thr_t*  thr); 
00319 /***********************************************************************/
00322 UNIV_INLINE
00323 ibool
00324 que_graph_is_select(
00325 /*================*/
00326   que_t*    graph);   
00327 /**********************************************************************/
00329 UNIV_INTERN
00330 void
00331 que_node_print_info(
00332 /*================*/
00333   que_node_t* node);  
00334 /*********************************************************************/
00337 UNIV_INTERN
00338 ulint
00339 que_eval_sql(
00340 /*=========*/
00341   pars_info_t*  info, 
00342   const char* sql,  
00343   ibool   reserve_dict_mutex,
00346   trx_t*    trx); 
00348 /* Query graph query thread node: the fields are protected by the kernel
00349 mutex with the exceptions named below */
00350 
00351 struct que_thr_struct{
00352   que_common_t  common;   
00353   ulint   magic_n;  
00355   que_node_t* child;    
00356   que_t*    graph;    
00357   ibool   is_active;  
00362   ulint   state;    
00363   UT_LIST_NODE_T(que_thr_t)
00364       thrs;   
00366   UT_LIST_NODE_T(que_thr_t)
00367       trx_thrs; 
00369   UT_LIST_NODE_T(que_thr_t)
00370       queue;    
00372   /*------------------------------*/
00373   /* The following fields are private to the OS thread executing the
00374   query thread, and are not protected by the kernel mutex: */
00375 
00376   que_node_t* run_node; 
00379   que_node_t* prev_node;  
00381   ulint   resource; 
00383   ulint   lock_state; 
00385   ulint   fk_cascade_depth; 
00388 };
00389 
00390 #define QUE_THR_MAGIC_N   8476583
00391 #define QUE_THR_MAGIC_FREED 123461526
00392 
00393 /* Query graph fork node: its fields are protected by the kernel mutex */
00394 struct que_fork_struct{
00395   que_common_t  common;   
00396   que_t*    graph;    
00397   ulint   fork_type;  
00398   ulint   n_active_thrs;  
00403   trx_t*    trx;    
00405   ulint   state;    
00406   que_thr_t*  caller;   
00408   UT_LIST_BASE_NODE_T(que_thr_t)
00409       thrs;   
00410   /*------------------------------*/
00411   /* The fields in this section are defined only in the root node */
00412   sym_tab_t*  sym_tab;  
00415   pars_info_t*  info;   
00416   /* The following cur_... fields are relevant only in a select graph */
00417 
00418   ulint   cur_end;  
00420   ulint   cur_pos;  
00425   ibool   cur_on_row; 
00428   sel_node_t* last_sel_node;  
00430   UT_LIST_NODE_T(que_fork_t)
00431       graphs;   
00433   /*------------------------------*/
00434   mem_heap_t* heap;   
00437 };
00438 
00439 /* Query fork (or graph) types */
00440 #define QUE_FORK_SELECT_NON_SCROLL  1 /* forward-only cursor */
00441 #define QUE_FORK_SELECT_SCROLL    2 /* scrollable cursor */
00442 #define QUE_FORK_INSERT     3
00443 #define QUE_FORK_UPDATE     4
00444 #define QUE_FORK_ROLLBACK   5
00445       /* This is really the undo graph used in rollback,
00446       no signal-sending roll_node in this graph */
00447 #define QUE_FORK_PURGE      6
00448 #define QUE_FORK_EXECUTE    7
00449 #define QUE_FORK_PROCEDURE    8
00450 #define QUE_FORK_PROCEDURE_CALL   9
00451 #define QUE_FORK_MYSQL_INTERFACE  10
00452 #define QUE_FORK_RECOVERY   11
00453 
00454 /* Query fork (or graph) states */
00455 #define QUE_FORK_ACTIVE   1
00456 #define QUE_FORK_COMMAND_WAIT 2
00457 #define QUE_FORK_INVALID  3
00458 #define QUE_FORK_BEING_FREED  4
00459 
00460 /* Flag which is ORed to control structure statement node types */
00461 #define QUE_NODE_CONTROL_STAT 1024
00462 
00463 /* Query graph node types */
00464 #define QUE_NODE_LOCK   1
00465 #define QUE_NODE_INSERT   2
00466 #define QUE_NODE_UPDATE   4
00467 #define QUE_NODE_CURSOR   5
00468 #define QUE_NODE_SELECT   6
00469 #define QUE_NODE_AGGREGATE  7
00470 #define QUE_NODE_FORK   8
00471 #define QUE_NODE_THR    9
00472 #define QUE_NODE_UNDO   10
00473 #define QUE_NODE_COMMIT   11
00474 #define QUE_NODE_ROLLBACK 12
00475 #define QUE_NODE_PURGE    13
00476 #define QUE_NODE_CREATE_TABLE 14
00477 #define QUE_NODE_CREATE_INDEX 15
00478 #define QUE_NODE_SYMBOL   16
00479 #define QUE_NODE_RES_WORD 17
00480 #define QUE_NODE_FUNC   18
00481 #define QUE_NODE_ORDER    19
00482 #define QUE_NODE_PROC   (20 + QUE_NODE_CONTROL_STAT)
00483 #define QUE_NODE_IF   (21 + QUE_NODE_CONTROL_STAT)
00484 #define QUE_NODE_WHILE    (22 + QUE_NODE_CONTROL_STAT)
00485 #define QUE_NODE_ASSIGNMENT 23
00486 #define QUE_NODE_FETCH    24
00487 #define QUE_NODE_OPEN   25
00488 #define QUE_NODE_COL_ASSIGNMENT 26
00489 #define QUE_NODE_FOR    (27 + QUE_NODE_CONTROL_STAT)
00490 #define QUE_NODE_RETURN   28
00491 #define QUE_NODE_ROW_PRINTF 29
00492 #define QUE_NODE_ELSIF    30
00493 #define QUE_NODE_CALL   31
00494 #define QUE_NODE_EXIT   32
00495 
00496 /* Query thread states */
00497 #define QUE_THR_RUNNING   1
00498 #define QUE_THR_PROCEDURE_WAIT  2
00499 #define QUE_THR_COMPLETED 3 /* in selects this means that the
00500           thread is at the end of its result set
00501           (or start, in case of a scroll cursor);
00502           in other statements, this means the
00503           thread has done its task */
00504 #define QUE_THR_COMMAND_WAIT  4
00505 #define QUE_THR_LOCK_WAIT 5
00506 #define QUE_THR_SIG_REPLY_WAIT  6
00507 #define QUE_THR_SUSPENDED 7
00508 #define QUE_THR_ERROR   8
00509 
00510 /* Query thread lock states */
00511 #define QUE_THR_LOCK_NOLOCK 0
00512 #define QUE_THR_LOCK_ROW  1
00513 #define QUE_THR_LOCK_TABLE  2
00514 
00515 /* From where the cursor position is counted */
00516 #define QUE_CUR_NOT_DEFINED 1
00517 #define QUE_CUR_START   2
00518 #define QUE_CUR_END   3
00519 
00520 
00521 #ifndef UNIV_NONINL
00522 #include "que0que.ic"
00523 #endif
00524 
00525 #endif