Reducer.sh – A powerful MySQL test-case simplification/reducer tool

Let me start by saying a big “thank you” to the staff at Oracle for deciding to open source reducer.sh. It’s a tool I developed whilst I was working for them several years ago. Its sole purpose is to do one thing – but do it good: test-case simplification.

So, let’s say some customer just sent you 120,000 lines of SQL code and affirms that “it definitely causes a crash.” Or maybe you ran RQG (the Random Query Generator) for awhile (with the general query log turned on) and now you have a nice SQL trace which may just lead to that crash the run resulted in. Or you’re a DBA testing the company’s usual queries with Valgrind, and noticed that 2 in 1000 queries give a Valgrind warning in the mysqld error log – you’re just not sure which one. Or maybe you’re a developer, and during testing you saw that a SELECT query output did not look the way it should – the output was “7” where it should have been “5” – the only problem – you have 1000 lines of INSERT statements and are not sure which one caused it. In all of these cases reducer can help.

Here are some of it’s benefits/features:

It can reduce large amount of SQL fast. 40K lines to just a few can usually be done in around 1 hour.

Related

Roel leads Percona's QA team. Before coming to Percona, he contributed significantly to the QA infrastructure at Oracle. Roel has a varied background in IT, backed up by many industry leading certifications. He also enjoys time with God, his wife and 5 children, or heading into nature.

4 Comments

I upgraded reducer.sh. It now produces fully self-contained test cases with a near-100% match with the original reducer environment.

An example: after (and during) reduction of a testcase, reducer now automatically stores these files in the same directory as the original (and now reduced) testcase;

1422244738_cl # client script, if needed to access the server after starting it with _start
1422244738_init # init script, sets up data dir etc. in /dev/shm
1422244738_mybase # contains the path to the mysql base dir to be used (the only file that needs editing)
1422244738_run # run the testcase (.sql file) using the mysql CLI
1422244738_run_pquery # run the testcase using the pquery binary, included with the bundle (only if pquery was used)
1422244738.sql # the final reduced sql file
1422244738_start # start mysqld in exactly the same way as reducer was able to reduce the testcase (same mysqld options)
1422244738_stop # stop mysqld server (if necessary)
1422244738_pquery[-ms] # an included copy of the pquery used for the run (only if pquery was used)
1422244738_bug_bundle.tar.gz # A bundle of all files above

So, for example, to start this particular testcase for replay, one would execute;

Reducer.sh is now covered in much more depth across 3 episodes in the new MySQL QA Series! See https://www.percona.com/blog/2015/07/21/mysql-qa-episode-7-single-threaded-reducer-sh-reducing-testcases-for-beginners and https://www.percona.com/blog/2015/03/17/free-mysql-qa-and-bash-linux-training-series/