MySQL and HeatWave

Top 5 Developer Enabling Nuggets in MySQL 5.6

Guest Author

MySQL 5.6 is truly a better MySQL and reflects Oracle's commitment to the evolution of the most popular and widely
used open source database on the planet.  The feature-complete 5.6 release candidate was announced at MySQL Connect in late September and the production-ready, generally available ("GA") product should be available in early 2013.  

While the message around 5.6 has been focused mainly on mass appeal, advanced topics like performance/scale, high availability, and self-healing replication clusters, MySQL 5.6 also provides many developer-friendly nuggets that
are designed to enable those who are building the next generation of web-based and embedded applications and services. Boiling down the 5.6 feature set into a smaller set, of simple, easy to use goodies designed with developer agility in mind, these things deserve a quick look:

Subquery Optimizations

Using semi-JOINs and late materialization, the MySQL 5.6 Optimizer delivers greatly improved subquery performance. Specifically, the optimizer is now more efficient in handling subqueries in the FROM clause; materialization of subqueries in the FROM clause is now postponed until their contents are needed during execution. Additionally, the optimizer may add an index to derived tables during execution to speed up row retrieval. Internal tests run using the DBT-3 benchmark Query #13, shown below, demonstrate an order of magnitude improvement in execution times (from days to seconds) over previous versions.

select c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice, sum(l_quantity)
from customer, orders, lineitem
where o_orderkey in (
                select l_orderkey
                from lineitem
                group by l_orderkey
                having sum(l_quantity) > 313
  and c_custkey = o_custkey
  and o_orderkey = l_orderkey
group by c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice
order by o_totalprice desc, o_orderdate
LIMIT 100;

What does this mean for developers?  For starters, simplified subqueries can now be coded instead of complex joins for cross table lookups:

title FROM film WHERE
film_id IN

(SELECT film_id

GROUP BY film_id
HAVING count(*) > 12);

And even more importantly subqueries embedded in packaged applications no longer need to be re-written into joins.  This is good news for both ISVs and their customers who have access to the underlying queries and who have spent development cycles writing, testing and maintaining their own versions of re-written queries across updated versions of a packaged app.

The details are in the MySQL 5.6 docs.

Online DDL Operations

Today's web-based applications are designed to rapidly evolve and adapt to meet business and revenue-generation
requirements. As a result, development SLAs are now most often measured in minutes vs days or weeks. For example, when an application must quickly support new product lines or new products within existing product lines, the backend database schema must adapt in kind, and most commonly while the application remains available for normal business operations.  MySQL 5.6 supports this level of online schema flexibility and agility by providing the following new ALTER TABLE online DDL syntax additions: 

  • Change AUTO_INCREMENT value for a column
  • Rename COLUMN
  • Change ROW FORMAT, KEY_BLOCK_SIZE for a table
  • Add, drop, reorder COLUMN

Again, the details are in the MySQL 5.6 docs.

Key-value access to InnoDB via Memcached API

Many of the next generation of web, cloud, social and mobile applications require fast operations against simple
Key/Value pairs. At the same time, they must retain the ability to run complex queries against the same data, as
well as ensure the data is protected with ACID guarantees. With the new NoSQL API for InnoDB, developers have all
the benefits of a transactional RDBMS, coupled with the performance capabilities of Key/Value store.

MySQL 5.6 provides simple, key-value interaction with InnoDB data via the familiar Memcached API.  Implemented via a new Memcached daemon plug-in to mysqld, the new Memcached protocol is mapped directly to the native InnoDB API and enables developers to use existing Memcached clients to bypass the expense of query parsing and go directly to InnoDB data for lookups and transactional compliant updates.  The API makes it possible to re-use standard Memcached libraries and clients, while extending Memcached functionality by integrating a persistent, crash-safe, transactional database back-end.  The implementation is shown here:

So does this option provide a performance benefit over SQL?  Internal performance benchmarks using a customized
Java application and test harness show some very promising results with a 9X improvement in overall throughput for SET/INSERT operations:

You can follow the InnoDB team blog for the methodology, implementation and internal test cases that generated these results here.

How to get started with Memcached API to InnoDB is here.

New Instrumentation in Performance Schema

The MySQL Performance Schema was introduced in MySQL 5.5 and is designed to provide point in time metrics for key performance indicators.  MySQL 5.6 improves the Performance Schema in answer to the most common DBA and Developer problems.  New instrumentations include:

  • Statements/Stages
    • What are my most resource intensive queries? Where do they spend time?
  • Table/Index I/O, Table Locks
    • Which application tables/indexes cause the most load or contention?
  • Users/Hosts/Accounts
    • Which application users, hosts, accounts are consuming the most resources?
  • Network I/O
    • What is the network load like? How long do sessions idle?
  • Summaries
    • Aggregated statistics grouped by statement, thread, user, host, account or object.

The MySQL 5.6 Performance Schema is now enabled by default in the my.cnf file with optimized and auto-tune settings that minimize overhead (< 5%, but mileage will vary), so using the Performance Schema on
a production server to monitor the most common application use cases is less of an issue.  In addition, new atomic levels of instrumentation enable the capture of granular levels of resource consumption by users, hosts, accounts, applications, etc. for billing and chargeback purposes in cloud computing environments.

The MySQL docs are an excellent resource for all that is available and that can be done with the 5.6 Performance Schema.

Better Condition Handling - GET DIAGNOSTICS

MySQL 5.6 enables developers to easily check for error conditions and code for exceptions by introducing the new
MySQL Diagnostics Area and corresponding GET DIAGNOSTICS interface command. The Diagnostic Area can be populated via multiple options and provides 2 kinds of information:

Statement - which provides affected row count and number of conditions that occurred
Condition - which provides error codes and messages for all conditions that were returned by a previous operation

The addressable items for each are:

The new GET DIAGNOSTICS command provides a standard interface into the Diagnostics Area and can be used via the CLI or from within application code to easily retrieve and handle the results of the most recent statement execution.  An example of how it is used might be:

mysql> DROP TABLE test.no_such_table;
ERROR 1051 (42S02): Unknown table 'test.no_such_table'
mysql> SELECT @p1, @p2;
| @p1   | @p2                                |
| 42S02 | Unknown table 'test.no_such_table' |

Options for leveraging the MySQL Diagnotics Area and GET DIAGNOSTICS are detailed in the MySQL Docs.

While the above is a summary of some of the key developer enabling 5.6 features, it is by no means exhaustive. You can dig deeper into what MySQL 5.6 has to offer by reading this developer zone article or checking out "What's New in MySQL 5.6" in the MySQL docs.

BONUS ALERT!  If you are developing on Windows or are considering MySQL as an alternative to SQL Server for your next project, application or shipping product, you should check out the MySQL Installer for Windows.  The installer includes the MySQL 5.6 RC database, all drivers, Visual Studio and Excel plugins, tray monitor and development tools all a single download and GUI installer.  

So what are your next steps?

  • Register for
    Dec. 12 "MySQL Replication: Simplifying Scaling and HA with GTIDs" live web event to learn about the new Replication features in MySQL 5.6.
  • Register for Dec. 13 "MySQL 5.6: Building the Next Generation of Web-Based Applications and Services" live web event.  Hurry!  Seats are limited.
  • Download the MySQL 5.6 Release Candidate (look under the Development Releases tab)
  • Provide Feedback <link to http://bugs.mysql.com/>
  • Join the Developer discussion on the MySQL Forums
  • Explore all MySQL Products and Developer Tools

As always, thanks for your continued support of MySQL!

Join the discussion

Comments ( 2 )
  • guest Friday, December 7, 2012

    I will like to use " GET DIAGNOSTICS " feature in my application but I am waiting for Production Version as Developer version is not stable. I had install MySql 5.6.7 but after one day I was not able to start MySql server ..!!

  • Rob Young Friday, December 7, 2012

    Not sure why you are having trouble with 5.6.7 at it has proven to be stable since it was released to community in Sept. We have been incrementally correcting community reported issues; as a result, 5.6.8 is now available (http://dev.mysql.com/downloads/mysql/#downloads) and we hope to post 5.6.9 soon.

    Please file a bug on the problems you are seeing so we can quickly resolve the issue (http://bugs.mysql.com/). Thanks, RobY

Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.