Databases Reference
In-Depth Information
Recalling the table from Chapter 8 , Storage Engine Plugins , we see that:
• The tables of the TOCAB engine are not transactional
• Any "sequential table scan" means a random disk access anyway, the
optimizer should not assume that sequential table access is much faster than
random
• MySQL should use the position() method to obtain the position
NULL values in indexes are supported
• The number of records that the info() method provides is exact,
not approximate
• Our engine supports indexes over BLOB fields
• An auto-increment column does not need to be at the beginning of the key
• In the keyread optimization the primary key columns are always included no
matter what index is selected
• Our engine expects a primary key to exist in all tables
The last requirement is not very user friendly. Most other engines that need a
primary key, such as InnoDB, do not force a user to specify it, but generate a hidden
primary key automatically, if necessary. However, for simplicity, we will require the
end user to create a primary key explicitly—when HA_REQUIRE_PRIMARY_KEY flag is
set the CREATE TABLE statement will fail if no primary key is present.
Creating, opening, and closing the table
To open a table in a Tokyo Cabinet one needs to create a new handle with tcbdbnew()
and actually open a file with tcbdbopen() . Before opening, one can prepare the handle
for multi-threaded use with tcbdbsetmutex() , set a custom comparison function with
tcbdbsetcmpfunc() , and set various tuning parameters with tcbdbtune() . MySQL
is multi-threaded, so we will use that handle concurrently, and, of course, we will
need our comparison function, but we won't do any tuning in our example. There is
no special function to create a Tokyo Cabinet file, it is created by opening. That is, both
ha_tocab::open() and ha_tocab::create() will open a Tokyo Cabinet file, and we
can factor out this functionality in a helper function:
static TCBDB *open_tcdb(const char *name, TABLE *table,
int *error)
{
char fname[FN_REFLEN+10];
strcpy(fname, name);
strcat(fname, ".tocab");
*error = 0;
 
Search WWH ::




Custom Search