Skip to content

Instantly share code, notes, and snippets.

@ffeast
Last active June 29, 2016 19:54
Show Gist options
  • Save ffeast/d16666cc799ce18cbce309b3858213ab to your computer and use it in GitHub Desktop.
Save ffeast/d16666cc799ce18cbce309b3858213ab to your computer and use it in GitHub Desktop.
Query that helps identify tables with missing PK as well as tables with FULLTEXT or SPATIAL functionality
# taken from http://severalnines.com/blog/field-live-migration-mmm-mariadb-galera-cluster
SELECT DISTINCT
CONCAT(t.table_schema,'.',t.table_name) as tbl,
t.engine,
IF(ISNULL(c.constraint_name),'NOPK','') AS nopk,
IF(s.index_type = 'FULLTEXT','FULLTEXT','') as ftidx,
IF(s.index_type = 'SPATIAL','SPATIAL','') as gisidx
FROM information_schema.tables AS t
LEFT JOIN information_schema.key_column_usage AS c
ON (t.table_schema = c.constraint_schema AND t.table_name = c.table_name
AND c.constraint_name = 'PRIMARY')
LEFT JOIN information_schema.statistics AS s
ON (t.table_schema = s.table_schema AND t.table_name = s.table_name
AND s.index_type IN ('FULLTEXT','SPATIAL'))
WHERE t.table_schema NOT IN ('information_schema','performance_schema','mysql')
AND t.table_type = 'BASE TABLE'
AND (t.engine <> 'InnoDB' OR c.constraint_name IS NULL OR s.index_type IN ('FULLTEXT','SPATIAL'))
ORDER BY t.table_schema,t.table_name;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment