在我的情况下,哪种索引方法更好?

which index approach is better in my case?

在 table 我有 4 列:

(a(int),b(int),c(var-char),d(var-char))

我有两个查询如下:

select *from table where a=1 and b=2 and c="abc";

select *from table where a=1 and b=2 and d="zyz";

现在索引方法:

哪种方法更好?

最好的办法就是尝试一下。除非您知道您计划使用的数据是什么,否则不可能说哪些索引更好。最好的方法是创建 table,插入一些样本数据,然后使用 EXPLAINEXPLAIN ANALYZE 进行一些典型的查询。

一个例子是

EXPLAIN select *from table where a=1 and b=2 and c="abc";

EXPLAIN select *from table where a=1 and b=2 and d="zyz";

EXPLAIN ANALYZE select *from table where a=1 and b=2 and c="abc";

EXPLAIN ANALYZE select *from table where a=1 and b=2 and d="zyz";

另见http://www.postgresql.org/docs/9.5/static/sql-explain.html