O'Reilly logo

Understanding MySQL Internals by Sasha Pachev

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Implementation of Request Handling

The server listens in the main thread for connections. For each connection, it allocates a thread to handle it. Depending on the server configuration settings and current status, the thread may be either created anew or dispatched from the thread cache. The client issues requests, and the server satisfies them until the client sends a session-terminating command (COM_QUIT) or until the session ends abnormally. Upon terminating the client session, depending on the server configuration settings and status, the thread may either terminate or enter the thread cache to wait for another request dispatch.

Structures, Variables, Classes, and API

Perhaps the most important class for threads is THD, which is a class for thread descriptors. Nearly every one of the server functions inside the parser and optimizer accepts a THD object as an argument, and it usually comes first in the parameter list. The THD class is discussed in detail in Chapter 3.

Whenever a thread is created, its descriptor is put into a global thread list I_List<THD> threads.(I_List<> is a class template for linked lists; see sql/sql_list.h and sql/sql_list.cc.) The list is mainly used for three purposes:

  • To provide the data for the SHOW PROCESSLIST command

  • To locate the target thread when executing the KILL command

  • To signal all threads to terminate during shutdown

Another list of I_List<THD> plays an important role: thread_cache. It is actually used in a rather unexpected manner: as a means ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required