开发者

MySQL request from multiple tables slow because of WHERE filters

开发者 https://www.devze.com 2023-04-06 04:01 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消