41
39
of SQL execution in the UNIV_SQL_DEBUG version */
42
40
extern ibool que_trace_on;
44
/***********************************************************************//**
42
/***************************************************************************
45
43
Adds a query graph to the session's list of graphs. */
50
que_t* graph, /*!< in: graph */
51
sess_t* sess); /*!< in: session */
52
/***********************************************************************//**
53
Creates a query graph fork node.
54
@return own: fork node */
48
que_t* graph, /* in: graph */
49
sess_t* sess); /* in: session */
50
/***************************************************************************
51
Creates a query graph fork node. */
59
que_t* graph, /*!< in: graph, if NULL then this
56
/* out, own: fork node */
57
que_t* graph, /* in: graph, if NULL then this
60
58
fork node is assumed to be the
62
que_node_t* parent, /*!< in: parent node */
63
ulint fork_type, /*!< in: fork type */
64
mem_heap_t* heap); /*!< in: memory heap where created */
65
/***********************************************************************//**
60
que_node_t* parent, /* in: parent node */
61
ulint fork_type, /* in: fork type */
62
mem_heap_t* heap); /* in: memory heap where created */
63
/***************************************************************************
66
64
Gets the first thr in a fork. */
69
67
que_fork_get_first_thr(
70
68
/*===================*/
71
que_fork_t* fork); /*!< in: query fork */
72
/***********************************************************************//**
69
que_fork_t* fork); /* in: query fork */
70
/***************************************************************************
73
71
Gets the child node of the first thr in a fork. */
76
74
que_fork_get_child(
77
75
/*===============*/
78
que_fork_t* fork); /*!< in: query fork */
79
/***********************************************************************//**
76
que_fork_t* fork); /* in: query fork */
77
/***************************************************************************
80
78
Sets the parent of a graph node. */
83
81
que_node_set_parent(
84
82
/*================*/
85
que_node_t* node, /*!< in: graph node */
86
que_node_t* parent);/*!< in: parent */
87
/***********************************************************************//**
88
Creates a query graph thread node.
89
@return own: query thread node */
83
que_node_t* node, /* in: graph node */
84
que_node_t* parent);/* in: parent */
85
/***************************************************************************
86
Creates a query graph thread node. */
94
que_fork_t* parent, /*!< in: parent node, i.e., a fork node */
95
mem_heap_t* heap); /*!< in: memory heap where created */
96
/**********************************************************************//**
91
/* out, own: query thread node */
92
que_fork_t* parent, /* in: parent node, i.e., a fork node */
93
mem_heap_t* heap); /* in: memory heap where created */
94
/**************************************************************************
95
Checks if the query graph is in a state where it should be freed, and
96
frees it in that case. If the session is in a state where it should be
97
closed, also this is done. */
102
/* out: TRUE if freed */
103
que_t* graph); /* in: query graph */
104
/**************************************************************************
97
105
Frees a query graph, but not the heap where it was created. Does not free
98
106
explicit cursor declarations, they are freed in que_graph_free. */
101
109
que_graph_free_recursive(
102
110
/*=====================*/
103
que_node_t* node); /*!< in: query graph node */
104
/**********************************************************************//**
111
que_node_t* node); /* in: query graph node */
112
/**************************************************************************
105
113
Frees a query graph. */
110
que_t* graph); /*!< in: query graph; we assume that the memory
118
que_t* graph); /* in: query graph; we assume that the memory
111
119
heap where this graph was created is private
112
120
to this graph: if not, then use
113
121
que_graph_free_recursive and free the heap
115
/**********************************************************************//**
123
/**************************************************************************
116
124
Stops a query thread if graph or trx is in a state requiring it. The
117
125
conditions are tested in the order (1) graph, (2) trx. The kernel mutex has
119
@return TRUE if stopped */
124
que_thr_t* thr); /*!< in: query thread */
125
/**********************************************************************//**
131
/* out: TRUE if stopped */
132
que_thr_t* thr); /* in: query thread */
133
/**************************************************************************
126
134
Moves a thread from another state to the QUE_THR_RUNNING state. Increments
127
135
the n_active_thrs counters of the query graph and transaction. */
130
138
que_thr_move_to_run_state_for_mysql(
131
139
/*================================*/
132
que_thr_t* thr, /*!< in: an query thread */
133
trx_t* trx); /*!< in: transaction */
134
/**********************************************************************//**
140
que_thr_t* thr, /* in: an query thread */
141
trx_t* trx); /* in: transaction */
142
/**************************************************************************
135
143
A patch for MySQL used to 'stop' a dummy query thread used in MySQL
136
144
select, when there is no error or lock wait. */
139
147
que_thr_stop_for_mysql_no_error(
140
148
/*============================*/
141
que_thr_t* thr, /*!< in: query thread */
142
trx_t* trx); /*!< in: transaction */
143
/**********************************************************************//**
149
que_thr_t* thr, /* in: query thread */
150
trx_t* trx); /* in: transaction */
151
/**************************************************************************
144
152
A patch for MySQL used to 'stop' a dummy query thread used in MySQL. The
145
153
query thread is stopped and made inactive, except in the case where
146
154
it was put to the lock wait state in lock0lock.c, but the lock has already
178
186
que_thr_end_wait(
179
187
/*=============*/
180
que_thr_t* thr, /*!< in: query thread in the
188
que_thr_t* thr, /* in: query thread in the
181
189
QUE_THR_LOCK_WAIT,
182
190
or QUE_THR_PROCEDURE_WAIT, or
183
191
QUE_THR_SIG_REPLY_WAIT state */
184
que_thr_t** next_thr); /*!< in/out: next query thread to run;
192
que_thr_t** next_thr); /* in/out: next query thread to run;
185
193
if the value which is passed in is
186
194
a pointer to a NULL pointer, then the
187
195
calling function can start running
188
196
a new query thread */
189
/**********************************************************************//**
197
/**************************************************************************
190
198
Same as que_thr_end_wait, but no parameter next_thr available. */
193
201
que_thr_end_wait_no_next_thr(
194
202
/*=========================*/
195
que_thr_t* thr); /*!< in: query thread in the
203
que_thr_t* thr); /* in: query thread in the
196
204
QUE_THR_LOCK_WAIT,
197
205
or QUE_THR_PROCEDURE_WAIT, or
198
206
QUE_THR_SIG_REPLY_WAIT state */
199
/**********************************************************************//**
207
/**************************************************************************
200
208
Starts execution of a command in a query fork. Picks a query thread which
201
209
is not in the QUE_THR_RUNNING state and moves it to that state. If none
202
210
can be chosen, a situation which may arise in parallelized fetches, NULL
204
@return a query thread of the graph moved to QUE_THR_RUNNING state, or
205
NULL; the query thread should be executed by que_run_threads by the
209
214
que_fork_start_command(
210
215
/*===================*/
211
que_fork_t* fork); /*!< in: a query fork */
212
/***********************************************************************//**
216
/* out: a query thread of the graph moved to
217
QUE_THR_RUNNING state, or NULL; the query
218
thread should be executed by que_run_threads
220
que_fork_t* fork); /* in: a query fork */
221
/***************************************************************************
213
222
Gets the trx of a query thread. */
218
que_thr_t* thr); /*!< in: query thread */
219
/*******************************************************************//**
220
Determines if this thread is rolling back an incomplete transaction
222
@return TRUE if thr is rolling back an incomplete transaction in crash
228
const que_thr_t* thr); /*!< in: query thread */
229
/***********************************************************************//**
227
que_thr_t* thr); /* in: query thread */
228
/***************************************************************************
230
229
Gets the type of a graph node. */
233
232
que_node_get_type(
234
233
/*==============*/
235
que_node_t* node); /*!< in: graph node */
236
/***********************************************************************//**
234
que_node_t* node); /* in: graph node */
235
/***************************************************************************
237
236
Gets pointer to the value data type field of a graph node. */
240
239
que_node_get_data_type(
241
240
/*===================*/
242
que_node_t* node); /*!< in: graph node */
243
/***********************************************************************//**
241
que_node_t* node); /* in: graph node */
242
/***************************************************************************
244
243
Gets pointer to the value dfield of a graph node. */
247
246
que_node_get_val(
248
247
/*=============*/
249
que_node_t* node); /*!< in: graph node */
250
/***********************************************************************//**
251
Gets the value buffer size of a graph node.
252
@return val buffer size, not defined if val.data == NULL in node */
248
que_node_t* node); /* in: graph node */
249
/***************************************************************************
250
Gets the value buffer size of a graph node. */
255
253
que_node_get_val_buf_size(
256
254
/*======================*/
257
que_node_t* node); /*!< in: graph node */
258
/***********************************************************************//**
255
/* out: val buffer size, not defined if
256
val.data == NULL in node */
257
que_node_t* node); /* in: graph node */
258
/***************************************************************************
259
259
Sets the value buffer size of a graph node. */
262
262
que_node_set_val_buf_size(
263
263
/*======================*/
264
que_node_t* node, /*!< in: graph node */
265
ulint size); /*!< in: size */
266
/*********************************************************************//**
264
que_node_t* node, /* in: graph node */
265
ulint size); /* in: size */
266
/*************************************************************************
267
267
Gets the next list node in a list of query graph nodes. */
270
270
que_node_get_next(
271
271
/*==============*/
272
que_node_t* node); /*!< in: node in a list */
273
/*********************************************************************//**
274
Gets the parent node of a query graph node.
275
@return parent node or NULL */
272
que_node_t* node); /* in: node in a list */
273
/*************************************************************************
274
Gets the parent node of a query graph node. */
278
277
que_node_get_parent(
279
278
/*================*/
280
que_node_t* node); /*!< in: node */
281
/****************************************************************//**
279
/* out: parent node or NULL */
280
que_node_t* node); /* in: node */
281
/********************************************************************
282
282
Get the first containing loop node (e.g. while_node_t or for_node_t) for the
283
given node, or NULL if the node is not within a loop.
284
@return containing loop node, or NULL. */
283
given node, or NULL if the node is not within a loop. */
287
286
que_node_get_containing_loop_node(
288
287
/*==============================*/
289
que_node_t* node); /*!< in: node */
290
/*********************************************************************//**
291
Catenates a query graph node to a list of them, possible empty list.
292
@return one-way list of nodes */
288
/* out: containing loop node, or NULL. */
289
que_node_t* node); /* in: node */
290
/*************************************************************************
291
Catenates a query graph node to a list of them, possible empty list. */
295
294
que_node_list_add_last(
296
295
/*===================*/
297
que_node_t* node_list, /*!< in: node list, or NULL */
298
que_node_t* node); /*!< in: node */
299
/*********************************************************************//**
300
Gets a query graph node list length.
301
@return length, for NULL list 0 */
296
/* out: one-way list of nodes */
297
que_node_t* node_list, /* in: node list, or NULL */
298
que_node_t* node); /* in: node */
299
/*************************************************************************
300
Gets a query graph node list length. */
304
303
que_node_list_get_len(
305
304
/*==================*/
306
que_node_t* node_list); /*!< in: node list, or NULL */
307
/**********************************************************************//**
305
/* out: length, for NULL list 0 */
306
que_node_t* node_list); /* in: node list, or NULL */
307
/**************************************************************************
308
308
Checks if graph, trx, or session is in a state where the query thread should
310
@return TRUE if should be stopped; NOTE that if the peek is made
311
without reserving the kernel mutex, then another peek with the mutex
312
reserved is necessary before deciding the actual stopping */
315
312
que_thr_peek_stop(
316
313
/*==============*/
317
que_thr_t* thr); /*!< in: query thread */
318
/***********************************************************************//**
319
Returns TRUE if the query graph is for a SELECT statement.
320
@return TRUE if a select */
314
/* out: TRUE if should be stopped; NOTE that
315
if the peek is made without reserving the
316
kernel mutex, then another peek with the
317
mutex reserved is necessary before deciding
318
the actual stopping */
319
que_thr_t* thr); /* in: query thread */
320
/***************************************************************************
321
Returns TRUE if the query graph is for a SELECT statement. */
323
324
que_graph_is_select(
324
325
/*================*/
325
que_t* graph); /*!< in: graph */
326
/**********************************************************************//**
326
/* out: TRUE if a select */
327
que_t* graph); /* in: graph */
328
/**************************************************************************
327
329
Prints info of an SQL query graph node. */
330
332
que_node_print_info(
331
333
/*================*/
332
que_node_t* node); /*!< in: query graph node */
333
/*********************************************************************//**
334
Evaluate the given SQL
335
@return error code or DB_SUCCESS */
334
que_node_t* node); /* in: query graph node */
335
/*************************************************************************
336
Evaluate the given SQL */
340
pars_info_t* info, /*!< in: info struct, or NULL */
341
const char* sql, /*!< in: SQL string */
341
/* out: error code or DB_SUCCESS */
342
pars_info_t* info, /* in: info struct, or NULL */
343
const char* sql, /* in: SQL string */
342
344
ibool reserve_dict_mutex,
343
/*!< in: if TRUE, acquire/release
345
/* in: if TRUE, acquire/release
344
346
dict_sys->mutex around call to pars_sql. */
345
trx_t* trx); /*!< in: trx */
347
trx_t* trx); /* in: trx */
347
349
/* Query graph query thread node: the fields are protected by the kernel
348
350
mutex with the exceptions named below */
350
352
struct que_thr_struct{
351
que_common_t common; /*!< type: QUE_NODE_THR */
352
ulint magic_n; /*!< magic number to catch memory
353
que_common_t common; /* type: QUE_NODE_THR */
354
ulint magic_n; /* magic number to catch memory
354
que_node_t* child; /*!< graph child node */
355
que_t* graph; /*!< graph where this node belongs */
356
ibool is_active; /*!< TRUE if the thread has been set
356
que_node_t* child; /* graph child node */
357
que_t* graph; /* graph where this node belongs */
358
ibool is_active; /* TRUE if the thread has been set
357
359
to the run state in
358
360
que_thr_move_to_run_state, but not
360
362
que_thr_dec_reference_count */
361
ulint state; /*!< state of the query thread */
363
ulint state; /* state of the query thread */
362
364
UT_LIST_NODE_T(que_thr_t)
363
thrs; /*!< list of thread nodes of the fork
365
thrs; /* list of thread nodes of the fork
365
367
UT_LIST_NODE_T(que_thr_t)
366
trx_thrs; /*!< lists of threads in wait list of
368
trx_thrs; /* lists of threads in wait list of
368
370
UT_LIST_NODE_T(que_thr_t)
369
queue; /*!< list of runnable thread nodes in
371
queue; /* list of runnable thread nodes in
370
372
the server task queue */
371
373
/*------------------------------*/
372
374
/* The following fields are private to the OS thread executing the
373
375
query thread, and are not protected by the kernel mutex: */
375
que_node_t* run_node; /*!< pointer to the node where the
377
que_node_t* run_node; /* pointer to the node where the
376
378
subgraph down from this node is
377
379
currently executed */
378
que_node_t* prev_node; /*!< pointer to the node from which
380
que_node_t* prev_node; /* pointer to the node from which
379
381
the control came */
380
ulint resource; /*!< resource usage of the query thread
382
ulint resource; /* resource usage of the query thread
382
ulint lock_state; /*!< lock state of thread (table or
384
ulint lock_state; /* lock state of thread (table or
384
ulint fk_cascade_depth; /*!< maximum cascading call depth
385
supported for foreign key constraint
386
related delete/updates */
389
388
#define QUE_THR_MAGIC_N 8476583
392
391
/* Query graph fork node: its fields are protected by the kernel mutex */
393
392
struct que_fork_struct{
394
que_common_t common; /*!< type: QUE_NODE_FORK */
395
que_t* graph; /*!< query graph of this node */
396
ulint fork_type; /*!< fork type */
397
ulint n_active_thrs; /*!< if this is the root of a graph, the
393
que_common_t common; /* type: QUE_NODE_FORK */
394
que_t* graph; /* query graph of this node */
395
ulint fork_type; /* fork type */
396
ulint n_active_thrs; /* if this is the root of a graph, the
398
397
number query threads that have been
399
398
started in que_thr_move_to_run_state
400
399
but for which que_thr_dec_refer_count
401
400
has not yet been called */
402
trx_t* trx; /*!< transaction: this is set only in
401
trx_t* trx; /* transaction: this is set only in
404
ulint state; /*!< state of the fork node */
405
que_thr_t* caller; /*!< pointer to a possible calling query
403
ulint state; /* state of the fork node */
404
que_thr_t* caller; /* pointer to a possible calling query
407
406
UT_LIST_BASE_NODE_T(que_thr_t)
408
thrs; /*!< list of query threads */
407
thrs; /* list of query threads */
409
408
/*------------------------------*/
410
409
/* The fields in this section are defined only in the root node */
411
sym_tab_t* sym_tab; /*!< symbol table of the query,
410
sym_tab_t* sym_tab; /* symbol table of the query,
412
411
generated by the parser, or NULL
413
412
if the graph was created 'by hand' */
414
pars_info_t* info; /*!< info struct, or NULL */
413
pars_info_t* info; /* in: info struct, or NULL */
415
414
/* The following cur_... fields are relevant only in a select graph */
417
ulint cur_end; /*!< QUE_CUR_NOT_DEFINED, QUE_CUR_START,
416
ulint cur_end; /* QUE_CUR_NOT_DEFINED, QUE_CUR_START,
419
ulint cur_pos; /*!< if there are n rows in the result
418
ulint cur_pos; /* if there are n rows in the result
420
419
set, values 0 and n + 1 mean before
421
420
first row, or after last row, depending
422
421
on cur_end; values 1...n mean a row
424
ibool cur_on_row; /*!< TRUE if cursor is on a row, i.e.,
423
ibool cur_on_row; /* TRUE if cursor is on a row, i.e.,
425
424
it is not before the first row or
426
425
after the last row */
427
sel_node_t* last_sel_node; /*!< last executed select node, or NULL
426
dulint n_inserts; /* number of rows inserted */
427
dulint n_updates; /* number of rows updated */
428
dulint n_deletes; /* number of rows deleted */
429
sel_node_t* last_sel_node; /* last executed select node, or NULL
429
431
UT_LIST_NODE_T(que_fork_t)
430
graphs; /*!< list of query graphs of a session
432
graphs; /* list of query graphs of a session
431
433
or a stored procedure */
432
434
/*------------------------------*/
433
mem_heap_t* heap; /*!< memory heap where the fork was
435
mem_heap_t* heap; /* memory heap where the fork was