PageRenderTime 52ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/libraries/classes/Engines/Innodb.php

http://github.com/phpmyadmin/phpmyadmin
PHP | 330 lines | 241 code | 27 blank | 62 comment | 5 complexity | e2e4325fa93515655f3e90a4c571406b MD5 | raw file
Possible License(s): GPL-2.0, MIT, LGPL-3.0
  1. <?php
  2. /**
  3. * The InnoDB storage engine
  4. */
  5. declare(strict_types=1);
  6. namespace PhpMyAdmin\Engines;
  7. use PhpMyAdmin\StorageEngine;
  8. use PhpMyAdmin\Util;
  9. use function __;
  10. use function htmlspecialchars;
  11. use function implode;
  12. /**
  13. * The InnoDB storage engine
  14. */
  15. class Innodb extends StorageEngine
  16. {
  17. /**
  18. * Returns array with variable names related to InnoDB storage engine
  19. *
  20. * @return array variable names
  21. */
  22. public function getVariables()
  23. {
  24. return [
  25. 'innodb_data_home_dir' => [
  26. 'title' => __('Data home directory'),
  27. 'desc' => __('The common part of the directory path for all InnoDB data files.'),
  28. ],
  29. 'innodb_data_file_path' => [
  30. 'title' => __('Data files'),
  31. ],
  32. 'innodb_autoextend_increment' => [
  33. 'title' => __('Autoextend increment'),
  34. 'desc' => __(
  35. 'The increment size for extending the size of an autoextending tablespace when it becomes full.'
  36. ),
  37. 'type' => StorageEngine::DETAILS_TYPE_NUMERIC,
  38. ],
  39. 'innodb_buffer_pool_size' => [
  40. 'title' => __('Buffer pool size'),
  41. 'desc' => __('The size of the memory buffer InnoDB uses to cache data and indexes of its tables.'),
  42. 'type' => StorageEngine::DETAILS_TYPE_SIZE,
  43. ],
  44. 'innodb_additional_mem_pool_size' => [
  45. 'title' => 'innodb_additional_mem_pool_size',
  46. 'type' => StorageEngine::DETAILS_TYPE_SIZE,
  47. ],
  48. 'innodb_buffer_pool_awe_mem_mb' => ['type' => StorageEngine::DETAILS_TYPE_SIZE],
  49. 'innodb_checksums' => [],
  50. 'innodb_commit_concurrency' => [],
  51. 'innodb_concurrency_tickets' => ['type' => StorageEngine::DETAILS_TYPE_NUMERIC],
  52. 'innodb_doublewrite' => [],
  53. 'innodb_fast_shutdown' => [],
  54. 'innodb_file_io_threads' => ['type' => StorageEngine::DETAILS_TYPE_NUMERIC],
  55. 'innodb_file_per_table' => [],
  56. 'innodb_flush_log_at_trx_commit' => [],
  57. 'innodb_flush_method' => [],
  58. 'innodb_force_recovery' => [],
  59. 'innodb_lock_wait_timeout' => ['type' => StorageEngine::DETAILS_TYPE_NUMERIC],
  60. 'innodb_locks_unsafe_for_binlog' => [],
  61. 'innodb_log_arch_dir' => [],
  62. 'innodb_log_archive' => [],
  63. 'innodb_log_buffer_size' => ['type' => StorageEngine::DETAILS_TYPE_SIZE],
  64. 'innodb_log_file_size' => ['type' => StorageEngine::DETAILS_TYPE_SIZE],
  65. 'innodb_log_files_in_group' => ['type' => StorageEngine::DETAILS_TYPE_NUMERIC],
  66. 'innodb_log_group_home_dir' => [],
  67. 'innodb_max_dirty_pages_pct' => ['type' => StorageEngine::DETAILS_TYPE_NUMERIC],
  68. 'innodb_max_purge_lag' => [],
  69. 'innodb_mirrored_log_groups' => ['type' => StorageEngine::DETAILS_TYPE_NUMERIC],
  70. 'innodb_open_files' => ['type' => StorageEngine::DETAILS_TYPE_NUMERIC],
  71. 'innodb_support_xa' => [],
  72. 'innodb_sync_spin_loops' => ['type' => StorageEngine::DETAILS_TYPE_NUMERIC],
  73. 'innodb_table_locks' => ['type' => StorageEngine::DETAILS_TYPE_BOOLEAN],
  74. 'innodb_thread_concurrency' => ['type' => StorageEngine::DETAILS_TYPE_NUMERIC],
  75. 'innodb_thread_sleep_delay' => ['type' => StorageEngine::DETAILS_TYPE_NUMERIC],
  76. ];
  77. }
  78. /**
  79. * Returns the pattern to be used in the query for SQL variables
  80. * related to InnoDb storage engine
  81. *
  82. * @return string SQL query LIKE pattern
  83. */
  84. public function getVariablesLikePattern()
  85. {
  86. return 'innodb\\_%';
  87. }
  88. /**
  89. * Get information pages
  90. *
  91. * @return array detail pages
  92. */
  93. public function getInfoPages()
  94. {
  95. if ($this->support < StorageEngine::SUPPORT_YES) {
  96. return [];
  97. }
  98. $pages = [];
  99. $pages['Bufferpool'] = __('Buffer Pool');
  100. $pages['Status'] = __('InnoDB Status');
  101. return $pages;
  102. }
  103. /**
  104. * returns html tables with stats over inno db buffer pool
  105. *
  106. * @return string html table with stats
  107. */
  108. public function getPageBufferpool()
  109. {
  110. global $dbi;
  111. // The following query is only possible because we know
  112. // that we are on MySQL 5 here (checked above)!
  113. // side note: I love MySQL 5 for this. :-)
  114. $sql = 'SHOW STATUS'
  115. . ' WHERE Variable_name LIKE \'Innodb\\_buffer\\_pool\\_%\''
  116. . ' OR Variable_name = \'Innodb_page_size\';';
  117. $status = $dbi->fetchResult($sql, 0, 1);
  118. /** @var string[] $bytes */
  119. $bytes = Util::formatByteDown($status['Innodb_buffer_pool_pages_total'] * $status['Innodb_page_size']);
  120. $output = '<table class="table table-light table-striped table-hover w-auto float-start caption-top">' . "\n"
  121. . ' <caption>' . "\n"
  122. . ' ' . __('Buffer Pool Usage') . "\n"
  123. . ' </caption>' . "\n"
  124. . ' <tfoot class="table-light">' . "\n"
  125. . ' <tr>' . "\n"
  126. . ' <th colspan="2">' . "\n"
  127. . ' ' . __('Total:') . ' '
  128. . Util::formatNumber($status['Innodb_buffer_pool_pages_total'], 0)
  129. . '&nbsp;' . __('pages')
  130. . ' / '
  131. . implode('&nbsp;', $bytes) . "\n"
  132. . ' </th>' . "\n"
  133. . ' </tr>' . "\n"
  134. . ' </tfoot>' . "\n"
  135. . ' <tbody>' . "\n"
  136. . ' <tr>' . "\n"
  137. . ' <th scope="row">' . __('Free pages') . '</th>' . "\n"
  138. . ' <td class="font-monospace text-end">'
  139. . Util::formatNumber($status['Innodb_buffer_pool_pages_free'], 0)
  140. . '</td>' . "\n"
  141. . ' </tr>' . "\n"
  142. . ' <tr>' . "\n"
  143. . ' <th scope="row">' . __('Dirty pages') . '</th>' . "\n"
  144. . ' <td class="font-monospace text-end">'
  145. . Util::formatNumber($status['Innodb_buffer_pool_pages_dirty'], 0)
  146. . '</td>' . "\n"
  147. . ' </tr>' . "\n"
  148. . ' <tr>' . "\n"
  149. . ' <th scope="row">' . __('Pages containing data') . '</th>' . "\n"
  150. . ' <td class="font-monospace text-end">'
  151. . Util::formatNumber($status['Innodb_buffer_pool_pages_data'], 0) . "\n"
  152. . '</td>' . "\n"
  153. . ' </tr>' . "\n"
  154. . ' <tr>' . "\n"
  155. . ' <th scope="row">' . __('Pages to be flushed') . '</th>' . "\n"
  156. . ' <td class="font-monospace text-end">'
  157. . Util::formatNumber($status['Innodb_buffer_pool_pages_flushed'], 0) . "\n"
  158. . '</td>' . "\n"
  159. . ' </tr>' . "\n"
  160. . ' <tr>' . "\n"
  161. . ' <th scope="row">' . __('Busy pages') . '</th>' . "\n"
  162. . ' <td class="font-monospace text-end">'
  163. . Util::formatNumber($status['Innodb_buffer_pool_pages_misc'], 0) . "\n"
  164. . '</td>' . "\n"
  165. . ' </tr>';
  166. // not present at least since MySQL 5.1.40
  167. if (isset($status['Innodb_buffer_pool_pages_latched'])) {
  168. $output .= ' <tr>'
  169. . ' <th scope="row">' . __('Latched pages') . '</th>'
  170. . ' <td class="font-monospace text-end">'
  171. . Util::formatNumber($status['Innodb_buffer_pool_pages_latched'], 0)
  172. . '</td>'
  173. . ' </tr>';
  174. }
  175. $output .= ' </tbody>' . "\n"
  176. . '</table>' . "\n\n"
  177. . '<table class="table table-light table-striped table-hover w-auto ms-4 float-start caption-top">' . "\n"
  178. . ' <caption>' . "\n"
  179. . ' ' . __('Buffer Pool Activity') . "\n"
  180. . ' </caption>' . "\n"
  181. . ' <tbody>' . "\n"
  182. . ' <tr>' . "\n"
  183. . ' <th scope="row">' . __('Read requests') . '</th>' . "\n"
  184. . ' <td class="font-monospace text-end">'
  185. . Util::formatNumber($status['Innodb_buffer_pool_read_requests'], 0) . "\n"
  186. . '</td>' . "\n"
  187. . ' </tr>' . "\n"
  188. . ' <tr>' . "\n"
  189. . ' <th scope="row">' . __('Write requests') . '</th>' . "\n"
  190. . ' <td class="font-monospace text-end">'
  191. . Util::formatNumber($status['Innodb_buffer_pool_write_requests'], 0) . "\n"
  192. . '</td>' . "\n"
  193. . ' </tr>' . "\n"
  194. . ' <tr>' . "\n"
  195. . ' <th scope="row">' . __('Read misses') . '</th>' . "\n"
  196. . ' <td class="font-monospace text-end">'
  197. . Util::formatNumber($status['Innodb_buffer_pool_reads'], 0) . "\n"
  198. . '</td>' . "\n"
  199. . ' </tr>' . "\n"
  200. . ' <tr>' . "\n"
  201. . ' <th scope="row">' . __('Write waits') . '</th>' . "\n"
  202. . ' <td class="font-monospace text-end">'
  203. . Util::formatNumber($status['Innodb_buffer_pool_wait_free'], 0) . "\n"
  204. . '</td>' . "\n"
  205. . ' </tr>' . "\n"
  206. . ' <tr>' . "\n"
  207. . ' <th scope="row">' . __('Read misses in %') . '</th>' . "\n"
  208. . ' <td class="font-monospace text-end">'
  209. . ($status['Innodb_buffer_pool_read_requests'] == 0
  210. ? '---'
  211. : htmlspecialchars(
  212. Util::formatNumber(
  213. $status['Innodb_buffer_pool_reads'] * 100
  214. / $status['Innodb_buffer_pool_read_requests'],
  215. 3,
  216. 2
  217. )
  218. ) . ' %') . "\n"
  219. . '</td>' . "\n"
  220. . ' </tr>' . "\n"
  221. . ' <tr>' . "\n"
  222. . ' <th scope="row">' . __('Write waits in %') . '</th>' . "\n"
  223. . ' <td class="font-monospace text-end">'
  224. . ($status['Innodb_buffer_pool_write_requests'] == 0
  225. ? '---'
  226. : htmlspecialchars(
  227. Util::formatNumber(
  228. $status['Innodb_buffer_pool_wait_free'] * 100
  229. / $status['Innodb_buffer_pool_write_requests'],
  230. 3,
  231. 2
  232. )
  233. ) . ' %') . "\n"
  234. . '</td>' . "\n"
  235. . ' </tr>' . "\n"
  236. . ' </tbody>' . "\n"
  237. . '</table>' . "\n";
  238. return $output;
  239. }
  240. /**
  241. * returns InnoDB status
  242. *
  243. * @return string result of SHOW ENGINE INNODB STATUS inside pre tags
  244. */
  245. public function getPageStatus()
  246. {
  247. global $dbi;
  248. return '<pre id="pre_innodb_status">' . "\n"
  249. . htmlspecialchars((string) $dbi->fetchValue(
  250. 'SHOW ENGINE INNODB STATUS;',
  251. 0,
  252. 'Status'
  253. )) . "\n" . '</pre>' . "\n";
  254. }
  255. /**
  256. * returns string with filename for the MySQL helppage
  257. * about this storage engine
  258. *
  259. * @return string mysql helppage filename
  260. */
  261. public function getMysqlHelpPage()
  262. {
  263. return 'innodb-storage-engine';
  264. }
  265. /**
  266. * Gets the InnoDB plugin version number
  267. *
  268. * @return string the version number, or empty if not running as a plugin
  269. */
  270. public function getInnodbPluginVersion()
  271. {
  272. global $dbi;
  273. return $dbi->fetchValue('SELECT @@innodb_version;');
  274. }
  275. /**
  276. * Gets the InnoDB file format
  277. *
  278. * (do not confuse this with phpMyAdmin's storage engine plugins!)
  279. *
  280. * @return string|null the InnoDB file format
  281. */
  282. public function getInnodbFileFormat(): ?string
  283. {
  284. global $dbi;
  285. $value = $dbi->fetchValue("SHOW GLOBAL VARIABLES LIKE 'innodb_file_format';", 0, 1);
  286. if ($value === false) {
  287. // This variable does not exist anymore on MariaDB >= 10.6.0
  288. // This variable does not exist anymore on MySQL >= 8.0.0
  289. return null;
  290. }
  291. return (string) $value;
  292. }
  293. /**
  294. * Verifies if this server supports the innodb_file_per_table feature
  295. *
  296. * (do not confuse this with phpMyAdmin's storage engine plugins!)
  297. */
  298. public function supportsFilePerTable(): bool
  299. {
  300. global $dbi;
  301. return $dbi->fetchValue("SHOW GLOBAL VARIABLES LIKE 'innodb_file_per_table';", 0, 1) === 'ON';
  302. }
  303. }