{"id":853,"date":"2009-06-30T08:38:27","date_gmt":"2009-06-30T06:38:27","guid":{"rendered":"http:\/\/code.openark.org\/blog\/?p=853"},"modified":"2009-06-30T08:38:55","modified_gmt":"2009-06-30T06:38:55","slug":"new-and-noteworthy-in-openark-kit","status":"publish","type":"post","link":"https:\/\/code.openark.org\/blog\/mysql\/new-and-noteworthy-in-openark-kit","title":{"rendered":"New and Noteworthy in openark kit"},"content":{"rendered":"<p>A new release of <a href=\"http:\/\/code.openark.org\/forge\/openark-kit\">openark kit<\/a> is out. Some interesting additions.changes are:<\/p>\n<ul>\n<li><a href=\"http:\/\/code.openark.org\/forge\/openark-kit\/oak-online-alter-table\">oak-online-alter-table<\/a>: now works with multicolumn UNIQUE KEYs<\/li>\n<li>New: <a title=\"oka-chunk-update\" href=\"http:\/\/code.openark.org\/forge\/openark-kit\/oak-chunk-update\">oak-chunk-update<\/a>: break an long running or non indexed UPDATE\/DELETE to small chunks<\/li>\n<li><a href=\"http:\/\/code.openark.org\/forge\/openark-kit\/oak-purge-master-logs\">oak-purge-master-logs<\/a>, <a href=\"http:\/\/code.openark.org\/forge\/openark-kit\/oak-show-replication-status\">oak-show-replication-status<\/a>: support for non standard slave ports<\/li>\n<\/ul>\n<p>openark kit is a set of utilities for MySQL, helping in easing out everyday&#8217;s work. Let&#8217;s look more closely at the changes.<\/p>\n<h4>oak-online-alter-table<\/h4>\n<p>The utility allows for non-blocking ALTER TABLE operations, under certain limitations. One limitation which has been removed in the current release was the single-column UNIQUE KEY limitation. As of now, a requirement for running <strong>oak-online-alter-table<\/strong> is that the altered table has <em>some<\/em> UNIQUE KEY. It could be numerical, textual, single column, multi-column (compound), anything.<!--more--><\/p>\n<p>Other requirements:<\/p>\n<ul>\n<li>The table must not have any FOREIGN KEY association (neither parent nor child). This will be the next requirement to change. Support for child-side FOREIGN KEY will be added. At current, I do not see a solution for parent-side.<\/li>\n<li>The altered table must share a UNIQUE KEY with the original one (that is, at least one UNIQUE KEY must stay in place after altering the table).<\/li>\n<li>The table must not have any &#8216;AFTER&#8217; triggers defined. At current, I do not see a solution for that, the reason being that the utility needs to create those triggers as port of its mechanism, and that MySQL does not allow for atomic alteration of triggers. Also see <a href=\"http:\/\/code.openark.org\/blog\/mysql\/why-of-the-week\">this post<\/a>.<\/li>\n<li>Some operations, such as TRUNCATE, OPTIMIZE etc. are not permitted on the table while the utility works.<\/li>\n<\/ul>\n<p>There was need (and there still is) for many MySQL issues workarounds. I&#8217;ll update as work progresses.<\/p>\n<h4>oak-chunk-update<\/h4>\n<p>Using similar techniques to oak-online-alter-table, and requiring a UNIQUE KEY on a table, this utility allows for breaking of a long running, or a non-indexed query, into small chunks, thereby allowing for relatively non blocking UPDATE\/DELETE operations.<\/p>\n<p>For example, a <strong>DELETE FROM log WHERE log_ts &lt; &#8216;2009-01-01 00:00:00&#8217;<\/strong> might prove to be a long running query. If the log_ts column is not indexed, the table is virtually locked, whether this was MyISAM or InnoDB. Assuming an AUTO_INCREMENT column called &#8216;id&#8217; exists (any UNIQUE KEY will do, so this is just an example), we can provide the following query as argument to oak-chunk-update:<\/p>\n<blockquote>\n<pre>DELETE FROM log WHERE log_ts &lt; '2009-01-01 00:00:00' AND <strong>OAK_CHUNK(log.id)<\/strong><\/pre>\n<\/blockquote>\n<p>The utility will parse the magic token <strong>OAK_CHUNK(&#8230;)<\/strong>, and will work the query over distinct ranges, e.g.:<\/p>\n<blockquote>\n<pre>DELETE FROM log WHERE log_ts &lt; '2009-01-01 00:00:00' AND log.id &gt; 11000 AND log.id &lt;= 12000\r\nDELETE FROM log WHERE log_ts &lt; '2009-01-01 00:00:00' AND log.id &gt; 12000 AND log.id &lt;= 13000\r\netc.<\/pre>\n<\/blockquote>\n<p>While the above can also be easily solved using a simple stored procedure, the magic becomes more interesting when you have a compound UNIQUE KEY, which may have non integral columns.<\/p>\n<p>The utility also supports operations on multiple tables. Thus, one can use <strong>DELETE FROM t1 USING t1,t2&#8230;<\/strong>, for example, as long as an <strong>OAK_CHUNK(&#8230;)<\/strong> is proivded on one of the tables. It is interesting to see how the choice of table affects the chunking process.<\/p>\n<h4>oak-purge-master-logs, oak-show-replication-status<\/h4>\n<p>The two now support non default ports for slaves. This is achieved by utilizing the <strong>report_port<\/strong> parameter on the slaves, reading the value on <strong>SHOW SLAVE HOSTS<\/strong> (see <a href=\"http:\/\/code.openark.org\/blog\/mysql\/the-importance-of-report_host-report_port\">this post<\/a>). Both utilities support skipping <strong>SHOW SLAVE HOSTS<\/strong> and just picking up slaves by looking at <strong>SHOW PROCESSLIST<\/strong>.<\/p>\n<h4>Bugs<\/h4>\n<p>I&#8217;ve had issues with Google&#8217;s Issues, which made me leave a couple of unanswered issues for a couple of months. Brrrr. (BTW both were only related to prerequisites). I&#8217;ll resolve my issues issues. I&#8217;m looking forward for input, even though my spare time is little these days.<\/p>\n<h4>Acknowledgments<\/h4>\n<p>Writing of the toolkit is mostly done at my spare time, though being utilized in my professional work. Recently, a customer in urgent need has agreed for paying out for required development time on these scripts, while recognizing the open source model and license under which it is being developed and released, and removing all claims for copyright. I very much appreciate the customer&#8217;s approach and wish to acknowledge his contribution.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A new release of openark kit is out. Some interesting additions.changes are: oak-online-alter-table: now works with multicolumn UNIQUE KEYs New: oak-chunk-update: break an long running or non indexed UPDATE\/DELETE to small chunks oak-purge-master-logs, oak-show-replication-status: support for non standard slave ports openark kit is a set of utilities for MySQL, helping in easing out everyday&#8217;s work. [&hellip;]<\/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,"enabled":false},"version":2}},"categories":[5],"tags":[34],"class_list":["post-853","post","type-post","status-publish","format-standard","hentry","category-mysql","tag-openark-kit"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2bZZp-dL","_links":{"self":[{"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/posts\/853","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/comments?post=853"}],"version-history":[{"count":14,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/posts\/853\/revisions"}],"predecessor-version":[{"id":1096,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/posts\/853\/revisions\/1096"}],"wp:attachment":[{"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/media?parent=853"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/categories?post=853"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/tags?post=853"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}