我有一个很大的表(超过500.000.000行,有50多个字段,在64个分区中按字段idterminal逐个散列)。
表定义为:
CREATE TABLE `historico` (
`Nombre` varchar(50) DEFAULT NULL,
[...]
`Clave` varchar(64) DEFAULT NULL,
[...]
`IdTerminal` int(11) NOT NULL DEFAULT '0',
[...]
UNIQUE KEY `idx_Historico_Clave` (`IdTerminal`,`Clave`),
KEY `idx_historico_FechaRecepcion` (`IdTerminal`,`FechaRecepcion`),
KEY `idx_historico_idterminal_fechagps` (`IdTerminal`,`FechaGPS`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
/*!50100 PARTITION BY HASH (`IdTerminal`)
PARTITIONS 64 */ |
我得到一些奇怪的结果:根据查询中输入的字段,我得到的行数是不同的:
mysql> select idterminal, clave from historico partition(p0) where clave = 'G20191016081555P41344';
+------------+-----------------------+
| idterminal | clave |
+------------+-----------------------+
| 41344 | G20191016081555P41344 |
+------------+-----------------------+
1 row in set (0.00 sec)
mysql> select nombre, idterminal, clave from historico partition(p0) where clave = 'G20191016081555P41344';
+----------+------------+-----------------------+
| nombre | idterminal | clave |
+----------+------------+-----------------------+
| A Name | 41344 | G20191016081555P41344 |
| A Name | 41344 | G20191016081555P41344 |
| A Name | 41344 | G20191016081555P41344 |
| A Name | 41344 | G20191016081555P41344 |
+----------+------------+-----------------------+
4 rows in set (5.07 sec)
此表在“ idTerminal”和“ clave”字段上具有唯一索引,因此我了解第二个查询必须仅返回一行。 当我尝试重建该分区时 更改表historico重建分区p0; 我得到:
第1行的错误1022(23000):无法写入;表'historico'中的重复键
其他疯狂的结果:
mysql> select count(*) as how_many, clave, idterminal from historico partition(p0) group by clave, idterminal order by how_many desc limit 10;
+----------+----------------------------+------------+
| how_many | clave | idterminal |
+----------+----------------------------+------------+
| 4 | G20191021142024P700653 | 15680 |
| 4 | G20191001182332P700653 | 15680 |
| 4 | G20191001183144P700653 | 15680 |
| 4 | G20191005063231P830677 | 53824 |
| 4 | G20191005080409P830677 | 53824 |
| 4 | G20191005103808P830677 | 53824 |
| 4 | G20191005123548A830677-124 | 53824 |
| 4 | G20191005144959P830677 | 53824 |
| 4 | G20191005161853P830677 | 53824 |
| 4 | G20191005172114P830677 | 53824 |
+----------+----------------------------+------------+
10 rows in set (1 min 25.36 sec)
mysql> select count(*) as how_many, clave, idterminal from historico partition(p0) where idterminal = 15680 and clave = 'G20191021142024P700653' group by clave, idterminal order by how_many desc limit 10;
+----------+------------------------+------------+
| how_many | clave | idterminal |
+----------+------------------------+------------+
| 1 | G20191021142024P700653 | 15680 |
+----------+------------------------+------------+
1 row in set (0.00 sec)
我的第一个怀疑是唯一索引已损坏,但是如果我检查分区:
alter table historico check partition p0;
我得到:
datos.historico check status OK
因此,它看起来像MySQL(版本8.0.17)中的错误,有人曾经疯狂过吗?关于我该怎么办的一些想法?