Skip to content

Commit 7a94bd5

Browse files
committed
minimal database list retrieval
Information schema access isn't particularly well optimized. As such, at least in older versions, fetching from the information_schema.TABLES would involve opening every table. The ANSI SQL standards SCHEMATA provides a quicker way, and we can reuse it.
1 parent 2999446 commit 7a94bd5

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

mysqltuner.pl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ package main;
239239
# Checks for supported or EOL'ed MySQL versions
240240
my ( $mysqlvermajor, $mysqlverminor, $mysqlvermicro );
241241

242+
# Database
243+
my @dblist;
244+
242245
# Super structure containing all information
243246
my %result;
244247
$result{'MySQLTuner'}{'version'} = $tunerversion;
@@ -5849,8 +5852,8 @@ sub mysql_databases {
58495852
return;
58505853
}
58515854

5852-
my @dblist = select_array(
5853-
"SELECT DISTINCT TABLE_SCHEMA FROM information_schema.TABLES WHERE TABLE_SCHEMA NOT IN ( 'mysql', 'performance_schema', 'information_schema', 'sys' );"
5855+
@dblist = select_array(
5856+
"SELECT SCHEMA_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME NOT IN ( 'mysql', 'performance_schema', 'information_schema', 'sys' );"
58545857
);
58555858
infoprint "There is " . scalar(@dblist) . " Database(s).";
58565859
my @totaldbinfo = split /\s/,
@@ -6027,9 +6030,6 @@ sub mysql_tables {
60276030
if (mysql_version_ge(8) and not mysql_version_eq(10)) {
60286031
infoprint "MySQL and Percona version 8 and greater have remove PROCEDURE ANALYSE feature"
60296032
}
6030-
my @dblist = select_array(
6031-
"SELECT DISTINCT TABLE_SCHEMA FROM information_schema.TABLES WHERE TABLE_SCHEMA NOT IN ( 'mysql', 'performance_schema', 'information_schema', 'sys' );"
6032-
);
60336033
foreach (@dblist) {
60346034
my $dbname = $_;
60356035
next unless defined $_;

0 commit comments

Comments
 (0)