I'm trying to reason about how Postgres partial indexes are stored inside Postgres. Suppose I create an index like this
CREATE INDEX orders_unbilled_index ON orders (order_nr)
WHERE billed is not true
in order to quickly run a query like
SELECT *
FROM orders
WHERE billed is not true AND order_nr > 1000000
Postgres obviously stores an index on order_nr
built over a subset of the orders
table as defined by the conditional expression billed is not true
. However, I have a couple of questions related to this:
- Does Postgres store another index internally on
billed is not true
to quickly find the rows associated with the partial index? - If (1) is not the case, would it then make the query above run faster if I made a separate index on
billed is not true
? (assuming a large table and few rows withbilled is true
)
EDIT: My example query based on the docs is not the best due to how boolean indexes are rarely used, but please consider my questions in the context of any conditional expression.