Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions innodb/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

33 changes: 33 additions & 0 deletions innodb/fragmented.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
def get_fragmented_tables(percent=10, session=None):
import mysqlsh
shell = mysqlsh.globals.shell

if session is None:
session = shell.get_session()
if session is None:
print("No session specified. Either pass a session object to this "
"function or connect the shell to a database")
return
stmt = "select variable_value from performance_schema.global_variables where variable_name='information_schema_stats_expiry';"
result = session.run_sql(stmt)
stats = result.fetch_all()
if len(stats) > 0:
for stat in stats:
if int(stat[0]) > 0:
print "Warning: information_schema_stats_expiry is set to {0}.".format(*stat)

stmt = """SELECT CONCAT(table_schema, '.', table_name) as 'TABLE',
ENGINE, CONCAT(ROUND(table_rows / 1000000, 2), 'M') `ROWS`,
CONCAT(ROUND(data_length / ( 1024 * 1024 * 1024 ), 2), 'G') DATA,
CONCAT(ROUND(index_length / ( 1024 * 1024 * 1024 ), 2), 'G') IDX,
CONCAT(ROUND(( data_length + index_length ) / ( 1024 * 1024 * 1024 ), 2), 'G') 'TOTAL SIZE',
ROUND(index_length / data_length, 2) IDXFRAC,
CONCAT(ROUND(( data_free / 1024 / 1024),2), 'MB') AS 'DATA FREE',
CONCAT('(',
IF(data_free< ( data_length + index_length ),
CONCAT(round(data_free/(data_length+index_length)*100,2),'%'),
'100%'),')') AS 'DATA FREE%'
FROM information_schema.TABLES WHERE (data_free/(data_length+index_length)*100) > {limit}
AND table_schema <> 'mysql' AND ENGINE='INNODB';""".format(limit=percent)
result = session.run_sql(stmt)
shell.dump_rows(result)
31 changes: 31 additions & 0 deletions innodb/init.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,33 @@
# init.py
# -------


from ext.mysqlsh_plugins_common import register_plugin
from ext.innodb import fragmented


register_plugin("getFragmentedTables", fragmented.get_fragmented_tables,
{"brief": "Prints InnoDB fragmented tables",
"parameters": [{
"name": "percent",
"brief": "Amount of free space to be considered as fragmented",
"type": "integer",
"required": False
},{
"name": "session",
"brief": "The session to be used on the operation.",
"type": "object",
"classes": ["Session", "ClassicSession"],
"required": False
}
]
},
"innodb",
{
"brief": "InnoDB management and utilities.",
"details": [
"A collection of InnoDB management tools and related "
"utilities that work on InnoDB Engine"
]
}
)