【发布时间】:2009-12-29 22:21:09
【问题描述】:
我使用的是 Mysql 5.0,对索引有点陌生。索引可以帮助以下哪些查询以及我应该创建哪个索引?
(不要假设任何一个表都具有唯一值。这不是家庭作业,它只是我编写的一些示例,以尝试了解索引。)
Query1:
Select a.*, b.*
From a
Left Join b on b.type=a.type;
Query2:
Select a.*, b.*
From a,b
Where a.type=b.type;
Query3:
Select a.*
From a
Where a.type in (Select b.type from b where b.brand=5);
以下是我对这些不同类型查询将使用哪些索引的猜测:
Query1:
Create Index Query1 Using Hash on b (type);
Query2:
Create Index Query2a Using Hash on a (type);
Create Index Query2b Using Hash on b (type);
Query3:
Create Index Query2a Using Hash on b (brand,type);
Query1 或 Query3 都不会使用表 a 上的任何索引,我是否正确?
我相信这些都应该是哈希,因为只有 = 或 !=,对吧?
谢谢
【问题讨论】:
标签: sql mysql optimization indexing