【发布时间】:2017-08-01 12:28:21
【问题描述】:
为了更好地了解在哪些情况下正确使用了索引,我想列举可能的情况。
假设我们有一个包含“a”、“b”、“c”、“d”列的表。
我们在 (a, b, c, d) 上创建一个索引:
create index my_index on table my_table (a, b, c, d)
在以下情况下使用:
1)
where a=% and b=% and c=% and d=%
2)
where a=% and b=%
3)
where a=%
4)
where b=% and c=% and d=%
5)
where c=% order by b
6)
where a=% and b=% and c=% order by case when d is not null then d else c end
7) 假设现在我们有更多的 7 点列,但索引仅在 (a, b, c, d) 上
where a=% and b=% and c=% and d=% and e=% and f=% and g=%
【问题讨论】:
标签: sql postgresql indexing