MyISAM Record Structure .MYD file

1k Views Asked by At

I having some problems trying to read the data from the .MYD file. I'm developing a software that needs to read the data directly from the file. I managed to read properly the .frm, but I'm struggling with the .myd.

I read pretty much all the info from the internal manuals (https://dev.mysql.com/doc/internals/en/myisam.html) and I also read the Understanding MyISAM record structure

So, I am wondering, how is it possible to know which column the data belongs to. My data is mostly mediumblob using dynamic file format, and I know that there is 3 bytes for the length of the blob and then the data itself. For example, if I have 10 columns, but only 2 of those are containing data, how do we know which column contains data from the .myd file?

I'm having trouble interpreting the record header and the flags.

Thank you.

1

There are 1 best solutions below

0
AForget On

Each record contains a flag. Each flag contains bits, one for each field.

If the bit value is 0: it contains data. If the bit value is 1: it is empty.

If the table contains 15 fields, then the flags will be 2 bytes. 15 bits, one for each field, and one filling bit.

For example, if you have 8 fields and you have the flag: FA

In bits: 01111010

Based on the byte order (in my case), you have to start at the end. So, in this example, for this record, the 1st, 3rd and 8th field would contain data and the others would be empty.

Also, I found this document: https://github.com/twitter/mysql/blob/master/storage/myisam/mi_dynrec.c#L1890 quite useful. At line 1890, it shows how to read each blocktype and which blocktype contains the flag.