Skip to content

Commit 99e5c83

Browse files
committed
Aria/MyISAM cleanup
Include calculation of Aria index size based of *.MAI files. Use find -0 | xargs -0 to allow for space containing names. Quote datadir in find in case it had spaces. Use xargs -r (GNU extension) (supported Linux, FreeBSD, OpenBSD, NetBSD, not Solaris, not OSX) to not run if there's no files that match. This prevents it running the total of the current directory if there are no M[YA]I files. A total size of 0 for Aria or MyISAM indexes isn't a problem because: * MySQL-5.[567] used MyISAM system tables which have indexes, so 0 wasn't possible (except for remote user without mysql.* access). * 0 size of index is equally likely to be 0 tables of this type (e.g. MySQL-8.0, or MariaDB-10.4+ (Aria default, not MyISAM)). Setting total_aria_indexes=1 when it was previously 0 is misleading. Aria was never called AriaDB despite the apparent convention in other storage engines so use just Aria, or Aria Storage Engine in messages. Differentiate between Aria not available and disabled in report.
1 parent 9a9ff55 commit 99e5c83

File tree

1 file changed

+26
-44
lines changed

1 file changed

+26
-44
lines changed

mysqltuner.pl

+26-44
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ sub pretty_uptime {
403403
}
404404

405405
# Retrieves the memory installed on this machine
406-
my ( $physical_memory, $swap_memory, $duflags );
406+
my ( $physical_memory, $swap_memory, $duflags, $xargsflags );
407407

408408
sub memerror {
409409
badprint
@@ -414,6 +414,7 @@ sub memerror {
414414
sub os_setup {
415415
my $os = `uname`;
416416
$duflags = ( $os =~ /Linux/ ) ? '-b' : '';
417+
$xargsflags = ( $os =~ /Darwin|SunOS/ ) ? '' : '-r';
417418
if ( $opt{'forcemem'} > 0 ) {
418419
$physical_memory = $opt{'forcemem'} * 1048576;
419420
infoprint "Assuming $opt{'forcemem'} MB of physical memory";
@@ -2562,30 +2563,23 @@ sub calculations {
25622563
my $size = 0;
25632564
$size += (split)[0]
25642565
for
2565-
`find $myvar{'datadir'} -name "*.MYI" 2>&1 | xargs du -L $duflags 2>&1`;
2566+
`find "$myvar{'datadir'}" -name "*.MYI" -print0 2>&1 | xargs $xargsflags -0 du -L $duflags 2>&1`;
25662567
$mycalc{'total_myisam_indexes'} = $size;
2567-
$mycalc{'total_aria_indexes'} = 0;
2568+
$size = 0 + (split)[0]
2569+
for
2570+
`find "$myvar{'datadir'}" -name "*.MAI" -print0 2>&1 | xargs $xargsflags -0 du -L $duflags 2>&1`;
2571+
$mycalc{'total_aria_indexes'} = $size;
25682572
}
25692573
elsif ( mysql_version_ge(5) ) {
25702574
$mycalc{'total_myisam_indexes'} = select_one
25712575
"SELECT IFNULL(SUM(INDEX_LENGTH),0) FROM information_schema.TABLES WHERE TABLE_SCHEMA NOT IN ('information_schema') AND ENGINE = 'MyISAM';";
25722576
$mycalc{'total_aria_indexes'} = select_one
25732577
"SELECT IFNULL(SUM(INDEX_LENGTH),0) FROM information_schema.TABLES WHERE TABLE_SCHEMA NOT IN ('information_schema') AND ENGINE = 'Aria';";
25742578
}
2575-
if ( defined $mycalc{'total_myisam_indexes'}
2576-
and $mycalc{'total_myisam_indexes'} == 0 )
2577-
{
2578-
$mycalc{'total_myisam_indexes'} = "fail";
2579-
}
2580-
elsif ( defined $mycalc{'total_myisam_indexes'} ) {
2579+
if ( defined $mycalc{'total_myisam_indexes'} ) {
25812580
chomp( $mycalc{'total_myisam_indexes'} );
25822581
}
2583-
if ( defined $mycalc{'total_aria_indexes'}
2584-
and $mycalc{'total_aria_indexes'} == 0 )
2585-
{
2586-
$mycalc{'total_aria_indexes'} = 1;
2587-
}
2588-
elsif ( defined $mycalc{'total_aria_indexes'} ) {
2582+
if ( defined $mycalc{'total_aria_indexes'} ) {
25892583
chomp( $mycalc{'total_aria_indexes'} );
25902584
}
25912585

@@ -3390,19 +3384,11 @@ sub mysql_myisam {
33903384
}
33913385

33923386
# Key buffer
3393-
if ( !defined( $mycalc{'total_myisam_indexes'} ) and $doremote == 1 ) {
3387+
if ( !defined( $mycalc{'total_myisam_indexes'} ) ) {
33943388
push( @generalrec,
3395-
"Unable to calculate MyISAM indexes on remote MySQL server < 5.0.0"
3389+
"Unable to calculate MyISAM index size on MySQL server < 5.0.0"
33963390
);
33973391
}
3398-
elsif ( $mycalc{'total_myisam_indexes'} =~ /^fail$/ ) {
3399-
badprint
3400-
"Cannot calculate MyISAM index size - re-run script as root user";
3401-
}
3402-
elsif ( $mycalc{'total_myisam_indexes'} == "0" ) {
3403-
badprint
3404-
"None of your MyISAM tables are indexed - add indexes immediately";
3405-
}
34063392
else {
34073393
if ( $myvar{'key_buffer_size'} < $mycalc{'total_myisam_indexes'}
34083394
&& $mycalc{'pct_keys_from_mem'} < 95 )
@@ -5032,31 +5018,27 @@ sub mysqsl_pfs {
50325018

50335019
}
50345020

5035-
# Recommendations for Ariadb
5036-
sub mariadb_ariadb {
5037-
subheaderprint "AriaDB Metrics";
5021+
# Recommendations for Aria Engine
5022+
sub mariadb_aria {
5023+
subheaderprint "Aria Metrics";
50385024

5039-
# AriaDB
5040-
unless ( defined $myvar{'have_aria'}
5041-
and $myvar{'have_aria'} eq "YES" )
5025+
# Aria
5026+
if ( ! defined $myvar{'have_aria'} )
5027+
{
5028+
infoprint "Aria Storage Engine not available.";
5029+
return;
5030+
}
5031+
if ( $myvar{'have_aria'} ne "YES" )
50425032
{
5043-
infoprint "AriaDB is disabled.";
5033+
infoprint "Aria Storage Engine is disabled.";
50445034
return;
50455035
}
5046-
infoprint "AriaDB is enabled.";
5036+
infoprint "Aria Storage Engine is enabled.";
50475037

50485038
# Aria pagecache
5049-
if ( !defined( $mycalc{'total_aria_indexes'} ) and $doremote == 1 ) {
5039+
if ( !defined( $mycalc{'total_aria_indexes'} ) ) {
50505040
push( @generalrec,
5051-
"Unable to calculate Aria indexes on remote MySQL server < 5.0.0" );
5052-
}
5053-
elsif ( $mycalc{'total_aria_indexes'} =~ /^fail$/ ) {
5054-
badprint
5055-
"Cannot calculate Aria index size - re-run script as root user";
5056-
}
5057-
elsif ( $mycalc{'total_aria_indexes'} == "0" ) {
5058-
badprint
5059-
"None of your Aria tables are indexed - add indexes immediately";
5041+
"Unable to calculate Aria index size on MySQL server" );
50605042
}
50615043
else {
50625044
if (
@@ -6389,7 +6371,7 @@ sub which {
63896371
mariadb_threadpool; # Print MariaDB ThreadPool stats
63906372
mysql_myisam; # Print MyISAM stats
63916373
mysql_innodb; # Print InnoDB stats
6392-
mariadb_ariadb; # Print MariaDB AriaDB stats
6374+
mariadb_aria; # Print MariaDB Aria stats
63936375
mariadb_tokudb; # Print MariaDB Tokudb stats
63946376
mariadb_xtradb; # Print MariaDB XtraDB stats
63956377

0 commit comments

Comments
 (0)