46#define QUE_PARALLELIZE_LIMIT (64 * 256 * 256 * 256)
47#define QUE_ROUND_ROBIN_LIMIT (64 * 256 * 256 * 256)
51UNIV_INTERN ibool que_trace_on = FALSE;
131que_thr_move_to_run_state(
144 ut_ad(mutex_own(&kernel_mutex));
167 fork =
static_cast<que_fork_t *
>(
mem_heap_alloc(heap,
sizeof(que_fork_t)));
172 fork->
state = QUE_FORK_COMMAND_WAIT;
207 ut_ad(parent && heap);
209 thr =
static_cast<que_thr_t *
>(
mem_heap_alloc(heap,
sizeof(que_thr_t)));
211 thr->common.type = QUE_NODE_THR;
212 thr->common.parent = parent;
214 thr->magic_n = QUE_THR_MAGIC_N;
218 thr->
state = QUE_THR_COMMAND_WAIT;
220 thr->is_active = FALSE;
222 thr->run_node = NULL;
224 thr->lock_state = QUE_THR_LOCK_NOLOCK;
244 que_thr_t** next_thr)
253 ut_ad(mutex_own(&kernel_mutex));
255 ut_ad((thr->state == QUE_THR_LOCK_WAIT)
256 || (thr->state == QUE_THR_PROCEDURE_WAIT)
257 || (thr->state == QUE_THR_SIG_REPLY_WAIT));
258 ut_ad(thr->run_node);
260 thr->prev_node = thr->run_node;
262 was_active = thr->is_active;
264 que_thr_move_to_run_state(thr);
271 if (next_thr && *next_thr == NULL) {
291 ut_a(thr->state == QUE_THR_LOCK_WAIT);
293 ut_ad(mutex_own(&kernel_mutex));
295 ut_ad((thr->state == QUE_THR_LOCK_WAIT)
296 || (thr->state == QUE_THR_PROCEDURE_WAIT)
297 || (thr->state == QUE_THR_SIG_REPLY_WAIT));
299 was_active = thr->is_active;
301 que_thr_move_to_run_state(thr);
325 thr->prev_node = thr->common.parent;
327 que_thr_move_to_run_state(thr);
345 que_thr_t* suspended_thr = NULL;
346 que_thr_t* completed_thr = NULL;
348 fork->
state = QUE_FORK_ACTIVE;
352 suspended_thr = NULL;
353 completed_thr = NULL;
369 switch (thr->state) {
370 case QUE_THR_COMMAND_WAIT:
375 que_thr_init_command(thr);
379 case QUE_THR_SUSPENDED:
383 if (!suspended_thr) {
389 case QUE_THR_COMPLETED:
390 if (!completed_thr) {
396 case QUE_THR_LOCK_WAIT:
407 que_thr_move_to_run_state(thr);
409 }
else if (completed_thr) {
412 que_thr_init_command(thr);
432 ut_ad(mutex_own(&kernel_mutex));
433 ut_ad(trx->sess->state == SESS_ERROR);
439 while (thr != NULL) {
440 ut_ad(!thr->is_active);
441 ut_ad(thr->state != QUE_THR_SIG_REPLY_WAIT);
442 ut_ad(thr->state != QUE_THR_LOCK_WAIT);
445 thr->prev_node = thr->child;
446 thr->state = QUE_THR_COMPLETED;
453 que_thr_move_to_run_state(thr);
465que_fork_all_thrs_in_state(
474 while (thr_node != NULL) {
475 if (thr_node->
state != state) {
490que_graph_free_stat_list(
528 fork =
static_cast<que_fork_t *
>(node);
541 thr =
static_cast<que_thr_t *
>(node);
543 if (thr->magic_n != QUE_THR_MAGIC_N) {
545 "que_thr struct appears corrupt;"
547 (
unsigned long) thr->magic_n);
552 thr->magic_n = QUE_THR_MAGIC_FREED;
559 undo =
static_cast<undo_node_t *
>(node);
564 case QUE_NODE_SELECT:
566 sel =
static_cast<sel_node_t *
>(node);
571 case QUE_NODE_INSERT:
573 ins =
static_cast<ins_node_t *
>(node);
581 purge =
static_cast<purge_node_t *
>(node);
587 case QUE_NODE_UPDATE:
589 upd =
static_cast<upd_node_t *
>(node);
591 if (upd->in_mysql_interface) {
593 btr_pcur_free_for_mysql(upd->
pcur);
598 if (upd->cascade_heap) {
607 case QUE_NODE_CREATE_TABLE:
608 cre_tab =
static_cast<tab_node_t *
>(node);
617 case QUE_NODE_CREATE_INDEX:
618 cre_ind =
static_cast<ind_node_t *
>(node);
628 que_graph_free_stat_list(((proc_node_t*)node)->stat_list);
632 que_graph_free_stat_list(((if_node_t*)node)->stat_list);
633 que_graph_free_stat_list(((if_node_t*)node)->else_part);
634 que_graph_free_stat_list(((if_node_t*)node)->elsif_list);
638 que_graph_free_stat_list(((elsif_node_t*)node)->stat_list);
642 que_graph_free_stat_list(((while_node_t*)node)->stat_list);
646 que_graph_free_stat_list(((for_node_t*)node)->stat_list);
650 case QUE_NODE_ASSIGNMENT:
652 case QUE_NODE_RETURN:
653 case QUE_NODE_COMMIT:
654 case QUE_NODE_ROLLBACK:
658 case QUE_NODE_ROW_PRINTF:
666 "que_node struct appears corrupt; type %lu\n",
714 ut_ad(thr->run_node == thr);
716 if (thr->prev_node == thr->common.parent) {
720 thr->run_node = thr->child;
725 mutex_enter(&kernel_mutex);
729 mutex_exit(&kernel_mutex);
736 thr->state = QUE_THR_COMPLETED;
738 mutex_exit(&kernel_mutex);
751que_thr_move_to_run_state(
757 ut_ad(thr->state != QUE_THR_RUNNING);
761 if (!thr->is_active) {
763 (thr->graph)->n_active_thrs++;
767 thr->is_active = TRUE;
769 ut_ad((thr->graph)->n_active_thrs == 1);
773 thr->state = QUE_THR_RUNNING;
786que_thr_dec_refer_count(
789 que_thr_t** next_thr)
800 fork =
static_cast<que_fork_t *
>(thr->common.parent);
803 mutex_enter(&kernel_mutex);
805 ut_a(thr->is_active);
807 if (thr->state == QUE_THR_RUNNING) {
819 if (next_thr && *next_thr == NULL) {
832 mutex_exit(&kernel_mutex);
844 thr->is_active = FALSE;
848 mutex_exit(&kernel_mutex);
857 if (que_fork_all_thrs_in_state(fork, QUE_THR_COMPLETED)) {
860 case QUE_FORK_ROLLBACK:
865 ut_ad(trx->handling_signals == TRUE);
871 case QUE_FORK_RECOVERY:
872 case QUE_FORK_MYSQL_INTERFACE:
896 mutex_exit(&kernel_mutex);
914 ut_ad(mutex_own(&kernel_mutex));
919 if (graph->
state == QUE_FORK_COMMAND_WAIT) {
920 thr->state = QUE_THR_SUSPENDED;
922 }
else if (trx->
que_state == TRX_QUE_LOCK_WAIT) {
925 thr->state = QUE_THR_LOCK_WAIT;
931 thr->state = QUE_THR_COMPLETED;
934 && graph->
fork_type != QUE_FORK_ROLLBACK) {
936 thr->state = QUE_THR_SUSPENDED;
961 mutex_enter(&kernel_mutex);
963 if (thr->state == QUE_THR_RUNNING) {
969 thr->state = QUE_THR_COMPLETED;
975 mutex_exit(&kernel_mutex);
981 ut_ad(thr->is_active == TRUE);
983 ut_ad(thr->graph->n_active_thrs == 1);
985 thr->is_active = FALSE;
986 (thr->graph)->n_active_thrs--;
990 mutex_exit(&kernel_mutex);
1004 if (thr->magic_n != QUE_THR_MAGIC_N) {
1006 "que_thr struct appears corrupt; magic n %lu\n",
1007 (
unsigned long) thr->magic_n);
1014 if (!thr->is_active) {
1016 thr->graph->n_active_thrs++;
1020 thr->is_active = TRUE;
1023 thr->state = QUE_THR_RUNNING;
1036 ut_ad(thr->state == QUE_THR_RUNNING);
1037 ut_ad(thr->is_active == TRUE);
1039 ut_ad(thr->graph->n_active_thrs == 1);
1041 if (thr->magic_n != QUE_THR_MAGIC_N) {
1043 "que_thr struct appears corrupt; magic n %lu\n",
1044 (
unsigned long) thr->magic_n);
1051 thr->state = QUE_THR_COMPLETED;
1053 thr->is_active = FALSE;
1054 (thr->graph)->n_active_thrs--;
1082 if ((type == QUE_NODE_FOR) || (type == QUE_NODE_WHILE)) {
1103 if (type == QUE_NODE_SELECT) {
1105 }
else if (type == QUE_NODE_INSERT) {
1107 }
else if (type == QUE_NODE_UPDATE) {
1109 }
else if (type == QUE_NODE_WHILE) {
1111 }
else if (type == QUE_NODE_ASSIGNMENT) {
1113 }
else if (type == QUE_NODE_IF) {
1115 }
else if (type == QUE_NODE_FETCH) {
1117 }
else if (type == QUE_NODE_OPEN) {
1119 }
else if (type == QUE_NODE_PROC) {
1120 str =
"STORED PROCEDURE";
1121 }
else if (type == QUE_NODE_FUNC) {
1123 }
else if (type == QUE_NODE_LOCK) {
1125 }
else if (type == QUE_NODE_THR) {
1126 str =
"QUERY THREAD";
1127 }
else if (type == QUE_NODE_COMMIT) {
1129 }
else if (type == QUE_NODE_UNDO) {
1131 }
else if (type == QUE_NODE_PURGE) {
1133 }
else if (type == QUE_NODE_ROLLBACK) {
1135 }
else if (type == QUE_NODE_CREATE_TABLE) {
1136 str =
"CREATE TABLE";
1137 }
else if (type == QUE_NODE_CREATE_INDEX) {
1138 str =
"CREATE INDEX";
1139 }
else if (type == QUE_NODE_FOR) {
1141 }
else if (type == QUE_NODE_RETURN) {
1143 }
else if (type == QUE_NODE_EXIT) {
1146 str =
"UNKNOWN NODE TYPE";
1149 fprintf(stderr,
"Node type %lu: %s, address %p\n",
1150 (ulong) type, str, (
void*) node);
1170 ut_ad(thr->state == QUE_THR_RUNNING);
1175 node = thr->run_node;
1182 fputs(
"To execute: ", stderr);
1186 if (type & QUE_NODE_CONTROL_STAT) {
1196 }
else if (type == QUE_NODE_IF) {
1198 }
else if (type == QUE_NODE_FOR) {
1200 }
else if (type == QUE_NODE_PROC) {
1212 }
else if (type == QUE_NODE_WHILE) {
1217 }
else if (type == QUE_NODE_ASSIGNMENT) {
1219 }
else if (type == QUE_NODE_SELECT) {
1221 }
else if (type == QUE_NODE_INSERT) {
1223 }
else if (type == QUE_NODE_UPDATE) {
1225 }
else if (type == QUE_NODE_FETCH) {
1227 }
else if (type == QUE_NODE_OPEN) {
1229 }
else if (type == QUE_NODE_FUNC) {
1232 }
else if (type == QUE_NODE_LOCK) {
1238 }
else if (type == QUE_NODE_THR) {
1239 thr = que_thr_node_step(thr);
1240 }
else if (type == QUE_NODE_COMMIT) {
1242 }
else if (type == QUE_NODE_UNDO) {
1244 }
else if (type == QUE_NODE_PURGE) {
1246 }
else if (type == QUE_NODE_RETURN) {
1247 thr = return_step(thr);
1248 }
else if (type == QUE_NODE_EXIT) {
1249 thr = exit_step(thr);
1250 }
else if (type == QUE_NODE_ROLLBACK) {
1252 }
else if (type == QUE_NODE_CREATE_TABLE) {
1253 thr = dict_create_table_step(thr);
1254 }
else if (type == QUE_NODE_CREATE_INDEX) {
1255 thr = dict_create_index_step(thr);
1256 }
else if (type == QUE_NODE_ROW_PRINTF) {
1262 if (type == QUE_NODE_EXIT) {
1283 que_thr_t* next_thr;
1285 ut_ad(thr->state == QUE_THR_RUNNING);
1287 ut_ad(!mutex_own(&kernel_mutex));
1301 next_thr = que_thr_step(thr);
1304 ut_a(!next_thr || (
thr_get_trx(next_thr)->error_state == DB_SUCCESS));
1306 if (next_thr != thr) {
1307 ut_a(next_thr == NULL);
1311 que_thr_dec_refer_count(thr, &next_thr);
1313 if (next_thr == NULL) {
1334 que_run_threads_low(thr);
1336 mutex_enter(&kernel_mutex);
1338 switch (thr->state) {
1340 case QUE_THR_RUNNING:
1344 mutex_exit(&kernel_mutex);
1348 case QUE_THR_LOCK_WAIT:
1349 mutex_exit(&kernel_mutex);
1356 if (
thr_get_trx(thr)->error_state != DB_SUCCESS) {
1360 que_thr_dec_refer_count(thr, NULL);
1367 case QUE_THR_COMPLETED:
1368 case QUE_THR_COMMAND_WAIT:
1376 mutex_exit(&kernel_mutex);
1388 ibool reserve_dict_mutex,
1398 if (reserve_dict_mutex) {
1399 mutex_enter(&dict_sys->mutex);
1404 if (reserve_dict_mutex) {
1405 mutex_exit(&dict_sys->mutex);
1413 graph->
fork_type = QUE_FORK_MYSQL_INTERFACE;
UNIV_INLINE que_thr_t * proc_eval_step(que_thr_t *thr)
UNIV_INLINE que_thr_t * proc_step(que_thr_t *thr)
UNIV_INLINE void log_free_check(void)
UNIV_INTERN void mem_analyze_corruption(void *ptr)
UNIV_INLINE void * mem_heap_alloc(mem_heap_t *heap, ulint n)
#define mem_heap_free(heap)
UNIV_INTERN void pars_info_free(pars_info_t *info)
UNIV_INTERN que_t * pars_sql(pars_info_t *info, const char *str)
UNIV_INTERN void sym_tab_free_private(sym_tab_t *sym_tab)
UNIV_INTERN void que_thr_stop_for_mysql(que_thr_t *thr)
UNIV_INLINE ulint que_node_get_type(que_node_t *node)
UNIV_INTERN void que_thr_move_to_run_state_for_mysql(que_thr_t *thr, trx_t *trx)
UNIV_INLINE que_node_t * que_node_get_parent(que_node_t *node)
UNIV_INTERN void que_graph_free(que_t *graph)
UNIV_INTERN void que_fork_error_handle(trx_t *trx, que_t *fork)
UNIV_INTERN ibool que_thr_stop(que_thr_t *thr)
UNIV_INTERN void que_run_threads(que_thr_t *thr)
UNIV_INTERN ulint que_eval_sql(pars_info_t *info, const char *sql, ibool reserve_dict_mutex, trx_t *trx)
UNIV_INTERN que_thr_t * que_thr_create(que_fork_t *parent, mem_heap_t *heap)
UNIV_INTERN void que_thr_end_wait(que_thr_t *thr, que_thr_t **next_thr)
UNIV_INLINE ibool que_thr_peek_stop(que_thr_t *thr)
UNIV_INTERN void que_node_print_info(que_node_t *node)
UNIV_INTERN que_thr_t * que_fork_start_command(que_fork_t *fork)
UNIV_INTERN void que_thr_stop_for_mysql_no_error(que_thr_t *thr, trx_t *trx)
UNIV_INTERN que_fork_t * que_fork_create(que_t *graph, que_node_t *parent, ulint fork_type, mem_heap_t *heap)
UNIV_INTERN void que_graph_publish(que_t *graph, sess_t *sess)
UNIV_INLINE que_node_t * que_node_get_next(que_node_t *node)
UNIV_INTERN que_node_t * que_node_get_containing_loop_node(que_node_t *node)
UNIV_INTERN void que_thr_end_wait_no_next_thr(que_thr_t *thr)
UNIV_INTERN void que_graph_free_recursive(que_node_t *node)
UNIV_INLINE trx_t * thr_get_trx(que_thr_t *thr)
UNIV_INTERN que_thr_t * row_ins_step(que_thr_t *thr)
UNIV_INTERN que_thr_t * row_purge_step(que_thr_t *thr)
UNIV_INTERN que_thr_t * row_printf_step(que_thr_t *thr)
UNIV_INTERN void sel_node_free_private(sel_node_t *node)
UNIV_INLINE que_thr_t * open_step(que_thr_t *thr)
UNIV_INTERN que_thr_t * row_sel_step(que_thr_t *thr)
UNIV_INTERN que_thr_t * fetch_step(que_thr_t *thr)
UNIV_INTERN que_thr_t * row_undo_step(que_thr_t *thr)
UNIV_INTERN que_thr_t * row_upd_step(que_thr_t *thr)
UNIV_INTERN void srv_release_mysql_thread_if_suspended(que_thr_t *thr)
UNIV_INTERN void srv_que_task_enqueue_low(que_thr_t *thr)
UNIV_INTERN void srv_suspend_mysql_thread(que_thr_t *thr)
sel_node_t * last_sel_node
UNIV_INTERN que_thr_t * trx_rollback_step(que_thr_t *thr)
UNIV_INTERN void trx_finish_rollback_off_kernel(que_t *graph, trx_t *trx, que_thr_t **next_thr)
UNIV_INTERN que_thr_t * trx_commit_step(que_thr_t *thr)
UNIV_INTERN void trx_end_signal_handling(trx_t *trx)
UNIV_INTERN void trx_sig_start_handle(trx_t *trx, que_thr_t **next_thr)
#define UT_LIST_GET_LEN(BASE)
#define UT_LIST_GET_FIRST(BASE)
#define UT_LIST_ADD_LAST(NAME, BASE, N)
#define UT_LIST_ADD_FIRST(NAME, BASE, N)
#define UT_LIST_GET_NEXT(NAME, N)
#define UT_LIST_INIT(BASE)