I have a table that has one boolean column.
productid integer
isactive boolean
When I execute the query
SELECT productid
FROM
product
WHERE ispublish
LIMIT 15 OFFSET 0
After that, I created an index for the ispublish
column:
CREATE INDEX idx_product_ispublish ON product USING btree (ispublish)
and re-execute
SELECT productid
FROM
product
WHERE ispublish
LIMIT 15 OFFSET 0
The result:
=> No difference
I've been tried the following, but the results are the same:
CREATE INDEX idx_product_ispublish ON product USING btree (ispublish)
CREATE INDEX idx_product_ispublish ON product USING btree (ispublish)
CREATE INDEX idx_product_ispublish ON product (ispublish) WHERE ispublish is TRUE
Who can explain that to me?
CREATE INDEX ... ON product (productid) WHERE ispublish
-- this should trigger index-only scans (for your specific query; at least most of the time: this depends on how many rows you have f.ex.). -- Predicates in partial indexes'WHERE
clause must match your queries' predicates in order to be used.WHERE ispublish
,WHERE ispublish = TRUE
andWHERE ispublish IS TRUE
are 3 different predicates.