【发布时间】:2020-12-24 20:54:29
【问题描述】:
我试图推断Postgres partial indexes 是如何存储在 Postgres 中的。假设我创建一个这样的索引
CREATE INDEX orders_unbilled_index ON orders (order_nr)
WHERE billed is not true
为了快速运行类似的查询
SELECT *
FROM orders
WHERE billed is not true AND order_nr > 1000000
Postgres 显然在order_nr 上存储了一个索引,该索引建立在由条件表达式billed is not true 定义的orders 表的子集上。但是,我有几个与此相关的问题:
- Postgres 是否在
billed is not true内部存储另一个索引以快速找到与部分索引关联的行? - 如果 (1) 不是这种情况,如果我在
billed is not true上创建单独的索引,是否会使上面的查询运行得更快? (假设有一个大表和几行billed is true)
编辑:由于how boolean indexes are rarely used,我基于文档的示例查询不是最好的,但请在任何条件表达式的上下文中考虑我的问题。
【问题讨论】:
标签: postgresql indexing partial-index