BUG #15136: gin index not used when using column with a where clause

Started by PG Bug reporting formabout 8 years ago1 messagesbugs
Jump to latest
#1PG Bug reporting form
noreply@postgresql.org

The following bug has been logged on the website:

Bug reference: 15136
Logged by: Improve query planner
Email address: cdalxndr@yahoo.com
PostgreSQL version: 9.6.0
Operating system: Windows 10
Description:

Index defined as:
CREATE INDEX product_en_idx
ON product USING GIN (lexeme)
WHERE language = 'en' :: REGCONFIG;

Column product.lexeme is of type tsvector, and product.language is
regconfig.

The following query doesn't use this index:
select count(*) from product p
where p.lexeme @@ plainto_tsquery(p.language, 'text') and p.language =
'en'::regconfig

But this one does:
select count(*) from product p
where p.lexeme @@ plainto_tsquery('en'::regconfig, 'text') and p.language =
'en'::regconfig

As language is restricted in the 'where' clause, both queries should use the
index.