简单的查询,返回同样的,用charge_id去关联,只要0.5s,但如果用order_id要18s! 什么原因?
用order_id时,执行计划是用了Using join buffer (Block Nested Loop);原因查明:把 order_forInit里的order_id字符集是utf8,而 order_item_forInit里的order_id字符集是utf8mb4, 不同的字符集造成两个做join时,不能用上索引,会出现“Using join buffer (Block Nested Loop) ”。把 order_forInit里的order_id字符集改成utf8mb4,就没性能问题了!! 不会出现Using join buffer (Block Nested Loop)
explain
select count(*) from
order_forInit a,
order_item_forInit c,
product d
WHERE
-- a.order_id = c.order_id
a.charge_id = c.charge_id
AND c.product_id = d. product_id;
附录:
mysql字符集 utf8 和utf8mb4 的区别: https://blog.csdn.net/qq_37054881/article/details/90023611