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

TABLE

The 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.

Instances of 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.

This structure is defined in sql/table.h as struct st_table, but then is aliased to TABLE with a typedef in sql/handler.h.

Note that in version 5.1 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.

Table 3-3. Members of the TABLE class

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.

Field **field

Array of field descriptors for each field in this table. The number of fields in the fields variable.

HASH name_hash

A hash for locating fields by name. Will be used if the number of fields is at least MAX_FIELDS_BEFORE_HASH ...

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