Spec-Zone .ru
спецификации, руководства, описания, API

14.2.9.7. Internals of the InnoDB memcached Plugin

This section explains the details of the underlying tables used by the InnoDB / memcached plugin.

The configuration script installs 3 tables needed by the InnoDB memcached. These tables are created in a dedicated database innodb_memcache:

mysql> use innodb_memcache;Database changedmysql> show tables;+---------------------------+| Tables_in_innodb_memcache |+---------------------------+| cache_policies            || config_options            || containers                |+---------------------------+3 rows in set (0.01 sec)

The tables are:

containers - This table is the most important table for the memcached daemon. It describes the table or tables used to store the memcached values. You must make changes to this table to start using the memcached interface with one or more of your own tables, rather than just experimenting with the test.demo_test table.

The mapping is done through specifying corresponding column values in the table:

mysql> desc containers;+------------------------+--------------+------+-----+---------+-------+| Field                  | Type         | Null | Key | Default | Extra |+------------------------+--------------+------+-----+---------+-------+| name                   | varchar(50)  | NO   | PRI | NULL    |       || db_schema              | varchar(250) | NO   |     | NULL    |       || db_table               | varchar(250) | NO   |     | NULL    |       || key_columns            | varchar(250) | NO   |     | NULL    |       || value_columns          | varchar(250) | YES  |     | NULL    |       || flags                  | varchar(250) | NO   |     | 0       |       || cas_column             | varchar(250) | YES  |     | NULL    |       || expire_time_column     | varchar(250) | YES  |     | NULL    |       || unique_idx_name_on_key | varchar(250) | NO   |     | NULL    |       |+------------------------+--------------+------+-----+---------+-------+9 rows in set (0.02 sec)

The above 5 column values (table name, key column, value column and index) must be supplied. Otherwise, the setup will fail.

Although the following values are optional, they are needed for full compliance with the memcached protocol:

Table cache_policies specifies whether to use InnoDB as the data store of memcached (innodb_only), or to use the traditional memcached engine as the backstore (cache-only), or both (caching). In the last case, if memcached cannot find a key in memory, it searches for the value in an InnoDB table.

Table config_options stores memcached-related settings that are appropriate to change at runtime, through SQL. Currently, MySQL supports the following configuration options through this table:

separator: The separator used to separate values of a long string into smaller values for multiple columns values. By default, this is the | character. For example, if you defined col1, col2 as value columns, And you define | as separator, you could issue the following command in memcached to insert values into col1 and col2 respectively:

set keyx 10 0 19valuecolx|valuecoly

So valuecol1x is stored in col1 and valuecoly is stored in col2.

table_map_delimiter: The character separating the schema name and the table name when you use the @@ notation in a key name to access a key in a specific table. For example, @@t1.some_key and @@t2.some_key have the same key value, but are stored in different tables and so do not conflict.

Example Tables

Finally, the configuration script creates a table demo_test in the test database as an example. It also allows the Daemon Memcached to work immediately, without creating any additional tables.

The entries in the container table define which column is used for what purpose as described above:

mysql> select * from innodb_memcache.containers;+------+-----------+-----------+-------------+---------------+-------+------------+--------------------+------------------------+| name | db_schema | db_table  | key_columns | value_columns | flags | cas_column | expire_time_column | unique_idx_name_on_key |+------+-----------+-----------+-------------+---------------+-------+------------+--------------------+------------------------+| aaa  | test      | demo_test | c1          | c2            | c3    | c4         | c5                 | PRIMARY                |+------+-----------+-----------+-------------+---------------+-------+------------+--------------------+------------------------+1 row in set (0.00 sec)mysql> desc test.demo_test;+-------+---------------------+------+-----+---------+-------+| Field | Type                | Null | Key | Default | Extra |+-------+---------------------+------+-----+---------+-------+| c1    | varchar(32)         | NO   | PRI |         |       || c2    | varchar(1024)       | YES  |     | NULL    |       || c3    | int(11)             | YES  |     | NULL    |       || c4    | bigint(20) unsigned | YES  |     | NULL    |       || c5    | int(11)             | YES  |     | NULL    |       |+-------+---------------------+------+-----+---------+-------+5 rows in set (0.01 sec)

When no table ID is requested through the @@ notation in the key name: