List:Internals« Previous MessageNext Message »
From:Timothy Smith Date:June 29 2001 12:08am
Subject:Re: question about rnd_next function
View as plain text  
On 2001 Jun 28, DAVE THOMAS <DAVET@stripped> wrote:
> What is the byte *buf variable that gets passed into this function used for?

This is where the record is stored.  You will need to take your
data, make it fit MySQL's record format, and put it into buf.
You don't need to allocate buf - buf is always pointing at a
buffer big enough to hold the record in question.

If you need to know the record format, look at how BDB or InnoDB
does it.  BDB is probably a bit simpler to follow.  Look at the
unpack_row() function - this is what takes the Berkeley DB data
and converts it into the record format that MySQL uses.

Think of it this way: each table handler obviously uses its own
internal structure for storing the data.  MySQL doesn't know
anything about it.  So there is a translation between the format
the table handler uses and the format MySQL uses.  MySQL, above
the table handler level, always uses one record format.  When you
are writing data out, you will get a buffer that is in the MySQL
record format, and you will need to call your own pack_row()
function to convert it into the table handler's format.  When you
are reading data from the handler, MySQL will pass an empty buffer
and you will need to take the data that is the table handler's
format and call unpack_row() on it, to convert it into MySQL's
format.

You'll notice in different places that there are three record
buffers (table->record[0..2]).  record[0] is the main buffer that
is used for reading and writing.  During an update, record[0]
holds the new row and record[1] holds the old row, so the handler
can write only the values that are changed.  record[2] is used as
a temporary buffer in a lot of places.


I hope that gives you something to go on.

Tim

P.S.:  Yes, this *should* be in a permanent document somewhere....
So should a lot more.  Dave, if you are keeping notes of what
you have to do to get this working, please consider writing up
a summary, or sending your notes to docs@stripped, so we can use
them as the basis for some MySQL internals documentation.  Thanks!

-- 
   __  ___     ___ ____  __
  /  |/  /_ __/ __/ __ \/ /    Tim Smith <tim@stripped>
 / /|_/ / // /\ \/ /_/ / /__   MySQL AB, Full-time Developer
/_/  /_/\_, /___/\___\_\___/   Boone, NC  USA
       <___/   www.mysql.com
Thread
question about rnd_next functionDAVE THOMAS29 Jun
  • Re: question about rnd_next functionTimothy Smith29 Jun
  • question about rnd_next functionMichael Widenius29 Jun