Last active
February 16, 2017 21:32
-
-
Save victorpendleton/5cf887052b7149a25106e4d167a38fe6 to your computer and use it in GitHub Desktop.
Get MySQL partition information
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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