Add support for displaying table size

https://github.com/webmin/webmin/issues/2386
This commit is contained in:
Ilia Ross
2025-02-02 23:45:31 +02:00
parent db213c812a
commit 45b88d85b5
3 changed files with 35 additions and 2 deletions

View File

@ -1349,6 +1349,26 @@ my $rs = &execute_sql_safe($db, $sql_query, $db, @tables);
return $rs;
}
# get_tables_size(db)
# Retrieves the size of all tables in the given database
sub get_tables_size
{
my ($db) = @_;
my @tables = list_tables($db);
my $sql_query = "
SELECT
TABLE_SCHEMA,
TABLE_NAME,
ENGINE,
DATA_LENGTH + INDEX_LENGTH AS total_size_bytes
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = ?
AND TABLE_NAME IN (" . join(", ", ("?") x @tables) . ")
";
my $rs = &execute_sql_safe($db, $sql_query, $db, @tables);
return $rs;
}
# list_indexes(db)
# Returns the names of all indexes in some database
sub list_indexes