Can you Trust CHECK TABLE ?

PREVIOUS POST
NEXT POST

Take a look at this:

The sort order is obviously wrong while CHECK TABLE is not reporting any error

Why ? Because CHECK TABLE only looks at MyISAM data and Index files and it does not compare information in these to table definition (.frm file)

In this particular case I replaced .frm file for the table from different one changing INT to UNSIGNED INT to see what effect it will give – as you can see you get quite funny table which is considered OK by CHECK TABLE, which does store values larger than max signed int but which sorts them as unsigned ints. Quite fun.

I hope the task of fixing this is somewhere on MySQL roadmap :)

PREVIOUS POST
NEXT POST

Comments

  1. kissimmee vacation homes says

    I wanted to thank you for this excellent read!! I definitely loved every little bit of it.Cheers for the info!!!! & This is the perfect blog for anyone who wants to know about this topic. You know so much its almost hard to argue with you ………
    thanks

  2. says

    Harmut,

    I remember I ran into this 4-5 years ago when I was still with MySQL and it was described as product feature.
    Though now it is the time to fix it I think – especially as there will be more and more meta data which will need to be tested. For example Global foreign keys with MyISAM – how do you check they are in order if there is no such command. What if you add CHECK constrains ?

  3. Pat says

    How’s check table even going to if there’s an error here w/o carrying a second copy of the metadata in the MYD file? Seems like he can only reasonably be expected to compare the data in the MYD with the data in the FRM and if they look consistent all is well.

    If you spoof the metadata like this, I think that qualifies as an event the product can’t reasonably be expected to recover from. Like going out and deleting the binary log from the file system and then opening a bug that replication is broken.

  4. says

    You can detect this situation to some extent by having some kind of hash of the frm in the myd/myi files. On the other hand, you can always break systems by messing directly with their internal files, so I wouldn’t argue that this is as important as perhaps providing tools for managing rollback/restore of these files as a group. Or just telling you not to do that sort of thing :-)

  5. says

    Pat,

    Actually there IS a second copy of meta data in MYI files…. which can be checked against what is in .frm files but it is not. This is artificial example of course but believe me I’ve seen mismatching .frm files from MYI/MYD files many times. In particular for MyISAM – because this is table type which is advertised as being possible to move around… so people do it. Not always correctly.

    The example with replication is wrong. If you delete the binary log file from the system replication will complain just as you would expect. If you trash binary log it may not… though it is common complain too what checksums are missing in binary logs.

Leave a Reply

Your email address will not be published. Required fields are marked *