The 'auto_increment' is actually a very quick hack. It does as
follows:
Just before doing a 'write' to a table, the 'handler' code does the
following:
- If there is a auto_increment field and the value of this is zero
- Set the table in 'read_only_keys' mode.
- Do a 'read_last' key on the table.
- Update the 'auto_increment' field with the found value+1.
- Set the table in 'normal' mode.
I didn't want to change the .ISM format when I added 'auto_increment'
and there is some issues that the above can handle much better than
with any other methods. For example:
- The above is very simple and one can always 'understand' what will happen.
There is no need to have special commands to reset a 'wrong'
auto_increment value.
- If one accidently inserts some wrong entries, one only have to remove the
entry and auto_increment continues as expected.
- One can start a new series by simple insert a new record at a new
bigger range.
The downside with this is:
- If one deletes the last record and inserts a new one will get the
last records id. As long as one first deletes all 'sub records' in
other tables this isn't really a problem.
- One can't start with a specific value without some simple hack.
Personally I think that the 'pro' is far better than the 'cons'
Monty
Bookmarks