1
我有來自多個表的多個嵌套的選擇查詢,如下所示:性能的嵌套選擇從多個表
select c.name,c.created_date,
( select count(id) from user u
where u.company_id=c.id) as users,
( select count(distinct uls.user_id) from user_login_status uls
where uls.company_id=c.id
and uls.date between '2013-11-18' and '2014-01-10') as unique_logins,
( select count(id) from cash_receiving cr
where cr.company_id=c.id
and cr.created_date between '2013-11-18' and '2014-01-10') as recognitions,
0 as licences,
( select count(id) from inventory_item i
where i.company_gid=c.id) as store_items,
( select count(id) from award a
where a.company_gid=c.id) as awards,
( select uls2.date from user_login_status uls2
where uls2.company_id=c.id
ORDER BY uls2.date DESC LIMIT 1) as last_login,
c.id as id,
c.is_live as live
from company c
order by c.name
的user_login_status
包含每個用戶的登錄條目,所以將有大量的數據,也就是在SQL我對上面的查詢調用了實體管理器 ,因此我想知道上述查詢的性能,它是否適合每個表的海量數據,或者更好地做出單獨的select語句,請告知如何使上述查詢執行得很好,謝謝。
你無法測試性能?你所能得到的只是對戰爭故事的猜測和隨機複述。 –
@Marko Topolnik,我的數據庫中沒有龐大的數據,所以我問這是否會在未來造成不好的表現? –
通過插入大數據來測試它,沒有其他方法知道。 –