{"id":2256,"date":"2012-02-05T04:59:23","date_gmt":"2012-02-05T09:59:23","guid":{"rendered":"http:\/\/www.bytebot.net\/blog\/?p=2256"},"modified":"2012-02-05T06:31:05","modified_gmt":"2012-02-05T11:31:05","slug":"mariadb-5-3-query-optimizer-by-sergey-petrunia","status":"publish","type":"post","link":"http:\/\/www.bytebot.net\/blog\/archives\/2012\/02\/05\/mariadb-5-3-query-optimizer-by-sergey-petrunia","title":{"rendered":"MariaDB 5.3 query optimizer by Sergey Petrunia"},"content":{"rendered":"<p><a href=\"http:\/\/s.petrunia.net\/blog\/\">Sergey Petrunia<\/a> of the <a href=\"http:\/\/mariadb.org\/\">MariaDB<\/a> project.<\/p>\n<p>What exactly is not working in MySQL? MySQL is poor at decision support\/analytics. With large datasets you need special disk access strategies. Complex queries like insufficient subquery support and big joins are common int he MySQL world.<\/p>\n<p>DBT-3 is used, scale=30, with a 75GB database and run a query &#8220;average price of item between a range of dates&#8221;. Query time took some 45 minutes to execute. Why? Run iostat -x to see what is going on. See that the CPU is mostly idle, so its an IO-bound load. Next you run SHOW ENGINE INNODB STATUS and you&#8217;ll see how many reads per second is happening. Possible solution is to get more RAM or get an SSD (good to speedup OLTP workloads, but analytics over data is probably not viable since SSDs are small and not cheap).<\/p>\n<p>The MySQL\/MariaDB solution to the above problem is improved disk access strategies: <a href=\"http:\/\/kb.askmonty.org\/en\/multi-range-read-optimization\">multi-range read (MRR)<\/a> and batched key access (BKA). In MariaDB, MRR\/BKA need to be enabled (they are not turned on by default). The query time only took 3 minutes 48 seconds, which is some 11.8x faster than the previous 45 minutes.If you look at EXPLAIN output, its almost as same as before, expect the Extra filed. iostat -x will now show some CPU load, svctm down as well (so its not random disk seeks anymore &#8212; some 8ms seek time on a regular 7,200rpm disk), SHOW ENGINE INNODB STATUS will show some 10,000 reads per second rather than the previous 200.<\/p>\n<p>If you are on Fedora, check out the Systemtap feature to look at I\/O patterns. stap <a href=\"http:\/\/sourceware.org\/systemtap\/examples\/io\/deviceseeks.stp\">deviceseeks.stp<\/a> -c &#8220;sleep 60&#8221;.<\/p>\n<p>Subqueries handling in MariaDB 5.3: check out the <a href=\"http:\/\/kb.askmonty.org\/en\/subquery-optimizations-map\">Subquery Optimizations Map<\/a>. Only about 10% of the audience use optimizer hints in MySQL.<\/p>\n<div class=\"sharedaddy sd-sharing-enabled\"><div class=\"robots-nocontent sd-block sd-social sd-social-icon-text sd-sharing\"><h3 class=\"sd-title\">Share this:<\/h3><div class=\"sd-content\"><ul><li class=\"share-email\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"\" class=\"share-email sd-button share-icon\" href=\"mailto:?subject=%5BShared%20Post%5D%20MariaDB%205.3%20query%20optimizer%20by%20Sergey%20Petrunia&body=http%3A%2F%2Fwww.bytebot.net%2Fblog%2Farchives%2F2012%2F02%2F05%2Fmariadb-5-3-query-optimizer-by-sergey-petrunia&share=email\" target=\"_blank\" title=\"Click to email a link to a friend\" data-email-share-error-title=\"Do you have email set up?\" data-email-share-error-text=\"If you&#039;re having problems sharing via email, you might not have email set up for your browser. You may need to create a new email yourself.\" data-email-share-nonce=\"6e2cc7c4a5\" data-email-share-track-url=\"http:\/\/www.bytebot.net\/blog\/archives\/2012\/02\/05\/mariadb-5-3-query-optimizer-by-sergey-petrunia?share=email\"><span>Email<\/span><\/a><\/li><li class=\"share-facebook\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-facebook-2256\" class=\"share-facebook sd-button share-icon\" href=\"http:\/\/www.bytebot.net\/blog\/archives\/2012\/02\/05\/mariadb-5-3-query-optimizer-by-sergey-petrunia?share=facebook\" target=\"_blank\" title=\"Click to share on Facebook\" ><span>Facebook<\/span><\/a><\/li><li class=\"share-linkedin\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-linkedin-2256\" class=\"share-linkedin sd-button share-icon\" href=\"http:\/\/www.bytebot.net\/blog\/archives\/2012\/02\/05\/mariadb-5-3-query-optimizer-by-sergey-petrunia?share=linkedin\" target=\"_blank\" title=\"Click to share on LinkedIn\" ><span>LinkedIn<\/span><\/a><\/li><li class=\"share-twitter\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-twitter-2256\" class=\"share-twitter sd-button share-icon\" href=\"http:\/\/www.bytebot.net\/blog\/archives\/2012\/02\/05\/mariadb-5-3-query-optimizer-by-sergey-petrunia?share=twitter\" target=\"_blank\" title=\"Click to share on Twitter\" ><span>Twitter<\/span><\/a><\/li><li class=\"share-end\"><\/li><\/ul><\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Sergey Petrunia of the MariaDB project. What exactly is not working in MySQL? MySQL is poor at decision support\/analytics. With large datasets you need special disk access strategies. Complex queries like insufficient subquery support and big joins are common int he MySQL world. DBT-3 is used, scale=30, with a 75GB database and run a query [&hellip;]<\/p>\n<div class=\"sharedaddy sd-sharing-enabled\"><div class=\"robots-nocontent sd-block sd-social sd-social-icon-text sd-sharing\"><h3 class=\"sd-title\">Share this:<\/h3><div class=\"sd-content\"><ul><li class=\"share-email\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"\" class=\"share-email sd-button share-icon\" href=\"mailto:?subject=%5BShared%20Post%5D%20MariaDB%205.3%20query%20optimizer%20by%20Sergey%20Petrunia&body=http%3A%2F%2Fwww.bytebot.net%2Fblog%2Farchives%2F2012%2F02%2F05%2Fmariadb-5-3-query-optimizer-by-sergey-petrunia&share=email\" target=\"_blank\" title=\"Click to email a link to a friend\" data-email-share-error-title=\"Do you have email set up?\" data-email-share-error-text=\"If you&#039;re having problems sharing via email, you might not have email set up for your browser. You may need to create a new email yourself.\" data-email-share-nonce=\"6e2cc7c4a5\" data-email-share-track-url=\"http:\/\/www.bytebot.net\/blog\/archives\/2012\/02\/05\/mariadb-5-3-query-optimizer-by-sergey-petrunia?share=email\"><span>Email<\/span><\/a><\/li><li class=\"share-facebook\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-facebook-2256\" class=\"share-facebook sd-button share-icon\" href=\"http:\/\/www.bytebot.net\/blog\/archives\/2012\/02\/05\/mariadb-5-3-query-optimizer-by-sergey-petrunia?share=facebook\" target=\"_blank\" title=\"Click to share on Facebook\" ><span>Facebook<\/span><\/a><\/li><li class=\"share-linkedin\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-linkedin-2256\" class=\"share-linkedin sd-button share-icon\" href=\"http:\/\/www.bytebot.net\/blog\/archives\/2012\/02\/05\/mariadb-5-3-query-optimizer-by-sergey-petrunia?share=linkedin\" target=\"_blank\" title=\"Click to share on LinkedIn\" ><span>LinkedIn<\/span><\/a><\/li><li class=\"share-twitter\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-twitter-2256\" class=\"share-twitter sd-button share-icon\" href=\"http:\/\/www.bytebot.net\/blog\/archives\/2012\/02\/05\/mariadb-5-3-query-optimizer-by-sergey-petrunia?share=twitter\" target=\"_blank\" title=\"Click to share on Twitter\" ><span>Twitter<\/span><\/a><\/li><li class=\"share-end\"><\/li><\/ul><\/div><\/div><\/div>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_options":[]},"categories":[1064,23],"tags":[1332,1052,1340,1339],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4vJD-Ao","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":2295,"url":"http:\/\/www.bytebot.net\/blog\/archives\/2012\/02\/05\/replication-features-of-2011-by-sergey-petrunia","url_meta":{"origin":2256,"position":0},"title":"Replication features of 2011 by Sergey Petrunia","date":"5\/2\/2012","format":false,"excerpt":"Sergey Petrunia of the\u00a0MariaDB project & Monty Program. MySQL 5.5 GA at the end of 2010. MariaDB 5.3 RC towards the end of 2011 (beta in June 2011). MySQL 5.5 is merged to Percona Server 5.5 which included semi-sync replication, slave fsync options, atuomatic relay log recovery, RBR slave type\u2026","rel":"","context":"In &quot;MariaDB&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2335,"url":"http:\/\/www.bytebot.net\/blog\/archives\/2012\/03\/22\/mariadb-at-percona-live-santa-clara","url_meta":{"origin":2256,"position":1},"title":"MariaDB at Percona Live Santa Clara","date":"22\/3\/2012","format":false,"excerpt":"I for one can say that I'm truly excited that MariaDB will be part of Percona Live Santa Clara. The MariaDB session list includes: A tutorial: Improving MySQL\/MariaDB query performance through optimizer tuning by\u00a0Timour Katchaounov and\u00a0Sergey Petrunia. You can benefit from this even as a stock MySQL user naturally. MySQL\u2026","rel":"","context":"In &quot;MariaDB&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2693,"url":"http:\/\/www.bytebot.net\/blog\/archives\/2013\/04\/12\/upcoming-talks-in-santa-clara","url_meta":{"origin":2256,"position":2},"title":"Upcoming talks in Santa Clara","date":"12\/4\/2013","format":false,"excerpt":"I'm planning my calendar and thought I'd share what talks I'd be giving in Santa Clara in a couple of weeks for the Percona Live MySQL Conference & Expo 2013 and the\u00a0MySQL & Cloud Database Solutions Day 2013. Its going to be a busy April 22-26 2013. MariaDB Cassandra Interoperability\u2026","rel":"","context":"In &quot;MariaDB&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3117,"url":"http:\/\/www.bytebot.net\/blog\/archives\/2015\/10\/24\/mysql-nl-community-meetup-with-mariadb-speakers-summary","url_meta":{"origin":2256,"position":3},"title":"MySQL NL Community Meetup with MariaDB speakers summary","date":"24\/10\/2015","format":false,"excerpt":"Last week we had the\u00a0MySQL Meetup with MariaDB Developers in\u00a0Amsterdam, which went on easily for about 3.5 hours. Thanks to all for listening (these were lightning talks, not with a strict 5 minute clock with Q&A thrown in), and Dani\u00c3\u00abl\u00a0van Eeden for organising this at the eBay offices (whom kindly\u2026","rel":"","context":"In &quot;MariaDB&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2704,"url":"http:\/\/www.bytebot.net\/blog\/archives\/2013\/04\/27\/mha-mariadb-cassandra-interoperability-talks","url_meta":{"origin":2256,"position":4},"title":"MHA &#038; MariaDB Cassandra Interoperability talks","date":"27\/4\/2013","format":false,"excerpt":"Together with Sergei Petrunia, we talked about\u00a0MariaDB Cassandra Interoperability. Sergei has done wonderful work here and I plan to showcase more Cassandra integration going forward. It's worth noting that Elena came up with the benchmarks for this talk as well. MariaDB Cassandra Interoperability from Colin Charles Later, I gave a\u2026","rel":"","context":"In &quot;MariaDB&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3199,"url":"http:\/\/www.bytebot.net\/blog\/archives\/2016\/04\/08\/tweet-summary-of-percona-live-2015","url_meta":{"origin":2256,"position":5},"title":"(tweet) Summary of Percona Live 2015","date":"8\/4\/2016","format":false,"excerpt":"The problem with Twitter is that we talk about something and before you know it, people forget. (e.g. does WebScaleSQL have an async client library?) How many blog posts are there about Percona Live Santa Clara 2015? This time (2016), I'm going to endeavour to write more than to just\u2026","rel":"","context":"In &quot;MySQL&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"amp_enabled":true,"_links":{"self":[{"href":"http:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/posts\/2256"}],"collection":[{"href":"http:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/comments?post=2256"}],"version-history":[{"count":4,"href":"http:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/posts\/2256\/revisions"}],"predecessor-version":[{"id":2274,"href":"http:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/posts\/2256\/revisions\/2274"}],"wp:attachment":[{"href":"http:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/media?parent=2256"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/categories?post=2256"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/tags?post=2256"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}