小编Hen*_*los的帖子

JOIN 子句中分组 MAX 的性能问题

问题

我的应用程序中有一些资产会不时以异步方式更新。

我要在这里使用的例子是Vehicles. 有两个表:

  • Vehicles保存有关车辆本身的信息
  • VehicleUpdates保存有关该车辆发生的所有更新的信息。

表结构的相关部分是:

CREATE TABLE `Vehicles` (
  `id` varchar(50) NOT NULL,
  `organizationId` varchar(50) NOT NULL,
  `plate` char(7) NOT NULL,
  `vehicleInfo` json DEFAULT NULL,
  `createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updatedAt` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `unq_Vehicles_orgId_plate_idx` (`organizationId`,`plate`) USING BTREE,
  KEY `Vehicles_createdAt_idx` (`createdAt`),
);

CREATE TABLE `VehicleUpdates` (
  `id` varchar(50) NOT NULL,
  `organizationId` varchar(50) NOT NULL,
  `vehiclePlate` char(7) NOT NULL,
  `status` varchar(15) NOT NULL, …
Run Code Online (Sandbox Code Playgroud)

mysql innodb index mysql-5.7

5
推荐指数
1
解决办法
230
查看次数

标签 统计

index ×1

innodb ×1

mysql ×1

mysql-5.7 ×1