简体   繁体   English

如果where子句的cols大于2,Postgres是否使用2-col索引?

[英]Does Postgres use 2-col index if where clause has more than 2 cols?

Suppose I have an index on 2 columns in my table. 假设我在表的2列上有一个索引。

Index on: title and subdomain.

If my query is 如果我的查询是

SELECT * FROM websites
where title = 'This is a title'
and subdomain = 'www.aol.com'
and meta_description = 'this is a meta desc'
and num_hits = 2

Will the 2-column index on title and subdomain still be used? 仍会使用标题和子域上的2列索引吗?

It may. 它可能。 the choice of when to use an index is a complicated one. 选择何时使用索引是一个复杂的选择。 PostgreSQL can use a multi-column index in this case. 在这种情况下,PostgreSQL可以使用多列索引。 Whether it will depends on the size of the table, the selectivity of the first column in the index, and the like. 是否取决于表的大小,索引中第一列的选择性等。

If you are asking whether PostgreSQL will rule out such an index, no it won't. 如果您要问PostgreSQL是否会排除这样的索引,则不会。 It may even dynamically combine it with other indexes if it seems like a good idea. 如果它似乎是一个好主意,它甚至可以将其与其他索引动态地组合在一起。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM