Documentation Home
MySQL Internals Manual
Download this Manual
EPUB - 0.8Mb

MySQL Internals Manual  /  ...  /  Implementing the info(uinf flag) Method

22.10.4 Implementing the info(uinf flag) Method

Prior to commencing a table scan, the [custom-engine.html#custom-engine-api-reference-info info()] method is called to provide extra table information to the optimizer.

The information required by the optimizer is not given through return values but instead by populating certain properties of the stats member of the handler class, which the optimizer reads after the info() call returns. The stats member is an instance of the ha_statistics class which is also defined in handler.h

In addition to being used by the optimizer, many of the values set during a call to the info() method are also used for the SHOW TABLE STATUS statement. The flag argument is a bitfield that conveys for which context the info method was called.

The flags are defined in include/my_base.h. The ones that are used are:

  • HA_STATUS_NO_LOCK - the handler may use outdated info if it can prevent locking the table shared

  • HA_STATUS_TIME - only update of stats->update_time required

  • HA_STATUS_CONST - update the immutable members of stats (max_data_file_length, max_index_file_length, create_time, sortkey, ref_length, block_size, data_file_name, index_file_name)

  • HA_STATUS_VARIABLE - records, deleted, data_file_length, index_file_length, delete_length, check_time, mean_rec_length

  • HA_STATUS_ERRKEY - status pertaining to last error key (errkey and dupp_ref)

  • HA_STATUS_AUTO - update autoincrement value

The public properties are listed in full in sql/handler.h; several of the more common ones are copied here:

ulonglong data_file_length;      /* Length off data file */
ulonglong max_data_file_length;  /* Length off data file */
ulonglong index_file_length;
ulonglong max_index_file_length;
ulonglong delete_length;         /* Free bytes */
ulonglong auto_increment_value;
ha_rows records;                 /* Records in table */
ha_rows deleted;                 /* Deleted records */
ulong raid_chunksize;
ulong mean_rec_length;           /* physical reclength */
time_t create_time;              /* When table was created */
time_t check_time;
time_t update_time;

For the purposes of a table scan, the most important property is records, which indicates the number of records in the table. The optimizer will perform differently when the storage engine indicates that there are zero or one rows in the table than it will when there are two or more. For this reason it is important to return a value of two or greater when you do not actually know how many rows are in the table before you perform the table scan (such as in a situation where the data may be externally populated).

The bare minimum implementation for the info method is probably something like what is used for the CSV (tina) engine:

int ha_tina::info(uint flag)
   /* This is a lie, but you don't want the optimizer to see zero or 1 */
   if (!records_is_known && stats.records < 2) 
     stats.records= 2;

Download this Manual
EPUB - 0.8Mb
User Comments
Sign Up Login You must be logged in to post a comment.