Postgres-查询需要很长时间

我有一个查询,需要很长时间。无论如何,有没有更好,更优化的方式编写它:

select 1, my_text from (
    select distinct a.my_text||'_'||b.my_text my_text from (
        select r_id, my_text 
        from tmp_v 
        where r_id in (
            select o_id 
            from tmp_recid
        ) and v_id in (
            select v_id 
            from o_v 
            where v_id in (
                select o_id from tmp_record_vaid 
                union 
                select o_id from tmp_vue_vaid
            ) and va_nm = 'My V'
        )
    ) a,
    (
        select r_id, my_text 
        from tmp_v 
        where r_id in (
            select o_id 
            from tmp_recid
        ) and v_id in (
            select v_id 
            from o_v 
            where v_id in (
                select o_id from tmp_record_vaid 
                union 
                select o_id from tmp_vue_vaid
            ) and va_nm = 'My V 2'
        )
    ) b
where a.r_id = b.r_id
except 
    select e_nm 
    from myp_ent_id 
    where p_m_id = 1 and entity_id in (
        select entity_id 
        from o_e_t 
        where p_m_id = 1 and tag = 'Ample' and tag_category = 'My Type'
    )
) a;
评论