MySQL Internals Files In MySQL Sources
← Back to MySQL Internals overview page
[edit] MySQL Source Code Distribution
This is a description of the files that you get when you download the source code of MySQL. This description begins with a list of the main directories and a short comment about each one. Then, for each directory, in alphabetical order, a longer description is supplied. When a directory contains significant program files, a list of each C program is given along with an explanation of its intended function.
[edit] Directory Listing
Directory Short Comment
- bdb The Berkeley Database table handler
- BitKeeper BitKeeper administration (not part of the source distribution)
- BUILD Frequently used build scripts
- client Client library
- cmd-line-utils Command-line utilities (libedit and readline)
- config Some files used during build
- dbug Fred Fish's dbug library
- Docs documentation files
- extra Some minor standalone utility programs
- heap The HEAP table handler
- include Header (*.h) files for most libraries; includes all header files distributed with the MySQL binary distribution
- innobase The Innobase (InnoDB) table handler
- libmysql For producing MySQL as a library (e.g. a Windows .DLL)
- libmysql_r For building a thread-safe libmysql library
- libmysqld The MySQL Server as an embeddable library
- man Some user-contributed manual pages
- myisam The
MyISAMtable handler - myisammrg The
MyISAMMerge table handler - mysql-test A test suite for mysqld
- mysys MySQL system library (Low level routines for file access etc.)
- ndb MySQL Cluster
- netware Files related to the Novell NetWare version of MySQL
- NEW-RPMS Directory to place RPMs while making a distribution
- os2 Routines for working with the OS/2 operating system
- pstack Process stack display (not currently used)
- regex Henry Spencer's Regular Expression library for support of REGEXP function
- SCCS Source Code Control System (not part of source distribution)
- scripts SQL batches, e.g. mysqlbug and mysql_install_db
- server-tools instance manager
- sql Programs for handling SQL commands; the "core" of MySQL
- sql-bench The MySQL benchmarks
- sql-common Some .c files related to sql directory
- SSL Secure Sockets Layer; includes an example certification one can use to test an SSL (secure) database connection
- strings Library for C string routines, e.g. atof, strchr
- support-files Files used to build MySQL on different systems
- tests Tests in Perl and in C
- tools mysqlmanager.c (tool under development, not yet useful)
- VC++Files Includes this entire directory, repeated for VC++ (Windows) use
- vio Virtual I/O Library
- zlib Data compression library, used on Windows
[edit] The bdb Directory
The Berkeley Database table handler.
The Berkeley Database (BDB) is maintained by Sleepycat Software. MySQL AB maintains only a few small patches to make BDB work better with MySQL.
The documentation for BDB is available at http://www.sleepycat.com/docs/. Since it's reasonably thorough documentation, a description of the BDB program files is not included in this document.
[edit] The BitKeeper Directory
BitKeeper administration.
Bitkeeper administration is not part of the source distribution. This directory may be present if you downloaded the MySQL source using BitKeeper rather than via the mysql.com site. The files in the BitKeeper directory are for maintenance purposes only they are not part of the MySQL package.
The MySQL Reference Manual explains how to use Bitkeeper to get the MySQL source. Please see http://www.mysql.com/doc/en/installing-source-tree.html. for more information.
[edit] The BUILD Directory
Frequently used build scripts.
This directory contains the build switches for compilation on various platforms. There is a subdirectory for each set of options. The main ones are:
- alpha
- ia64
- pentium (with and without debug or bdb, etc.)
- solaris
[edit] The client Directory
Client library.
The client library includes mysql.cc (the source of the mysql executable) and other utilities. Most of the utilities are mentioned in the MySQL Reference Manual. Generally these are standalone C programs which one runs in "client mode", that is, they call the server.
The C program files in the directory are:
- get_password.c --- ask for a password from the console
- mysql.cc --- "The MySQL command tool"
- mysqladmin.cc --- maintenance of MySQL databases
- mysqlcheck.c --- check all databases, check connect, etc.
- mysqldump.c --- dump table's contents as SQL statements, suitable to backup a MySQL database
- mysqlimport.c --- import text files in different formats into tables
- mysqlmanager-pwgen.c --- pwgen stands for "password generation" (not currently maintained)
- mysqlmanagerc.c --- entry point for mysql manager (not currently maintained)
- mysqlshow.c --- show databases, tables or columns
- mysqltest.c --- test program used by the mysql-test suite, mysql-test-run
[edit] The config Directory
Macros for use during build.
There is a single subdirectory: \ac-macros. All the files in it have the extension .m4, which is a normal expectation of the GNU autoconf tool.
[edit] The cmd-line-utils Directory
Command-line utilities (libedit and readline).
There are two subdirectories: \readline and \libedit. All the files here are "non-MySQL" files, in the sense that MySQL AB didn't produce them, it just uses them. It should be unnecessary to study the programs in these files unless you are writing or debugging a tty-like client for MySQL, such as mysql.exe.
The \readline subdirectory contains the files of the GNU Readline Library, "a library for reading lines of text with interactive input and history editing". The programs are copyrighted by the Free Software Foundation.
The \libedit (library of edit functions) subdirectory has files written by Christos Zoulas. They are distributed and modifed under the BSD License. These files are for editing the line contents.
These are the program files in the \libedit subdirectory:
- chared.c --- character editor
- common.c --- common editor functions
- el.c --- editline interface functions
- emacs.c --- emacs functions
- fgetln.c --- get line
- hist.c --- history access functions
- history.c --- more history access functions
- key.c --- procedures for maintaining the extended-key map
- map.c --- editor function definitions
- parse.c --- parse an editline extended command
- prompt.c --- prompt printing functions
- read.c --- terminal read functions
- readline.c --- read line
- refresh.c --- "lower level screen refreshing functions"
- search.c --- "history and character search functions"
- sig.c --- for signal handling
- strlcpy.c --- string copy
- term.c --- "editor/termcap-curses interface"
- tokenizer.c --- Bourne shell line tokenizer
- tty.c --- for a tty interface
- unvis.c --- reverse effect of vis.c
- vi.c --- commands used when in the vi (editor) mode
- vis.c --- encode characters
[edit] The dbug Directory
Fred Fish's dbug library.
This is not really part of the MySQL package. Rather, it's a set of public-domain routines which are useful for debugging MySQL programs. The MySQL Server and all .c and .cc programs support the use of this package.
How it works: One inserts a function call that begins with DBUG_* in one of the regular MYSQL programs. For example, in get_password.c, you will find this line:
DBUG_ENTER("get_tty_password");
at the start of a routine, and this line:
DBUG_RETURN(my_strdup(to,MYF(MY_FAE)));
at the end of the routine. These lines don't affect production code. Features of the dbug library include extensive reporting and profiling (the latter has not been used by the MySQL team).
The C programs in this directory are:
- dbug.c --- The main module
- dbug_analyze.c --- Reads a file produced by trace functions
- example1.c --- A tiny example
- example2.c --- A tiny example
- example3.c --- A tiny example
- factorial.c --- A tiny example
- main.c --- A tiny example
- my_main.c --- MySQL-specific main.c variant
- sanity.c --- Declaration of a variable
[edit] The Docs Directory
With the BitKeeper downloads, /Docs is nearly empty. Binary and source distributions include some pre-formatted documentation files, such as the MySQL Reference manual in Info format (for Unix) or CHM format (for Windows).
[edit] The extra Directory
Some minor standalone utility programs.
These programs are all standalone utilities, that is, they have a main() function and their main role is to show information that the MySQL server needs or produces. Most are unimportant. They are as follows:
- charset2html.c --- checks your browser's character set
- comp_err.c --- makes error-message files from a multi-language source
- my_print_defaults.c --- print parameters from my.ini files. Can also be used in scripts to enable processing of my.ini files.
- mysql_waitpid.c --- wait for a program to terminate. Useful for shell scripts when one needs to wait until a process terminates.
- perror.c --- "print error" --- given error number, display message
- replace.c --- replace strings in text files or pipe
- resolve_stack_dump.c --- show symbolic information from a MySQL stack dump, normally found in the mysql.err file
- resolveip.c --- convert an IP address to a hostname, or vice versa
[edit] The heap Directory
The HEAP (MEMORY) table handler.
All the MySQL table handlers (i.e. the handlers that MySQL itself produces) have files with similar names and functions. Thus, this (heap) directory contains a lot of duplication of the myisam directory (for the MyISAM table handler). Such duplicates have been marked with an "*" in the following list. For example, you will find that \heap\hp_extra.c has a close equivalent in the myisam directory (\myisam\mi_extra.c) with the same descriptive comment. (Some of the differences arise because HEAP has different structures. HEAP does not need to use the sort of B-tree indexing that ISAM and MyISAM use; instead there is a hash index. Most importantly, HEAP is entirely in memory. File-I/O routines lose some of their vitality in such a context.)
- hp_block.c --- Read/write a block (i.e. a page)
- hp_clear.c --- Remove all records in the table
- hp_close.c --- * close database
- hp_create.c --- * create a table
- hp_delete.c --- * delete a row
- hp_extra.c --- * for setting options and buffer sizes when optimizing
- hp_hash.c --- Hash functions used for saving keys
- hp_info.c --- * Information about database status
- hp_open.c --- * open database
- hp_panic.c --- * the hp_panic routine, for shutdowns and flushes
- hp_rename.c --- * rename a table
- hp_rfirst.c --- * read first row through a specific key (very short)
- hp_rkey.c --- * read record using a key
- hp_rlast.c --- * read last row with same key as previously-read row
- hp_rnext.c --- * read next row with same key as previously-read row
- hp_rprev.c --- * read previous row with same key as previously-read row
- hp_rrnd.c --- * read a row based on position
- hp_rsame.c --- * find current row using positional read or key-based read
- hp_scan.c --- * read all rows sequentially
- hp_static.c --- * static variables (very short)
- hp_test1.c --- * testing basic functions
- hp_test2.c --- * testing database and storing results
- hp_update.c --- * update an existing row
- hp_write.c --- * insert a new row
There are fewer files in the heap directory than in the myisam directory, because fewer are necessary. For example, there is no need for a \myisam\mi_cache.c equivalent (to cache reads) or a \myisam\mi_log.c equivalent (to log statements).
[edit] The include Directory
Header (*.h) files for most libraries; includes all header files distributed with the MySQL binary distribution.
These files may be included in C program files. Note that each individual directory will also have its own *.h files, for including in its own *.c programs. The *.h files in the include directory are ones that might be included from more than one place.
For example, the mysys directory contains a C file named rijndael.c, but does not include rijndael.h. The include directory contains rijndael.h. Looking further, you'll find that rijndael.h is also included in other places: by my_aes.c and my_aes.h.
The include directory contains 55 *.h (header) files.
[edit] The innobase Directory
The Innobase (InnoDB) table handler.
A full description of these files can be found elsewhere in this document.
[edit] The libmysql Directory
The MySQL Library, Part 1.
The files here are for producing MySQL as a library (e.g. a Windows DLL). The idea is that, instead of producing separate mysql (client) and mysqld (server) programs, one produces a library. Instead of sending messages, the client part merely calls the server part.
The libmysql files are split into three directories: libmysql (this one), libmysql_r (the next one), and libmysqld (the next one after that).
The "library of mysql" has some client-connection modules. For example, as described in an earlier section of this manual, there is a discussion of libmysql/libmysql.c which sends packets from the client to the server. Many of the entries in the libmysql directory (and in the following libmysqld directory) are 'symlinks' on Linux, that is, they are in fact pointers to files in other directories.
The program files on this directory are:
- conf_to_src.c --- has to do with charsets
- dll.c --- initialization of the dll library
- errmsg.c --- English error messages, compare \mysys\errors.c
- get_password.c --- get password
- libmysql.c --- the code that implements the MySQL API, i.e. the functions a client that wants to connect to MySQL will call
- manager.c --- initialize/connect/fetch with MySQL manager
[edit] The libmysql_r Directory
The MySQL Library, Part 2.
There is only one file here, used to build a thread-safe libmysql library:
- makefile.am
[edit] The libmysqld Directory
The MySQL library, Part 3.
The Embedded MySQL Server Library. The product of libmysqld is not a client/server affair, but a library. There is a wrapper to emulate the client calls. The program files on this directory are:
- libmysqld.c --- The called side, compare the mysqld.exe source
- lib_sql.c --- Emulate the vio directory's communication buffer
[edit] The man Directory
Some user-contributed manual pages
These are user-contributed "man" (manual) pages in a special markup format. The format is described in a document with a heading like "man page for man" or "macros to format man pages" which you can find in a Linux directory or on the Internet.
[edit] The myisam Directory
The MyISAM table handler.
The C files in this subdirectory come in six main groups:
- ft*.c files --- ft stands for "Full Text", code contributed by Sergei Golubchik
- mi*.c files --- mi stands for "My Isam", these are the main programs for Myisam
- myisam*.c files --- for example, "myisamchk" utility routine functions source
- rt*.c files --- rt stands for "rtree", some code was written by Alexander Barkov
- sp*.c files --- sp stands for "spatial", some code was written by Ramil Kalimullin
- sort.c --- this is a single file that sorts keys for index-create purposes
The "full text" and "rtree" and "spatial" program sets are for special purposes, so this document focuses only on the mi*.c "myisam" C programs. They are:
- mi_cache.c --- for reading records from a cache
- mi_changed.c --- a single routine for setting a "changed" flag (very short)
- mi_check.c --- for checking and repairing tables. Used by the myisamchk program and by the MySQL server.
- mi_checksum.c --- calculates a checksum for a row
- mi_close.c --- close database
- mi_create.c --- create a table
- mi_dbug.c --- support routines for use with "dbug" (see \dbug description)
- mi_delete.c --- delete a row
- mi_delete_all.c --- delete all rows
- mi_delete_table.c --- delete a table (very short)
- mi_dynrec.c --- functions to handle space-packed records and blobs
- mi_extra.c --- setting options and buffer sizes when optimizing
- mi_info.c --- return useful base information for an open table
- mi_key.c --- for handling keys
- mi_keycache.c --- for handling key caches
- mi_locking.c --- lock database
- mi_log.c --- save commands in a log file which myisamlog program can read. Can be used to exactly replay a set of changes to a table.
- mi_open.c --- open database
- mi_packrec.c --- read from a data file compressed with myisampack
- mi_page.c --- read and write pages containing keys
- mi_panic.c --- the mi_panic routine, probably for sudden shutdowns
- mi_preload.c --- preload indexes into key cache
- mi_range.c --- approximate count of how many records lie between two keys
- mi_rename.c --- rename a table
- mi_rfirst.c --- read first row through a specific key (very short)
- mi_rkey.c --- read a record using a key
- mi_rlast.c --- read last row with same key as previously-read row
- mi_rnext.c --- read next row with same key as previously-read row
- mi_rnext_same.c --- same as mi_rnext.c, but abort if the key changes
- mi_rprev.c --- read previous row with same key as previously-read row
- mi_rrnd.c --- read a row based on position
- mi_rsame.c --- find current row using positional read or key-based read
- mi_rsamepos.c --- positional read
- mi_scan.c --- read all rows sequentially
- mi_search.c --- key-handling functions
- mi_static.c --- static variables (very short)
- mi_statrec.c --- functions to handle fixed-length records
- mi_test1.c --- testing basic functions
- mi_test2.c --- testing database and storing results
- mi_test3.c --- testing locking
- mi_unique.c --- functions to check if a row is unique
- mi_update.c --- update an existing row
- mi_write.c --- insert a new row
[edit] The myisammrg Directory
MyISAM Merge table handler.
As with other table handlers, you'll find that the *.c files in the myissammrg directory have counterparts in the myisam directory. In fact, this general description of a myisammrg program is almost always true: The myisammrg function checks an argument, the myisammrg function formulates an expression for passing to a myisam function, the myisammrg calls a myisam function, the myisammrg function returns.
These are the 22 files in the myisammrg directory, with notes about the myisam functions or programs they're connected with:
- myrg_close.c --- mi_close.c
- myrg_create.c --- mi_create.c
- myrg_delete.c --- mi_delete.c / delete last-read record
- myrg_extra.c --- mi_extra.c / "extra functions we want to do ..."
- myrg_info.c --- mi_info.c / display information about a mymerge file
- myrg_locking.c --- mi_locking.c / lock databases
- myrg_open.c --- mi_open.c / open a
MyISAMMERGEtable - myrg_panic.c --- mi_panic.c / close in a hurry
- myrg_queue.c --- read record based on a key
- myrg_range.c --- mi_range.c / find records in a range
- myrg_rfirst.c --- mi_rfirst.c / read first record according to specific key
- myrg_rkey.c --- mi_rkey.c / read record based on a key
- myrg_rlast.c --- mi_rlast.c / read last row with same key as previous read
- myrg_rnext.c --- mi_rnext.c / read next row with same key as previous read
- myrg_rnext_same.c --- mi_rnext_same.c / read next row with same key
- myrg_rprev.c --- mi_rprev.c / read previous row with same key
- myrg_rrnd.c --- mi_rrnd.c / read record with random access
- myrg_rsame.c --- mi_rsame.c / call mi_rsame function, see \myisam\mi_rsame.c
- myrg_static.c --- mi_static.c / static variable declaration
- myrg_update.c --- mi_update.c / call mi_update function, see \myisam\mi_update.c
- myrg_write.c --- mi_write.c / call mi_write function, see \myisam\mi_write.c
[edit] The mysql-test Directory
A test suite for mysqld.
The directory has a README file which explains how to run the tests, how to make new tests (in files with the filename extension *.test), and how to report errors.
There are four subdirectories:
- \misc --- contains one minor Perl program
- \ndb --- for MySQL Cluster tests
- \r --- contains *.result, i.e. "what happened" files and *.required, i.e. "what should happen" file
- \std_data --- contains standard data for input to tests
- \t --- contains tests
There are 400 *.test files in the \t subdirectory. Primarily these are SQL scripts which try out a feature, output a result, and compare the result with what's required. Some samples of what the test files check are: latin1_de comparisons, date additions, the HAVING clause, outer joins, openSSL, load data, logging, truncate, and UNION.
There are other tests in these directories:
- sql-bench
- tests
[edit] The mysys Directory
MySQL system library. Low level routines for file access and so on.
There are 125 *.c programs in this directory:
- array.c --- Dynamic array handling
- charset.c --- Using dynamic character sets, set default character set, ...
- charset-def.c --- Include character sets in the client using
- checksum.c --- Calculate checksum for a memory block, used for pack_isam
- default.c --- Find defaults from *.cnf or *.ini files
- default_modify.c --- edit option file
- errors.c --- English text of global errors
- hash.c --- Hash search/compare/free functions "for saving keys"
- list.c --- Double-linked lists
- make-conf.c --- "Make a charset .conf file out of a ctype-charset.c file"
- md5.c --- MD5 ("Message Digest 5") algorithm from RSA Data Security
- mf_brkhant.c --- Prevent user from doing a Break during critical execution (not used in MySQL; can be used by standalone
MyISAMapplications) - mf_cache.c --- "Open a temporary file and cache it with io_cache"
- mf_dirname.c --- Parse/convert directory names
- mf_fn_ext.c --- Get filename extension
- mf_format.c --- Format a filename
- mf_getdate.c --- Get date, return in yyyy-mm-dd hh:mm:ss format
- mf_iocache.c --- Cached read/write of files in fixed-size units
- mf_iocache2.c --- Continuation of mf_iocache.c
- mf_keycache.c --- Key block caching for certain file types
- mf_keycaches.c --- Handling of multiple key caches
- mf_loadpath.c --- Return full path name (no ..\ stuff)
- mf_pack.c --- Packing/unpacking directory names for create purposes
- mf_path.c --- Determine where a program can find its files
- mf_qsort.c --- Quicksort
- mf_qsort2.c --- Quicksort, part 2 (allows the passing of an extra argument to the sort-compare routine)
- mf_radix.c --- Radix sort
- mf_same.c --- Determine whether filenames are the same
- mf_sort.c --- Sort with choice of Quicksort or Radix sort
- mf_soundex.c --- Soundex algorithm derived from EDN Nov. 14, 1985 (pg. 36)
- mf_strip.c --- Strip trail spaces from a string
- mf_tempdir.c --- Initialize/find/free temporary directory
- mf_tempfile.c --- Create a temporary file
- mf_unixpath.c --- Convert filename to UNIX-style filename
- mf_util.c --- Routines, #ifdef'd, which may be missing on some machines
- mf_wcomp.c --- Comparisons with wildcards
- mf_wfile.c --- Finding files with wildcards
- mulalloc.c --- Malloc many pointers at the same time
- my_access.c --- Check if file or path is accessible
- my_aes.c --- AES encryption
- my_alarm.c --- Set a variable value when an alarm is received
- my_alloc.c --- malloc of results which will be freed simultaneously
- my_append.c --- one file to another
- my_bit.c --- smallest X where 2^X >= value, maybe useful for divisions
- my_bitmap.c --- Handle uchar arrays as large bitmaps
- my_chsize.c --- Truncate file if shorter, else fill with a filler character
- my_clock.c --- Time-of-day ("clock()") function, with OS-dependent #ifdef's
- my_compress.c --- Compress packet (see also description of \zlib directory)
- my_copy.c --- Copy files
- my_crc32.c --- Include \zlib\crc32.c
- my_create.c --- Create file
- my_delete.c --- Delete file
- my_div.c --- Get file's name
- my_dup.c --- Open a duplicated file
- my_error.c --- Return formatted error to user
- my_file.c --- See how many open files we want
- my_fopen.c --- File open
- my_fstream.c --- Streaming file read/write
- my_gethostbyname.c --- Thread-safe version of standard net gethostbyname() func
- my_gethwaddr.c --- Get hardware address for an interface
- my_getopt.c --- Find out what options are in effect
- my_getsystime.c --- Time-of-day functions, portably
- my_getwd.c --- Get working directory
- my_handler.c --- Compare two keys in various possible formats
- my_init.c --- Initialize variables and functions in the mysys library
- my_largepage.c --- Gets the size of large pages from the OS
- my_lib.c --- Compare/convert directory names and file names
- my_lock.c --- Lock part of a file
- my_lockmem.c --- "Allocate a block of locked memory"
- my_lread.c --- Read a specified number of bytes from a file into memory
- my_lwrite.c --- Write a specified number of bytes from memory into a file
- my_malloc.c --- Malloc (memory allocate) and dup functions
- my_messnc.c --- Put out a message on stderr with "no curses"
- my_mkdir.c --- Make directory
- my_mmap.c --- Memory mapping
- my_net.c --- Thread-safe version of net inet_ntoa function
- my_netware.c --- Functions used only with the Novell Netware version of MySQL
- my_once.c --- Allocation / duplication for "things we don't need to free"
- my_open.c --- Open a file
- my_os2cond.c --- OS2-specific: "A simple implementation of posix conditions"
- my_os2dirsrch.c --- OS2-specific: Emulate a Win32 directory search
- my_os2dlfcn.c --- OS2-specific: Emulate UNIX dynamic loading
- my_os2file64.c --- OS2-specific: For File64bit setting
- my_os2mutex.c --- OS2-specific: For mutex handling
- my_os2thread.c --- OS2-specific: For thread handling
- my_os2tls.c --- OS2-specific: For thread-local storage
- my_port.c --- OS/machine-dependent porting functions, e.g. AIX-specific my_ulonglong2double()
- my_pread.c --- Read a specified number of bytes from a file
- my_pthread.c --- A wrapper for thread-handling functions in different OSs
- my_quick.c --- Read/write (labeled a "quicker" interface, perhaps obsolete)
- my_read.c --- Read a specified number of bytes from a file, possibly retry
- my_realloc.c --- Reallocate memory allocated with my_alloc.c (probably)
- my_redel.c --- Rename and delete file
- my_rename.c --- Rename without delete
- my_seek.c --- Seek, i.e. point to a spot within a file
- my_semaphore.c --- Semaphore routines, for use on OS that doesn't support them
- my_sleep.c --- Wait n microseconds
- my_static.c --- Static variables used by the mysys library
- my_symlink.c --- Read a symbolic link (symlinks are a UNIX thing, I guess)
- my_symlink2.c --- Part 2 of my_symlink.c
- my_sync.c --- Sync data in file to disk
- my_thr_init.c --- initialize/allocate "all mysys & debug thread variables"
- my_wincond.c --- Windows-specific: emulate Posix conditions
- my_windac.c --- Windows NT/2000 discretionary access control functions
- my_winsem.c --- Windows-specific: emulate Posix threads
- my_winthread.c --- Windows-specific: emulate Posix threads
- my_write.c --- Write a specified number of bytes to a file
- ptr_cmp.c --- Point to an optimal byte-comparison function
- queues.c --- Handle priority queues as in Robert Sedgewick's book
- raid2.c --- RAID support (the true implementation is in raid.cc)
- rijndael.c --- "Optimized ANSI C code for the Rijndael cipher (now AES")
- safemalloc.c --- A version of the standard malloc() with safety checking
- sha1.c --- Implementation of Secure Hashing Algorithm 1
- string.c --- Initialize/append/free dynamically-sized strings; see also sql_string.cc in the /sql directory
- testhash.c --- Standalone program: test the hash library routines
- test_charset.c --- Standalone program: display character set information
- test_dir.c --- Standalone program: placeholder for "test all functions" idea
- test_fn.c --- Standalone program: apparently tests a function
- test_xml.c --- Standalone program: test XML routines
- thr_alarm.c --- Thread alarms and signal handling
- thr_lock.c --- "Read and write locks for Posix threads"
- thr_mutex.c --- A wrapper for mutex functions
- thr_rwlock.c --- Synchronizes the readers' thread locks with the writer's lock
- tree.c --- Initialize/search/free binary trees
- typelib.c --- Find a string in a set of strings; returns the offset to the string found
You can find documentation for the main functions in these files elsewhere in this document. For example, the main functions in my_getwd.c are described thus:
"int my_getwd _A((string buf, uint size, myf MyFlags));
int my_setwd _A((const char *dir, myf MyFlags));
Get and set working directory."
[edit] The ndb Directory
The ndb (MySQL Cluster) source code.
MySQL's shared-nothing in-memory feature is practically a DBMS by itself. We generally use the term "ndb" when referring to the storage engine, and the term "MySQL Cluster" when referring to the combination of the storage engine and the rest of the MySQL facilities.
The sub-directories within ndb are:
- bin --- Two script files
- config --- Files needed for building
- demos --- Demonstration scripts
- docs --- A doxygen output and a .txt file
- home --- Some scripts and .pl files
- include --- The .h files
- lib --- empty
- ndbapi-examples --- Examples for the API
- src --- The .cpp files
- test --- Files for testing
- tools --- Programs for testing select, drop, and so on
[edit] The netware Directory
Files related to the Novell NetWare version of MySQL.
There are 43 files on this directory. Most have filename extensions of *.def, *.sql, or *.c.
The twenty-eight *.def files are all from Novell Inc. They contain import or export symbols. (.def is a common filename extension for "definition".)
The three *.sql files are short scripts of SQL statements used in testing.
These are the five *.c files, all from Novell Inc.:
- libmysqlmain.c --- Only one function: init_available_charsets()
- my_manage.c --- Standalone management utility
- mysql_install_db.c --- Compare \scripts\mysql_install_db.sh
- mysql_test_run.c --- Short test program
- mysqld_safe.c --- Compare \scripts\mysqld_safe.sh
Perhaps the most important files are:
- netware/BUILD/*patch --- NetWare-specific build instructions and switches (compare the files in the BUILD directory)
For instructions about basic installation, see "Deployment Guide For NetWare AMP" at: http://developer.novell.com/ndk/whitepapers/namp.htm
[edit] The NEW-RPMS Directory
Directory to place RPMs while making a distribution.
This directory is not part of the Windows distribution. It is a temporary directory used during RPM builds with Linux distributions. You only see it after you've done a "build".
[edit] The os2 Directory
Routines for working with the OS2 operating system.
The files in this directory are the product of the efforts of three people from outside MySQL: Yuri Dario, Timo Maier, and John M Alfredsson. There are no .C program files in this directory.
The contents of \os2 are:
- A Readme.Txt file
- An \include subdirectory containing .h files which are for OS/2 only
- Files used in the build process (configuration, switches, and one .obj)
The README file refers to MySQL version 3.23, which suggests that there have been no updates for MySQL 4.0 for this section.
[edit] The pstack Directory
Process stack display (not currently used).
This is a set of publicly-available debugging aids which all do pretty well the same thing: display the contents of the stack, along with symbolic information, for a running process. There are versions for various object file formats (such as ELF and IEEE-695). Most of the programs are copyrighted by the Free Software Foundation and are marked as "part of GNU Binutils".
In other words, the pstack files are not really part of the MySQL library. They are merely useful when you re-program some MYSQL code and it crashes.
[edit] The regex Directory
Henry Spencer's Regular Expression library for support of REGEXP function.
This is the copyrighted product of Henry Spencer from the University of Toronto. It's a fairly-well-known implementation of the requirements of POSIX 1003.2 Section 2.8. The library is bundled with Apache and is the default implementation for regular-expression handling in BSD Unix. MySQL's Monty Widenius has made minor changes in three programs (debug.c, engine.c, regexec.c) but this is not a MySQL package. MySQL calls it only in order to support two MySQL functions: REGEXP and RLIKE.
Some of Mr Spencer's documentation for the regex library can be found in the README and WHATSNEW files.
One MySQL program which uses regex is \cmd-line-utils\libedit\search.c
This program calls the 'regcomp' function, which is the entry point in \regex\regexp.c.
[edit] The SCCS Directory
Source Code Control System (not part of source distribution).
You will see this directory if and only if you used BitKeeper for downloading the source. The files here are for BitKeeper administration and are not of interest to application programmers.
[edit] The scripts Directory
SQL batches, e.g. mysqlbug and mysql_install_db.
The *.sh filename extension stands for "shell script". Linux programmers use it where Windows programmers would use a *.bat (batch filename extension).
Some of the *.sh files on this directory are:
- fill_help_tables.sh --- Create help-information tables and insert
- make_binary_distribution.sh --- Get configure information, make, produce tar
- msql2mysql.sh --- Convert (partly) mSQL programs and scripts to MySQL
- mysqlbug.sh --- Create a bug report and mail it
- mysqld_multi.sh --- Start/stop any number of mysqld instances
- mysqld_safe-watch.sh --- Start/restart in safe mode
- mysqld_safe.sh --- Start/restart in safe mode
- mysqldumpslow.sh --- Parse and summarize the slow query log
- mysqlhotcopy.sh --- Hot backup
- mysql_config.sh --- Get configuration information that might be needed to compile a client
- mysql_convert_table_format.sh --- Conversion, e.g. from
ISAMtoMyISAM - mysql_explain_log.sh --- Put a log (made with
--log) into a MySQL table - mysql_find_rows.sh --- Search for queries containing
<regexp> - mysql_fix_extensions.sh --- Renames some file extensions, not recommended
- mysql_fix_privilege_tables.sh --- Fix
mysql.useretc. when upgrading. Can be safely run during any upgrade to get the newest MySQL privilege tables - mysql_install_db.sh --- Create privilege tables and func table
- mysql_secure_installation.sh --- Disallow remote root login, eliminate test, etc.
- mysql_setpermission.sh --- Aid to add users or databases, sets privileges
- mysql_tableinfo.sh --- Puts info re MySQL tables into a MySQL table
- mysql_zap.sh --- Kill processes that match pattern
[edit] The server-tools Directory
The instance manager.
Quoting from the README file within this directory: "Instance Manager - manage MySQL instances locally and remotely. File description: mysqlmanager.cc - entry point to the manager, main, options.{h,cc} - handle startup options. manager.{h,cc} - manager process. mysql_connection.{h,cc} - handle one connection with mysql client. See also instance manager architecture description in mysqlmanager.cc.
[edit] The sql Directory
Programs for handling SQL commands. The "core" of MySQL.
These are the .c and .cc files in the sql directory:
- derror.cc --- read language-dependent message file
- des_key_file.cc --- load DES keys from plaintext file
- discover.cc --- Functions for discovery of frm file from handler
- field.cc --- "implement classes defined in
field.h" (long); defines all storage methods MySQL uses to store field information into records that are then passed to handlers - field_conv.cc --- functions to copy data between fields
- filesort.cc --- sort a result set, using memory or temporary files
- frm_crypt.cc --- contains only one short function:
get_crypt_for_frm - gen_lex_hash.cc --- Knuth's algorithm from Vol 3 Sorting and Searching, SQL keywords in a query
- gstream.cc --- GTextReadStream, used to read GIS objects
- handler.cc --- handler-calling functions
- hash_filo.cc --- static-sized hash tables, used to store info like hostname -> ip tables in a FIFO manner
- ha_berkeley.cc --- Handler: BDB
- ha_blackhole.cc --- Handler: Black Hole
- ha_federated.cc --- Handler: Federated
- ha_heap.cc --- Handler: Heap
- ha_innodb.cc --- Handler: InnoDB
- ha_myisam.cc --- Handler: MyISAM
- ha_myisammrg.cc --- Handler: (MyISAM MERGE)
- ha_ndbcluster.cc --- Handler: NDB
- hostname.cc --- Given IP, return hostname
- init.cc --- Init and dummy functions for interface with unireg
- item.cc --- Item functions
- item_buff.cc --- Buffers to save and compare item values
- item_cmpfunc.cc --- Definition of all compare functions
- item_create.cc --- Create an item. Used by
lex.h. - item_func.cc --- Numerical functions
- item_geofunc.cc --- Geometry functions
- item_row.cc --- Row items for comparing rows and for
INon rows - item_strfunc.cc --- String functions
- item_subselect.cc --- Subqueries
- item_sum.cc --- Set functions (
SUM(),AVG(), etc.) - item_strfunc.cc --- String functions
- item_subselect.cc --- Item subquery
- item_timefunc.cc --- Date/time functions, e.g. week of year
- item_uniq.cc --- Empty file, here for compatibility reasons
- key.cc --- Functions to create keys from records and compare a key to a key in a record
- lock.cc --- Locks
- log.cc --- Logs
- log_event.cc --- Log event (a binary log consists of a stream of log events)
- matherr.c --- Handling overflow, underflow, etc.
- mf_iocache.cc --- Caching of (sequential) reads and writes
- mysqld.cc --- Source for
mysqld.exe; includes themain()program that startsmysqld, handling of signals and connections - mf_decimal.cc --- New decimal and numeric code
- my_lock.c --- Lock part of a file (like
/mysys/my_lock.c, but with timeout handling for threads) - net_serv.cc --- Read/write of packets on a network socket
- nt_servc.cc --- Initialize/register/remove an NT service
- opt_range.cc --- Range of keys
- opt_sum.cc --- Optimize functions in presence of (implied)
GROUP BY - parse_file.cc --- Text .frm files management routines
- password.c --- Password checking
- procedure.cc --- Procedure interface, as used in
SELECT * FROM Table_name PROCEDURE ANALYSE() - protocol.cc --- Low level functions for PACKING data that is sent to client; actual sending done with
net_serv.cc - protocol_cursor.cc --- Low level functions for storing data to be sent to the MySQL client
- records.cc --- Functions for easy reading of records, possible through a cache
- repl_failsafe.cc --- Replication fail-save (not yet implemented)
- set_var.cc --- Set and retrieve MySQL user variables
- slave.cc --- Procedures for a slave in a master/slave (replication) relation
- sp.cc --- DB storage of stored procedures and functions
- sp_cache.cc --- For stored procedures
- sp_head.cc --- For stored procedures
- sp_pcontext.cc --- For stored procedures
- sp_rcontext.cc --- For stored procedures
- spatial.cc --- Geometry stuff (lines, points, etc.)
- sql_acl.cc --- Functions related to ACL security; checks, stores, retrieves, and deletes MySQL user level privileges
- sql_analyse.cc --- Implements the
PROCEDURE ANALYSE(), which analyzes a query result and returns the 'optimal' data type for each result column - sql_base.cc --- Basic functions needed by many modules, like opening and closing tables with table cache management
- sql_cache.cc --- SQL query cache, with long comments about how caching works
- sql_class.cc --- SQL class; implements the SQL base classes, of which THD (THREAD object) is the most important
- sql_client.cc --- A function called by my_net_init() to set some check variables
- sql_crypt.cc --- Encode / decode, very short
- sql_db.cc --- Create / drop database
- sql_delete.cc --- The
DELETEstatement - sql_derived.cc --- Derived tables, with long comments
- sql_do.cc --- The
DOstatement - sql_error.cc --- Errors and warnings
- sql_handler.cc --- Implements the
HANDLERinterface, which gives direct access to rows inMyISAMandInnoDB - sql_help.cc --- The
HELPstatement - sql_insert.cc --- The
INSERTstatement - sql_lex.cc --- Does lexical analysis of a query; i.e. breaks a query string into pieces and determines the basic type (number, string, keyword, etc.) of each piece
- sql_list.cc --- Only list_node_end_of_list, short (the rest of the list class is implemented in
sql_list.h) - sql_load.cc --- The
LOAD DATAstatement - sql_manager.cc --- Maintenance tasks, e.g. flushing the buffers periodically; used with
BDBtable logs - sql_map.cc --- Memory-mapped files (not yet in use)
- sql_olap.cc ---
ROLLUP - sql_parse.cc --- Parse an SQL statement; do initial checks and then jump to the function that should execute the statement
- sql_prepare.cc --- Prepare an SQL statement, or use a prepared statement
- sql_rename.cc --- Rename table
- sql_repl.cc --- Replication
- sql_select.cc --- Select and join optimization
- sql_show.cc --- The
SHOWstatement - sql_state.c --- Functions to map mysqld errno to sqlstate
- sql_string.cc --- String functions: alloc, realloc, copy, convert, etc.
- sql_table.cc --- The
DROP TABLEandALTER TABLEstatements - sql_test.cc --- Some debugging information
- sql_trigger.cc --- Triggers
- sql_udf.cc --- User-defined functions
- sql_union.cc --- The
UNIONoperator - sql_update.cc --- The
UPDATEstatement - sql_view.cc --- Views
- stacktrace.c --- Display stack trace (Linux/Intel only)
- strfunc.cc --- String functions
- table.cc --- Table metadata retrieval; read the table definition from a
.frmfile and store it in a TABLE object - thr_malloc.cc --- Thread-safe interface to
/mysys/my_alloc.c - time.cc --- Date and time functions
- udf_example.cc --- Example file of user-defined functions
- uniques.cc --- Function to handle quick removal of duplicates
- unireg.cc --- Create a unireg form file (.frm) from a
FIELDand field-info struct
[edit] The sql-bench Directory
The MySQL Benchmarks.
This directory has the programs and input files which MySQL uses for its comparisons of MySQL, PostgreSQL, mSQL, Solid, etc. Since MySQL publishes the comparative results, it's only right that it should make available all the material necessary to reproduce all the tests.
There are five subdirectories and sub-subdirectories:
- \Comments --- Comments about results from tests of Access, Adabas, etc.
- \Data\ATIS ---
.txtfiles containing input data for the "ATIS" tests - \Data\Wisconsin ---
.txtfiles containing input data for the "Wisconsin" tests - \Results --- old test results
- \Results-win32 --- old test results from Windows 32-bit tests
There are twenty-four *.sh (shell script) files, which involve Perl programs.
There are three *.bat (batch) files.
There is one README file and one TODO file.
[edit] The sql-common Directory
Three files: client.c, my_time.c, pack.c. You will file symlinks to these files in other directories.
[edit] The SSL Directory
Secure Sockets Layer; includes an example certification one can use test an SSL (secure) database connection.
This isn't a code directory. It contains a short note from Tonu Samuel (the NOTES file) and seven *.pem files. PEM stands for "Privacy Enhanced Mail" and is an Internet standard for adding security to electronic mail. Finally, there are two short scripts for running clients and servers over SSL connections.
[edit] The strings Directory
The string library.
Many of the files in this subdirectory are equivalent to well-known functions that appear in most C string libraries. For those, there is documentation available in most compiler handbooks.
On the other hand, some of the files are MySQL additions or improvements. Often the MySQL changes are attempts to optimize the standard libraries. It doesn't seem that anyone tried to optimize for recent Pentium class processors, though.
The .C files are:
- bchange.c --- short replacement routine written by Monty Widenius in 1987
- bcmp.c --- binary compare, rarely used
- bcopy-duff.c --- block copy: attempt to copy memory blocks faster than cmemcpy
- bfill.c --- byte fill, to fill a buffer with (length) copies of a byte
- bmove.c --- block move
- bmove512.c --- "should be the fastest way to move a multiple of 512 bytes"
- bmove_upp.c --- bmove.c variant, starting with last byte
- bzero.c --- something like bfill with an argument of 0
- conf_to_src.c --- reading a configuration file
- ctype*.c --- string handling programs for each char type MySQL handles
- decimal.c --- for decimal and numeric conversions
- do_ctype.c --- display case-conversion and sort-conversion tables
- dump_map.c --- standalone file
- int2str.c --- integer-to-string
- is_prefix.c --- checks whether string1 starts with string2
- llstr.c --- convert long long to temporary-buffer string, return pointer
- longlong2str.c --- ditto, but to argument-buffer
- memcmp.c --- memory compare
- memcpy.c --- memory copy
- memset.c --- memory set
- my_strtoll10.c --- longlong2str for radix 10
- my_vsnprintf.c --- variant of printf
- r_strinstr.c --- see if one string is within another
- str2int.c --- convert string to integer
- strappend.c --- fill up a string to n characters
- strcat.c --- concatenate strings
- strcend.c --- point to where a character C occurs within str, or NULL
- strchr.c --- point to first place in string where character occurs
- strcmp.c --- compare two strings
- strcont.c --- point to where any one of a set of characters appears
- strend.c --- point to the '\0' byte which terminates str
- strfill.c --- fill a string with n copies of a byte
- strinstr.c --- find string within string
- strlen.c --- return length of string in bytes
- strmake.c --- create new string from old string with fixed length, append end \0 if needed
- strmov.c --- move source to dest and return pointer to end
- strnlen.c --- return min(length of string, n)
- strnmov.c --- move source to dest for source size, or for n bytes
- strrchr.c --- find a character within string, searching from end
- strstr.c --- find an instance of pattern within source
- strto.c --- string to long, to long long, to unsigned long, etc.
- strtod.c --- string to double
- strtol.c --- string to long
- strtoll.c --- string to long long
- strtoul.c --- string to unsigned long
- strtoull.c --- string to unsigned long long
- strxmov.c --- move a series of concatenated source strings to dest
- strxnmov.c --- like strxmov.c but with a maximum length n
- str_test.c --- test of all the string functions encoded in assembler
- uca-dump.c --- shows unicode collation algorithm dump
- udiv.c --- unsigned long divide, for operating systems that don't support these
- utr11-dump.c --- dump east Asian wide text file
- xml.c --- read and parse XML strings; used to read character definition information stored in /sql/share/charsets
There are also four .ASM files --- macros.asm, ptr_cmp.asm, strings.asm, and strxmov.asm --- which can replace some of the C-program functions. But again, they look like optimizations for old members of the Intel processor family.
[edit] The support-files Directory
Files used to build MySQL on different systems.
The files here are for building ("making") MySQL given a package manager, compiler, linker, and other build tools. The support files provide instructions and switches for the build processes. They include example my.cnf files one can use as a default setup for MySQL.
[edit] The tests Directory
Tests in Perl and in C.
The files in this directory are test programs that can be used as a base to write a program to simulate problems in MySQL in various scenarios: forks, locks, big records, exporting, truncating, and so on. Some examples are:
- connect_test.c --- test that a connect is possible
- insert_test.c --- test that an insert is possible
- list_test.c --- test that a select is possible
- select_test.c --- test that a select is possible
- showdb_test.c --- test that a show-databases is possible
- ssl_test.c --- test that SSL is possible
- thread_test.c --- test that threading is possible
[edit] The tools Directory
Tools --- well, actually, one tool.
The only file is:
- mysqlmanager.c --- A "server management daemon" by Sasha Pachev. This is a tool under development and is not yet useful. Related to fail-safe replication.
[edit] The VC++Files Directory
Visual C++ Files.
Includes this entire directory, repeated for VC++ (Windows) use.
VC++Files includes a complete environment to compile MySQL with the VC++ compiler. To use it, just copy the files on this directory; the make_win_src_distribution.sh script uses these files to create a Windows source installation.
This directory has subdirectories which are copies of the main directories. For example, there is a subdirectory \VC++Files\heap, which has the Microsoft developer studio project file to compile \heap with VC++. So for a description of the files in \VC++Files\heap, see the description of the files in \heap. The same applies for almost all of VC++Files's subdirectories (bdb, client, isam, libmysql, etc.). The difference is that the \VC++Files variants are specifically for compilation with Microsoft Visual C++ in 32-bit Windows environments.
In addition to the "subdirectories which are duplicates of directories", VC++Files contains these subdirectories, which are not duplicates:
- comp_err --- (nearly empty)
- contrib --- (nearly empty)
- InstallShield --- script files
- isamchk --- (nearly empty)
- libmysqltest --- one small non-MySQL test program: mytest.c
- myisamchk --- (nearly empty)
- myisamlog --- (nearly empty)
- myisammrg --- (nearly empty)
- mysqlbinlog --- (nearly empty)
- mysqlmanager --- MFC foundation class files created by AppWizard
- mysqlserver --- (nearly empty)
- mysqlshutdown --- one short program, mysqlshutdown.c
- mysqlwatch.c --- Windows service initialization and monitoring
- my_print_defaults --- (nearly empty)
- pack_isam --- (nearly empty)
- perror --- (nearly empty)
- prepare --- (nearly empty)
- replace --- (nearly empty)
- SCCS --- source code control system
- test1 --- tests connecting via X threads
- thr_insert_test --- (nearly empty)
- thr_test --- one short program used to test for memory-allocation bug
- winmysqladmin --- the winmysqladmin.exe source
The "nearly empty" subdirectories noted above (e.g. comp_err and isamchk) are needed because VC++ requires one directory per project (i.e. executable). We are trying to keep to the MySQL standard source layout and compile only to different directories.
[edit] The vio Directory
Virtual I/O Library.
The VIO routines are wrappers for the various network I/O calls that happen with different protocols. The idea is that in the main modules one won't have to write separate bits of code for each protocol. Thus vio's purpose is somewhat like the purpose of Microsoft's winsock library.
The underlying protocols at this moment are: TCP/IP, Named Pipes (for WindowsNT), Shared Memory, and Secure Sockets (SSL).
The C programs are:
- test-ssl.c --- Short standalone test program: SSL
- test-sslclient.c --- Short standalone test program: clients
- test-sslserver.c --- Short standalone test program: server
- vio.c --- Declarations + open/close functions
- viosocket.c --- Send/retrieve functions
- viossl.c --- SSL variations for the above
- viosslfactories.c --- Certification / Verification
- viotest.cc --- Short standalone test program: general
- viotest-ssl.c --- Short standalone test program: SSL
- viotest-sslconnect.cc --- Short standalone test program: SSL connect
The older functions --- raw_net_read, raw_net_write --- are now obsolete.
[edit] The zlib Directory
Data compression library, used on Windows.
zlib is a data compression library used to support the compressed protocol and the COMPRESS/UNCOMPRESS functions under Windows. On Unix, MySQL uses the system libgz.a library for this purpose.
Zlib --- which presumably stands for "Zip Library" --- is not a MySQL package. It was produced by the GNU Zip (gzip.org) people. Zlib is a variation of the famous "Lempel-Ziv" method, which is also used by "Zip". The method for reducing the size of any arbitrary string of bytes is as follows:
- Find a substring which occurs twice in the string.
- Replace the second occurrence of the substring with (a) a pointer to the first occurrence, plus (b) an indication of the length of the first occurrence.
There is a full description of the library's functions in the gzip manual at http://www.gzip.org/zlib/manual.html. There is therefore no need to list the modules in this document.
The MySQL program \mysys\my_compress.c uses zlib for packet compression. The client sends messages to the server which are compressed by zlib. See also: \sql\net_serv.cc.