在many-to-many的中间表中配置索引
customer(1)-(n)account(n)-card(n)
三张表分别:30万,60万,90万记录Select * From card a,Account b,account_card c ,customer d Where a.card_number = '4518100348128286' And a.Id=c.card_id And b.Id=c.account_id And d.Id=a.customer_id And b.customer_Id = d.Id
这个查询如果在中间表account_card上不加索引将需要10s钟才能完成,加上索引后0.046s就搞定了。当然card_number肯定是得有索引的。 1 楼 mercyblitz 2007-04-12 索引会大大的提高速度! 2 楼 remanhu 2007-04-17 索引是一把双刃剑,用的好可以带来很大的收益,用的不好简直就是恶梦,所以并不是说所有地方都能使用,还是要实事求是的用 3 楼 javadev 2007-04-29 数据库不同,索引也不一样,DB2建立索引后,还得运行runstat命令才起作用。