【发布时间】:2019-07-30 07:54:01
【问题描述】:
如何优化类似的查询
select a.*,b.* from a join b
on a.foo = b.foo
and a.bar = b.bar
and a.bazz = b.bazz
-- ...(many and omitted here)
是否需要在这些列上添加索引,以便它们在加入时运行得更快?
【问题讨论】:
-
索引的基本原则是让索引中的所有列在Join条件、where子句和order by子句中使用。
-
我建议在表 A 上创建一个 unique_ID
VARBINARY列(使用 a.foo、a.bar、a.bazz 的组合来导出 ID)和 B 并将其用于加入