Skip to content

Instantly share code, notes, and snippets.

@victorpendleton
Last active February 16, 2017 21:32
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 victorpendleton/5cf887052b7149a25106e4d167a38fe6 to your computer and use it in GitHub Desktop.
Save victorpendleton/5cf887052b7149a25106e4d167a38fe6 to your computer and use it in GitHub Desktop.
Get MySQL partition information
-- Get the unique PARTITION_EXPRESSION values
SELECT DISTINCT PARTITION_EXPRESSION
FROM information_schema.partitions;
-- Mappings
-- TO_DAYS() => FROM_DAYS()
-- UNIX_TIMESTAMP() => FROM_UNIXTIME()
SELECT TABLE_SCHEMA
, TABLE_NAME
, PARTITION_NAME
, CASE TRIM(SUBSTRING(PARTITION_EXPRESSION, 1, LOCATE('(', PARTITION_EXPRESSION)- 1 ))
WHEN 'TO_DAYS' THEN FROM_DAYS(PARTITION_DESCRIPTION)
WHEN 'UNIX_TIMESTAMP' THEN FROM_UNIXTIME(PARTITION_DESCRIPTION)
ELSE PARTITION_DESCRIPTION END AS PARTITION_DESCRIPTION
, TABLE_ROWS
FROM information_schema.partitions
WHERE TABLE_NAME = <table_name>
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment