MySQL 慢sql优化

表结构:

CREATE TABLE `user_rewards_record` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `user_uuid` varchar(32) CHARACTER SET utf8mb4 DEFAULT '0' COMMENT '用户id',
  `type` tinyint(4) DEFAULT '0' COMMENT '类型 0注册 1 签到',
  `rewards_type` tinyint(4) DEFAULT '0' COMMENT '奖励类型 0金币 1道具 2砖石',
  `amount` int(11) DEFAULT '0' COMMENT '奖励数量',
  `gift_uuid` bigint(20) DEFAULT '0' COMMENT '礼物uuid',
  `create_time` bigint(14) DEFAULT '0' COMMENT '创建时间',
  `is_pop_message` tinyint(4) DEFAULT '0' COMMENT '是否发送过弹窗消息',
  `update_time` bigint(14) DEFAULT '0' COMMENT '修改时间',
  `prop_uuid` varchar(32) CHARACTER SET utf8mb4 DEFAULT '' COMMENT '道具uuid, 当奖励类型为1时才有数据',
  PRIMARY KEY (`id`),
  KEY `idx_user_rewards_record_user_uuid` (`user_uuid`) USING BTREE COMMENT '用户uuid',
  KEY `idx_rewards_type` (`rewards_type`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=11554 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_icelandic_ci COMMENT='用户奖励记录表';

SQL:

SELECT
    user_uuid,
    `type`,
    rewards_type,
    amount,
    gift_uuid,
    create_time,
    is_pop_message 
FROM
    user_rewards_record 
WHERE
    `type` = 0 
    AND is_pop_message = 0 
    AND rewards_type IN ( 0, 2 ) 
    AND create_time > 1628218524000 
ORDER BY
    id DESC 
    LIMIT 1000
    
    

生产环境大概80w左右数据,

img

where条件的四个列,建一个联合索引试试

题主有结论了吗