I am trying to understand how MyISAM physically store its records and how it maintains its structure after record insertion and record deletion. I have read the following link:
I want to make sure if I understand it correctly, please correct me if it is not right.
Fixed-sized record
- Delete marker determines whether record is deleted or not deleted.
- Record header holds which column of a row contains NULL value
- The length of data is fixed.
Variable-sized record
- Delete marker is replaced with BLOCK_DELETED block type
- Record header holds length of data and length of unused data
- A single record can be seperated into multiple block connected by overflow pointer.
Deletion
- For variable-sized record, change block type to BLOCK_DELETED
- Maintain double linked-list of all deleted record by having the previous pointer of the newly deleted record points to last deleted record. Then, the last deleted record's next pointer points to the newly deleted record.
- For fixed-sized record, simply change delete marker as deleted. (unsure if they use double linked-list to connect all the deleted record with fixed-sized record)
Insertion
- If there is no unused space (deleted records), append the data at the end of the file
- If there is unused space that fits the newly inserted record, write the new record there.
- If there is unused space that is far bigger than newly inserted record, split into two records: the new record and the deleted record.
- If there is unused space that is smaller than newly inserted record, write data there, have overflow pointer to points to the unfitted data at other block.
Updating
- What if users update existed data with longer data? Will MyISAM marked the record as deleted and find place that fits the new data or simply use overflow pointer to point to unfitted data?
Recap the question again
I want to make sure if I understand it correctly, please correct me if it is not right.
Additional questions
- Would it be very inefficient if the table has been deleted and inserted for many times since the record structure could potentially full of overflow pointers and unused space?
OPTIMIZE TABLE
every now and then. – Nb