Skip to content

Instantly share code, notes, and snippets.

@nilsmeyer
Created October 4, 2017 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nilsmeyer/2e1396fe5e504b2af20dd54054b3dca5 to your computer and use it in GitHub Desktop.
Save nilsmeyer/2e1396fe5e504b2af20dd54054b3dca5 to your computer and use it in GitHub Desktop.
Get the maximum size for an index
$database would be the database/schema...
SELECT c.TABLE_NAME, CONSTRAINT_NAME, SUM(CHARACTER_OCTET_LENGTH) AS length FROM KEY_COLUMN_USAGE kcu INNER JOIN COLUMNS c ON c.TABLE_SCHEMA = kcu.TABLE_SCHEMA AND c.TABLE_NAME = kcu.TABLE_NAME AND c.COLUMN_NAME = kcu.COLUMN_NAME WHERE kcu.TABLE_SCHEMA='$database' GROUP BY CONSTRAINT_NAME, c.TABLE_NAME ORDER BY length;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment