{"id":483,"date":"2016-09-20T19:43:08","date_gmt":"2016-09-21T00:43:08","guid":{"rendered":"http:\/\/thenoyes.com\/littlenoise\/?p=483"},"modified":"2016-10-06T11:50:23","modified_gmt":"2016-10-06T16:50:23","slug":"debugging-large-data-with-rewriter","status":"publish","type":"post","link":"https:\/\/thenoyes.com\/littlenoise\/?p=483","title":{"rendered":"Debugging Large Data with Rewriter"},"content":{"rendered":"<p>A customer showed that a particular client reported a less-than-helpful error message when it tried to display some meta-data about a table.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/thenoyes.com\/littlenoise\/wp-content\/uploads\/2016\/09\/unhandled_exception.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/thenoyes.com\/littlenoise\/wp-content\/uploads\/2016\/09\/unhandled_exception.png?resize=300%2C70&#038;ssl=1\" alt=\"A less-than-helpful error message that hints at an int.\" width=\"300\" height=\"70\" class=\"alignnone size-medium wp-image-486\" srcset=\"https:\/\/i0.wp.com\/thenoyes.com\/littlenoise\/wp-content\/uploads\/2016\/09\/unhandled_exception.png?resize=300%2C70&amp;ssl=1 300w, https:\/\/i0.wp.com\/thenoyes.com\/littlenoise\/wp-content\/uploads\/2016\/09\/unhandled_exception.png?w=515&amp;ssl=1 515w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>I couldn&#8217;t repeat the behavior with just a copy of the schema, so I suspected it was because of the size of data in the customer&#8217;s server &#8211; somebody had used an int where they needed a long.<\/p>\n<p>The customer&#8217;s data was quite large &#8211; many hundreds of GB &#8211; more than I could easily whip up on my laptop to test. But, I didn&#8217;t really need all that data, or even any data at all; I just needed MySQL to pretend it had all that data. Specifically, I needed information_schema to report a large data_length.<\/p>\n<p>Enter <a href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/rewriter-query-rewrite-plugin.html\">Rewriter<\/a>, the query rewrite plugin that ships with MySQL 5.7 and later.<\/p>\n<p>First, the general query log gave the exact query sent by the client:<\/p>\n<p><code>select * FROM information_schema.partitions WHERE TABLE_SCHEMA = 'schemaNameHere' AND TABLE_NAME = 'tableNameHere'<\/code><\/p>\n<p>Create a copy of that table:<\/p>\n<p><code>CREATE DATABASE debug_schema;<br \/>\nCREATE TABLE debug_schema.partitions LIKE information_schema.partitions;<br \/>\nINSERT INTO debug_schema.partitions SELECT * FROM information_schema.partitions;<\/code><\/p>\n<p>Adjust the copy to report a different value:<\/p>\n<p><code>UPDATE debug_schema.partitions SET data_length = POW(2, 32);<\/code><\/p>\n<p><a href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/rewriter-query-rewrite-plugin-installation.html\">Install the Rewriter plugin<\/a>, and add a rule to modify the schema name:<\/p>\n<p><code>INSERT INTO query_rewrite.rewrite_rules(pattern, replacement) VALUES (<br \/>\n\t'select * FROM <em>information_schema<\/em>.partitions WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ?',<br \/>\n\t'select * FROM <em>debug_schema<\/em>.partitions WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ?'<br \/>\n);<\/p>\n<p>CALL query_rewrite.flush_rewrite_rules();<\/code><\/p>\n<p>Now when I try the client, it thinks information_schema has reported a huge data_length, and I get the same error which my customer had reported. Success!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A customer showed that a particular client reported a less-than-helpful error message when it tried to display some meta-data about a table. I couldn&#8217;t repeat the behavior with just a copy of the schema, so I suspected it was because of the size of data in the customer&#8217;s server &#8211; somebody had used an int [&hellip;]<\/p>\n","protected":false},"author":1,"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":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4],"tags":[],"class_list":["post-483","post","type-post","status-publish","format-standard","hentry","category-mysql"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2IBF1-7N","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/posts\/483","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=483"}],"version-history":[{"count":6,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/posts\/483\/revisions"}],"predecessor-version":[{"id":492,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/posts\/483\/revisions\/492"}],"wp:attachment":[{"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=483"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=483"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=483"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}