【发布时间】:2014-10-23 20:53:57
【问题描述】:
如果我有一张大桌子:
varchar foo
integer foo_id
integer other_id
varchar other_field
我可能会做如下查询:
select * from table where other_id=x
显然我需要在 other_id 上建立索引以避免表扫描。
如果我也在做:
select * from table where other_id=x and other_field='y'
我是否要在 other_field 上创建另一个索引,或者如果我从不这样做,那是不是很浪费:
select * from table where other_field='y'
即我只在查询中同时使用 other_field 和 other_id。
两个 [other_id, other_field] 的复合索引会更好吗?或者这会导致第一个简单查询的表扫描?
【问题讨论】:
标签: database postgresql database-design database-indexes