Skip to content

Find what will probably turn out to be totally awful queries before they ruin everything.

Notifications You must be signed in to change notification settings

danieljharvey/stinky-query-finder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

stinky-query-finder

Find what will probably turn out to be totally awful MySQL queries before they ruin everything. Build Status

What does it do then?

You pass it a PDO object and a SQL call, it learns a little about your DB, and works out whether your query is potentially garbage

How does it decide?

Basically, by whether a) the table is very long - if it's not, it'll be fine. b) if the table IS long, whether the query is using one or more indexes to give it a fighting chance of being OK.

How do I use it?

Make a PDO object, pass it into a nice new Stinkers object, and ask it whether your SQL is dogshit or not.

$dbName = "greatDB"

$dsn = "mysql:dbname={$dbName};host=127.0.0.1";

$pdo = new \PDO($dsn, "username", "excellentPassword");

$sql = "SELECT COUNT(1) FROM excellentTable WHERE thingID=2229 AND theDate='2017-05-12'";

$stinkers = new \DanielJHarvey\QueryStinkers\Stinkers($dbName, $tables, $pdo);

$problematicQuery = $stinkers->checkQuery($sql);

$problematicQuery will either return false (not a problem, great) or an array-based stack trace (so that the offending query creating code can be located)

That's going to slow things down a bit isn't it?

Yeah, unfortunately so, so please please please don't use this in production. If you wish to speed things up, you can cache the DB tables data created by Stinkers like this:


$tables = $stinkers->getTables();

cacheTablesDataWithYourExcellentCachingSolution($tables);

Then you're free to use it again like this:


$dbName="excellentDB"
$tables = getCachedTablesFromYourGreatCachingFunction();

$stinkers = new \DanielJHarvey\QueryStinkers\Stinkers($dbName, $tables);

// no need to rebuild table data, everything is fine

About

Find what will probably turn out to be totally awful queries before they ruin everything.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages