{"id":1262,"date":"2008-11-22T10:00:47","date_gmt":"2008-11-22T00:00:47","guid":{"rendered":"http:\/\/www.flamingspork.com\/blog\/?p=1262"},"modified":"2009-02-21T13:34:05","modified_gmt":"2009-02-21T03:34:05","slug":"drop-table-fail-on-the-road-to-removing-the-frm","status":"publish","type":"post","link":"https:\/\/www.flamingspork.com\/blog\/2008\/11\/22\/drop-table-fail-on-the-road-to-removing-the-frm\/","title":{"rendered":"drop table fail (on the road to removing the FRM)"},"content":{"rendered":"<p>So&#8230; in removing the FRM file in Drizzle, I found a bit of a nugget on how drop table works (currently in the MySQL server and now &#8220;did&#8221; in Drizzle).<\/p>\n<p>If you DROP TABLE t1; this is what happens<\/p>\n<ul>\n<li>open the .frm file<\/li>\n<li>read first 10bytes (oh, and if you get EIO there, in a SELECT * FROM INFORMATION_SCHEMA.TABLES you&#8217;ll get &#8220;Error&#8221; instead of &#8220;Base Table&#8221;)<\/li>\n<li>if (header[0] != (unsigned char) 254 || header[1] != 1 ||<br \/>\n(header[2] != FRM_VER &amp;&amp; header[2] != FRM_VER+1 &amp;&amp;<br \/>\n(header[2] &lt; FRM_VER+3 || header[2] &gt; FRM_VER+4)))<br \/>\nreturn true;<br \/>\nWhich means that you probably (well, should have) set your enum legacy_db_type to DB_TYPE_UNKNOWN in the caller of bool mysql_frm_type(Session *, char *path, enum legacy_db_type *dbt) otherwise you end up in some form of pain.<\/li>\n<li>Else, *dbt= (enum legacy_db_type) (uint) *(header + 3);<br \/>\nreturn true;\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \/\/ Is probably a .frm table<\/li>\n<\/ul>\n<p>I do like the &#8220;probably&#8221;.<\/p>\n<p>Oh, and on a &#8220;storage engine api&#8221; front, some places seem to expect handler::delete_table(const char* name) to return ENOENT on table not existing. In reality however:<\/p>\n<ul>\n<li> int ha_heap::delete_table(const char *name)<br \/>\n{<br \/>\n-\u00c2\u00a0 int error= heap_delete_table(name);<br \/>\n-\u00c2\u00a0 return error == ENOENT ? 0 : error;<br \/>\n+\u00c2\u00a0 return heap_delete_table(name);<br \/>\n}<\/li>\n<li>InnoDB (note the behaviour of returning DB_TABLE_NOT_FOUND&#8230; which isn&#8217;t ENOENT)<br \/>\nerr = DB_TABLE_NOT_FOUND;<br \/>\nut_print_timestamp(stderr);<\/p>\n<p>fputs(&#8220;\u00c2\u00a0 InnoDB: Error: table &#8220;, stderr);<br \/>\nut_print_name(stderr, trx, TRUE, name);<br \/>\nfputs(&#8221; does not exist in the InnoDB internaln&#8221;<br \/>\n&#8220;InnoDB: data dictionary though MySQL is&#8221;<br \/>\n&#8221; trying to drop it.n&#8221;<br \/>\n&#8220;InnoDB: Have you copied the .frm file&#8221;<br \/>\n&#8221; of the table to then&#8221;<br \/>\n&#8220;InnoDB: MySQL database directory&#8221;<br \/>\n&#8221; from another database?n&#8221;<br \/>\n&#8220;InnoDB: You can look for further help fromn&#8221;<br \/>\n&#8220;InnoDB: http:\/\/dev.mysql.com\/doc\/refman\/5.1\/en\/&#8221;<br \/>\n&#8220;innodb-troubleshooting.htmln&#8221;,<br \/>\nstderr);<\/li>\n<li>and MyISAM would generate the error message itself, but that&#8217;s fixed with:<br \/>\n-\u00c2\u00a0 if (my_delete_with_symlink(from, MYF(MY_WME)))<br \/>\n+\u00c2\u00a0 if (my_delete_with_symlink(from, 0))<br \/>\nreturn(my_errno);<\/li>\n<\/ul>\n<p>and just to add to the fun, elsewhere in the code, a access(2) call on the frm file name is used to determine if the table exists or not.<\/p>\n<p>The road to removing the FRM has all sorts of these weird-ass things along it. Kinda nice to be able to replace this with something better (and, hopefully &#8211; good).<\/p>\n<p>But let me sum up with sql_table.cc:<\/p>\n<p>&#8220;This code is wrong and will be removed, please do not copy.&#8221;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So&#8230; in removing the FRM file in Drizzle, I found a bit of a nugget on how drop table works (currently in the MySQL server and now &#8220;did&#8221; in Drizzle). If you DROP TABLE t1; this is what happens open &hellip; <a href=\"https:\/\/www.flamingspork.com\/blog\/2008\/11\/22\/drop-table-fail-on-the-road-to-removing-the-frm\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[75,14],"tags":[70,87],"class_list":["post-1262","post","type-post","status-publish","format-standard","hentry","category-drizzle-work-et-al","category-mysql","tag-drizzle","tag-frm"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p5a6n8-km","jetpack-related-posts":[{"id":2041,"url":"https:\/\/www.flamingspork.com\/blog\/2010\/06\/29\/enum-now-works-properly-in-drizzle\/","url_meta":{"origin":1262,"position":0},"title":"ENUM now works properly (in Drizzle)","author":"Stewart Smith","date":"2010-06-29","format":false,"excerpt":"Over at the Drizzle blog, the recent 2010-06-07 tarball was announced. This tarball release has my fixes for the ENUM type, so that it now works as it should. I was quite amazed that such a small block of code could have so many bugs! One of the most interesting\u2026","rel":"","context":"In &quot;drizzle&quot;","block_context":{"text":"drizzle","link":"https:\/\/www.flamingspork.com\/blog\/category\/work-et-al\/drizzle-work-et-al\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":4180,"url":"https:\/\/www.flamingspork.com\/blog\/2016\/09\/27\/mysql-removes-the-frm-7-years-after-drizzle-did\/","url_meta":{"origin":1262,"position":1},"title":"MySQL removes the FRM (7 years after Drizzle did)","author":"Stewart Smith","date":"2016-09-27","format":false,"excerpt":"The new MySQL 8.0.0 milestone release that was recently announced brings something that has been a looooong time coming: the removal of the FRM file. I was the one who implemented this in Drizzle way back in 2009 (July 28th 2009 according to Brian)- and I may have had a\u2026","rel":"","context":"In &quot;code&quot;","block_context":{"text":"code","link":"https:\/\/www.flamingspork.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2036,"url":"https:\/\/www.flamingspork.com\/blog\/2010\/06\/03\/new-create-table-performance-record\/","url_meta":{"origin":1262,"position":2},"title":"New CREATE TABLE performance record!","author":"Stewart Smith","date":"2010-06-03","format":false,"excerpt":"\u00ef\u00bb\u00bf\u00ef\u00bb\u00bf4 min 20 sec So next time somebody complains about NDB taking a long time in CREATE TABLE, you're welcome to point them to this :) A single CREATE TABLE statement It had ONE column It was an ENUM column. With 70,000 possible values. It was 605kb of SQL. It\u2026","rel":"","context":"In &quot;drizzle&quot;","block_context":{"text":"drizzle","link":"https:\/\/www.flamingspork.com\/blog\/category\/work-et-al\/drizzle-work-et-al\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2323,"url":"https:\/\/www.flamingspork.com\/blog\/2011\/03\/17\/things-ive-done-in-drizzle\/","url_meta":{"origin":1262,"position":3},"title":"Things I&#8217;ve done in Drizzle","author":"Stewart Smith","date":"2011-03-17","format":false,"excerpt":"When writing my Dropping ACID: Eating Data in a Web 2.0 Cloud World talk for LCA2011 I came to the realisation that I had forgotten a lot of the things I had worked on in MySQL and MySQL Cluster. So, as a bit of a retrospective as part of the\u2026","rel":"","context":"In &quot;drizzle&quot;","block_context":{"text":"drizzle","link":"https:\/\/www.flamingspork.com\/blog\/category\/work-et-al\/drizzle-work-et-al\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1390,"url":"https:\/\/www.flamingspork.com\/blog\/2009\/02\/15\/the-frm-file-format\/","url_meta":{"origin":1262,"position":4},"title":"The FRM file format","author":"Stewart Smith","date":"2009-02-15","format":false,"excerpt":"It's fortunate that I'm watching Veronica Mars again with a mate; a more-than-you-think amount of detective work is required to understand the relationship (and format) of the TABLE_SHARE, the FRM file and HA_CREATE_INFO. Oh, also you'll need drizzled\/base.h and drizzled\/structs.h and drizzled\/table_share.h is also a good one to have open.\u2026","rel":"","context":"In &quot;drizzle&quot;","block_context":{"text":"drizzle","link":"https:\/\/www.flamingspork.com\/blog\/category\/work-et-al\/drizzle-work-et-al\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1745,"url":"https:\/\/www.flamingspork.com\/blog\/2009\/12\/09\/drizzle-frm-replacement-the-table-proto\/","url_meta":{"origin":1262,"position":5},"title":"Drizzle FRM replacement: the table proto","author":"Stewart Smith","date":"2009-12-09","format":false,"excerpt":"Drizzle originally inherited the FRM file from MySQL (which inherited it from UNIREG). The FRM file stores metadata about a table; what columns it has, what type those columns are, what indexes, any default values, comments etc are all stored in the FRM. In the days of MyISAM, this worked\u2026","rel":"","context":"In &quot;drizzle&quot;","block_context":{"text":"drizzle","link":"https:\/\/www.flamingspork.com\/blog\/category\/work-et-al\/drizzle-work-et-al\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.flamingspork.com\/blog\/wp-json\/wp\/v2\/posts\/1262","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.flamingspork.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.flamingspork.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.flamingspork.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.flamingspork.com\/blog\/wp-json\/wp\/v2\/comments?post=1262"}],"version-history":[{"count":3,"href":"https:\/\/www.flamingspork.com\/blog\/wp-json\/wp\/v2\/posts\/1262\/revisions"}],"predecessor-version":[{"id":1453,"href":"https:\/\/www.flamingspork.com\/blog\/wp-json\/wp\/v2\/posts\/1262\/revisions\/1453"}],"wp:attachment":[{"href":"https:\/\/www.flamingspork.com\/blog\/wp-json\/wp\/v2\/media?parent=1262"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.flamingspork.com\/blog\/wp-json\/wp\/v2\/categories?post=1262"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.flamingspork.com\/blog\/wp-json\/wp\/v2\/tags?post=1262"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}