0

我对 MySQL (5.5.59) 有一个奇怪的问题:

我有一个日志数据库(我存储供应商请求的原始数据)。此表已压缩:

CREATE TABLE `logs` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `idLogType` tinyint(3) unsigned NOT NULL,
  `idAccount` mediumint(8) unsigned NOT NULL,
  (...)
  `message` text NOT NULL,
  `date` datetime NOT NULL,
  PRIMARY KEY (`id`),
  KEY `LOGTYPE` (`idLogType`),
  KEY `ACCOUNT` (`idAccount`),
) ENGINE=InnoDB AUTO_INCREMENT=(...) DEFAULT CHARSET=utf8 ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8

我的目标是通过删除旧记录并重建表来清理这张表。因为它是一张大桌子,所以我使用了 pt-online-schema-change 和 Oak-chunk-update 来完成这项工作。

我使用https://shlomi-noach.github.io/openarkkit/oak-chunk-update.html删除了所有去年的旧记录

然后我执行表的重建以释放可用空间(启用了 innodb_file_per_table

pt-online-schema-change 
    --alter "ENGINE=InnoDB" 
    --nocheck-replication-filters --execute --statistics --progress=percentage,1 
    --set-vars='lock_wait_timeout=60' --check-alter 
    --no-swap-tables --no-drop-triggers --no-drop-old-table --no-drop-new-table 
    --chunk-time=1 --chunk-size=20 --new-table-name='__new_logs'         
    h=**HOST_#########**,D=DB_#########,t=logs,u=root --ask-pass

(重点是 --alter 语句)

所以现在,我有 2 张桌子:

  • 日志(原始的)
  • __new_logs 新日志(优化)

但它们在结构上并不相同:

SELECT TABLE_NAME, ENGINE, ROW_FORMAT, CREATE_OPTIONS
FROM information_schema.tables  
WHERE 
    ENGINE = 'innodb' AND TABLE_NAME LIKE '%logs'

返回此结果:

'TABLE_NAME'         'ENGINE'         'ROW_FORMAT'         'CREATE_OPTIONS',
'__new_logs'         'InnoDB'         'Compact'         'row_format=COMPRESSED KEY_BLOCK_SIZE=8',
'logs'         'InnoDB'         'Compressed'         'row_format=COMPRESSED KEY_BLOCK_SIZE=8',

Why the table __new_logs is flagged "compact" and not compressed, but still has "create options" set to row_format=COMPRESSED KEY_BLOCK_SIZE=8

A show create table of the __new_logs table shows:

CREATE TABLE `__new_logs` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `idLogType` tinyint(3) unsigned NOT NULL,
  `idAccount` mediumint(8) unsigned NOT NULL,
  (...)
  `message` text NOT NULL,
  `date` datetime NOT NULL,
  PRIMARY KEY (`id`),
  KEY `LOGTYPE` (`idLogType`),
  KEY `ACCOUNT` (`idAccount`),
) ENGINE=InnoDB AUTO_INCREMENT=(...) DEFAULT CHARSET=utf8 ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8

So it is still marked as compressed.

Last strange thing, the table __new_logs is bigger than the original logs table... I feel like the compression is not really done on this new table...

4

1 回答 1

1

I think I found the solution...

https://www.percona.com/blog/2014/01/14/innodb-file-formats-here-is-one-pitfall-to-avoid/

SHOW VARIABLES LIKE 'innodb_file_format'

=> Antelope.

Compression is only available with barracuda.

So my table logs which is already compressed, must have been compressed with innodb_file_format=Barracuda, but the variable certainly was reverted to Antelope...

Si I need to recreate the table... but this time with the good file format.

于 2018-05-15T15:24:24.337 回答