如何在不同的表中创建索引

时间:2010-09-21 11:54:42

标签: mysql database indexing

    Table A consists of (id, fieldA, fieldB, fieldC, fieldD)
    Table B consists of (id, tableA-id, fieldE, fieldF, fieldG)

My queries looks like this:-

1. select * from tableB b, tableA a where a.fieldA=? and a.fieldB=? and a.fieldC=? and a.fieldD=? and (b.fieldF >= '09/01/10' and b.fieldF <= '09/30/10');

2. select * from tableB b, tableA a where a.fieldA=? and a.fieldB=? and a.fieldC=? and a.fieldD=? and b.fieldE=? and (b.fieldF >= '09/01/10' and b.fieldF <= '09/30/10');

注意:fieldE是[2]

的额外参数

如何定义索引以适应这些查询

1 个答案:

答案 0 :(得分:0)

我认为一个好的开始是:

create index huge_index on tableA (fieldA, fieldB, fieldC, fieldD)
create index modest_index on tableB (fieldF, fieldE);

也可能是B.tableA-id。大师可能会建议B上的某种索引(包括tableA-id和其他值)是否有帮助。