起飞小宇 发表于 2024-4-30 16:19:12

MYISAM的引擎性能问题

CREATE TABLE `order_discount` (
`id` char(32) NOT NULL,
`name` char(255) DEFAULT '' COMMENT '优惠名称',
`type` char(120) DEFAULT '' COMMENT '优惠类型 ',
`order_id` char(32) DEFAULT NULL COMMENT '订单id',
`discount_price` int(10) DEFAULT NULL COMMENT '优惠金额',
`vender_pay_price` int(10) DEFAULT NULL COMMENT '商家承担金额',
`plat_pay_price` int(10) DEFAULT NULL COMMENT '平台承担金额',
`remark` varchar(255) DEFAULT NULL COMMENT '优惠备注',
PRIMARY KEY (`id`),
KEY `idx_order_id` (`order_id`),
KEY `type` (`type`) USING BTREE
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

--大约20-30秒
SELECT * from order_discount where id > '001ec21cc00e264d94cc55399d3fb0c4'ORDER BY id asc LIMIT 2000;

--大约1-2秒
SELECT * from order_discount where order_id >'1000199783976320321' ORDER BY order_id asc LIMIT 2000;



order_discount 大约7KW条数据。
为什么用ID是主键反而更慢呢?


起飞小宇 发表于 2024-4-30 16:21:38

都能走索引,ID是主键反而更慢?因为UUID吗?

yejr 发表于 2024-4-30 16:27:44

起飞小宇 发表于 2024-4-30 16:21
都能走索引,ID是主键反而更慢?因为UUID吗?

帖执行计划先

起飞小宇 发表于 2024-4-30 16:39:54

yejr 发表于 2024-4-30 16:27
帖执行计划先

--大约20-30秒
SELECT * from order_discount where id > '001ec21cc00e264d94cc55399d3fb0c4'ORDER BY id asc LIMIT 2000;
执行计划:
1        SIMPLE        order_discount                range        PRIMARY        PRIMARY        96                78957507        100        Using index condition


--大约1-2秒
SELECT * from order_discount where order_id >'1000199783976320321' ORDER BY order_id asc LIMIT 2000;

执行计划:
1        SIMPLE        order_discount                range        idx_order_id        idx_order_id        97                78973849        100        Using index condition

yejr 发表于 2024-4-30 21:09:52

起飞小宇 发表于 2024-4-30 16:39
--大约20-30秒
SELECT * from order_discount where id > '001ec21cc00e264d94cc55399d3fb0c4'ORDER BY ...

执行计划看起来相差不大,可能是统计信息不准确,重新执行analyze table后再次查看执行计划

P.S,贴执行计划时,嵌入代码格式,否则没法看

15167759230 发表于 2024-5-1 14:58:39

是不是语句存在着数据类型类型转换导致的

起飞小宇 发表于 2024-5-1 16:59:57

15167759230 发表于 2024-5-1 14:58
是不是语句存在着数据类型类型转换导致的

应该是没有的吧。我看profile 慢在sending data

yejr 发表于 2024-5-6 09:34:52

起飞小宇 发表于 2024-5-1 16:59
应该是没有的吧。我看profile 慢在sending data

应该不是发生类型转换,因为如果是的话,则无法使用索引,会走全表扫描

sending data通常表示要扫描的数据量太大了

起飞小宇 发表于 2024-5-6 17:48:19

yejr 发表于 2024-4-30 21:09
执行计划看起来相差不大,可能是统计信息不准确,重新执行analyze table后再次查看执行计划

P.S,贴执行 ...

myisam执行analyze table会锁表吗? 另外感觉这个执行计划看起来只能走这个主键索引。--大约20-30秒
SELECT * from order_discount where id > '001ec21cc00e264d94cc55399d3fb0c4'ORDER BY id asc LIMIT 2000;
执行计划:
1      SIMPLE      order_discount                range      PRIMARY      PRIMARY      96                78957507      100      Using index condition


--大约1-2秒
SELECT * from order_discount where order_id >'1000199783976320321' ORDER BY order_id asc LIMIT 2000;

执行计划:
1      SIMPLE      order_discount                range      idx_order_id      idx_order_id      97                78973849      100      Using index condition

yejr 发表于 2024-5-7 08:45:37

起飞小宇 发表于 2024-5-1 16:59
应该是没有的吧。我看profile 慢在sending data

可以把两次查询的profiling结果也贴上来看看
页: [1] 2
查看完整版本: MYISAM的引擎性能问题