In addition to table scanning, storage engines can implement
methods for non-sequential reading. (Note: this is not "can" but
rather a "must" because certain operations rely on proper
implementation of position() and
rnd_pos() calls. Two examples of such
operations are multi-table UPDATE and SELECT ..
table.blob_column ORDER BY something). The MySQL server
uses these methods for certain sort operations.
The [custom-engine.html#custom-engine-api-reference-position
position()] method is called after every call
to rnd_next() if the data needs to be
reordered:
void ha_foo::position(const byte *record)
It stores a "position" of a record in
this->ref. The contents of this "position"
is up to you, whatever value you provide will be returned in a
later call to retrieve the row. The only rule - "position" or a
row must contain enough information to allow you later to
retrieve this very row. Most storage engines will store some
form of offset or a primary key value.
The [custom-engine.html#custom-engine-api-reference-rnd_pos
rnd_pos()] method behaves in a similar
fashion to the rnd_next() method but takes an
additional parameter:
int ha_foo::rnd_pos(byte * buf, byte *pos)
The *pos parameter contains positioning
information previously recorded using the
position() method.
A storage engine must locate the row specified by the position
and return it through *buf in the internal
MySQL row format.
