Created
December 21, 2019 00:12
-
-
Save davidegreenwald/8c115fad017e35d8f905d7c118685386 to your computer and use it in GitHub Desktop.
Giant union of queries to get WordPress options table data
This file contains hidden or 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
# Giant union of queries to get all the information you possibly need about your options table | |
# change wp_options in all locations to match your WP table's prefix | |
SELECT COUNT(*) as `Rows`, | |
'All rows' as `Status`, | |
ROUND( | |
SUM( | |
LENGTH( | |
CONCAT(option_id, option_name, option_value, autoload) | |
) | |
)/1048567, 2 | |
) AS `Data_in_MB` | |
FROM wp_options | |
UNION | |
SELECT COUNT(*), | |
'Non-autoloading rows', | |
ROUND( | |
SUM( | |
LENGTH( | |
CONCAT(option_id, option_name, option_value, autoload) | |
) | |
)/1048567, 2 | |
) | |
FROM wp_options | |
WHERE autoload = 'no' | |
UNION | |
SELECT COUNT(*), | |
'Autoloading rows', | |
ROUND( | |
SUM( | |
LENGTH( | |
CONCAT(option_id, option_name, option_value, autoload) | |
) | |
)/1048567, 2 | |
) | |
FROM wp_options | |
WHERE autoload = 'yes' | |
UNION | |
SELECT COUNT(*), | |
'All transients', | |
ROUND( | |
SUM( | |
LENGTH( | |
CONCAT(option_id, option_name, option_value, autoload) | |
) | |
)/1048567, 2 | |
) | |
FROM wp_options | |
WHERE option_name LIKE ('%\_transient\_%') | |
UNION | |
SELECT COUNT(*), | |
'Autoloading transients', | |
ROUND( | |
SUM( | |
LENGTH( | |
CONCAT(option_id, option_name, option_value, autoload) | |
) | |
)/1048567, 2 | |
) | |
FROM wp_options | |
WHERE option_name LIKE ('%\_transient\_%') AND autoload = 'yes' | |
UNION | |
SELECT COUNT(*), | |
'Non-autoloading transients', | |
ROUND( | |
SUM( | |
LENGTH( | |
CONCAT(option_id, option_name, option_value, autoload) | |
) | |
)/1048567, 2 | |
) | |
FROM wp_options | |
WHERE option_name LIKE ('%\_transient\_%') AND autoload = 'no'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment