刚和同事讨论一个问题,关于orm 不知不觉,又谈到了 mysql之表关联
他的意思是尽量少用表关联,而使用多次查询的方式。
如果使用表关联,如何达到最佳效果呢?
使用mysql的 explain 函数可以 让mysql 得到解析
加上map1.uid 是索引 而user.id 也是其主键的话。
explain select * from map1 left join user on map1.uid = `user`.id;#101.297s
explain select * from map1 ,user where map1.uid = `user`.id; #87.422s
explain select * from map1 inner join user on map1.uid = `user`.id;#84.063s
本文讨论了MySQL中表关联的不同方式及其性能影响。通过对比LEFT JOIN、INNER JOIN及使用WHERE子句模拟JOIN的效果,分析了不同场景下最优的关联方式。

被折叠的 条评论
为什么被折叠?



