Skip to content

Commit

Permalink
made the mysql 5.7 tables with sizes query less fragile
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <[email protected]>
  • Loading branch information
systay committed Feb 9, 2021
1 parent 46a09f7 commit f4ebe62
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions go/mysql/flavor_mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,19 @@ func (mysqlFlavor) disableBinlogPlaybackCommand() string {
const TablesWithSize56 = `SELECT table_name, table_type, unix_timestamp(create_time), table_comment, SUM( data_length + index_length), SUM( data_length + index_length)
FROM information_schema.tables WHERE table_schema = database() group by table_name`

// TablesWithSize57 is a query to select table along with size for mysql 5.7
const TablesWithSize57 = `SELECT t.table_name, t.table_type, unix_timestamp(t.create_time), t.table_comment, i.file_size, i.allocated_size
FROM information_schema.tables t, information_schema.innodb_sys_tablespaces i
WHERE t.table_schema = database() and i.name = concat(t.table_schema,'/',t.table_name)`
// TablesWithSize57 is a query to select table along with size for mysql 5.7.
// It's a little weird, because the JOIN predicate only works if the table and databases do not contain weird characters.
// As a fallback, we use the mysql 5.6 query, which is not always up to date, but works for all table/db names.
const TablesWithSize57 = `
SELECT t.table_name, t.table_type, unix_timestamp(t.create_time), t.table_comment, i.file_size, i.allocated_size
FROM information_schema.tables t, information_schema.innodb_sys_tablespaces i
WHERE t.table_schema = database() and i.name = concat(t.table_schema,'/',t.table_name)
UNION ALL
SELECT table_name, table_type, unix_timestamp(create_time), table_comment, SUM( data_length + index_length), SUM( data_length + index_length)
FROM information_schema.tables
WHERE table_schema = database() AND NOT EXISTS(SELECT * FROM information_schema.tables t, information_schema.innodb_sys_tablespaces i WHERE t.table_schema = database() and i.name = concat(t.table_schema,'/',t.table_name))
group by table_name
`

// TablesWithSize80 is a query to select table along with size for mysql 8.0
const TablesWithSize80 = `SELECT t.table_name, t.table_type, unix_timestamp(t.create_time), t.table_comment, i.file_size, i.allocated_size
Expand Down

0 comments on commit f4ebe62

Please sign in to comment.