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