Merge pull request #16323 from mauriciofauth/advisory-rules
Remove the advisory rules file parser
This commit is contained in:
commit
bf6e901316
692
libraries/advisory_rules_generic.php
Normal file
692
libraries/advisory_rules_generic.php
Normal file
@ -0,0 +1,692 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
return [
|
||||
// Queries
|
||||
[
|
||||
'id' => 'Uptime below one day',
|
||||
'name' => __('Uptime below one day'),
|
||||
'formula' => 'Uptime',
|
||||
'test' => 'value < 86400',
|
||||
'issue' => __('Uptime is less than 1 day, performance tuning may not be accurate.'),
|
||||
'recommendation' => __(
|
||||
'To have more accurate averages it is recommended to let the server run for'
|
||||
. ' longer than a day before running this analyzer'
|
||||
),
|
||||
'justification' => __('The uptime is only %s'),
|
||||
'justification_formula' => 'ADVISOR_timespanFormat(Uptime)',
|
||||
],
|
||||
[
|
||||
'id' => 'Questions below 1,000',
|
||||
'name' => __('Questions below 1,000'),
|
||||
'formula' => 'Questions',
|
||||
'test' => 'value < 1000',
|
||||
'issue' => __(
|
||||
'Fewer than 1,000 questions have been run against this server.'
|
||||
. ' The recommendations may not be accurate.'
|
||||
),
|
||||
'recommendation' => __(
|
||||
'Let the server run for a longer time until it has executed a greater amount of queries.'
|
||||
),
|
||||
'justification' => __('Current amount of Questions: %s'),
|
||||
'justification_formula' => 'Questions',
|
||||
],
|
||||
[
|
||||
'id' => 'Percentage of slow queries',
|
||||
'name' => __('Percentage of slow queries'),
|
||||
'precondition' => 'Questions > 0',
|
||||
'formula' => 'Slow_queries / Questions * 100',
|
||||
'test' => 'value >= 5',
|
||||
'issue' => __('There is a lot of slow queries compared to the overall amount of Queries.'),
|
||||
'recommendation' => __(
|
||||
'You might want to increase {long_query_time}'
|
||||
. ' or optimize the queries listed in the slow query log'
|
||||
),
|
||||
'justification' => __('The slow query rate should be below 5%%, your value is %s%%.'),
|
||||
'justification_formula' => 'round(value,2)',
|
||||
],
|
||||
[
|
||||
'id' => 'Slow query rate',
|
||||
'name' => __('Slow query rate'),
|
||||
'precondition' => 'Questions > 0',
|
||||
'formula' => '(Slow_queries / Questions * 100) / Uptime',
|
||||
'test' => 'value * 60 * 60 > 1',
|
||||
'issue' => __('There is a high percentage of slow queries compared to the server uptime.'),
|
||||
'recommendation' => __(
|
||||
'You might want to increase {long_query_time}'
|
||||
. ' or optimize the queries listed in the slow query log'
|
||||
),
|
||||
'justification' => __('You have a slow query rate of %s per hour, you should have less than 1%% per hour.'),
|
||||
'justification_formula' => 'ADVISOR_bytime(value,2)',
|
||||
],
|
||||
[
|
||||
'id' => 'Long query time',
|
||||
'name' => __('Long query time'),
|
||||
'formula' => 'long_query_time',
|
||||
'test' => 'value >= 10',
|
||||
'issue' => __(
|
||||
'{long_query_time} is set to 10 seconds or more,'
|
||||
. ' thus only slow queries that take above 10 seconds are logged.'
|
||||
),
|
||||
'recommendation' => __(
|
||||
'It is suggested to set {long_query_time} to a lower value, depending on your environment.'
|
||||
. ' Usually a value of 1-5 seconds is suggested.'
|
||||
),
|
||||
'justification' => __('long_query_time is currently set to %ds.'),
|
||||
'justification_formula' => 'value',
|
||||
],
|
||||
[
|
||||
'id' => 'Slow query logging',
|
||||
'name' => __('Slow query logging'),
|
||||
'precondition' => 'PMA_MYSQL_INT_VERSION < 50600',
|
||||
'formula' => 'log_slow_queries',
|
||||
'test' => 'value == \'OFF\'',
|
||||
'issue' => __('The slow query log is disabled.'),
|
||||
'recommendation' => __(
|
||||
'Enable slow query logging by setting {log_slow_queries} to \'ON\'.'
|
||||
. ' This will help troubleshooting badly performing queries.'
|
||||
),
|
||||
'justification' => __('log_slow_queries is set to \'OFF\''),
|
||||
],
|
||||
[
|
||||
'id' => 'Slow query logging',
|
||||
'name' => __('Slow query logging'),
|
||||
'precondition' => 'PMA_MYSQL_INT_VERSION >= 50600',
|
||||
'formula' => 'slow_query_log',
|
||||
'test' => 'value == \'OFF\'',
|
||||
'issue' => __('The slow query log is disabled.'),
|
||||
'recommendation' => __(
|
||||
'Enable slow query logging by setting {slow_query_log} to \'ON\'.'
|
||||
. ' This will help troubleshooting badly performing queries.'
|
||||
),
|
||||
'justification' => __('slow_query_log is set to \'OFF\''),
|
||||
],
|
||||
// Versions
|
||||
[
|
||||
'id' => 'Release Series',
|
||||
'name' => __('Release Series'),
|
||||
'formula' => 'version',
|
||||
'test' => 'substr(value,0,2) <= \'5.\' && substr(value,2,1) < 1',
|
||||
'issue' => __('The MySQL server version less than 5.1.'),
|
||||
'recommendation' => __(
|
||||
'You should upgrade, as MySQL 5.1 has improved performance, and MySQL 5.5 even more so.'
|
||||
),
|
||||
'justification' => __('Current version: %s'),
|
||||
'justification_formula' => 'value',
|
||||
],
|
||||
[
|
||||
'id' => 'Minor Version',
|
||||
'name' => __('Minor Version'),
|
||||
'precondition' => '! fired(\'Release Series\')',
|
||||
'formula' => 'version',
|
||||
'test' => 'substr(value,0,2) <= \'5.\' && substr(value,2,1) <= 1 && substr(value,4,2) < 30',
|
||||
'issue' => __('Version less than 5.1.30 (the first GA release of 5.1).'),
|
||||
'recommendation' => __(
|
||||
'You should upgrade, as recent versions of MySQL 5.1 have improved performance'
|
||||
. ' and MySQL 5.5 even more so.'
|
||||
),
|
||||
'justification' => __('Current version: %s'),
|
||||
'justification_formula' => 'value',
|
||||
],
|
||||
[
|
||||
'id' => 'Minor Version',
|
||||
'name' => __('Minor Version'),
|
||||
'precondition' => '! fired(\'Release Series\')',
|
||||
'formula' => 'version',
|
||||
'test' => 'substr(value,0,1) == 5 && substr(value,2,1) == 5 && substr(value,4,2) < 8',
|
||||
'issue' => __('Version less than 5.5.8 (the first GA release of 5.5).'),
|
||||
'recommendation' => __('You should upgrade, to a stable version of MySQL 5.5.'),
|
||||
'justification' => __('Current version: %s'),
|
||||
'justification_formula' => 'value',
|
||||
],
|
||||
[
|
||||
'id' => 'Distribution',
|
||||
'name' => __('Distribution'),
|
||||
'formula' => 'version_comment',
|
||||
'test' => 'preg_match(\'/source/i\',value)',
|
||||
'issue' => __('Version is compiled from source, not a MySQL official binary.'),
|
||||
'recommendation' => __(
|
||||
'If you did not compile from source, you may be using a package modified by a distribution.'
|
||||
. ' The MySQL manual only is accurate for official MySQL binaries,'
|
||||
. ' not any package distributions (such as RedHat, Debian/Ubuntu etc).'
|
||||
),
|
||||
'justification' => __('\'source\' found in version_comment'),
|
||||
],
|
||||
[
|
||||
'id' => 'Distribution',
|
||||
'name' => __('Distribution'),
|
||||
'formula' => 'version_comment',
|
||||
'test' => 'preg_match(\'/percona/i\',value)',
|
||||
'issue' => __('The MySQL manual only is accurate for official MySQL binaries.'),
|
||||
'recommendation' => __(
|
||||
'Percona documentation is at <a href="https://www.percona.com/software/documentation/">'
|
||||
. 'https://www.percona.com/software/documentation/</a>'
|
||||
),
|
||||
'justification' => __('\'percona\' found in version_comment'),
|
||||
],
|
||||
[
|
||||
'id' => 'MySQL Architecture',
|
||||
'name' => __('MySQL Architecture'),
|
||||
'formula' => 'system_memory',
|
||||
'test' => 'value > 3072*1024 && !preg_match(\'/64/\',version_compile_machine)'
|
||||
. ' && !preg_match(\'/64/\',version_compile_os)',
|
||||
'issue' => __('MySQL is not compiled as a 64-bit package.'),
|
||||
'recommendation' => __(
|
||||
'Your memory capacity is above 3 GiB (assuming the Server is on localhost),'
|
||||
. ' so MySQL might not be able to access all of your memory.'
|
||||
. ' You might want to consider installing the 64-bit version of MySQL.'
|
||||
),
|
||||
'justification' => __('Available memory on this host: %s'),
|
||||
'justification_formula' => 'ADVISOR_formatByteDown(value*1024, 2, 2)',
|
||||
],
|
||||
// Query cache
|
||||
[
|
||||
'id' => 'Query caching method',
|
||||
'name' => __('Query caching method'),
|
||||
'precondition' => '!fired(\'Query cache disabled\')',
|
||||
'formula' => 'Questions / Uptime',
|
||||
'test' => 'value > 100',
|
||||
'issue' => __('Suboptimal caching method.'),
|
||||
'recommendation' => __(
|
||||
'You are using the MySQL Query cache with a fairly high traffic database.'
|
||||
. ' It might be worth considering to use '
|
||||
. '<a href="https://dev.mysql.com/doc/refman/5.6/en/ha-memcached.html">memcached</a>'
|
||||
. ' instead of the MySQL Query cache, especially if you have multiple slaves.'
|
||||
),
|
||||
'justification' => __(
|
||||
'The query cache is enabled and the server receives %d queries per second.'
|
||||
. ' This rule fires if there is more than 100 queries per second.'
|
||||
),
|
||||
'justification_formula' => 'round(value,1)',
|
||||
],
|
||||
// Sorts
|
||||
[
|
||||
'id' => 'Percentage of sorts that cause temporary tables',
|
||||
'name' => __('Percentage of sorts that cause temporary tables'),
|
||||
'precondition' => 'Sort_scan + Sort_range > 0',
|
||||
'formula' => 'Sort_merge_passes / (Sort_scan + Sort_range) * 100',
|
||||
'test' => 'value > 10',
|
||||
'issue' => __('Too many sorts are causing temporary tables.'),
|
||||
'recommendation' => __(
|
||||
'Consider increasing {sort_buffer_size} and/or {read_rnd_buffer_size},'
|
||||
. ' depending on your system memory limits.'
|
||||
),
|
||||
'justification' => __('%s%% of all sorts cause temporary tables, this value should be lower than 10%%.'),
|
||||
'justification_formula' => 'round(value,1)',
|
||||
],
|
||||
[
|
||||
'id' => 'Rate of sorts that cause temporary tables',
|
||||
'name' => __('Rate of sorts that cause temporary tables'),
|
||||
'formula' => 'Sort_merge_passes / Uptime',
|
||||
'test' => 'value * 60 * 60 > 1',
|
||||
'issue' => __('Too many sorts are causing temporary tables.'),
|
||||
'recommendation' => __(
|
||||
'Consider increasing {sort_buffer_size} and/or {read_rnd_buffer_size},'
|
||||
. ' depending on your system memory limits.'
|
||||
),
|
||||
'justification' => __('Temporary tables average: %s, this value should be less than 1 per hour.'),
|
||||
'justification_formula' => 'ADVISOR_bytime(value,2)',
|
||||
],
|
||||
[
|
||||
'id' => 'Sort rows',
|
||||
'name' => __('Sort rows'),
|
||||
'formula' => 'Sort_rows / Uptime',
|
||||
'test' => 'value * 60 >= 1',
|
||||
'issue' => __('There are lots of rows being sorted.'),
|
||||
'recommendation' => __(
|
||||
'While there is nothing wrong with a high amount of row sorting, you might want to'
|
||||
. ' make sure that the queries which require a lot of sorting use indexed columns in'
|
||||
. ' the ORDER BY clause, as this will result in much faster sorting.'
|
||||
),
|
||||
'justification' => __('Sorted rows average: %s'),
|
||||
'justification_formula' => 'ADVISOR_bytime(value,2)',
|
||||
],
|
||||
// Joins, scans
|
||||
[
|
||||
'id' => 'Rate of joins without indexes',
|
||||
'name' => __('Rate of joins without indexes'),
|
||||
'formula' => '(Select_range_check + Select_scan + Select_full_join) / Uptime',
|
||||
'test' => 'value * 60 * 60 > 1',
|
||||
'issue' => __('There are too many joins without indexes.'),
|
||||
'recommendation' => __(
|
||||
'This means that joins are doing full table scans. Adding indexes for the columns being'
|
||||
. ' used in the join conditions will greatly speed up table joins.'
|
||||
),
|
||||
'justification' => __('Table joins average: %s, this value should be less than 1 per hour'),
|
||||
'justification_formula' => 'ADVISOR_bytime(value,2)',
|
||||
],
|
||||
[
|
||||
'id' => 'Rate of reading first index entry',
|
||||
'name' => __('Rate of reading first index entry'),
|
||||
'formula' => 'Handler_read_first / Uptime',
|
||||
'test' => 'value * 60 * 60 > 1',
|
||||
'issue' => __('The rate of reading the first index entry is high.'),
|
||||
'recommendation' => __(
|
||||
'This usually indicates frequent full index scans. Full index scans are faster than'
|
||||
. ' table scans but require lots of CPU cycles in big tables, if those tables that have or'
|
||||
. ' had high volumes of UPDATEs and DELETEs, running \'OPTIMIZE TABLE\' might reduce the'
|
||||
. ' amount of and/or speed up full index scans. Other than that full index scans can'
|
||||
. ' only be reduced by rewriting queries.'
|
||||
),
|
||||
'justification' => __('Index scans average: %s, this value should be less than 1 per hour'),
|
||||
'justification_formula' => 'ADVISOR_bytime(value,2)',
|
||||
],
|
||||
[
|
||||
'id' => 'Rate of reading fixed position',
|
||||
'name' => __('Rate of reading fixed position'),
|
||||
'formula' => 'Handler_read_rnd / Uptime',
|
||||
'test' => 'value * 60 * 60 > 1',
|
||||
'issue' => __('The rate of reading data from a fixed position is high.'),
|
||||
'recommendation' => __(
|
||||
'This indicates that many queries need to sort results and/or do a full table scan,'
|
||||
. ' including join queries that do not use indexes. Add indexes where applicable.'
|
||||
),
|
||||
'justification' => __('Rate of reading fixed position average: %s, this value should be less than 1 per hour'),
|
||||
'justification_formula' => 'ADVISOR_bytime(value,2)',
|
||||
],
|
||||
[
|
||||
'id' => 'Rate of reading next table row',
|
||||
'name' => __('Rate of reading next table row'),
|
||||
'formula' => 'Handler_read_rnd_next / Uptime',
|
||||
'test' => 'value * 60 * 60 > 1',
|
||||
'issue' => __('The rate of reading the next table row is high.'),
|
||||
'recommendation' => __(
|
||||
'This indicates that many queries are doing full table scans. Add indexes where applicable.'
|
||||
),
|
||||
'justification' => __('Rate of reading next table row: %s, this value should be less than 1 per hour'),
|
||||
'justification_formula' => 'ADVISOR_bytime(value,2)',
|
||||
],
|
||||
// Temp tables
|
||||
[
|
||||
'id' => 'Different tmp_table_size and max_heap_table_size',
|
||||
'name' => __('Different tmp_table_size and max_heap_table_size'),
|
||||
'formula' => 'tmp_table_size - max_heap_table_size',
|
||||
'test' => 'value !=0',
|
||||
'issue' => __('{tmp_table_size} and {max_heap_table_size} are not the same.'),
|
||||
'recommendation' => __(
|
||||
'If you have deliberately changed one of either: The server uses the lower value of either'
|
||||
. ' to determine the maximum size of in-memory tables. So if you wish to increase the'
|
||||
. ' in-memory table limit you will have to increase the other value as well.'
|
||||
),
|
||||
'justification' => __('Current values are tmp_table_size: %s, max_heap_table_size: %s'),
|
||||
'justification_formula' => 'ADVISOR_formatByteDown(tmp_table_size, 2, 2),'
|
||||
. ' ADVISOR_formatByteDown(max_heap_table_size, 2, 2)',
|
||||
],
|
||||
[
|
||||
'id' => 'Percentage of temp tables on disk',
|
||||
'name' => __('Percentage of temp tables on disk'),
|
||||
'precondition' => 'Created_tmp_tables + Created_tmp_disk_tables > 0',
|
||||
'formula' => 'Created_tmp_disk_tables / (Created_tmp_tables + Created_tmp_disk_tables) * 100',
|
||||
'test' => 'value > 25',
|
||||
'issue' => __('Many temporary tables are being written to disk instead of being kept in memory.'),
|
||||
'recommendation' => __(
|
||||
'Increasing {max_heap_table_size} and {tmp_table_size} might help. However some'
|
||||
. ' temporary tables are always being written to disk, independent of the value of these variables.'
|
||||
. ' To eliminate these you will have to rewrite your queries to avoid those conditions'
|
||||
. ' (Within a temporary table: Presence of a BLOB or TEXT column or presence of a column'
|
||||
. ' bigger than 512 bytes) as mentioned in the beginning of an <a href="'
|
||||
. 'https://www.facebook.com/note.php?note_id=10150111255065841&comments'
|
||||
. '">Article by the Pythian Group</a>'
|
||||
),
|
||||
'justification' => __(
|
||||
'%s%% of all temporary tables are being written to disk, this value should be below 25%%'
|
||||
),
|
||||
'justification_formula' => 'round(value,1)',
|
||||
],
|
||||
[
|
||||
'id' => 'Temp disk rate',
|
||||
'name' => __('Temp disk rate'),
|
||||
'precondition' => '!fired(\'Percentage of temp tables on disk\')',
|
||||
'formula' => 'Created_tmp_disk_tables / Uptime',
|
||||
'test' => 'value * 60 * 60 > 1',
|
||||
'issue' => __('Many temporary tables are being written to disk instead of being kept in memory.'),
|
||||
'recommendation' => __(
|
||||
'Increasing {max_heap_table_size} and {tmp_table_size} might help. However some'
|
||||
. ' temporary tables are always being written to disk, independent of the value of these variables.'
|
||||
. ' To eliminate these you will have to rewrite your queries to avoid those conditions'
|
||||
. ' (Within a temporary table: Presence of a BLOB or TEXT column or presence of a column'
|
||||
. ' bigger than 512 bytes) as mentioned in the <a href="'
|
||||
. 'https://dev.mysql.com/doc/refman/8.0/en/internal-temporary-tables.html'
|
||||
. '">MySQL Documentation</a>'
|
||||
),
|
||||
'justification' => __(
|
||||
'Rate of temporary tables being written to disk: %s, this value should be less than 1 per hour'
|
||||
),
|
||||
'justification_formula' => 'ADVISOR_bytime(value,2)',
|
||||
],
|
||||
// MyISAM index cache
|
||||
[
|
||||
'id' => 'MyISAM key buffer size',
|
||||
'name' => __('MyISAM key buffer size'),
|
||||
'formula' => 'key_buffer_size',
|
||||
'test' => 'value == 0',
|
||||
'issue' => __('Key buffer is not initialized. No MyISAM indexes will be cached.'),
|
||||
'recommendation' => __(
|
||||
'Set {key_buffer_size} depending on the size of your MyISAM indexes. 64M is a good start.'
|
||||
),
|
||||
'justification' => __('key_buffer_size is 0'),
|
||||
],
|
||||
[
|
||||
'id' => 'Max % MyISAM key buffer ever used',
|
||||
'name' => __('Max % MyISAM key buffer ever used'),
|
||||
'precondition' => 'key_buffer_size > 0',
|
||||
'formula' => 'Key_blocks_used * key_cache_block_size / key_buffer_size * 100',
|
||||
'test' => 'value < 95',
|
||||
'issue' => __('MyISAM key buffer (index cache) % used is low.'),
|
||||
'recommendation' => __(
|
||||
'You may need to decrease the size of {key_buffer_size}, re-examine your tables to see'
|
||||
. ' if indexes have been removed, or examine queries and expectations'
|
||||
. ' about what indexes are being used.'
|
||||
),
|
||||
'justification' => __('max %% MyISAM key buffer ever used: %s%%, this value should be above 95%%'),
|
||||
'justification_formula' => 'round(value,1)',
|
||||
],
|
||||
[
|
||||
'id' => 'Percentage of MyISAM key buffer used',
|
||||
'name' => __('Percentage of MyISAM key buffer used'),
|
||||
// Don't fire if above rule fired - we don't need the same advice twice
|
||||
'precondition' => 'key_buffer_size > 0 && !fired(\'Max % MyISAM key buffer ever used\')',
|
||||
'formula' => '( 1 - Key_blocks_unused * key_cache_block_size / key_buffer_size) * 100',
|
||||
'test' => 'value < 95',
|
||||
'issue' => __('MyISAM key buffer (index cache) % used is low.'),
|
||||
'recommendation' => __(
|
||||
'You may need to decrease the size of {key_buffer_size}, re-examine your tables to see'
|
||||
. ' if indexes have been removed, or examine queries and expectations'
|
||||
. ' about what indexes are being used.'
|
||||
),
|
||||
'justification' => __('%% MyISAM key buffer used: %s%%, this value should be above 95%%'),
|
||||
'justification_formula' => 'round(value,1)',
|
||||
],
|
||||
[
|
||||
'id' => 'Percentage of index reads from memory',
|
||||
'name' => __('Percentage of index reads from memory'),
|
||||
'precondition' => 'Key_read_requests > 0',
|
||||
'formula' => '100 - (Key_reads / Key_read_requests * 100)',
|
||||
'test' => 'value < 95',
|
||||
'issue' => __('The % of indexes that use the MyISAM key buffer is low.'),
|
||||
'recommendation' => __('You may need to increase {key_buffer_size}.'),
|
||||
'justification' => __('Index reads from memory: %s%%, this value should be above 95%%'),
|
||||
'justification_formula' => 'round(value,1)',
|
||||
],
|
||||
// Other caches
|
||||
[
|
||||
'id' => 'Rate of table open',
|
||||
'name' => __('Rate of table open'),
|
||||
'formula' => 'Opened_tables / Uptime',
|
||||
'test' => 'value*60*60 > 10',
|
||||
'issue' => __('The rate of opening tables is high.'),
|
||||
'recommendation' => __(
|
||||
'Opening tables requires disk I/O which is costly.'
|
||||
. ' Increasing {table_open_cache} might avoid this.'
|
||||
),
|
||||
'justification' => __('Opened table rate: %s, this value should be less than 10 per hour'),
|
||||
'justification_formula' => 'ADVISOR_bytime(value,2)',
|
||||
],
|
||||
[
|
||||
'id' => 'Percentage of used open files limit',
|
||||
'name' => __('Percentage of used open files limit'),
|
||||
'formula' => 'Open_files / open_files_limit * 100',
|
||||
'test' => 'value > 85',
|
||||
'issue' => __(
|
||||
'The number of open files is approaching the max number of open files.'
|
||||
. ' You may get a "Too many open files" error.'
|
||||
),
|
||||
'recommendation' => __(
|
||||
'Consider increasing {open_files_limit}, and check the error log when'
|
||||
. ' restarting after changing {open_files_limit}.'
|
||||
),
|
||||
'justification' => __('The number of opened files is at %s%% of the limit. It should be below 85%%'),
|
||||
'justification_formula' => 'round(value,1)',
|
||||
],
|
||||
[
|
||||
'id' => 'Rate of open files',
|
||||
'name' => __('Rate of open files'),
|
||||
'formula' => 'Open_files / Uptime',
|
||||
'test' => 'value * 60 * 60 > 5',
|
||||
'issue' => __('The rate of opening files is high.'),
|
||||
'recommendation' => __(
|
||||
'Consider increasing {open_files_limit}, and check the error log when'
|
||||
. ' restarting after changing {open_files_limit}.'
|
||||
),
|
||||
'justification' => __('Opened files rate: %s, this value should be less than 5 per hour'),
|
||||
'justification_formula' => 'ADVISOR_bytime(value,2)',
|
||||
],
|
||||
[
|
||||
'id' => 'Immediate table locks %',
|
||||
'name' => __('Immediate table locks %'),
|
||||
'precondition' => 'Table_locks_waited + Table_locks_immediate > 0',
|
||||
'formula' => 'Table_locks_immediate / (Table_locks_waited + Table_locks_immediate) * 100',
|
||||
'test' => 'value < 95',
|
||||
'issue' => __('Too many table locks were not granted immediately.'),
|
||||
'recommendation' => __('Optimize queries and/or use InnoDB to reduce lock wait.'),
|
||||
'justification' => __('Immediate table locks: %s%%, this value should be above 95%%'),
|
||||
'justification_formula' => 'round(value,1)',
|
||||
],
|
||||
[
|
||||
'id' => 'Table lock wait rate',
|
||||
'name' => __('Table lock wait rate'),
|
||||
'formula' => 'Table_locks_waited / Uptime',
|
||||
'test' => 'value * 60 * 60 > 1',
|
||||
'issue' => __('Too many table locks were not granted immediately.'),
|
||||
'recommendation' => __('Optimize queries and/or use InnoDB to reduce lock wait.'),
|
||||
'justification' => __('Table lock wait rate: %s, this value should be less than 1 per hour'),
|
||||
'justification_formula' => 'ADVISOR_bytime(value,2)',
|
||||
],
|
||||
[
|
||||
'id' => 'Thread cache',
|
||||
'name' => __('Thread cache'),
|
||||
'formula' => 'thread_cache_size',
|
||||
'test' => 'value < 1',
|
||||
'issue' => __('Thread cache is disabled, resulting in more overhead from new connections to MySQL.'),
|
||||
'recommendation' => __('Enable the thread cache by setting {thread_cache_size} > 0.'),
|
||||
'justification' => __('The thread cache is set to 0'),
|
||||
],
|
||||
[
|
||||
'id' => 'Thread cache hit rate %',
|
||||
'name' => __('Thread cache hit rate %'),
|
||||
'precondition' => 'thread_cache_size > 0',
|
||||
'formula' => '100 - Threads_created / Connections',
|
||||
'test' => 'value < 80',
|
||||
'issue' => __('Thread cache is not efficient.'),
|
||||
'recommendation' => __('Increase {thread_cache_size}.'),
|
||||
'justification' => __('Thread cache hitrate: %s%%, this value should be above 80%%'),
|
||||
'justification_formula' => 'round(value,1)',
|
||||
],
|
||||
[
|
||||
'id' => 'Threads that are slow to launch',
|
||||
'name' => __('Threads that are slow to launch'),
|
||||
'precondition' => 'slow_launch_time > 0',
|
||||
'formula' => 'Slow_launch_threads',
|
||||
'test' => 'value > 0',
|
||||
'issue' => __('There are too many threads that are slow to launch.'),
|
||||
'recommendation' => __(
|
||||
'This generally happens in case of general system overload as it is pretty simple'
|
||||
. ' operations. You might want to monitor your system load carefully.'
|
||||
),
|
||||
'justification' => __('%s thread(s) took longer than %s seconds to start, it should be 0'),
|
||||
'justification_formula' => 'value, slow_launch_time',
|
||||
],
|
||||
[
|
||||
'id' => 'Slow launch time',
|
||||
'name' => __('Slow launch time'),
|
||||
'formula' => 'slow_launch_time',
|
||||
'test' => 'value > 2',
|
||||
'issue' => __('Slow_launch_time is above 2s.'),
|
||||
'recommendation' => __(
|
||||
'Set {slow_launch_time} to 1s or 2s to correctly count threads that are slow to launch.'
|
||||
),
|
||||
'justification' => __('slow_launch_time is set to %s'),
|
||||
'justification_formula' => 'value',
|
||||
],
|
||||
// Connections
|
||||
[
|
||||
'id' => 'Percentage of used connections',
|
||||
'name' => __('Percentage of used connections'),
|
||||
'formula' => 'Max_used_connections / max_connections * 100',
|
||||
'test' => 'value > 80',
|
||||
'issue' => __(
|
||||
'The maximum amount of used connections is getting close to the value of {max_connections}.'
|
||||
),
|
||||
'recommendation' => __(
|
||||
'Increase {max_connections}, or decrease {wait_timeout} so that connections that do not'
|
||||
. ' close database handlers properly get killed sooner.'
|
||||
. ' Make sure the code closes database handlers properly.'
|
||||
),
|
||||
'justification' => __('Max_used_connections is at %s%% of max_connections, it should be below 80%%'),
|
||||
'justification_formula' => 'round(value,1)',
|
||||
],
|
||||
[
|
||||
'id' => 'Percentage of aborted connections',
|
||||
'name' => __('Percentage of aborted connections'),
|
||||
'formula' => 'Aborted_connects / Connections * 100',
|
||||
'test' => 'value > 1',
|
||||
'issue' => __('Too many connections are aborted.'),
|
||||
'recommendation' => __(
|
||||
'Connections are usually aborted when they cannot be authorized. <a href="'
|
||||
. 'https://www.percona.com/blog/2008/08/23/how-to-track-down-the-source-of-aborted_connects/'
|
||||
. '">This article</a> might help you track down the source.'
|
||||
),
|
||||
'justification' => __('%s%% of all connections are aborted. This value should be below 1%%'),
|
||||
'justification_formula' => 'round(value,1)',
|
||||
],
|
||||
[
|
||||
'id' => 'Rate of aborted connections',
|
||||
'name' => __('Rate of aborted connections'),
|
||||
'formula' => 'Aborted_connects / Uptime',
|
||||
'test' => 'value * 60 * 60 > 1',
|
||||
'issue' => __('Too many connections are aborted.'),
|
||||
'recommendation' => __(
|
||||
'Connections are usually aborted when they cannot be authorized. <a href="'
|
||||
. 'https://www.percona.com/blog/2008/08/23/how-to-track-down-the-source-of-aborted_connects/'
|
||||
. '">This article</a> might help you track down the source.'
|
||||
),
|
||||
'justification' => __('Aborted connections rate is at %s, this value should be less than 1 per hour'),
|
||||
'justification_formula' => 'ADVISOR_bytime(value,2)',
|
||||
],
|
||||
[
|
||||
'id' => 'Percentage of aborted clients',
|
||||
'name' => __('Percentage of aborted clients'),
|
||||
'formula' => 'Aborted_clients / Connections * 100',
|
||||
'test' => 'value > 2',
|
||||
'issue' => __('Too many clients are aborted.'),
|
||||
'recommendation' => __(
|
||||
'Clients are usually aborted when they did not close their connection to MySQL properly.'
|
||||
. ' This can be due to network issues or code not closing a database handler properly.'
|
||||
. ' Check your network and code.'
|
||||
),
|
||||
'justification' => __('%s%% of all clients are aborted. This value should be below 2%%'),
|
||||
'justification_formula' => 'round(value,1)',
|
||||
],
|
||||
[
|
||||
'id' => 'Rate of aborted clients',
|
||||
'name' => __('Rate of aborted clients'),
|
||||
'formula' => 'Aborted_clients / Uptime',
|
||||
'test' => 'value * 60 * 60 > 1',
|
||||
'issue' => __('Too many clients are aborted.'),
|
||||
'recommendation' => __(
|
||||
'Clients are usually aborted when they did not close their connection to MySQL properly.'
|
||||
. ' This can be due to network issues or code not closing a database handler properly.'
|
||||
. ' Check your network and code.'
|
||||
),
|
||||
'justification' => __('Aborted client rate is at %s, this value should be less than 1 per hour'),
|
||||
'justification_formula' => 'ADVISOR_bytime(value,2)',
|
||||
],
|
||||
// InnoDB
|
||||
[
|
||||
'id' => 'Is InnoDB disabled?',
|
||||
'name' => __('Is InnoDB disabled?'),
|
||||
'precondition' => 'PMA_MYSQL_INT_VERSION < 50600',
|
||||
'formula' => 'have_innodb',
|
||||
'test' => 'value != "YES"',
|
||||
'issue' => __('You do not have InnoDB enabled.'),
|
||||
'recommendation' => __('InnoDB is usually the better choice for table engines.'),
|
||||
'justification' => __('have_innodb is set to \'value\''),
|
||||
],
|
||||
[
|
||||
'id' => 'InnoDB log size',
|
||||
'name' => __('InnoDB log size'),
|
||||
'precondition' => 'innodb_buffer_pool_size > 0',
|
||||
'formula' => '(innodb_log_file_size * innodb_log_files_in_group)/ innodb_buffer_pool_size * 100',
|
||||
'test' => 'value < 20 && innodb_log_file_size / (1024 * 1024) < 256',
|
||||
'issue' => __(
|
||||
'The InnoDB log file size is not an appropriate size, in relation to the InnoDB buffer pool.'
|
||||
),
|
||||
'recommendation' => __(
|
||||
'Especially on a system with a lot of writes to InnoDB tables you should set'
|
||||
. ' {innodb_log_file_size} to 25% of {innodb_buffer_pool_size}. However the bigger this value,'
|
||||
. ' the longer the recovery time will be when database crashes, so this value should not be set'
|
||||
. ' much higher than 256 MiB. Please note however that you cannot simply change the value of'
|
||||
. ' this variable. You need to shutdown the server, remove the InnoDB log files, set the new'
|
||||
. ' value in my.cnf, start the server, then check the error logs if everything went fine.'
|
||||
. ' See also <a href="'
|
||||
. 'https://mysqldatabaseadministration.blogspot.com/2007/01/increase-innodblogfilesize-proper-way.html'
|
||||
. '">this blog entry</a>'
|
||||
),
|
||||
'justification' => __(
|
||||
'Your InnoDB log size is at %s%% in relation to the InnoDB buffer pool size,'
|
||||
. ' it should not be below 20%%'
|
||||
),
|
||||
'justification_formula' => 'round(value,1)',
|
||||
],
|
||||
[
|
||||
'id' => 'Max InnoDB log size',
|
||||
'name' => __('Max InnoDB log size'),
|
||||
'precondition' => 'innodb_buffer_pool_size > 0 && innodb_log_file_size / innodb_buffer_pool_size * 100 < 30',
|
||||
'formula' => 'innodb_log_file_size / (1024 * 1024)',
|
||||
'test' => 'value > 256',
|
||||
'issue' => __('The InnoDB log file size is inadequately large.'),
|
||||
'recommendation' => __(
|
||||
'It is usually sufficient to set {innodb_log_file_size} to 25% of the size of'
|
||||
. ' {innodb_buffer_pool_size}. A very big {innodb_log_file_size} slows down the recovery'
|
||||
. ' time after a database crash considerably. See also '
|
||||
. '<a href="https://www.percona.com/blog/2006/07/03/choosing-proper-innodb_log_file_size/">'
|
||||
. 'this Article</a>. You need to shutdown the server, remove the InnoDB log files, set the'
|
||||
. ' new value in my.cnf, start the server, then check the error logs'
|
||||
. ' if everything went fine. See also <a href="'
|
||||
. 'https://mysqldatabaseadministration.blogspot.com/2007/01/increase-innodblogfilesize-proper-way.html'
|
||||
. '">this blog entry</a>'
|
||||
),
|
||||
'justification' => __('Your absolute InnoDB log size is %s MiB'),
|
||||
'justification_formula' => 'round(value,1)',
|
||||
],
|
||||
[
|
||||
'id' => 'InnoDB buffer pool size',
|
||||
'name' => __('InnoDB buffer pool size'),
|
||||
'precondition' => 'system_memory > 0',
|
||||
'formula' => 'innodb_buffer_pool_size / system_memory * 100',
|
||||
'test' => 'value < 60',
|
||||
'issue' => __('Your InnoDB buffer pool is fairly small.'),
|
||||
'recommendation' => __(
|
||||
'The InnoDB buffer pool has a profound impact on performance for InnoDB tables.'
|
||||
. ' Assign all your remaining memory to this buffer. For database servers that use solely InnoDB'
|
||||
. ' as storage engine and have no other services (e.g. a web server) running, you may set this'
|
||||
. ' as high as 80% of your available memory. If that is not the case, you need to carefully'
|
||||
. ' assess the memory consumption of your other services and non-InnoDB-Tables and set this'
|
||||
. ' variable accordingly. If it is set too high, your system will start swapping,'
|
||||
. ' which decreases performance significantly. See also '
|
||||
. '<a href="https://www.percona.com/blog/2007/11/03/choosing-innodb_buffer_pool_size/">this article</a>'
|
||||
),
|
||||
'justification' => __(
|
||||
'You are currently using %s%% of your memory for the InnoDB buffer pool.'
|
||||
. ' This rule fires if you are assigning less than 60%%, however this might be perfectly'
|
||||
. ' adequate for your system if you don\'t have much InnoDB tables'
|
||||
. ' or other services running on the same machine.'
|
||||
),
|
||||
'justification_formula' => 'value',
|
||||
],
|
||||
// Other
|
||||
[
|
||||
'id' => 'MyISAM concurrent inserts',
|
||||
'name' => __('MyISAM concurrent inserts'),
|
||||
'formula' => 'concurrent_insert',
|
||||
'test' => 'value === 0 || value === \'NEVER\'',
|
||||
'issue' => __('Enable {concurrent_insert} by setting it to 1'),
|
||||
'recommendation' => __(
|
||||
'Setting {concurrent_insert} to 1 reduces contention between'
|
||||
. ' readers and writers for a given table. See also '
|
||||
. '<a href="https://dev.mysql.com/doc/refman/5.5/en/concurrent-inserts.html">MySQL Documentation</a>'
|
||||
),
|
||||
'justification' => __('concurrent_insert is set to 0'),
|
||||
],
|
||||
];
|
||||
@ -1,402 +0,0 @@
|
||||
# phpMyAdmin Advisory rules file
|
||||
#
|
||||
# Use only UNIX style newlines
|
||||
#
|
||||
# This file is being parsed by Advisor.php, which should handle syntax
|
||||
# errors correctly. However, PHP Warnings and the like are being consumed by
|
||||
# the phpMyAdmin error handler, so those won't show up E.g.: Justification line
|
||||
# is empty because you used an unescape percent sign, sprintf() returns an
|
||||
# empty string and no warning/error is shown
|
||||
#
|
||||
# Rule Syntax:
|
||||
# 'rule' identifier[the name of the rule] eexpr [an optional precondition]
|
||||
# expr [variable or value calculation used for the test]
|
||||
# expr [test, if evaluted to 'true' it fires the rule. Use 'value' to insert the calculated value (without quotes)]
|
||||
# string [the issue (what is the problem?)]
|
||||
# string [the recommendation (how do i fix it?)]
|
||||
# formatted-string '|' comma-seperated-expr [the justification (result of the calculated value / why did this rule fire?)]
|
||||
|
||||
# comma-seperated-expr: expr(,expr)*
|
||||
# eexpr: [expr] - expr enclosed in []
|
||||
# expr: a php code literal with extras:
|
||||
# - variable names are replaced with their respective values
|
||||
# - fired('name of rule') is replaced with true/false when given rule has
|
||||
# been fired. Note however that this is a very simple rules engine.
|
||||
# Rules are only checked in sequential order as they are written down
|
||||
# here. If given rule has not been checked yet, fired() will always
|
||||
# evaluate to false
|
||||
# - 'value' is replaced with the calculated value. If it is a string, it
|
||||
# will be put within single quotes
|
||||
# - other than that you may use any php function, initialized variable or
|
||||
# constant
|
||||
#
|
||||
# identifier: A string enclosed in single quotes
|
||||
# string: A quoteless string, may contain HTML. Variable names enclosed in
|
||||
# curly braces are replaced with links to directly edit this variable.
|
||||
# e.g. {tmp_table_size}
|
||||
# formatted-string: You may use classic php sprintf() string formatting here,
|
||||
# the arguments must be appended after a trailing pipe (|) as
|
||||
# mentioned in above syntax percent signs (%) are
|
||||
# automatically escaped (%%) in the following cases: When
|
||||
# followed by a space, dot or comma and at the end of the
|
||||
# line)
|
||||
#
|
||||
# Comments start with #
|
||||
#
|
||||
|
||||
# Queries
|
||||
|
||||
rule 'Uptime below one day'
|
||||
Uptime
|
||||
value < 86400
|
||||
Uptime is less than 1 day, performance tuning may not be accurate.
|
||||
To have more accurate averages it is recommended to let the server run for longer than a day before running this analyzer
|
||||
The uptime is only %s | ADVISOR_timespanFormat(Uptime)
|
||||
|
||||
rule 'Questions below 1,000'
|
||||
Questions
|
||||
value < 1000
|
||||
Fewer than 1,000 questions have been run against this server. The recommendations may not be accurate.
|
||||
Let the server run for a longer time until it has executed a greater amount of queries.
|
||||
Current amount of Questions: %s | Questions
|
||||
|
||||
rule 'Percentage of slow queries' [Questions > 0]
|
||||
Slow_queries / Questions * 100
|
||||
value >= 5
|
||||
There is a lot of slow queries compared to the overall amount of Queries.
|
||||
You might want to increase {long_query_time} or optimize the queries listed in the slow query log
|
||||
The slow query rate should be below 5%, your value is %s%. | round(value,2)
|
||||
|
||||
rule 'Slow query rate' [Questions > 0]
|
||||
(Slow_queries / Questions * 100) / Uptime
|
||||
value * 60 * 60 > 1
|
||||
There is a high percentage of slow queries compared to the server uptime.
|
||||
You might want to increase {long_query_time} or optimize the queries listed in the slow query log
|
||||
You have a slow query rate of %s per hour, you should have less than 1% per hour. | ADVISOR_bytime(value,2)
|
||||
|
||||
rule 'Long query time'
|
||||
long_query_time
|
||||
value >= 10
|
||||
{long_query_time} is set to 10 seconds or more, thus only slow queries that take above 10 seconds are logged.
|
||||
It is suggested to set {long_query_time} to a lower value, depending on your environment. Usually a value of 1-5 seconds is suggested.
|
||||
long_query_time is currently set to %ds. | value
|
||||
|
||||
rule 'Slow query logging' [PMA_MYSQL_INT_VERSION < 50600]
|
||||
log_slow_queries
|
||||
value == 'OFF'
|
||||
The slow query log is disabled.
|
||||
Enable slow query logging by setting {log_slow_queries} to 'ON'. This will help troubleshooting badly performing queries.
|
||||
log_slow_queries is set to 'OFF'
|
||||
|
||||
rule 'Slow query logging' [PMA_MYSQL_INT_VERSION >= 50600]
|
||||
slow_query_log
|
||||
value == 'OFF'
|
||||
The slow query log is disabled.
|
||||
Enable slow query logging by setting {slow_query_log} to 'ON'. This will help troubleshooting badly performing queries.
|
||||
slow_query_log is set to 'OFF'
|
||||
|
||||
#
|
||||
# versions
|
||||
rule 'Release Series'
|
||||
version
|
||||
substr(value,0,2) <= '5.' && substr(value,2,1) < 1
|
||||
The MySQL server version less than 5.1.
|
||||
You should upgrade, as MySQL 5.1 has improved performance, and MySQL 5.5 even more so.
|
||||
Current version: %s | value
|
||||
|
||||
rule 'Minor Version' [! fired('Release Series')]
|
||||
version
|
||||
substr(value,0,2) <= '5.' && substr(value,2,1) <= 1 && substr(value,4,2) < 30
|
||||
Version less than 5.1.30 (the first GA release of 5.1).
|
||||
You should upgrade, as recent versions of MySQL 5.1 have improved performance and MySQL 5.5 even more so.
|
||||
Current version: %s | value
|
||||
|
||||
rule 'Minor Version' [! fired('Release Series')]
|
||||
version
|
||||
substr(value,0,1) == 5 && substr(value,2,1) == 5 && substr(value,4,2) < 8
|
||||
Version less than 5.5.8 (the first GA release of 5.5).
|
||||
You should upgrade, to a stable version of MySQL 5.5.
|
||||
Current version: %s | value
|
||||
|
||||
rule 'Distribution'
|
||||
version_comment
|
||||
preg_match('/source/i',value)
|
||||
Version is compiled from source, not a MySQL official binary.
|
||||
If you did not compile from source, you may be using a package modified by a distribution. The MySQL manual only is accurate for official MySQL binaries, not any package distributions (such as RedHat, Debian/Ubuntu etc).
|
||||
'source' found in version_comment
|
||||
|
||||
rule 'Distribution'
|
||||
version_comment
|
||||
preg_match('/percona/i',value)
|
||||
The MySQL manual only is accurate for official MySQL binaries.
|
||||
Percona documentation is at <a href="https://www.percona.com/software/documentation/">https://www.percona.com/software/documentation/</a>
|
||||
'percona' found in version_comment
|
||||
|
||||
rule 'MySQL Architecture'
|
||||
system_memory
|
||||
value > 3072*1024 && !preg_match('/64/',version_compile_machine) && !preg_match('/64/',version_compile_os)
|
||||
MySQL is not compiled as a 64-bit package.
|
||||
Your memory capacity is above 3 GiB (assuming the Server is on localhost), so MySQL might not be able to access all of your memory. You might want to consider installing the 64-bit version of MySQL.
|
||||
Available memory on this host: %s | ADVISOR_formatByteDown(value*1024, 2, 2)
|
||||
|
||||
#
|
||||
# Query cache
|
||||
|
||||
rule 'Query caching method' [!fired('Query cache disabled')]
|
||||
Questions / Uptime
|
||||
value > 100
|
||||
Suboptimal caching method.
|
||||
You are using the MySQL Query cache with a fairly high traffic database. It might be worth considering to use <a href="https://dev.mysql.com/doc/refman/5.6/en/ha-memcached.html">memcached</a> instead of the MySQL Query cache, especially if you have multiple slaves.
|
||||
The query cache is enabled and the server receives %d queries per second. This rule fires if there is more than 100 queries per second. | round(value,1)
|
||||
|
||||
#
|
||||
# Sorts
|
||||
rule 'Percentage of sorts that cause temporary tables' [Sort_scan + Sort_range > 0]
|
||||
Sort_merge_passes / (Sort_scan + Sort_range) * 100
|
||||
value > 10
|
||||
Too many sorts are causing temporary tables.
|
||||
Consider increasing {sort_buffer_size} and/or {read_rnd_buffer_size}, depending on your system memory limits.
|
||||
%s% of all sorts cause temporary tables, this value should be lower than 10%. | round(value,1)
|
||||
|
||||
rule 'Rate of sorts that cause temporary tables'
|
||||
Sort_merge_passes / Uptime
|
||||
value * 60 * 60 > 1
|
||||
Too many sorts are causing temporary tables.
|
||||
Consider increasing {sort_buffer_size} and/or {read_rnd_buffer_size}, depending on your system memory limits.
|
||||
Temporary tables average: %s, this value should be less than 1 per hour. | ADVISOR_bytime(value,2)
|
||||
|
||||
rule 'Sort rows'
|
||||
Sort_rows / Uptime
|
||||
value * 60 >= 1
|
||||
There are lots of rows being sorted.
|
||||
While there is nothing wrong with a high amount of row sorting, you might want to make sure that the queries which require a lot of sorting use indexed columns in the ORDER BY clause, as this will result in much faster sorting.
|
||||
Sorted rows average: %s | ADVISOR_bytime(value,2)
|
||||
|
||||
# Joins, scans
|
||||
rule 'Rate of joins without indexes'
|
||||
(Select_range_check + Select_scan + Select_full_join) / Uptime
|
||||
value * 60 * 60 > 1
|
||||
There are too many joins without indexes.
|
||||
This means that joins are doing full table scans. Adding indexes for the columns being used in the join conditions will greatly speed up table joins.
|
||||
Table joins average: %s, this value should be less than 1 per hour | ADVISOR_bytime(value,2)
|
||||
|
||||
rule 'Rate of reading first index entry'
|
||||
Handler_read_first / Uptime
|
||||
value * 60 * 60 > 1
|
||||
The rate of reading the first index entry is high.
|
||||
This usually indicates frequent full index scans. Full index scans are faster than table scans but require lots of CPU cycles in big tables, if those tables that have or had high volumes of UPDATEs and DELETEs, running 'OPTIMIZE TABLE' might reduce the amount of and/or speed up full index scans. Other than that full index scans can only be reduced by rewriting queries.
|
||||
Index scans average: %s, this value should be less than 1 per hour | ADVISOR_bytime(value,2)
|
||||
|
||||
rule 'Rate of reading fixed position'
|
||||
Handler_read_rnd / Uptime
|
||||
value * 60 * 60 > 1
|
||||
The rate of reading data from a fixed position is high.
|
||||
This indicates that many queries need to sort results and/or do a full table scan, including join queries that do not use indexes. Add indexes where applicable.
|
||||
Rate of reading fixed position average: %s, this value should be less than 1 per hour | ADVISOR_bytime(value,2)
|
||||
|
||||
rule 'Rate of reading next table row'
|
||||
Handler_read_rnd_next / Uptime
|
||||
value * 60 * 60 > 1
|
||||
The rate of reading the next table row is high.
|
||||
This indicates that many queries are doing full table scans. Add indexes where applicable.
|
||||
Rate of reading next table row: %s, this value should be less than 1 per hour | ADVISOR_bytime(value,2)
|
||||
|
||||
# temp tables
|
||||
rule 'Different tmp_table_size and max_heap_table_size'
|
||||
tmp_table_size - max_heap_table_size
|
||||
value !=0
|
||||
{tmp_table_size} and {max_heap_table_size} are not the same.
|
||||
If you have deliberately changed one of either: The server uses the lower value of either to determine the maximum size of in-memory tables. So if you wish to increase the in-memory table limit you will have to increase the other value as well.
|
||||
Current values are tmp_table_size: %s, max_heap_table_size: %s | ADVISOR_formatByteDown(tmp_table_size, 2, 2), ADVISOR_formatByteDown(max_heap_table_size, 2, 2)
|
||||
|
||||
rule 'Percentage of temp tables on disk' [Created_tmp_tables + Created_tmp_disk_tables > 0]
|
||||
Created_tmp_disk_tables / (Created_tmp_tables + Created_tmp_disk_tables) * 100
|
||||
value > 25
|
||||
Many temporary tables are being written to disk instead of being kept in memory.
|
||||
Increasing {max_heap_table_size} and {tmp_table_size} might help. However some temporary tables are always being written to disk, independent of the value of these variables. To eliminate these you will have to rewrite your queries to avoid those conditions (Within a temporary table: Presence of a BLOB or TEXT column or presence of a column bigger than 512 bytes) as mentioned in the beginning of an <a href="https://www.facebook.com/note.php?note_id=10150111255065841&comments">Article by the Pythian Group</a>
|
||||
%s% of all temporary tables are being written to disk, this value should be below 25% | round(value,1)
|
||||
|
||||
rule 'Temp disk rate' [!fired('Percentage of temp tables on disk')]
|
||||
Created_tmp_disk_tables / Uptime
|
||||
value * 60 * 60 > 1
|
||||
Many temporary tables are being written to disk instead of being kept in memory.
|
||||
Increasing {max_heap_table_size} and {tmp_table_size} might help. However some temporary tables are always being written to disk, independent of the value of these variables. To eliminate these you will have to rewrite your queries to avoid those conditions (Within a temporary table: Presence of a BLOB or TEXT column or presence of a column bigger than 512 bytes) as mentioned in the <a href="https://dev.mysql.com/doc/refman/8.0/en/internal-temporary-tables.html">MySQL Documentation</a>
|
||||
Rate of temporary tables being written to disk: %s, this value should be less than 1 per hour | ADVISOR_bytime(value,2)
|
||||
|
||||
#
|
||||
# MyISAM index cache
|
||||
rule 'MyISAM key buffer size'
|
||||
key_buffer_size
|
||||
value == 0
|
||||
Key buffer is not initialized. No MyISAM indexes will be cached.
|
||||
Set {key_buffer_size} depending on the size of your MyISAM indexes. 64M is a good start.
|
||||
key_buffer_size is 0
|
||||
|
||||
rule 'Max % MyISAM key buffer ever used' [key_buffer_size > 0]
|
||||
Key_blocks_used * key_cache_block_size / key_buffer_size * 100
|
||||
value < 95
|
||||
MyISAM key buffer (index cache) % used is low.
|
||||
You may need to decrease the size of {key_buffer_size}, re-examine your tables to see if indexes have been removed, or examine queries and expectations about what indexes are being used.
|
||||
max % MyISAM key buffer ever used: %s%, this value should be above 95% | round(value,1)
|
||||
|
||||
# Don't fire if above rule fired - we don't need the same advice twice
|
||||
rule 'Percentage of MyISAM key buffer used' [key_buffer_size > 0 && !fired('Max % MyISAM key buffer ever used')]
|
||||
( 1 - Key_blocks_unused * key_cache_block_size / key_buffer_size) * 100
|
||||
value < 95
|
||||
MyISAM key buffer (index cache) % used is low.
|
||||
You may need to decrease the size of {key_buffer_size}, re-examine your tables to see if indexes have been removed, or examine queries and expectations about what indexes are being used.
|
||||
% MyISAM key buffer used: %s%, this value should be above 95% | round(value,1)
|
||||
|
||||
rule 'Percentage of index reads from memory' [Key_read_requests > 0]
|
||||
100 - (Key_reads / Key_read_requests * 100)
|
||||
value < 95
|
||||
The % of indexes that use the MyISAM key buffer is low.
|
||||
You may need to increase {key_buffer_size}.
|
||||
Index reads from memory: %s%, this value should be above 95% | round(value,1)
|
||||
|
||||
#
|
||||
# other caches
|
||||
rule 'Rate of table open'
|
||||
Opened_tables / Uptime
|
||||
value*60*60 > 10
|
||||
The rate of opening tables is high.
|
||||
Opening tables requires disk I/O which is costly. Increasing {table_open_cache} might avoid this.
|
||||
Opened table rate: %s, this value should be less than 10 per hour | ADVISOR_bytime(value,2)
|
||||
|
||||
rule 'Percentage of used open files limit'
|
||||
Open_files / open_files_limit * 100
|
||||
value > 85
|
||||
The number of open files is approaching the max number of open files. You may get a "Too many open files" error.
|
||||
Consider increasing {open_files_limit}, and check the error log when restarting after changing {open_files_limit}.
|
||||
The number of opened files is at %s% of the limit. It should be below 85% | round(value,1)
|
||||
|
||||
rule 'Rate of open files'
|
||||
Open_files / Uptime
|
||||
value * 60 * 60 > 5
|
||||
The rate of opening files is high.
|
||||
Consider increasing {open_files_limit}, and check the error log when restarting after changing {open_files_limit}.
|
||||
Opened files rate: %s, this value should be less than 5 per hour | ADVISOR_bytime(value,2)
|
||||
|
||||
rule 'Immediate table locks %' [Table_locks_waited + Table_locks_immediate > 0]
|
||||
Table_locks_immediate / (Table_locks_waited + Table_locks_immediate) * 100
|
||||
value < 95
|
||||
Too many table locks were not granted immediately.
|
||||
Optimize queries and/or use InnoDB to reduce lock wait.
|
||||
Immediate table locks: %s%, this value should be above 95% | round(value,1)
|
||||
|
||||
rule 'Table lock wait rate'
|
||||
Table_locks_waited / Uptime
|
||||
value * 60 * 60 > 1
|
||||
Too many table locks were not granted immediately.
|
||||
Optimize queries and/or use InnoDB to reduce lock wait.
|
||||
Table lock wait rate: %s, this value should be less than 1 per hour | ADVISOR_bytime(value,2)
|
||||
|
||||
rule 'Thread cache'
|
||||
thread_cache_size
|
||||
value < 1
|
||||
Thread cache is disabled, resulting in more overhead from new connections to MySQL.
|
||||
Enable the thread cache by setting {thread_cache_size} > 0.
|
||||
The thread cache is set to 0
|
||||
|
||||
rule 'Thread cache hit rate %' [thread_cache_size > 0]
|
||||
100 - Threads_created / Connections
|
||||
value < 80
|
||||
Thread cache is not efficient.
|
||||
Increase {thread_cache_size}.
|
||||
Thread cache hitrate: %s%, this value should be above 80% | round(value,1)
|
||||
|
||||
rule 'Threads that are slow to launch' [slow_launch_time > 0]
|
||||
Slow_launch_threads
|
||||
value > 0
|
||||
There are too many threads that are slow to launch.
|
||||
This generally happens in case of general system overload as it is pretty simple operations. You might want to monitor your system load carefully.
|
||||
%s thread(s) took longer than %s seconds to start, it should be 0 | value, slow_launch_time
|
||||
|
||||
rule 'Slow launch time'
|
||||
slow_launch_time
|
||||
value > 2
|
||||
Slow_launch_time is above 2s.
|
||||
Set {slow_launch_time} to 1s or 2s to correctly count threads that are slow to launch.
|
||||
slow_launch_time is set to %s | value
|
||||
|
||||
#
|
||||
#Connections
|
||||
rule 'Percentage of used connections'
|
||||
Max_used_connections / max_connections * 100
|
||||
value > 80
|
||||
The maximum amount of used connections is getting close to the value of {max_connections}.
|
||||
Increase {max_connections}, or decrease {wait_timeout} so that connections that do not close database handlers properly get killed sooner. Make sure the code closes database handlers properly.
|
||||
Max_used_connections is at %s% of max_connections, it should be below 80% | round(value,1)
|
||||
|
||||
rule 'Percentage of aborted connections'
|
||||
Aborted_connects / Connections * 100
|
||||
value > 1
|
||||
Too many connections are aborted.
|
||||
Connections are usually aborted when they cannot be authorized. <a href="https://www.percona.com/blog/2008/08/23/how-to-track-down-the-source-of-aborted_connects/">This article</a> might help you track down the source.
|
||||
%s% of all connections are aborted. This value should be below 1% | round(value,1)
|
||||
|
||||
rule 'Rate of aborted connections'
|
||||
Aborted_connects / Uptime
|
||||
value * 60 * 60 > 1
|
||||
Too many connections are aborted.
|
||||
Connections are usually aborted when they cannot be authorized. <a href="https://www.percona.com/blog/2008/08/23/how-to-track-down-the-source-of-aborted_connects/">This article</a> might help you track down the source.
|
||||
Aborted connections rate is at %s, this value should be less than 1 per hour | ADVISOR_bytime(value,2)
|
||||
|
||||
rule 'Percentage of aborted clients'
|
||||
Aborted_clients / Connections * 100
|
||||
value > 2
|
||||
Too many clients are aborted.
|
||||
Clients are usually aborted when they did not close their connection to MySQL properly. This can be due to network issues or code not closing a database handler properly. Check your network and code.
|
||||
%s% of all clients are aborted. This value should be below 2% | round(value,1)
|
||||
|
||||
rule 'Rate of aborted clients'
|
||||
Aborted_clients / Uptime
|
||||
value * 60 * 60 > 1
|
||||
Too many clients are aborted.
|
||||
Clients are usually aborted when they did not close their connection to MySQL properly. This can be due to network issues or code not closing a database handler properly. Check your network and code.
|
||||
Aborted client rate is at %s, this value should be less than 1 per hour | ADVISOR_bytime(value,2)
|
||||
|
||||
#
|
||||
# InnoDB
|
||||
rule 'Is InnoDB disabled?' [PMA_MYSQL_INT_VERSION < 50600]
|
||||
have_innodb
|
||||
value != "YES"
|
||||
You do not have InnoDB enabled.
|
||||
InnoDB is usually the better choice for table engines.
|
||||
have_innodb is set to 'value'
|
||||
|
||||
rule 'InnoDB log size' [innodb_buffer_pool_size > 0]
|
||||
(innodb_log_file_size * innodb_log_files_in_group)/ innodb_buffer_pool_size * 100
|
||||
value < 20 && innodb_log_file_size / (1024 * 1024) < 256
|
||||
The InnoDB log file size is not an appropriate size, in relation to the InnoDB buffer pool.
|
||||
Especially on a system with a lot of writes to InnoDB tables you should set {innodb_log_file_size} to 25% of {innodb_buffer_pool_size}. However the bigger this value, the longer the recovery time will be when database crashes, so this value should not be set much higher than 256 MiB. Please note however that you cannot simply change the value of this variable. You need to shutdown the server, remove the InnoDB log files, set the new value in my.cnf, start the server, then check the error logs if everything went fine. See also <a href="https://mysqldatabaseadministration.blogspot.com/2007/01/increase-innodblogfilesize-proper-way.html">this blog entry</a>
|
||||
Your InnoDB log size is at %s% in relation to the InnoDB buffer pool size, it should not be below 20% | round(value,1)
|
||||
|
||||
rule 'Max InnoDB log size' [innodb_buffer_pool_size > 0 && innodb_log_file_size / innodb_buffer_pool_size * 100 < 30]
|
||||
innodb_log_file_size / (1024 * 1024)
|
||||
value > 256
|
||||
The InnoDB log file size is inadequately large.
|
||||
It is usually sufficient to set {innodb_log_file_size} to 25% of the size of {innodb_buffer_pool_size}. A very big {innodb_log_file_size} slows down the recovery time after a database crash considerably. See also <a href="https://www.percona.com/blog/2006/07/03/choosing-proper-innodb_log_file_size/">this Article</a>. You need to shutdown the server, remove the InnoDB log files, set the new value in my.cnf, start the server, then check the error logs if everything went fine. See also <a href="https://mysqldatabaseadministration.blogspot.com/2007/01/increase-innodblogfilesize-proper-way.html">this blog entry</a>
|
||||
Your absolute InnoDB log size is %s MiB | round(value,1)
|
||||
|
||||
rule 'InnoDB buffer pool size' [system_memory > 0]
|
||||
innodb_buffer_pool_size / system_memory * 100
|
||||
value < 60
|
||||
Your InnoDB buffer pool is fairly small.
|
||||
The InnoDB buffer pool has a profound impact on performance for InnoDB tables. Assign all your remaining memory to this buffer. For database servers that use solely InnoDB as storage engine and have no other services (e.g. a web server) running, you may set this as high as 80% of your available memory. If that is not the case, you need to carefully assess the memory consumption of your other services and non-InnoDB-Tables and set this variable accordingly. If it is set too high, your system will start swapping, which decreases performance significantly. See also <a href="https://www.percona.com/blog/2007/11/03/choosing-innodb_buffer_pool_size/">this article</a>
|
||||
You are currently using %s% of your memory for the InnoDB buffer pool. This rule fires if you are assigning less than 60%, however this might be perfectly adequate for your system if you don't have much InnoDB tables or other services running on the same machine. | value
|
||||
|
||||
#
|
||||
# other
|
||||
rule 'MyISAM concurrent inserts'
|
||||
concurrent_insert
|
||||
value === 0 || value === 'NEVER'
|
||||
Enable {concurrent_insert} by setting it to 1
|
||||
Setting {concurrent_insert} to 1 reduces contention between readers and writers for a given table. See also <a href="https://dev.mysql.com/doc/refman/5.5/en/concurrent-inserts.html">MySQL Documentation</a>
|
||||
concurrent_insert is set to 0
|
||||
|
||||
# INSERT DELAYED USAGE
|
||||
#Delayed_errors 0
|
||||
#Delayed_insert_threads 0
|
||||
#Delayed_writes 0
|
||||
#Not_flushed_delayed_rows
|
||||
120
libraries/advisory_rules_mysql_before80003.php
Normal file
120
libraries/advisory_rules_mysql_before80003.php
Normal file
@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
return [
|
||||
// Query cache
|
||||
[
|
||||
'id' => 'Query cache disabled',
|
||||
'name' => __('Query cache disabled'),
|
||||
'formula' => 'query_cache_size',
|
||||
'test' => 'value == 0 || query_cache_type == \'OFF\' || query_cache_type == \'0\'',
|
||||
'issue' => __('The query cache is not enabled.'),
|
||||
'recommendation' => __(
|
||||
'The query cache is known to greatly improve performance if configured correctly. Enable it by'
|
||||
. ' setting {query_cache_size} to a 2 digit MiB value and setting {query_cache_type} to \'ON\'.'
|
||||
. ' <b>Note:</b> If you are using memcached, ignore this recommendation.'
|
||||
),
|
||||
'justification' => __('query_cache_size is set to 0 or query_cache_type is set to \'OFF\''),
|
||||
],
|
||||
[
|
||||
'id' => 'Query cache efficiency (%)',
|
||||
'name' => __('Query cache efficiency (%)'),
|
||||
'precondition' => 'Com_select + Qcache_hits > 0 && !fired(\'Query cache disabled\')',
|
||||
'formula' => 'Qcache_hits / (Com_select + Qcache_hits) * 100',
|
||||
'test' => 'value < 20',
|
||||
'issue' => __('Query cache not running efficiently, it has a low hit rate.'),
|
||||
'recommendation' => __('Consider increasing {query_cache_limit}.'),
|
||||
'justification' => __('The current query cache hit rate of %s%% is below 20%%'),
|
||||
'justification_formula' => 'round(value,1)',
|
||||
],
|
||||
[
|
||||
'id' => 'Query Cache usage',
|
||||
'name' => __('Query Cache usage'),
|
||||
'precondition' => '!fired(\'Query cache disabled\')',
|
||||
'formula' => '100 - Qcache_free_memory / query_cache_size * 100',
|
||||
'test' => 'value < 80',
|
||||
'issue' => __('Less than 80% of the query cache is being utilized.'),
|
||||
'recommendation' => __(
|
||||
'This might be caused by {query_cache_limit} being too low.'
|
||||
. ' Flushing the query cache might help as well.'
|
||||
),
|
||||
'justification' => __(
|
||||
'The current ratio of free query cache memory to total query'
|
||||
. ' cache size is %s%%. It should be above 80%%'
|
||||
),
|
||||
'justification_formula' => 'round(value,1)',
|
||||
],
|
||||
[
|
||||
'id' => 'Query cache fragmentation',
|
||||
'name' => __('Query cache fragmentation'),
|
||||
'precondition' => '!fired(\'Query cache disabled\')',
|
||||
'formula' => 'Qcache_free_blocks / (Qcache_total_blocks / 2) * 100',
|
||||
'test' => 'value > 20',
|
||||
'issue' => __('The query cache is considerably fragmented.'),
|
||||
'recommendation' => __(
|
||||
'Severe fragmentation is likely to (further) increase Qcache_lowmem_prunes. This might be'
|
||||
. ' caused by many Query cache low memory prunes due to {query_cache_size} being too small. For a'
|
||||
. ' immediate but short lived fix you can flush the query cache (might lock the query cache for a'
|
||||
. ' long time). Carefully adjusting {query_cache_min_res_unit} to a lower value might help too,'
|
||||
. ' e.g. you can set it to the average size of your queries in the cache using this formula:'
|
||||
. ' (query_cache_size - qcache_free_memory) / qcache_queries_in_cache'
|
||||
),
|
||||
'justification' => __(
|
||||
'The cache is currently fragmented by %s%% , with 100%% fragmentation meaning that the query'
|
||||
. ' cache is an alternating pattern of free and used blocks. This value should be below 20%%.'
|
||||
),
|
||||
'justification_formula' => 'round(value,1)',
|
||||
],
|
||||
[
|
||||
'id' => 'Query cache low memory prunes',
|
||||
'name' => __('Query cache low memory prunes'),
|
||||
'precondition' => 'Qcache_inserts > 0 && !fired(\'Query cache disabled\')',
|
||||
'formula' => 'Qcache_lowmem_prunes / Qcache_inserts * 100',
|
||||
'test' => 'value > 0.1',
|
||||
'issue' => __('Cached queries are removed due to low query cache memory from the query cache.'),
|
||||
'recommendation' => __(
|
||||
'You might want to increase {query_cache_size}, however keep in mind that the overhead of'
|
||||
. ' maintaining the cache is likely to increase with its size, so do this in small increments'
|
||||
. ' and monitor the results.'
|
||||
),
|
||||
'justification' => __(
|
||||
'The ratio of removed queries to inserted queries is %s%%. The lower this value is,'
|
||||
. ' the better (This rules firing limit: 0.1%%)'
|
||||
),
|
||||
'justification_formula' => 'round(value,1)',
|
||||
],
|
||||
[
|
||||
'id' => 'Query cache max size',
|
||||
'name' => __('Query cache max size'),
|
||||
'precondition' => '!fired(\'Query cache disabled\')',
|
||||
'formula' => 'query_cache_size',
|
||||
'test' => 'value > 1024 * 1024 * 128',
|
||||
'issue' => __(
|
||||
'The query cache size is above 128 MiB. Big query caches may cause significant'
|
||||
. ' overhead that is required to maintain the cache.'
|
||||
),
|
||||
'recommendation' => __(
|
||||
'Depending on your environment, it might be performance increasing to reduce this value.'
|
||||
),
|
||||
'justification' => __('Current query cache size: %s'),
|
||||
'justification_formula' => 'ADVISOR_formatByteDown(value, 2, 2)',
|
||||
],
|
||||
[
|
||||
'id' => 'Query cache min result size',
|
||||
'name' => __('Query cache min result size'),
|
||||
'precondition' => '!fired(\'Query cache disabled\')',
|
||||
'formula' => 'query_cache_limit',
|
||||
'test' => 'value == 1024*1024',
|
||||
'issue' => __('The max size of the result set in the query cache is the default of 1 MiB.'),
|
||||
'recommendation' => __(
|
||||
'Changing {query_cache_limit} (usually by increasing) may increase efficiency. This variable'
|
||||
. ' determines the maximum size a query result may have to be inserted into the query cache.'
|
||||
. ' If there are many query results above 1 MiB that are well cacheable (many reads, little writes)'
|
||||
. ' then increasing {query_cache_limit} will increase efficiency. Whereas in the case of many query'
|
||||
. ' results being above 1 MiB that are not very well cacheable (often invalidated due to table'
|
||||
. ' updates) increasing {query_cache_limit} might reduce efficiency.'
|
||||
),
|
||||
'justification' => __('query_cache_limit is set to 1 MiB'),
|
||||
],
|
||||
];
|
||||
@ -1,57 +0,0 @@
|
||||
# phpMyAdmin Advisory rules file
|
||||
#
|
||||
# See doc in advisory_rules_generic.txt
|
||||
#
|
||||
|
||||
#
|
||||
# Query cache
|
||||
|
||||
# Lame: 'ON' == 0 is true, so you need to compare 'ON' == '0'
|
||||
rule 'Query cache disabled'
|
||||
query_cache_size
|
||||
value == 0 || query_cache_type == 'OFF' || query_cache_type == '0'
|
||||
The query cache is not enabled.
|
||||
The query cache is known to greatly improve performance if configured correctly. Enable it by setting {query_cache_size} to a 2 digit MiB value and setting {query_cache_type} to 'ON'. <b>Note:</b> If you are using memcached, ignore this recommendation.
|
||||
query_cache_size is set to 0 or query_cache_type is set to 'OFF'
|
||||
|
||||
rule 'Query cache efficiency (%)' [Com_select + Qcache_hits > 0 && !fired('Query cache disabled')]
|
||||
Qcache_hits / (Com_select + Qcache_hits) * 100
|
||||
value < 20
|
||||
Query cache not running efficiently, it has a low hit rate.
|
||||
Consider increasing {query_cache_limit}.
|
||||
The current query cache hit rate of %s% is below 20% | round(value,1)
|
||||
|
||||
rule 'Query Cache usage' [!fired('Query cache disabled')]
|
||||
100 - Qcache_free_memory / query_cache_size * 100
|
||||
value < 80
|
||||
Less than 80% of the query cache is being utilized.
|
||||
This might be caused by {query_cache_limit} being too low. Flushing the query cache might help as well.
|
||||
The current ratio of free query cache memory to total query cache size is %s%. It should be above 80% | round(value,1)
|
||||
|
||||
rule 'Query cache fragmentation' [!fired('Query cache disabled')]
|
||||
Qcache_free_blocks / (Qcache_total_blocks / 2) * 100
|
||||
value > 20
|
||||
The query cache is considerably fragmented.
|
||||
Severe fragmentation is likely to (further) increase Qcache_lowmem_prunes. This might be caused by many Query cache low memory prunes due to {query_cache_size} being too small. For a immediate but short lived fix you can flush the query cache (might lock the query cache for a long time). Carefully adjusting {query_cache_min_res_unit} to a lower value might help too, e.g. you can set it to the average size of your queries in the cache using this formula: (query_cache_size - qcache_free_memory) / qcache_queries_in_cache
|
||||
The cache is currently fragmented by %s% , with 100% fragmentation meaning that the query cache is an alternating pattern of free and used blocks. This value should be below 20%. | round(value,1)
|
||||
|
||||
rule 'Query cache low memory prunes' [Qcache_inserts > 0 && !fired('Query cache disabled')]
|
||||
Qcache_lowmem_prunes / Qcache_inserts * 100
|
||||
value > 0.1
|
||||
Cached queries are removed due to low query cache memory from the query cache.
|
||||
You might want to increase {query_cache_size}, however keep in mind that the overhead of maintaining the cache is likely to increase with its size, so do this in small increments and monitor the results.
|
||||
The ratio of removed queries to inserted queries is %s%. The lower this value is, the better (This rules firing limit: 0.1%) | round(value,1)
|
||||
|
||||
rule 'Query cache max size' [!fired('Query cache disabled')]
|
||||
query_cache_size
|
||||
value > 1024 * 1024 * 128
|
||||
The query cache size is above 128 MiB. Big query caches may cause significant overhead that is required to maintain the cache.
|
||||
Depending on your environment, it might be performance increasing to reduce this value.
|
||||
Current query cache size: %s | ADVISOR_formatByteDown(value, 2, 2)
|
||||
|
||||
rule 'Query cache min result size' [!fired('Query cache disabled')]
|
||||
query_cache_limit
|
||||
value == 1024*1024
|
||||
The max size of the result set in the query cache is the default of 1 MiB.
|
||||
Changing {query_cache_limit} (usually by increasing) may increase efficiency. This variable determines the maximum size a query result may have to be inserted into the query cache. If there are many query results above 1 MiB that are well cacheable (many reads, little writes) then increasing {query_cache_limit} will increase efficiency. Whereas in the case of many query results being above 1 MiB that are not very well cacheable (often invalidated due to table updates) increasing {query_cache_limit} might reduce efficiency.
|
||||
query_cache_limit is set to 1 MiB
|
||||
@ -1,62 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
* A simple rules engine, that parses and executes the rules in advisory_rules.txt.
|
||||
* Adjusted to phpMyAdmin.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin;
|
||||
|
||||
use Exception;
|
||||
use PhpMyAdmin\Server\SysInfo\SysInfo;
|
||||
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
|
||||
use Throwable;
|
||||
use const FILE_IGNORE_NEW_LINES;
|
||||
use function array_merge;
|
||||
use function array_merge_recursive;
|
||||
use function count;
|
||||
use function file;
|
||||
use function htmlspecialchars;
|
||||
use function implode;
|
||||
use function mb_substr;
|
||||
use function pow;
|
||||
use function preg_match;
|
||||
use function preg_replace;
|
||||
use function preg_replace_callback;
|
||||
use function preg_split;
|
||||
use function round;
|
||||
use function rtrim;
|
||||
use function sprintf;
|
||||
use function strpos;
|
||||
use function substr;
|
||||
use function vsprintf;
|
||||
|
||||
/**
|
||||
* Advisor class
|
||||
* A simple rules engine, that executes the rules in the advisory_rules files.
|
||||
*/
|
||||
class Advisor
|
||||
final class Advisor
|
||||
{
|
||||
public const GENERIC_RULES_FILE = 'libraries/advisory_rules_generic.txt';
|
||||
public const BEFORE_MYSQL80003_RULES_FILE = 'libraries/advisory_rules_mysql_before80003.txt';
|
||||
private const GENERIC_RULES_FILE = 'libraries/advisory_rules_generic.php';
|
||||
private const BEFORE_MYSQL80003_RULES_FILE = 'libraries/advisory_rules_mysql_before80003.php';
|
||||
|
||||
/** @var DatabaseInterface */
|
||||
protected $dbi;
|
||||
private $dbi;
|
||||
|
||||
/** @var array */
|
||||
protected $variables;
|
||||
private $variables;
|
||||
|
||||
/** @var array */
|
||||
protected $globals;
|
||||
private $globals;
|
||||
|
||||
/** @var array */
|
||||
protected $parseResult;
|
||||
private $rules;
|
||||
|
||||
/** @var array */
|
||||
protected $runResult;
|
||||
private $runResult;
|
||||
|
||||
/** @var ExpressionLanguage */
|
||||
protected $expression;
|
||||
private $expression;
|
||||
|
||||
/**
|
||||
* @param DatabaseInterface $dbi DatabaseInterface object
|
||||
@ -131,7 +118,7 @@ class Advisor
|
||||
* @param string $seconds
|
||||
*/
|
||||
static function ($arguments, $seconds) {
|
||||
return self::timespanFormat((int) $seconds);
|
||||
return Util::timespanFormat((int) $seconds);
|
||||
}
|
||||
);
|
||||
$this->expression->register(
|
||||
@ -145,7 +132,7 @@ class Advisor
|
||||
* @param int $comma
|
||||
*/
|
||||
static function ($arguments, $value, $limes = 6, $comma = 0) {
|
||||
return self::formatByteDown($value, $limes, $comma);
|
||||
return implode(' ', (array) Util::formatByteDown($value, $limes, $comma));
|
||||
}
|
||||
);
|
||||
$this->expression->register(
|
||||
@ -177,72 +164,43 @@ class Advisor
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get variables
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getVariables(): array
|
||||
private function setVariables(): void
|
||||
{
|
||||
return $this->variables;
|
||||
$globalStatus = $this->dbi->fetchResult('SHOW GLOBAL STATUS', 0, 1);
|
||||
$globalVariables = $this->dbi->fetchResult('SHOW GLOBAL VARIABLES', 0, 1);
|
||||
|
||||
$sysInfo = SysInfo::get();
|
||||
$memory = $sysInfo->memory();
|
||||
$systemMemory = ['system_memory' => $memory['MemTotal'] ?? 0];
|
||||
|
||||
$this->variables = array_merge($globalStatus, $globalVariables, $systemMemory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set variables
|
||||
*
|
||||
* @param array $variables Variables
|
||||
*
|
||||
* @return Advisor
|
||||
*/
|
||||
public function setVariables(array $variables): self
|
||||
{
|
||||
$this->variables = $variables;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a variable and its value
|
||||
*
|
||||
* @param string|int $variable Variable to set
|
||||
* @param mixed $value Value to set
|
||||
*
|
||||
* @return Advisor
|
||||
*/
|
||||
public function setVariable($variable, $value): self
|
||||
public function setVariable($variable, $value): void
|
||||
{
|
||||
$this->variables[$variable] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get parseResult
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getParseResult(): array
|
||||
private function setRules(): void
|
||||
{
|
||||
return $this->parseResult;
|
||||
$isMariaDB = strpos($this->variables['version'], 'MariaDB') !== false;
|
||||
$genericRules = include ROOT_PATH . self::GENERIC_RULES_FILE;
|
||||
|
||||
if (! $isMariaDB && $this->globals['PMA_MYSQL_INT_VERSION'] >= 80003) {
|
||||
$this->rules = $genericRules;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$extraRules = include ROOT_PATH . self::BEFORE_MYSQL80003_RULES_FILE;
|
||||
$this->rules = array_merge($genericRules, $extraRules);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set parseResult
|
||||
*
|
||||
* @param array $parseResult Parse result
|
||||
*
|
||||
* @return Advisor
|
||||
*/
|
||||
public function setParseResult(array $parseResult): self
|
||||
{
|
||||
$this->parseResult = $parseResult;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get runResult
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getRunResult(): array
|
||||
@ -251,58 +209,15 @@ class Advisor
|
||||
}
|
||||
|
||||
/**
|
||||
* Set runResult
|
||||
*
|
||||
* @param array $runResult Run result
|
||||
*
|
||||
* @return Advisor
|
||||
*/
|
||||
public function setRunResult(array $runResult): self
|
||||
{
|
||||
$this->runResult = $runResult;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses and executes advisor rules
|
||||
*
|
||||
* @return array with run and parse results
|
||||
* @return array
|
||||
*/
|
||||
public function run(): array
|
||||
{
|
||||
// HowTo: A simple Advisory system in 3 easy steps.
|
||||
|
||||
// Step 1: Get some variables to evaluate on
|
||||
$this->setVariables(
|
||||
array_merge(
|
||||
$this->dbi->fetchResult('SHOW GLOBAL STATUS', 0, 1),
|
||||
$this->dbi->fetchResult('SHOW GLOBAL VARIABLES', 0, 1)
|
||||
)
|
||||
);
|
||||
|
||||
// Add total memory to variables as well
|
||||
$sysinfo = SysInfo::get();
|
||||
$memory = $sysinfo->memory();
|
||||
$this->variables['system_memory'] = $memory['MemTotal'] ?? 0;
|
||||
|
||||
$ruleFiles = $this->defineRulesFiles();
|
||||
|
||||
// Step 2: Read and parse the list of rules
|
||||
$parsedResults = [];
|
||||
foreach ($ruleFiles as $ruleFile) {
|
||||
$parsedResults[] = static::parseRulesFile($ruleFile);
|
||||
}
|
||||
$this->setParseResult(array_merge_recursive(...$parsedResults));
|
||||
|
||||
// Step 3: Feed the variables to the rules and let them fire. Sets
|
||||
// $runResult
|
||||
$this->setVariables();
|
||||
$this->setRules();
|
||||
$this->runRules();
|
||||
|
||||
return [
|
||||
'parse' => ['errors' => $this->parseResult['errors']],
|
||||
'run' => $this->runResult,
|
||||
];
|
||||
return $this->runResult;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -311,37 +226,33 @@ class Advisor
|
||||
* @param string $description description of an error.
|
||||
* @param Throwable $exception exception raised
|
||||
*/
|
||||
public function storeError(string $description, Throwable $exception): void
|
||||
private function storeError(string $description, Throwable $exception): void
|
||||
{
|
||||
$this->runResult['errors'][] = $description
|
||||
. ' '
|
||||
. sprintf(
|
||||
__('Error when evaluating: %s'),
|
||||
$exception->getMessage()
|
||||
);
|
||||
$this->runResult['errors'][] = $description . ' ' . sprintf(
|
||||
__('Error when evaluating: %s'),
|
||||
$exception->getMessage()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes advisor rules
|
||||
*/
|
||||
public function runRules(): bool
|
||||
private function runRules(): void
|
||||
{
|
||||
$this->setRunResult(
|
||||
[
|
||||
'fired' => [],
|
||||
'notfired' => [],
|
||||
'unchecked' => [],
|
||||
'errors' => [],
|
||||
]
|
||||
);
|
||||
$this->runResult = [
|
||||
'fired' => [],
|
||||
'notfired' => [],
|
||||
'unchecked' => [],
|
||||
'errors' => [],
|
||||
];
|
||||
|
||||
foreach ($this->parseResult['rules'] as $rule) {
|
||||
foreach ($this->rules as $rule) {
|
||||
$this->variables['value'] = 0;
|
||||
$precond = true;
|
||||
$precondition = true;
|
||||
|
||||
if (isset($rule['precondition'])) {
|
||||
try {
|
||||
$precond = $this->ruleExprEvaluate($rule['precondition']);
|
||||
$precondition = $this->evaluateRuleExpression($rule['precondition']);
|
||||
} catch (Throwable $e) {
|
||||
$this->storeError(
|
||||
sprintf(
|
||||
@ -354,93 +265,43 @@ class Advisor
|
||||
}
|
||||
}
|
||||
|
||||
if (! $precond) {
|
||||
if (! $precondition) {
|
||||
$this->addRule('unchecked', $rule);
|
||||
} else {
|
||||
try {
|
||||
$value = $this->ruleExprEvaluate($rule['formula']);
|
||||
} catch (Throwable $e) {
|
||||
$this->storeError(
|
||||
sprintf(
|
||||
__('Failed calculating value for rule \'%s\'.'),
|
||||
$rule['name']
|
||||
),
|
||||
$e
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->variables['value'] = $value;
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
if ($this->ruleExprEvaluate($rule['test'])) {
|
||||
$this->addRule('fired', $rule);
|
||||
} else {
|
||||
$this->addRule('notfired', $rule);
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
$this->storeError(
|
||||
sprintf(
|
||||
__('Failed running test for rule \'%s\'.'),
|
||||
$rule['name']
|
||||
),
|
||||
$e
|
||||
);
|
||||
try {
|
||||
$value = $this->evaluateRuleExpression($rule['formula']);
|
||||
} catch (Throwable $e) {
|
||||
$this->storeError(
|
||||
sprintf(
|
||||
__('Failed calculating value for rule \'%s\'.'),
|
||||
$rule['name']
|
||||
),
|
||||
$e
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->variables['value'] = $value;
|
||||
|
||||
try {
|
||||
if ($this->evaluateRuleExpression($rule['test'])) {
|
||||
$this->addRule('fired', $rule);
|
||||
} else {
|
||||
$this->addRule('notfired', $rule);
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
$this->storeError(
|
||||
sprintf(
|
||||
__('Failed running test for rule \'%s\'.'),
|
||||
$rule['name']
|
||||
),
|
||||
$e
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes percent string to be used in format string.
|
||||
*
|
||||
* @param string $str string to escape
|
||||
*/
|
||||
public static function escapePercent(string $str): string
|
||||
{
|
||||
return (string) preg_replace('/%( |,|\.|$|\(|\)|<|>)/', '%%\1', $str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper function for translating.
|
||||
*
|
||||
* @param string $str the string
|
||||
* @param string $param the parameters
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function translate(string $str, ?string $param = null): string
|
||||
{
|
||||
$string = _gettext(self::escapePercent($str));
|
||||
if ($param !== null) {
|
||||
$params = $this->ruleExprEvaluate('[' . $param . ']');
|
||||
} else {
|
||||
$params = [];
|
||||
}
|
||||
|
||||
return vsprintf($string, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits justification to text and formula.
|
||||
*
|
||||
* @param array $rule the rule
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public static function splitJustification(array $rule): array
|
||||
{
|
||||
$jst = preg_split('/\s*\|\s*/', $rule['justification'], 2);
|
||||
if ($jst !== false && count($jst) > 1) {
|
||||
return [
|
||||
$jst[0],
|
||||
$jst[1],
|
||||
];
|
||||
}
|
||||
|
||||
return [$rule['justification']];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -448,80 +309,52 @@ class Advisor
|
||||
*
|
||||
* @param string $type type of rule
|
||||
* @param array $rule rule itself
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function addRule(string $type, array $rule): void
|
||||
{
|
||||
switch ($type) {
|
||||
case 'notfired':
|
||||
case 'fired':
|
||||
$jst = self::splitJustification($rule);
|
||||
if (count($jst) > 1) {
|
||||
try {
|
||||
/* Translate */
|
||||
$str = $this->translate($jst[0], $jst[1]);
|
||||
} catch (Throwable $e) {
|
||||
$this->storeError(
|
||||
sprintf(
|
||||
__('Failed formatting string for rule \'%s\'.'),
|
||||
$rule['name']
|
||||
),
|
||||
$e
|
||||
);
|
||||
if ($type !== 'notfired' && $type !== 'fired') {
|
||||
$this->runResult[$type][] = $rule;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$rule['justification'] = $str;
|
||||
} else {
|
||||
$rule['justification'] = $this->translate($rule['justification']);
|
||||
}
|
||||
$rule['id'] = $rule['name'];
|
||||
$rule['name'] = $this->translate($rule['name']);
|
||||
$rule['issue'] = $this->translate($rule['issue']);
|
||||
|
||||
// Replaces {server_variable} with 'server_variable'
|
||||
// linking to /server/variables
|
||||
$rule['recommendation'] = preg_replace_callback(
|
||||
'/\{([a-z_0-9]+)\}/Ui',
|
||||
function (array $matches) {
|
||||
return $this->replaceVariable($matches);
|
||||
},
|
||||
$this->translate($rule['recommendation'])
|
||||
);
|
||||
|
||||
// Replaces external Links with Core::linkURL() generated links
|
||||
$rule['recommendation'] = preg_replace_callback(
|
||||
'#href=("|\')(https?://[^\1]+)\1#i',
|
||||
function (array $matches) {
|
||||
return $this->replaceLinkURL($matches);
|
||||
},
|
||||
$rule['recommendation']
|
||||
);
|
||||
break;
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($rule['justification_formula'])) {
|
||||
try {
|
||||
$params = $this->evaluateRuleExpression('[' . $rule['justification_formula'] . ']');
|
||||
} catch (Throwable $e) {
|
||||
$this->storeError(
|
||||
sprintf(__('Failed formatting string for rule \'%s\'.'), $rule['name']),
|
||||
$e
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$rule['justification'] = vsprintf($rule['justification'], $params);
|
||||
}
|
||||
|
||||
// Replaces {server_variable} with 'server_variable'
|
||||
// linking to /server/variables
|
||||
$rule['recommendation'] = preg_replace_callback(
|
||||
'/\{([a-z_0-9]+)\}/Ui',
|
||||
function (array $matches) {
|
||||
return $this->replaceVariable($matches);
|
||||
},
|
||||
$rule['recommendation']
|
||||
);
|
||||
|
||||
// Replaces external Links with Core::linkURL() generated links
|
||||
$rule['recommendation'] = preg_replace_callback(
|
||||
'#href=("|\')(https?://[^\1]+)\1#i',
|
||||
function (array $matches) {
|
||||
return $this->replaceLinkURL($matches);
|
||||
},
|
||||
$rule['recommendation']
|
||||
);
|
||||
|
||||
$this->runResult[$type][] = $rule;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the rules files to use
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function defineRulesFiles(): array
|
||||
{
|
||||
$isMariaDB = strpos($this->getVariables()['version'], 'MariaDB') !== false;
|
||||
$ruleFiles = [self::GENERIC_RULES_FILE];
|
||||
// If MariaDB (= not MySQL) OR MYSQL < 8.0.3, add another rules file.
|
||||
if ($isMariaDB || $this->globals['PMA_MYSQL_INT_VERSION'] < 80003) {
|
||||
$ruleFiles[] = self::BEFORE_MYSQL80003_RULES_FILE;
|
||||
}
|
||||
|
||||
return $ruleFiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for wrapping links with Core::linkURL
|
||||
*
|
||||
@ -548,148 +381,13 @@ class Advisor
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs a code expression, replacing variable names with their respective
|
||||
* values
|
||||
*
|
||||
* @param string $expr expression to evaluate
|
||||
* Runs a code expression, replacing variable names with their respective values
|
||||
*
|
||||
* @return mixed result of evaluated expression
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function ruleExprEvaluate(string $expr)
|
||||
private function evaluateRuleExpression(string $expression)
|
||||
{
|
||||
// Actually evaluate the code
|
||||
// This can throw exception
|
||||
return $this->expression->evaluate(
|
||||
$expr,
|
||||
array_merge($this->variables, $this->globals)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the rule file into an array, throwing errors messages on syntax
|
||||
* errors.
|
||||
*
|
||||
* @param string $filename Name of file to parse
|
||||
*
|
||||
* @return array with parsed data
|
||||
*/
|
||||
public static function parseRulesFile(string $filename): array
|
||||
{
|
||||
$file = file($filename, FILE_IGNORE_NEW_LINES);
|
||||
|
||||
$errors = [];
|
||||
$rules = [];
|
||||
$lines = [];
|
||||
|
||||
if ($file === false) {
|
||||
$errors[] = sprintf(
|
||||
__('Error in reading file: The file \'%s\' does not exist or is not readable!'),
|
||||
$filename
|
||||
);
|
||||
|
||||
return [
|
||||
'rules' => $rules,
|
||||
'lines' => $lines,
|
||||
'errors' => $errors,
|
||||
];
|
||||
}
|
||||
|
||||
$ruleSyntax = [
|
||||
'name',
|
||||
'formula',
|
||||
'test',
|
||||
'issue',
|
||||
'recommendation',
|
||||
'justification',
|
||||
];
|
||||
$numRules = count($ruleSyntax);
|
||||
$numLines = count($file);
|
||||
$ruleNo = -1;
|
||||
$ruleLine = -1;
|
||||
|
||||
for ($i = 0; $i < $numLines; $i++) {
|
||||
$line = $file[$i];
|
||||
if ($line == '' || $line[0] === '#') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Reading new rule
|
||||
if (substr($line, 0, 4) === 'rule') {
|
||||
if ($ruleLine > 0) {
|
||||
$errors[] = sprintf(
|
||||
__(
|
||||
'Invalid rule declaration on line %1$s, expected line '
|
||||
. '%2$s of previous rule.'
|
||||
),
|
||||
$i + 1,
|
||||
$ruleSyntax[$ruleLine++]
|
||||
);
|
||||
continue;
|
||||
}
|
||||
if (preg_match("/rule\s'(.*)'( \[(.*)\])?$/", $line, $match)) {
|
||||
$ruleLine = 1;
|
||||
$ruleNo++;
|
||||
$rules[$ruleNo] = ['name' => $match[1]];
|
||||
$lines[$ruleNo] = ['name' => $i + 1];
|
||||
if (isset($match[3])) {
|
||||
$rules[$ruleNo]['precondition'] = $match[3];
|
||||
$lines[$ruleNo]['precondition'] = $i + 1;
|
||||
}
|
||||
} else {
|
||||
$errors[] = sprintf(
|
||||
__('Invalid rule declaration on line %s.'),
|
||||
$i + 1
|
||||
);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($ruleLine == -1) {
|
||||
$errors[] = sprintf(
|
||||
__('Unexpected characters on line %s.'),
|
||||
$i + 1
|
||||
);
|
||||
}
|
||||
|
||||
// Reading rule lines
|
||||
if ($ruleLine > 0) {
|
||||
if (! isset($line[0])) {
|
||||
continue; // Empty lines are ok
|
||||
}
|
||||
// Non tabbed lines are not
|
||||
if ($line[0] != "\t") {
|
||||
$errors[] = sprintf(
|
||||
__(
|
||||
'Unexpected character on line %1$s. Expected tab, but '
|
||||
. 'found "%2$s".'
|
||||
),
|
||||
$i + 1,
|
||||
$line[0]
|
||||
);
|
||||
continue;
|
||||
}
|
||||
$rules[$ruleNo][$ruleSyntax[$ruleLine]] = rtrim(
|
||||
mb_substr($line, 1)
|
||||
);
|
||||
$lines[$ruleNo][$ruleSyntax[$ruleLine]] = $i + 1;
|
||||
++$ruleLine;
|
||||
}
|
||||
|
||||
// Rule complete
|
||||
if ($ruleLine != $numRules) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$ruleLine = -1;
|
||||
}
|
||||
|
||||
return [
|
||||
'rules' => $rules,
|
||||
'lines' => $lines,
|
||||
'errors' => $errors,
|
||||
];
|
||||
return $this->expression->evaluate($expression, array_merge($this->variables, $this->globals));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -723,34 +421,4 @@ class Advisor
|
||||
|
||||
return $num . ' ' . $per;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for PhpMyAdmin\Util::timespanFormat
|
||||
*
|
||||
* This function is used when evaluating advisory_rules.txt
|
||||
*
|
||||
* @param int $seconds the timespan
|
||||
*
|
||||
* @return string the formatted value
|
||||
*/
|
||||
public static function timespanFormat(int $seconds): string
|
||||
{
|
||||
return Util::timespanFormat($seconds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper around PhpMyAdmin\Util::formatByteDown
|
||||
*
|
||||
* This function is used when evaluating advisory_rules.txt
|
||||
*
|
||||
* @param double|int $value the value to format
|
||||
* @param int $limes the sensitiveness
|
||||
* @param int $comma the number of decimals to retain
|
||||
*
|
||||
* @return string the formatted value with unit
|
||||
*/
|
||||
public static function formatByteDown($value, int $limes = 6, int $comma = 0): string
|
||||
{
|
||||
return implode(' ', (array) Util::formatByteDown($value, $limes, $comma));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,108 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Translates advisory rules to Gettext format
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Command;
|
||||
|
||||
use PhpMyAdmin\Advisor;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use function addcslashes;
|
||||
use function array_search;
|
||||
use function implode;
|
||||
use function strstr;
|
||||
|
||||
/**
|
||||
* Translates advisory rules to Gettext format
|
||||
*/
|
||||
class AdvisoryRulesCommand extends Command
|
||||
{
|
||||
/** @var string */
|
||||
protected static $defaultName = 'po:advisory-rules';
|
||||
|
||||
/** @var array */
|
||||
private $messages = [];
|
||||
|
||||
/** @var array */
|
||||
private $locations = [];
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->setDescription('Translates advisory rules to Gettext format');
|
||||
$this->setHelp(
|
||||
'This command parses advisory rules and output them'
|
||||
. ' as Gettext POT formatted strings for translation.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param InputInterface $input input
|
||||
* @param OutputInterface $output output
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$ruleFiles = [];
|
||||
$ruleFiles[Advisor::GENERIC_RULES_FILE] = Advisor::parseRulesFile(
|
||||
Advisor::GENERIC_RULES_FILE
|
||||
);
|
||||
$ruleFiles[Advisor::BEFORE_MYSQL80003_RULES_FILE] = Advisor::parseRulesFile(
|
||||
Advisor::BEFORE_MYSQL80003_RULES_FILE
|
||||
);
|
||||
|
||||
foreach ($ruleFiles as $file => $rules) {
|
||||
foreach ($rules['rules'] as $idx => $rule) {
|
||||
$this->addMessage($file, $rules, $idx, 'name');
|
||||
$this->addMessage($file, $rules, $idx, 'issue');
|
||||
$this->addMessage($file, $rules, $idx, 'recommendation');
|
||||
$this->addMessage($file, $rules, $idx, 'justification');
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->messages as $index => $message) {
|
||||
$output->writeln('');
|
||||
$output->write('#: ');
|
||||
$output->writeln(implode(' ', $this->locations[$index]));
|
||||
if (strstr($this->messages[$index], '%') !== false) {
|
||||
$output->writeln('#, php-format');
|
||||
}
|
||||
$output->write('msgid "');
|
||||
$output->write(addcslashes(
|
||||
Advisor::escapePercent($this->messages[$index]),
|
||||
'"\\'
|
||||
));
|
||||
$output->writeln('"');
|
||||
$output->writeln('msgstr ""');
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $file file name
|
||||
* @param array $rules rules array
|
||||
* @param int $index rule index
|
||||
* @param string $type rule type
|
||||
*/
|
||||
private function addMessage(string $file, array $rules, int $index, string $type): void
|
||||
{
|
||||
if ($type === 'justification') {
|
||||
$messages = Advisor::splitJustification($rules['rules'][$index]);
|
||||
$message = $messages[0];
|
||||
} else {
|
||||
$message = $rules['rules'][$index][$type];
|
||||
}
|
||||
$line = $file . ':' . $rules['lines'][$index][$type];
|
||||
|
||||
$pos = array_search($message, $this->messages);
|
||||
if ($pos === false) {
|
||||
$this->messages[] = $message;
|
||||
$this->locations[] = [$line];
|
||||
} else {
|
||||
$this->locations[$pos][] = $line;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,11 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<files psalm-version="3.14.2@3538fe1955d47f6ee926c0769d71af6db08aa488">
|
||||
<file src="libraries/classes/Advisor.php">
|
||||
<InvalidArrayOffset occurrences="2">
|
||||
<code>$ruleSyntax[$ruleLine++]</code>
|
||||
<code>$ruleSyntax[$ruleLine]</code>
|
||||
</InvalidArrayOffset>
|
||||
</file>
|
||||
<file src="libraries/classes/CentralColumns.php">
|
||||
<InvalidScalarArgument occurrences="1">
|
||||
<code>$tn_pageNow</code>
|
||||
@ -2342,7 +2336,7 @@
|
||||
<code>$result</code>
|
||||
<code>$fields_meta</code>
|
||||
</PossiblyInvalidArgument>
|
||||
<PossiblyNullArgument occurrences="27">
|
||||
<PossiblyNullArgument occurrences="25">
|
||||
<code>$db</code>
|
||||
<code>$table</code>
|
||||
<code>$db</code>
|
||||
@ -2354,8 +2348,6 @@
|
||||
<code>$printview</code>
|
||||
<code>$printview</code>
|
||||
<code>$result</code>
|
||||
<code>$url_query</code>
|
||||
<code>$showtable</code>
|
||||
<code>$sql_data ?? null</code>
|
||||
<code>$disp_message ?? null</code>
|
||||
<code>$url_query</code>
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
use PhpMyAdmin\Command\AdvisoryRulesCommand;
|
||||
use PhpMyAdmin\Command\CacheWarmupCommand;
|
||||
use PhpMyAdmin\Config;
|
||||
use PhpMyAdmin\DatabaseInterface;
|
||||
@ -64,7 +63,6 @@ $twig->setExtensions([
|
||||
|
||||
$application = new Application('phpMyAdmin Console Tool');
|
||||
|
||||
$application->add(new AdvisoryRulesCommand());
|
||||
$application->add(new CacheWarmupCommand());
|
||||
$application->add(new LintCommand($twig));
|
||||
|
||||
|
||||
@ -43,9 +43,6 @@ php scripts/fix-po-twig
|
||||
# Remote twig templates
|
||||
rm -rf twig-templates/
|
||||
|
||||
# Generate PHP code for advisor rules
|
||||
php scripts/console po:advisory-rules >> po/phpmyadmin.pot
|
||||
|
||||
ver=`sed -n "/PMA_VERSION', '/ s/.*PMA_VERSION', '\(.*\)'.*/\1/p" libraries/classes/Config.php`
|
||||
|
||||
sed -i.~ '
|
||||
|
||||
@ -50,33 +50,22 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if data.parse.errors|length > 0 %}
|
||||
<div class="alert alert-danger mt-2 mb-2" role="alert">
|
||||
<h4 class="alert-heading">{% trans %}Rules file is not well formed, the following errors were found:{% notes %}Advisor rules file{% endtrans %}</h4>
|
||||
<ul>
|
||||
{% for error in data.parse.errors %}
|
||||
<li>{{ error }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if data.run.errors|length > 0 %}
|
||||
{% if data.errors|length > 0 %}
|
||||
<div class="alert alert-danger mt-2 mb-2" role="alert">
|
||||
<h4 class="alert-heading">{% trans 'Errors occurred while executing rule expressions:' %}</h4>
|
||||
<ul>
|
||||
{% for error in data.run.errors %}
|
||||
{% for error in data.errors %}
|
||||
<li>{{ error }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if data.run.fired|length > 0 %}
|
||||
{% if data.fired|length > 0 %}
|
||||
<h4>{% trans 'Possible performance issues' %}</h4>
|
||||
|
||||
<div class="accordion mb-4" id="rulesAccordion">
|
||||
{% for rule in data.run.fired %}
|
||||
{% for rule in data.fired %}
|
||||
<div class="card">
|
||||
<div class="card-header" id="heading{{ loop.index }}">
|
||||
<button class="btn btn-link{{ not loop.first ? ' collapsed' }}" type="button" data-toggle="collapse" data-target="#collapse{{ loop.index }}" aria-expanded="{{ loop.first ? 'true' : 'false' }}" aria-controls="collapse{{ loop.index }}">
|
||||
|
||||
@ -1,7 +1,4 @@
|
||||
<?php
|
||||
/**
|
||||
* tests for Advisor class
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
@ -10,15 +7,8 @@ namespace PhpMyAdmin\Tests;
|
||||
use PhpMyAdmin\Advisor;
|
||||
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
|
||||
|
||||
/**
|
||||
* Tests behaviour of PMA_Advisor class
|
||||
*/
|
||||
class AdvisorTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
@ -26,51 +16,6 @@ class AdvisorTest extends AbstractTestCase
|
||||
$GLOBALS['server'] = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests string escaping
|
||||
*
|
||||
* @param string $text Text to escape
|
||||
* @param string $expected Expected output
|
||||
*
|
||||
* @dataProvider escapeStrings
|
||||
*/
|
||||
public function testEscape(string $text, string $expected): void
|
||||
{
|
||||
$this->assertEquals(Advisor::escapePercent($text), $expected);
|
||||
}
|
||||
|
||||
public function escapeStrings(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'80%',
|
||||
'80%%',
|
||||
],
|
||||
[
|
||||
'%s%',
|
||||
'%s%%',
|
||||
],
|
||||
[
|
||||
'80% foo',
|
||||
'80%% foo',
|
||||
],
|
||||
[
|
||||
'%s% foo',
|
||||
'%s%% foo',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* test for parseRulesFile
|
||||
*/
|
||||
public function testParse(): void
|
||||
{
|
||||
$advisor = new Advisor($GLOBALS['dbi'], new ExpressionLanguage());
|
||||
$parseResult = $advisor->parseRulesFile(Advisor::GENERIC_RULES_FILE);
|
||||
$this->assertEquals($parseResult['errors'], []);
|
||||
}
|
||||
|
||||
/**
|
||||
* test for Advisor::byTime
|
||||
*
|
||||
@ -111,18 +56,6 @@ class AdvisorTest extends AbstractTestCase
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* test for Advisor::timespanFormat
|
||||
*/
|
||||
public function testAdvisorTimespanFormat(): void
|
||||
{
|
||||
$result = Advisor::timespanFormat(1200);
|
||||
$this->assertEquals('0 days, 0 hours, 20 minutes and 0 seconds', $result);
|
||||
|
||||
$result = Advisor::timespanFormat(100);
|
||||
$this->assertEquals('0 days, 0 hours, 1 minutes and 40 seconds', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for adding rule
|
||||
*
|
||||
@ -130,7 +63,6 @@ class AdvisorTest extends AbstractTestCase
|
||||
* @param array $expected Expected rendered rule in fired/errors list
|
||||
* @param string|null $error Expected error string (null if none error expected)
|
||||
*
|
||||
* @depends testParse
|
||||
* @dataProvider rulesProvider
|
||||
*/
|
||||
public function testAddRule(array $rule, array $expected, ?string $error): void
|
||||
@ -138,8 +70,10 @@ class AdvisorTest extends AbstractTestCase
|
||||
parent::loadDefaultConfig();
|
||||
parent::setLanguage();
|
||||
$advisor = new Advisor($GLOBALS['dbi'], new ExpressionLanguage());
|
||||
$parseResult = $advisor->parseRulesFile(Advisor::GENERIC_RULES_FILE);
|
||||
$this->assertEquals($parseResult['errors'], []);
|
||||
$parseResult = include ROOT_PATH . 'libraries/advisory_rules_generic.php';
|
||||
$this->assertIsArray($parseResult);
|
||||
$this->assertArrayHasKey(0, $parseResult);
|
||||
$this->assertIsArray($parseResult[0]);
|
||||
$advisor->setVariable('value', 0);
|
||||
$advisor->addRule('fired', $rule);
|
||||
$runResult = $advisor->getRunResult();
|
||||
@ -158,6 +92,7 @@ class AdvisorTest extends AbstractTestCase
|
||||
return [
|
||||
[
|
||||
[
|
||||
'id' => 'Basic',
|
||||
'justification' => 'foo',
|
||||
'name' => 'Basic',
|
||||
'issue' => 'issue',
|
||||
@ -174,6 +109,7 @@ class AdvisorTest extends AbstractTestCase
|
||||
],
|
||||
[
|
||||
[
|
||||
'id' => 'Variable',
|
||||
'justification' => 'foo',
|
||||
'name' => 'Variable',
|
||||
'issue' => 'issue',
|
||||
@ -191,13 +127,16 @@ class AdvisorTest extends AbstractTestCase
|
||||
],
|
||||
[
|
||||
[
|
||||
'justification' => '%s foo | value',
|
||||
'id' => 'Format',
|
||||
'justification' => '%s foo',
|
||||
'justification_formula' => 'value',
|
||||
'name' => 'Format',
|
||||
'issue' => 'issue',
|
||||
'recommendation' => 'Recommend',
|
||||
],
|
||||
[
|
||||
'justification' => '0 foo',
|
||||
'justification_formula' => 'value',
|
||||
'id' => 'Format',
|
||||
'name' => 'Format',
|
||||
'issue' => 'issue',
|
||||
@ -207,13 +146,16 @@ class AdvisorTest extends AbstractTestCase
|
||||
],
|
||||
[
|
||||
[
|
||||
'justification' => '%s% foo | value',
|
||||
'id' => 'Percent',
|
||||
'justification' => '%s%% foo',
|
||||
'justification_formula' => 'value',
|
||||
'name' => 'Percent',
|
||||
'issue' => 'issue',
|
||||
'recommendation' => 'Recommend',
|
||||
],
|
||||
[
|
||||
'justification' => '0% foo',
|
||||
'justification_formula' => 'value',
|
||||
'id' => 'Percent',
|
||||
'name' => 'Percent',
|
||||
'issue' => 'issue',
|
||||
@ -223,13 +165,16 @@ class AdvisorTest extends AbstractTestCase
|
||||
],
|
||||
[
|
||||
[
|
||||
'justification' => '%s% %d foo | value, value',
|
||||
'id' => 'Double',
|
||||
'justification' => '%s%% %d foo',
|
||||
'justification_formula' => 'value, value',
|
||||
'name' => 'Double',
|
||||
'issue' => 'issue',
|
||||
'recommendation' => 'Recommend',
|
||||
],
|
||||
[
|
||||
'justification' => '0% 0 foo',
|
||||
'justification_formula' => 'value, value',
|
||||
'id' => 'Double',
|
||||
'name' => 'Double',
|
||||
'issue' => 'issue',
|
||||
@ -239,6 +184,7 @@ class AdvisorTest extends AbstractTestCase
|
||||
],
|
||||
[
|
||||
[
|
||||
'id' => 'Quotes',
|
||||
'justification' => '"\'foo',
|
||||
'name' => 'Quotes',
|
||||
'issue' => 'issue',
|
||||
@ -255,7 +201,8 @@ class AdvisorTest extends AbstractTestCase
|
||||
],
|
||||
[
|
||||
[
|
||||
'justification' => 'foo | fsafdsa',
|
||||
'justification' => 'foo',
|
||||
'justification_formula' => 'fsafdsa',
|
||||
'name' => 'Failure',
|
||||
'issue' => 'issue',
|
||||
'recommendation' => 'Recommend',
|
||||
@ -267,13 +214,16 @@ class AdvisorTest extends AbstractTestCase
|
||||
],
|
||||
[
|
||||
[
|
||||
'justification' => 'Version string (%s) | value',
|
||||
'id' => 'Distribution',
|
||||
'justification' => 'Version string (%s)',
|
||||
'justification_formula' => 'value',
|
||||
'name' => 'Distribution',
|
||||
'issue' => 'official MySQL binaries.',
|
||||
'recommendation' => 'See <a href="https://example.com/">web</a>',
|
||||
],
|
||||
[
|
||||
'justification' => 'Version string (0)',
|
||||
'justification_formula' => 'value',
|
||||
'name' => 'Distribution',
|
||||
'issue' => 'official MySQL binaries.',
|
||||
'recommendation' => 'See <a href="./url.php?url=https%3A%2F%2F' .
|
||||
@ -284,13 +234,16 @@ class AdvisorTest extends AbstractTestCase
|
||||
],
|
||||
[
|
||||
[
|
||||
'justification' => 'Timestamp (%s) | ADVISOR_timespanFormat(1377027)',
|
||||
'id' => 'Distribution',
|
||||
'justification' => 'Timestamp (%s)',
|
||||
'justification_formula' => 'ADVISOR_timespanFormat(1377027)',
|
||||
'name' => 'Distribution',
|
||||
'issue' => 'official MySQL binaries.',
|
||||
'recommendation' => 'See <a href="https://example.com/">web</a>',
|
||||
],
|
||||
[
|
||||
'justification' => 'Timestamp (15 days, 22 hours, 30 minutes and 27 seconds)',
|
||||
'justification_formula' => 'ADVISOR_timespanFormat(1377027)',
|
||||
'name' => 'Distribution',
|
||||
'issue' => 'official MySQL binaries.',
|
||||
'recommendation' => 'See <a href="./url.php?url=https%3A%2F%2F' .
|
||||
@ -301,13 +254,16 @@ class AdvisorTest extends AbstractTestCase
|
||||
],
|
||||
[
|
||||
[
|
||||
'justification' => 'Memory: %s | ADVISOR_formatByteDown(1000000, 2, 2)',
|
||||
'id' => 'Distribution',
|
||||
'justification' => 'Memory: %s',
|
||||
'justification_formula' => 'ADVISOR_formatByteDown(1000000, 2, 2)',
|
||||
'name' => 'Distribution',
|
||||
'issue' => 'official MySQL binaries.',
|
||||
'recommendation' => 'See <a href="https://example.com/">web</a>',
|
||||
],
|
||||
[
|
||||
'justification' => 'Memory: 0.95 MiB',
|
||||
'justification_formula' => 'ADVISOR_formatByteDown(1000000, 2, 2)',
|
||||
'name' => 'Distribution',
|
||||
'issue' => 'official MySQL binaries.',
|
||||
'recommendation' => 'See <a href="./url.php?url=https%3A%2F%2F' .
|
||||
@ -318,13 +274,16 @@ class AdvisorTest extends AbstractTestCase
|
||||
],
|
||||
[
|
||||
[
|
||||
'justification' => 'Time: %s | ADVISOR_bytime(0.02, 2)',
|
||||
'id' => 'Distribution',
|
||||
'justification' => 'Time: %s',
|
||||
'justification_formula' => 'ADVISOR_bytime(0.02, 2)',
|
||||
'name' => 'Distribution',
|
||||
'issue' => 'official MySQL binaries.',
|
||||
'recommendation' => 'See <a href="https://example.com/">web</a>',
|
||||
],
|
||||
[
|
||||
'justification' => 'Time: 1.2 per minute',
|
||||
'justification_formula' => 'ADVISOR_bytime(0.02, 2)',
|
||||
'name' => 'Distribution',
|
||||
'issue' => 'official MySQL binaries.',
|
||||
'recommendation' => 'See <a href="./url.php?url=https%3A%2F%2F' .
|
||||
@ -335,7 +294,9 @@ class AdvisorTest extends AbstractTestCase
|
||||
],
|
||||
[
|
||||
[
|
||||
'justification' => 'Current version: %s | value',
|
||||
'id' => 'Minor Version',
|
||||
'justification' => 'Current version: %s',
|
||||
'justification_formula' => 'value',
|
||||
'name' => 'Minor Version',
|
||||
'precondition' => '! fired(\'Release Series\')',
|
||||
'issue' => 'Version less than 5.1.30',
|
||||
@ -345,6 +306,7 @@ class AdvisorTest extends AbstractTestCase
|
||||
],
|
||||
[
|
||||
'justification' => 'Current version: 0',
|
||||
'justification_formula' => 'value',
|
||||
'name' => 'Minor Version',
|
||||
'issue' => 'Version less than 5.1.30',
|
||||
'recommendation' => 'You should upgrade',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user