I am using request to select data from 10 tables and at the end i have WHERE and 2 conditions first one is simple but with second one it slows down dramatically even when there is no results returned.
AND (eligible_users.id IS NULL OR
((eligible_users.program = 3 AND eligible_users.status = 0)
O开发者_运维百科R eligible_users.status = 35))
When i remove it, page loads much fast, is there some way to make it faster but still keep this filter because i need it.
You have 3 OR statements in the query, try splitting them into 1 or more unions like so:
select ...
where ...
eligible_users.id IS NULL
UNION
select ...
where ...
(eligible_users.program = 3 AND eligible_users.status = 0)
OR eligible_users.status = 35
Adding two indexes, one for program and one for status would probably speed things up nicely.
精彩评论