我有此WordPress表格,其大小为26GB:

SELECT
    *
FROM information_schema.TABLES
WHERE table_schema = "my_database"
    AND table_name = "wpii_options";


结果:

{
  "TABLE_CATALOG": "def",
  "TABLE_SCHEMA": "my_database",
  "TABLE_NAME": "wpii_options",
  "TABLE_TYPE": "BASE TABLE",
  "ENGINE": "InnoDB",
  "VERSION": 10,
  "ROW_FORMAT": "Compact",
  "TABLE_ROWS": 13793552,
  "AVG_ROW_LENGTH": 2025,
  "DATA_LENGTH": 27932049408,
  "MAX_DATA_LENGTH": 0,
  "INDEX_LENGTH": 98304,
  "DATA_FREE": 7340032,
  "AUTO_INCREMENT": 16465,
  "CREATE_TIME": "2016-07-26 04:28:08",
  "UPDATE_TIME": null,
  "CHECK_TIME": null,
  "TABLE_COLLATION": "utf8_general_ci",
  "CHECKSUM": null,
  "CREATE_OPTIONS": "",
  "TABLE_COMMENT": ""
}


每次我运行上面的查询时,用于启动“ TABLE_ROWS”字段的波动在1000万到4000万之间,但实际上行数不是很多:

select count(*) from wpii_options;


结果:

292


但是最重​​要的部分是我不知道所有26GB的存储位置:

show create table wpii_options;


结果:

CREATE TABLE `wpii_options` (
  `option_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `option_name` varchar(191) NOT NULL DEFAULT '',
  `option_value` longtext NOT NULL,
  `autoload` varchar(20) NOT NULL DEFAULT 'yes',
  PRIMARY KEY (`option_id`),
  UNIQUE KEY `option_name` (`option_name`)
) ENGINE=InnoDB AUTO_INCREMENT=16465 DEFAULT CHARSET=utf8


检查每列的大小:

select
  sum(length(option_id)) as option_id_length,
  sum(length(option_name)) as option_name_length,
  sum(length(option_value)) as option_value_length,
  sum(length(autoload)) as autoload_length
from wpii_options;


结果:

{
  "option_id_length": 816,
  "option_name_length": 6533,
  "option_value_length": 523982,
  "autoload_length": 836
}


所以我的问题是:


该表使用的26GB在哪里?
为什么表状态中的“行数”是数百万,但如果我明确地计算它们,只有几(262)?

最佳答案

这解决了我的问题:

optimize table wpii_options;

10-05 18:31