We have a query that retrieves some data from a master-detail simple schema. the WHERE clause looks like:
-- These are just random numbers
Where ticket.type_id in ( 2, 3, 4, 5, 7 ) and
(
ticket.color_id is null or
ticket.color_id in ( 1, 2 , 8 )
)
we already have indexes in the columns: ticket.type_id and ticket.color_id, anyway the QUERY EXPLAIN ANALYZE still show us that Postgresql is making a sequential scan to satisfy the query.
This query is really important and recurrent in the system, so we want to create an index specially for this case.
Where ticket.type_id in ( 2, 3, 4, 5, 7 )will it use the index?type_ids are a small fraction of the data, it's probably right.EXPLAINforWhere ticket.type_id in ( 2, 3, 4, 5, 7 )?WHERE? Does it haveHAVING?ORDER BY?LIMIT? How many tables are joined?