我有一个大约有 30 列的表, column a integer not null,b boolean not null其中c integer not null包括。并且有一个经常运行的查询a = 2 and b is true and c = <something>,即
select * from my_table where a = 2 and b is true and c = 3215
问题是:我应该在部分索引中包含a和b列,如下所示:
创建索引 idx_my_table_a_b_c 在 my_table 上 使用 btree (a, b, c) 其中 a = 2 且 b 为真;
或者我不应该像这样:
创建索引 idx_my_table_a_b_c 在 my_table 上 使用 btree (c) 其中 a = 2 且 b 为真;
在第一种情况下explain输出
“在 my_table 上使用 idx_my_table_a_b_c 进行索引扫描(成本=0.00..8.27 行=1 宽度=4007)” " 索引条件:((b = true) AND (a = 2))"
第二Index cond部分没有
“在 my_table 上使用 idx_my_table_a_b_c 进行索引扫描(成本=0.00..8.27 行=1 宽度=4007)”
顺便说一句,这是什么Index cond意思?