有大數據的表,有人知道如何優化count語句嗎?例如:表預訂(ID,電子郵件,手機,...)(約30個字段)。Oracle - 在有大量數據的表上需要多次計數的建議
Function GetBookingCount(p_email, p_mobile) return number
Select count(id)
from Booking
Where email = p_email
or mobile = p_mobile
Function GetBookingStatus3Count(p_email, p_mobile) return number
Select count(id)
from Booking
Where (email = p_email or mobile = p_mobile)
and status = 3;
最終選擇:
Select GetBookingCount(email, mobile) as BookingCount
, GetBookingStatus3Count(email, mobile) as BookingStatus3Count
, ...
From Booking
where ....
解決方法1:設置在WHERE子句中算作電子郵件列,移動,狀態欄什麼的字段列索引。
解決方案2:創建一個包含少量列的新表。 新表:Booking_Stats(id,電子郵件,手機,狀態)。
感謝您的任何建議。
謝謝,但你的SQL可能是錯誤的,不工作,請參閱oracle中的sql – hungudgm