2017 © Pedro Peláez
 

library stinky-query-finder

Find stinky queries

image

danieljharvey/stinky-query-finder

Find stinky queries

  • Friday, June 2, 2017
  • by danieljharvey
  • Repository
  • 0 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

stinky-query-finder

Find what will probably turn out to be totally awful MySQL queries before they ruin everything. Build Status, (*1)

What does it do then?, (*2)

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, (*3)

How does it decide?, (*4)

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., (*5)

How do I use it?, (*6)

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

$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), (*8)

That's going to slow things down a bit isn't it?, (*9)

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:, (*10)


$tables = $stinkers->getTables(); cacheTablesDataWithYourExcellentCachingSolution($tables);

Then you're free to use it again like this:, (*11)


$dbName="excellentDB" $tables = getCachedTablesFromYourGreatCachingFunction(); $stinkers = new \DanielJHarvey\QueryStinkers\Stinkers($dbName, $tables); // no need to rebuild table data, everything is fine

The Versions

02/06 2017

dev-master

9999999-dev

Find stinky queries

  Sources   Download

MIT

The Development Requires

by Daniel Harvey