select * from stores 
where schedule_id in    <- this line
(
    select distinct id  from schedules
    where user_id in 
    (
        select distinct Y.id from tb_CMSTempRute X
        join users Y
        on X.kode = Y.account_id 
        where X.flag = 'xxx'
        and X.create_user = 'ADMIN'
    )
    and date in 
    (
        select distinct X.tgl from tb_CMSTempRute X
        where X.flag = 'xxx'
        and X.create_user =  'ADMIN'
    )
)
I have query like above, but it tooks very slow and then I cancel the query. I tried to select only subquery from line 3 until end, the query is going fast, but why when join with query line 1-2 it's going very slow.
But if the second line of query where schedule_id in change using join, it's going fast.
and I have other query and have same issue, very slow when using IN.
anyonw know why?
NB
