MySQL 8.0.40
Source Code Documentation
que0que.cc File Reference

Query graph. More...

#include <stddef.h>
#include "dict0crea.h"
#include "eval0eval.h"
#include "eval0proc.h"
#include "ha_prototypes.h"
#include "lock0lock.h"
#include "log0chkp.h"
#include "pars0types.h"
#include "que0que.h"
#include "row0ins.h"
#include "row0purge.h"
#include "row0sel.h"
#include "row0undo.h"
#include "row0upd.h"
#include "trx0roll.h"
#include "trx0trx.h"
#include "usr0sess.h"
#include "my_dbug.h"

Functions

static void que_thr_move_to_run_state (que_thr_t *thr)
 Moves a thread from another state to the QUE_THR_RUNNING state. More...
 
que_fork_tque_fork_create (que_t *graph, que_node_t *parent, ulint fork_type, mem_heap_t *heap)
 Creates a query graph fork node. More...
 
que_thr_tque_thr_create (que_fork_t *parent, mem_heap_t *heap, row_prebuilt_t *prebuilt)
 Creates a query graph thread node. More...
 
que_thr_tque_thr_end_lock_wait (trx_t *trx)
 Moves a suspended query thread to the QUE_THR_RUNNING state and may release a worker thread to execute it. More...
 
static void que_thr_init_command (que_thr_t *thr)
 Inits a query thread for a command. More...
 
que_thr_tque_fork_scheduler_round_robin (que_fork_t *fork, que_thr_t *thr)
 Round robin scheduler. More...
 
que_thr_tque_fork_start_command (que_fork_t *fork)
 Starts execution of a command in a query fork. More...
 
static void que_graph_free_stat_list (que_node_t *node)
 Calls que_graph_free_recursive for statements in a statement list. More...
 
void que_graph_free_recursive (que_node_t *node)
 Frees a query graph, but not the heap where it was created. More...
 
void que_graph_free (que_t *graph)
 Frees a query graph. More...
 
static que_thr_tque_thr_node_step (que_thr_t *thr)
 Performs an execution step on a thr node. More...
 
bool que_thr_stop (que_thr_t *thr)
 Stops a query thread if graph or trx is in a state requiring it. More...
 
static void que_thr_dec_refer_count (que_thr_t *thr, que_thr_t **next_thr)
 Decrements the query thread reference counts in the query graph and the transaction. More...
 
void que_thr_stop_for_mysql (que_thr_t *thr)
 A patch for MySQL used to 'stop' a dummy query thread used in MySQL. More...
 
void que_thr_move_to_run_state_for_mysql (que_thr_t *thr, trx_t *trx)
 Moves a thread from another state to the QUE_THR_RUNNING state. More...
 
void que_thr_stop_for_mysql_no_error (que_thr_t *thr, trx_t *trx)
 A patch for MySQL used to 'stop' a dummy query thread used in MySQL select, when there is no error or lock wait. More...
 
que_node_tque_node_get_containing_loop_node (que_node_t *node)
 Get the first containing loop node (e.g. More...
 
static const char * que_node_type_string (const que_node_t *node)
 Gets information of an SQL query graph node. More...
 
static que_thr_tque_thr_step (que_thr_t *thr)
 Performs an execution step on a query thread. More...
 
static void que_run_threads_low (que_thr_t *thr)
 Run a query thread until it finishes or encounters e.g. More...
 
void que_run_threads (que_thr_t *thr)
 Run a query thread. More...
 
dberr_t que_eval_sql (pars_info_t *info, const char *sql, trx_t *trx)
 Evaluate the given SQL. More...
 
void que_init (void)
 Initialise the query sub-system. More...
 
void que_close (void)
 Close the query sub-system. More...
 

Detailed Description

Query graph.

Created 5/27/1996 Heikki Tuuri

Function Documentation

◆ que_close()

void que_close ( void  )

Close the query sub-system.

◆ que_eval_sql()

dberr_t que_eval_sql ( pars_info_t info,
const char *  sql,
trx_t trx 
)

Evaluate the given SQL.

Parameters
[in]infoInfo struct, or nullptr.
[in]sqlSQL string.
[in]trxTransaction.
Returns
error code or DB_SUCCESS

◆ que_fork_create()

que_fork_t * que_fork_create ( que_t graph,
que_node_t parent,
ulint  fork_type,
mem_heap_t heap 
)

Creates a query graph fork node.

Returns
own: fork node
Parameters
graphin: graph, if NULL then this fork node is assumed to be the graph root
parentin: parent node
fork_typein: fork type
heapin: memory heap where created

◆ que_fork_scheduler_round_robin()

que_thr_t * que_fork_scheduler_round_robin ( que_fork_t fork,
que_thr_t thr 
)

Round robin scheduler.

Returns
a query thread of the graph moved to QUE_THR_RUNNING state, or NULL; the query thread should be executed by que_run_threads by the caller
Parameters
forkin: a query fork
thrin: current pos

◆ que_fork_start_command()

que_thr_t * que_fork_start_command ( que_fork_t fork)

Starts execution of a command in a query fork.

Picks a query thread which is not in the QUE_THR_RUNNING state and moves it to that state. If none can be chosen, a situation which may arise in parallelized fetches, NULL is returned.

Returns
a query thread of the graph moved to QUE_THR_RUNNING state, or NULL; the query thread should be executed by que_run_threads by the caller
Parameters
forkin: a query fork

◆ que_graph_free()

void que_graph_free ( que_t graph)

Frees a query graph.

in: query graph; we assume that the memory heap where this graph was created is private to this graph: if not, then use que_graph_free_recursive and free the heap afterwards!

Parameters
graphin: query graph; we assume that the memory heap where this graph was created is private to this graph: if not, then use que_graph_free_recursive and free the heap afterwards!

◆ que_graph_free_recursive()

void que_graph_free_recursive ( que_node_t node)

Frees a query graph, but not the heap where it was created.

Does not free explicit cursor declarations, they are freed in que_graph_free.

Parameters
nodein: query graph node

◆ que_graph_free_stat_list()

static void que_graph_free_stat_list ( que_node_t node)
static

Calls que_graph_free_recursive for statements in a statement list.

Parameters
nodein: first query graph node in the list

◆ que_init()

void que_init ( void  )

Initialise the query sub-system.

◆ que_node_get_containing_loop_node()

que_node_t * que_node_get_containing_loop_node ( que_node_t node)

Get the first containing loop node (e.g.

while_node_t or for_node_t) for the given node, or NULL if the node is not within a loop.

Returns
containing loop node, or NULL.
Parameters
nodein: node

◆ que_node_type_string()

static const char * que_node_type_string ( const que_node_t node)
static

Gets information of an SQL query graph node.

Returns
type description
Parameters
nodein: query graph node

◆ que_run_threads()

void que_run_threads ( que_thr_t thr)

Run a query thread.

Handles lock waits.

Parameters
thrin: query thread

◆ que_run_threads_low()

static void que_run_threads_low ( que_thr_t thr)
static

Run a query thread until it finishes or encounters e.g.

a lock wait.

Parameters
thrin: query thread

◆ que_thr_create()

que_thr_t * que_thr_create ( que_fork_t parent,
mem_heap_t heap,
row_prebuilt_t prebuilt 
)

Creates a query graph thread node.

Parameters
[in]parentparent node, i.e., a fork node
[in]heapmemory heap where created
[in]prebuiltrow prebuilt structure
Returns
own: query thread node

◆ que_thr_dec_refer_count()

static void que_thr_dec_refer_count ( que_thr_t thr,
que_thr_t **  next_thr 
)
static

Decrements the query thread reference counts in the query graph and the transaction.

NOTE ***: This and que_thr_stop_for_mysql are the only functions where the reference count can be decremented and this function may only be called from inside que_run_threads! These restrictions exist to make the rollback code easier to maintain.

Parameters
thrin: query thread
next_thrin/out: next query thread to run; if the value which is passed in is a pointer to a NULL pointer, then the calling function can start running a new query thread

◆ que_thr_end_lock_wait()

que_thr_t * que_thr_end_lock_wait ( trx_t trx)

Moves a suspended query thread to the QUE_THR_RUNNING state and may release a worker thread to execute it.

Moves a suspended query thread to the QUE_THR_RUNNING state and release a worker thread to execute it.

This function should be used to end the wait state of a query thread waiting for a lock or a stored procedure completion.

Returns
the query thread that needs to be released.
Parameters
trxin: transaction with que_state in QUE_THR_LOCK_WAIT

◆ que_thr_init_command()

static void que_thr_init_command ( que_thr_t thr)
inlinestatic

Inits a query thread for a command.

Parameters
thrin: query thread

◆ que_thr_move_to_run_state()

static void que_thr_move_to_run_state ( que_thr_t thr)
static

Moves a thread from another state to the QUE_THR_RUNNING state.

Increments the n_active_thrs counters of the query graph and transaction. NOTE***: This is the only function in which such a transition is allowed to happen! in: an query thread

Increments the n_active_thrs counters of the query graph and transaction if thr was not active. NOTE***: This and ..._mysql are the only functions in which such a transition is allowed to happen!

Parameters
thrin: an query thread

◆ que_thr_move_to_run_state_for_mysql()

void que_thr_move_to_run_state_for_mysql ( que_thr_t thr,
trx_t trx 
)

Moves a thread from another state to the QUE_THR_RUNNING state.

Increments the n_active_thrs counters of the query graph and transaction if thr was not active.

Parameters
thrin: an query thread
trxin: transaction

◆ que_thr_node_step()

static que_thr_t * que_thr_node_step ( que_thr_t thr)
static

Performs an execution step on a thr node.

Returns
query thread to run next, or NULL if none
Parameters
thrin: query thread where run_node must be the thread node itself

◆ que_thr_step()

static que_thr_t * que_thr_step ( que_thr_t thr)
inlinestatic

Performs an execution step on a query thread.

Returns
query thread to run next: it may differ from the input parameter if, e.g., a subprocedure call is made
Parameters
thrin: query thread

◆ que_thr_stop()

bool que_thr_stop ( que_thr_t thr)

Stops a query thread if graph or trx is in a state requiring it.

The conditions are tested in the order (1) graph, (2) trx. Caller must hold the trx mutex.

Parameters
[in,out]thrquery thread
Returns
true if stopped

◆ que_thr_stop_for_mysql()

void que_thr_stop_for_mysql ( que_thr_t thr)

A patch for MySQL used to 'stop' a dummy query thread used in MySQL.

The query thread is stopped and made inactive, except in the case where it was put to the lock wait state in lock0lock.cc, but the lock has already been granted or the transaction chosen as a victim in deadlock resolution.

Parameters
thrin: query thread

◆ que_thr_stop_for_mysql_no_error()

void que_thr_stop_for_mysql_no_error ( que_thr_t thr,
trx_t trx 
)

A patch for MySQL used to 'stop' a dummy query thread used in MySQL select, when there is no error or lock wait.

Parameters
[in]thrQuery thread
[in]trxTransaction