By Sasha Pachev
Book Price: $49.99 USD
£35.50 GBP
PDF Price: $39.99
Cover | Table of Contents | Colophon
mi_open( )" than to hear "This happens on the MyISAM storage engine level." MySQL developers know the code so well that they are able to think conceptually on the level of functions, structures, and classes. They will probably find the abstractions in this section rather useless. However, it would be helpful to a person used to thinking in terms of modules and managers.
/bin/sh
http://www.bitmover.com) for source revision control. A BitKeeper repository containing MySQL source code is publicly available with read-only access. Although MySQL source code can also be obtained by downloading a compressed archive, using BitKeeper offers a number of advantages:
/bin/sh
http://www.bitmover.com) for source revision control. A BitKeeper repository containing MySQL source code is publicly available with read-only access. Although MySQL source code can also be obtained by downloading a compressed archive, using BitKeeper offers a number of advantages:http://www.bitmover.com/bk-client.shar.|
Tool
|
Minimum required version
|
URL
|
|---|---|---|
|
autoconf
|
2.53
|
http://www.gnu.org/software/autoconf/
|
|
automake
|
1.8
|
|
extra_flags="$pentium_cflags $debug_cflags" to extra_flags="-g $debug_cflags".extra_configs=.extra_configs="" before the line. "$path/FINISH.sh".#! /bin/sh path='dirname $0' . "$path/SETUP.sh" $@ --with-debug=full extra_flags="-g $debug_cflags" c_warnings="$c_warnings $debug_extra_warnings" cxx_warnings="$cxx_warnings $debug_extra_warnings" extra_configs="" . "$path/FINISH.sh"
$ BUILD/compile-generic-debug
$ make testhttp://www.gnu.org/software/tar) and gzip (http://www.gnu.org/software/gzip) utilities to unpack the archive. If you have a non-GNU tar already installed, it is recommended that you still install GNU tar. MySQL is archived using GNU tar, and some variants of tar are not compatible with it.http://dev.mysql.com/downloads/mysql/4.1.html (note the version number in the URL), scroll down to the bottom of the page where it says "Source downloads," and click on the link that says "Pick a mirror" on the "Tarball" line.$ make install
–prefix=
/path/to/other-prefix to the extra_configs variable in the build script. If you do not have root privileges on the system, another build configuration option will be helpful: add --with-mysqld-user=
your_user_name to extra_configs. A full listing of build configuration options can be obtained by executing:
# ./configure -help
|
Subdirectory
|
Description
|
|---|---|
|
BUILD
|
Developer build scripts.
|
|
Build-tools
|
Mostly scripts for building binary distributions.
|
|
Docs
|
Documentation.
|
|
NEW-RPMS
|
Used by the distribution build scripts to hold new RPMs.
|
|
SSL
|
Some configuration files from early SSL development.
|
|
VC++Files
|
Used for building MySQL binaries on Windows.
|
|
bdb
|
Berkeley DB storage engine code. Berkeley DB supports transactions and page locks. However, the interface between Berkeley DB and core MySQL is not very well developed, and InnoDB storage engine is a better choice when transactions are needed. Removed in version 5.1. |
http://www.gnu.org/software/gdb/) installed on your system, and be present in your PATH. You also need to have the X Window System, including a terminal program such as xterm. There are a number of X standard implementations, perhaps the most popular of them being X.org (http://www.x.org).$ file -L /lib/libthread_db.so /lib/libthread_db.so: ELF 32-bit LSB shared object, Intel 80386, version 1, not stripped $ file -L /lib/libpthread.so /lib/libpthread.so: ELF 32-bit LSB shared object, Intel 80386, version 1, not stripped
select 1;
$ ./mysql-test-run --local --record example
$ ./mysql-test-run --gdb example
mysql_parse( ) function in the file sql/sql_ parse.ccList of classes of commands: aliases -- Aliases of other commands breakpoints -- Making program stop at certain points data -- Examining data files -- Specifying and examining files internals -- Maintenance commands obscure -- Obscure features running -- Running the program stack -- Examining the stack status -- Status inquiries support -- Support facilities tracepoints -- Tracing of program execution without stopping the program user-defined -- User-defined commands Type "help" followed by a class name for a list of commands in that class. Type "help" followed by command name for full documentation. Command name abbreviations are allowed if unambiguous.
Running the program. List of commands: advance --Continue the program up to the given location (same form as args for break command) attach -- Attach to a process or file outside of GDB continue -- Continue program being debugged detach -- Detach a process or file previously attached disconnect -- Disconnect from a target finish -- Execute until selected stack frame returns handle -- Specify how to handle a signal info handle -- What debugger does when program gets various signals interrupt -- Interrupt the execution of the debugged program jump -- Continue program being debugged at specified line or address kill -- Kill execution of program being debugged next -- Step program nexti -- Step one instruction run -- Start debugged program set args -- Set argument list to give program being debugged when it is started set environment -- Set environment variable value to give the program set follow-fork-mode -- Set debugger response to a program call of fork or vfork set scheduler-locking -- Set mode for locking scheduler during execution set step-mode -- Set mode of the step operation show args -- Show argument list to give program being debugged when it is started show follow-fork-mode -- Show debugger response to a program call of fork or vfork show scheduler-locking -- Show mode for locking scheduler during execution show step-mode -- Show mode of the step operation signal -- Continue program giving it signal specified by the argument step -- Step program until it reaches a different source line stepi -- Step one instruction exactly target -- Connect to a target machine or process thread -- Use this command to switch between threads thread apply -- Apply a command to a list of threads apply all -- Apply a command to all threads tty -- Set terminal for future runs of program being debugged unset environment -- Cancel environment variable VAR for the program until -- Execute until the program reaches a source line greater than the current Type "help" followed by command name for full documentation. Command name abbreviations are allowed if unambiguous.
get_and_lock_X( ) defined?" There are many techniques to find the answer, and many programmers have their own favorites. For those who do not, or who are having a hard time adapting them to the MySQL source, I will share mine.mysql_lock_tables( ). Follow these steps:i li mysql_lock_tables
Line 86 of "lock.cc" starts at address 0x8125540 <mysql_lock_tables__FP3THDPP8st_tableUi> and ends at 0x812554f <mysql_lock_tables__FP3THDPP8st_tableUi+15>.
mysql_lock_tables() is defined on line 86 of lock.cc. Unfortunately, it doesn't say which directory the file is in, so one more step is necessary.
$ find . -name lock.cc | xargs ls -l
lrwxrwxrwx 1 sasha sasha 16 Jul 29 15:08 ./libmysqld/lock.cc -> ./../ sql/lock.cc -rw-rw-r-- 1 sasha sasha 20863 Jul 14 21:40 ./sql/lock.cc
ha_commit( ), and the debugger has already told you that there is no such symbol. Execute the following command from the root of the source tree:init_X( ) function, but where in the world does the meat really begin when I do operation Y?
|
Operation
|
Good place for an entry breakpoint
|
Interesting variables to examine
|
|---|---|---|
|
Select query
|
mysql_select( )
|
*thd
thd->query
*tables
*join
|
|
Insert query
|
mysql_insert( )
|
$ make
SOURCES. For example, in the sql directory, the variable is called mysqld_SOURCES, and in the myisam directory, libmyisam_a_SOURCES.SOURCES variable.INCLUDES and noinst_HEADERS. Add the names of the new headers that you want to be installed by a make install command to INCLUDES, and the ones that do not need to be installed to
noinst_HEADERS
.http://dev.mysql.com/doc/internals/en/index.html.sql_alloc( ) or my_malloc( ).sql_alloc( ) over my_malloc( ) for small allocations. sql_ alloc( ) allocates memory from a pre-allocated connection memory pool, while my_malloc( ) is just a wrapper around the regular malloc( ) call. sql_alloc( ) can be called anywhere in the stack of execution below do_command( ). To verify the stack position in question, set a breakpoint there in the debugger, and when it is reached, run the bt command. Note that the memory allocated with sql_alloc( ) lasts until the end of the query execution. If you want your allocation to persist past that, use my_malloc( ).my_malloc( ), and free the allocated blocks with #! /bin/sh exit 0
$ bk citool &
$ bk pull
$ bk -r diffs -c > /tmp/mysql-patch.diff
THD class defines a thread descriptor. It contains the information pertinent to the thread that is handling the given request. Each client connection is handled by a thread. Each thread has a descriptor object. Handling client requests is not the only time a thread is created. MySQL has a number of system threads, such as the replication slave threads and delayed insert threads. Additionally, there exists a special case when a thread descriptor object is created without a thread—the server running in bootstrap mode to create the necessary system tables during installation.
THD class defines a thread descriptor. It contains the information pertinent to the thread that is handling the given request. Each client connection is handled by a thread. Each thread has a descriptor object. Handling client requests is not the only time a thread is created. MySQL has a number of system threads, such as the replication slave threads and delayed insert threads. Additionally, there exists a special case when a thread descriptor object is created without a thread—the server running in bootstrap mode to create the necessary system tables during installation.
THD is perhaps the most frequently referenced type in the server code. It is passed as the first argument in most of the higher-level calls. With the exception of low-level storage and retrieval operations, few things of significance happen inside the server without some involvement of this class. Familiarity with its members will give you a good idea of the overall architecture and capabilities of the server.THD is defined in sql/sql_class.h and implemented in sql/sql_class.cc.THD*. Therefore, if you are trying to find places in the code where a particular member of this class is used, the following command will work almost without fail:
grep "thd->var_name" sql/*.cc
NET structure defines a network connection descriptor. MySQL uses a fairly complex protocol on top of the one already provided by the operating system for client/ server communication. This structure lies at the core of the protocol's implementation.NET one way or the other, usually by accepting it as an argument. Becoming familiar with the members of NET is a major step toward understanding the client/server communication protocol.NET is a rather small structure, which permits us to cover it in its entirety. It is defined in include/mysql_com.h. The same definition is also used by the client library, which is written in C. This would exclude any possibility for NET to have any methods. However, there are a number of functions that accept NET* as an argument, which will be covered in Chapter 5.|
Member definition
|
Description
|
|---|---|
Vio* vio
|
Low-level network I/O socket descriptor. V stands for virtual. The VIO abstraction was originally created to support SSL. Now it is also used to support Windows shared memory and named pipe connections. It also facilitates cross-platform porting in many other ways.
|
unsigned char *buff
|
Start of the data buffer.
|
TABLE structure defines a database table descriptor. A table can exist in an open or closed state. In order to be used in the server, it has to be opened. Whenever this happens, a table descriptor is created, and placed in the table cache to be reused later when another request is made that references the same table.TABLE are frequently referenced in the parser, optimizer, access control, and query cache code. It glues things together in a number of ways. Studying its members is a good way to become acquainted to a degree with the low-level details of the server implementation.st_table, but then is aliased to TABLE with a typedef in sql/handler.h.TABLE was refactored, and portions of it were moved to TABLE_SHARE class, which is shared between the instances of the same physical table. TABLE_SHAREs are cached in the table definition cache.TABLE is a large structure. We will cover only the most essential parts. Table 3-3 lists some of its members.|
Member definition
|
Description
|
|---|---|
handler *file
|
Pointer to the storage engine (handler) object for this table. The object is used for all low-level data storage and retrieval operations.
|