~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/que/que0que.c

  • Committer: Brian Aker
  • Date: 2008-11-04 15:39:09 UTC
  • mfrom: (575.1.2 devel)
  • Revision ID: brian@tangent.org-20081104153909-c72hn65udxs1ccal
Merge of Monty's work

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
#define QUE_ROUND_ROBIN_LIMIT   (64 * 256 * 256 * 256)
32
32
#define QUE_MAX_LOOPS_WITHOUT_CHECK     16
33
33
 
 
34
#ifdef UNIV_DEBUG
34
35
/* If the following flag is set TRUE, the module will print trace info
35
36
of SQL execution in the UNIV_SQL_DEBUG version */
36
 
ibool   que_trace_on            = FALSE;
37
 
 
38
 
ibool   que_always_false        = FALSE;
 
37
UNIV_INTERN ibool       que_trace_on            = FALSE;
 
38
#endif /* UNIV_DEBUG */
39
39
 
40
40
/* Short introduction to query graphs
41
41
   ==================================
120
120
 
121
121
/***************************************************************************
122
122
Adds a query graph to the session's list of graphs. */
123
 
 
 
123
UNIV_INTERN
124
124
void
125
125
que_graph_publish(
126
126
/*==============*/
134
134
 
135
135
/***************************************************************************
136
136
Creates a query graph fork node. */
137
 
 
 
137
UNIV_INTERN
138
138
que_fork_t*
139
139
que_fork_create(
140
140
/*============*/
180
180
 
181
181
/***************************************************************************
182
182
Creates a query graph thread node. */
183
 
 
 
183
UNIV_INTERN
184
184
que_thr_t*
185
185
que_thr_create(
186
186
/*===========*/
219
219
a single worker thread to execute it. This function should be used to end
220
220
the wait state of a query thread waiting for a lock or a stored procedure
221
221
completion. */
222
 
 
 
222
UNIV_INTERN
223
223
void
224
224
que_thr_end_wait(
225
225
/*=============*/
264
264
 
265
265
/**************************************************************************
266
266
Same as que_thr_end_wait, but no parameter next_thr available. */
267
 
 
 
267
UNIV_INTERN
268
268
void
269
269
que_thr_end_wait_no_next_thr(
270
270
/*=========================*/
318
318
is not in the QUE_THR_RUNNING state and moves it to that state. If none
319
319
can be chosen, a situation which may arise in parallelized fetches, NULL
320
320
is returned. */
321
 
 
 
321
UNIV_INTERN
322
322
que_thr_t*
323
323
que_fork_start_command(
324
324
/*===================*/
336
336
 
337
337
        fork->last_sel_node = NULL;
338
338
 
 
339
        suspended_thr = NULL;
 
340
        completed_thr = NULL;
 
341
 
339
342
        /* Choose the query thread to run: usually there is just one thread,
340
343
        but in a parallelized select, which necessarily is non-scrollable,
341
344
        there may be several to choose from */
403
406
After signal handling is finished, returns control to a query graph error
404
407
handling routine. (Currently, just returns the control to the root of the
405
408
graph so that the graph can communicate an error message to the client.) */
406
 
 
 
409
UNIV_INTERN
407
410
void
408
411
que_fork_error_handle(
409
412
/*==================*/
485
488
/**************************************************************************
486
489
Frees a query graph, but not the heap where it was created. Does not free
487
490
explicit cursor declarations, they are freed in que_graph_free. */
488
 
 
 
491
UNIV_INTERN
489
492
void
490
493
que_graph_free_recursive(
491
494
/*=====================*/
648
651
 
649
652
/**************************************************************************
650
653
Frees a query graph. */
651
 
 
 
654
UNIV_INTERN
652
655
void
653
656
que_graph_free(
654
657
/*===========*/
681
684
Checks if the query graph is in a state where it should be freed, and
682
685
frees it in that case. If the session is in a state where it should be
683
686
closed, also this is done. */
684
 
 
 
687
UNIV_INTERN
685
688
ibool
686
689
que_graph_try_free(
687
690
/*===============*/
802
805
{
803
806
        que_fork_t*     fork;
804
807
        trx_t*          trx;
805
 
        sess_t*         sess;
806
808
        ulint           fork_type;
807
809
        ibool           stopped;
808
810
 
809
811
        fork = thr->common.parent;
810
812
        trx = thr_get_trx(thr);
811
 
        sess = trx->sess;
812
813
 
813
814
        mutex_enter(&kernel_mutex);
814
815
 
835
836
 
836
837
                                *next_thr = thr;
837
838
                        } else {
838
 
                                ut_a(0);
 
839
                                ut_error;
839
840
                                srv_que_task_enqueue_low(thr);
840
841
                        }
841
842
 
866
867
 
867
868
        if (que_fork_all_thrs_in_state(fork, QUE_THR_COMPLETED)) {
868
869
 
869
 
                if (fork_type == QUE_FORK_ROLLBACK) {
 
870
                switch (fork_type) {
 
871
                case QUE_FORK_ROLLBACK:
870
872
                        /* This is really the undo graph used in rollback,
871
873
                        no roll_node in this graph */
872
874
 
874
876
                        ut_ad(trx->handling_signals == TRUE);
875
877
 
876
878
                        trx_finish_rollback_off_kernel(fork, trx, next_thr);
877
 
 
878
 
                } else if (fork_type == QUE_FORK_PURGE) {
879
 
 
880
 
                        /* Do nothing */
881
 
                } else if (fork_type == QUE_FORK_RECOVERY) {
882
 
 
883
 
                        /* Do nothing */
884
 
                } else if (fork_type == QUE_FORK_DRIZZLE_INTERFACE) {
885
 
 
886
 
                        /* Do nothing */
887
 
                } else {
 
879
                        break;
 
880
 
 
881
                case QUE_FORK_PURGE:
 
882
                case QUE_FORK_RECOVERY:
 
883
                case QUE_FORK_MYSQL_INTERFACE:
 
884
 
 
885
                        /* Do nothing */
 
886
                        break;
 
887
 
 
888
                default:
888
889
                        ut_error;       /* not used in MySQL */
889
890
                }
890
891
        }
910
911
Stops a query thread if graph or trx is in a state requiring it. The
911
912
conditions are tested in the order (1) graph, (2) trx. The kernel mutex has
912
913
to be reserved. */
913
 
 
 
914
UNIV_INTERN
914
915
ibool
915
916
que_thr_stop(
916
917
/*=========*/
958
959
query thread is stopped and made inactive, except in the case where
959
960
it was put to the lock wait state in lock0lock.c, but the lock has already
960
961
been granted or the transaction chosen as a victim in deadlock resolution. */
961
 
 
 
962
UNIV_INTERN
962
963
void
963
964
que_thr_stop_for_mysql(
964
965
/*===================*/
1004
1005
Moves a thread from another state to the QUE_THR_RUNNING state. Increments
1005
1006
the n_active_thrs counters of the query graph and transaction if thr was
1006
1007
not active. */
1007
 
 
 
1008
UNIV_INTERN
1008
1009
void
1009
1010
que_thr_move_to_run_state_for_mysql(
1010
1011
/*================================*/
1036
1037
/**************************************************************************
1037
1038
A patch for MySQL used to 'stop' a dummy query thread used in MySQL
1038
1039
select, when there is no error or lock wait. */
1039
 
 
 
1040
UNIV_INTERN
1040
1041
void
1041
1042
que_thr_stop_for_mysql_no_error(
1042
1043
/*============================*/
1069
1070
/********************************************************************
1070
1071
Get the first containing loop node (e.g. while_node_t or for_node_t) for the
1071
1072
given node, or NULL if the node is not within a loop. */
1072
 
 
 
1073
UNIV_INTERN
1073
1074
que_node_t*
1074
1075
que_node_get_containing_loop_node(
1075
1076
/*==============================*/
1099
1100
 
1100
1101
/**************************************************************************
1101
1102
Prints info of an SQL query graph node. */
1102
 
 
 
1103
UNIV_INTERN
1103
1104
void
1104
1105
que_node_print_info(
1105
1106
/*================*/
1345
1346
 
1346
1347
/**************************************************************************
1347
1348
Run a query thread. Handles lock waits. */
 
1349
UNIV_INTERN
1348
1350
void
1349
1351
que_run_threads(
1350
1352
/*============*/
1399
1401
 
1400
1402
/*************************************************************************
1401
1403
Evaluate the given SQL. */
1402
 
 
 
1404
UNIV_INTERN
1403
1405
ulint
1404
1406
que_eval_sql(
1405
1407
/*=========*/
1431
1433
        graph->trx = trx;
1432
1434
        trx->graph = NULL;
1433
1435
 
1434
 
        graph->fork_type = QUE_FORK_DRIZZLE_INTERFACE;
 
1436
        graph->fork_type = QUE_FORK_MYSQL_INTERFACE;
1435
1437
 
1436
1438
        ut_a(thr = que_fork_start_command(graph));
1437
1439