Databases Reference
In-Depth Information
What's left
Not much. We need to know when to use the keyread optimization. MySQL tells
it using the HA_EXTRA_KEYREAD hint. The extra() method is used by MySQL
to give various hints to the engine that are safe to ignore. In other words, this
method is completely optional. In our case, though, we are interested in the keyread
optimization hint:
int ha_tocab::extra(enum ha_extra_function hint)
{
if (hint == HA_EXTRA_KEYREAD)
keyread=true;
if (hint == HA_EXTRA_NO_KEYREAD)
keyread=false;
return 0;
}
In table_flags() we had the HA_STATS_RECORDS_IS_EXACT flag, that is, we need
to return the exact number of records in stats.records . On a unique constraint
violation we need to tell MySQL what index has caused the failure. The method
info() is used for both purposes:
int ha_tocab::info(uint flag)
{
if (flag & HA_STATUS_VARIABLE)
stats.records = tcbdbrnum(share->dbh) / table->s->keys;
if (flag & HA_STATUS_ERRKEY)
errkey = last_key;
return 0;
}
When optimizing, MySQL uses the records_in_range() method to get an estimate
for a number of records that fall into a certain range of values for a given key inx .
These estimates are used to choose the best query execution plan, for example, the
range with the least number of records. Unfortunately, the Tokyo Cabinet API does
not provide a way of obtaining this estimate. We could traverse the index from the
lower to the upper range limits and count keys, but this method would be too slow
if the range contains, say, many millions of keys. It is not too difficult to add this
feature to Tokyo Cabinet, but for the purpose of this example, we will just return a
fixed number, because we do not know better:
ha_rows ha_tocab::records_in_range(uint inx,
key_range *min_key,
key_range *max_key)
{
return 10;
}
 
Search WWH ::




Custom Search