【 TiDB 使用环境】生产环境
【 TiDB 版本】v 7.5.2
【遇到的问题:问题现象及影响】
昨天数据库单台TiDB主机,响应时间突然变慢,产生了大量的慢查询,没有定位到问题原因。
查看面板的时候发现有大量的空region产生。期间数据库没做什么其他操作,只是建了一个如下的分区表。
期间我们的处理方法是:将数据库连接切换到另一台TiDB主机是,数据库就恢复正常了
CREATE TABLE test.`tmp_std_DeviceEvent_Clue` (
`id` bigint(20) NOT NULL /*T![auto_rand] AUTO_RANDOM(5) */ COMMENT '随机Id',
`_$tidx` tinyint(4) NOT NULL COMMENT '从sql server同步过来的分表索引,如std_DeviceEvent64,则同步值为64',
`EventID` bigint(20) NOT NULL COMMENT 'sql server的主键',
`OldEventID` bigint(20) NOT NULL DEFAULT '0',
`ObjectID` bigint(20) NOT NULL,
`EventType` int(11) NOT NULL,
`EventTime` datetime NOT NULL,
`Lng` decimal(18,6) NOT NULL,
`Lat` decimal(18,6) NOT NULL,
`Speed` int(11) DEFAULT NULL,
`Direct` int(11) DEFAULT NULL,
`GPSTime` datetime NOT NULL,
`KeyVideoUrl` varchar(256) NOT NULL,
`KeyVideoPath` varchar(256) NOT NULL,
`KeyThumUrl` varchar(256) DEFAULT NULL,
`OriVideoPath` varchar(256) NOT NULL,
`RelVideoPath` varchar(256) DEFAULT NULL,
`CreateTime` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`UpdateTime` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
`isLoved` bit(1) DEFAULT b'0',
`KeyImageUrl` text DEFAULT NULL,
`isShare` bit(1) DEFAULT b'0',
`SerialNumber` varchar(33) DEFAULT NULL,
`tmpUrl` varchar(128) DEFAULT NULL,
`processFailState` int(11) DEFAULT NULL,
`isDeleted` bit(1) DEFAULT b'0',
`Source` smallint(6) DEFAULT '0',
`City` varchar(30) DEFAULT NULL,
`channel` bigint(20) NOT NULL DEFAULT '0',
`uid` bigint(20) NOT NULL DEFAULT '0',
`callbackUrl` varchar(255) DEFAULT '' COMMENT '',
`EventSource` tinyint(4) NOT NULL DEFAULT '0' COMMENT '',
`KeyImageList` text DEFAULT NULL COMMENT '',
`KeyVideoList` text DEFAULT NULL COMMENT '',
`rv` bigint(20) NOT NULL COMMENT '',
`SRContent` text DEFAULT NULL COMMENT '',
`GsensorUrl` varchar(200) DEFAULT '' COMMENT '',
`ConfigId4s` int(11) NOT NULL DEFAULT '0' COMMENT '',
`BigDataMark` tinyint(3) NOT NULL DEFAULT '-1' COMMENT '',
`aiMark` tinyint(3) NOT NULL DEFAULT '-1' COMMENT '',
`HoldID4s` int(11) NOT NULL DEFAULT '0' COMMENT '',
`FinalMark` tinyint(3) GENERATED ALWAYS AS (if(`aiMark` = 1, 1, `BigDataMark`)) VIRTUAL,
`DiffSecond` bigint(20) NOT NULL DEFAULT '0' COMMENT 'CreateTime与EventTime相差的秒数(CreateTime减去EventTime), 单位:秒',
PRIMARY KEY (`id`,EventTime) /*T![clustered_index] CLUSTERED */,
UNIQUE KEY `UK_EventID_$tidx_EventTime` (`EventID`,`_$tidx`,EventTime),
KEY `idx_EventTime_EventType` (`EventTime`,`EventType`),
KEY `idx_CreateTime_BigDataMark` (`CreateTime`,`BigDataMark`),
KEY `idx_configId4s_EventTime_EventType` (`ConfigId4s`,`EventTime`,`EventType`),
KEY `idx_HoldID4s_EventTime` (`HoldID4s`,`EventTime`),
KEY `idx_FinalMark` (`CreateTime`,`FinalMark`),
KEY `idx_ObjectID_EventID_EventType` (`ObjectID`,`EventID`,`EventType`),
KEY `idx_ObjectID_EventTime` (`ObjectID`,`EventTime`),
KEY `idx_EventTime_DiffSecond` (`EventTime`,`DiffSecond`),
KEY `idx_CreateTime_DiffSecond` (`CreateTime`,`DiffSecond`),
KEY `idx_CreateTime_DiffSecond_HoldID4s` (`CreateTime`,`DiffSecond`,`HoldID4s`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin /*T![auto_rand_base] AUTO_RANDOM_BASE=610151301 */
PARTITION BY RANGE COLUMNS (EventTime)
INTERVAL (1 day) FIRST PARTITION LESS THAN ('2024-01-01') LAST PARTITION LESS THAN ('2050-12-31');