嗨我有一個數據庫大量的記錄粗略,400K應該增長更多。Oracle查詢微調
我有一個查詢來從該表中獲取數據以向用戶顯示記錄。我的查詢如下。
SELECT "PC0".PYID AS "pyID" ,
"PC0".NAME AS "Name" ,
"PC0".OPPORTUNITYSTAGE AS "OpportunityStage" ,
"PC0".PXCREATEOPNAME AS "pxCreateOpName" ,
"PC0".PZINSKEY AS "pzInsKey" ,
"PC0".OPPORTUNITYSHORTNAME AS "OpportunityShortName" ,
"PC0".IDTYPE AS "IDType" ,
"PC0".IDNO AS "IDNo" ,
"Campaign".PROGRAMNAME AS "ProgramName" ,
"Campaign".ENDDATE AS "EndDate" ,
"PC0".PRODUCTNAME AS "ProductName" ,
"PC0".PRODUCTTYPE AS "ProductType" ,
"PC0".OPPORTUNITYSTAGE AS "OpportunityStage" ,
"PC0".PXCREATEOPNAME AS "pxCreateOpName" ,
"PC0".OPPORTUNITYSOURCE AS "OpportunitySource" ,
"PC0".OPPORTUNITYOWNER AS "OpportunityOwner" ,
"PC0".IDTYPE
||"PC0".IDNO AS "pyTextValue(1)" ,
"PC0".REMINDERDATE AS "ReminderDate" ,
"PC0".STAGELASTCHANGED AS "StageLastChanged" ,
ROUND((CAST(SYSDATE AS DATE) - CAST("PC0".STAGELASTCHANGED AS DATE))) AS "pyIntegerValue(1)" ,
(
CASE
WHEN ROUND((CAST(SYSDATE AS DATE) - CAST("PC0".REMINDERDATE AS DATE))) > 0
THEN 1
WHEN ROUND((CAST(SYSDATE AS DATE) - CAST("PC0".STAGELASTCHANGED AS DATE))) > 7
THEN 2
ELSE 3
END) AS "pyIntegerValue(2)" ,
"PC0".PXCREATEDATETIME AS "pxCreateDateTime" ,
"PC0".CAMPAIGNID AS "CampaignID" ,
ROUND((CAST(SYSDATE AS DATE) - CAST("PC0".REMINDERDATE AS DATE))) AS "pyIntegerValue(3)"
FROM MYCO_OPPORTUNITY "PC0"
LEFT OUTER JOIN MYCO_CAMPAIGN "Campaign"
ON ("PC0".CAMPAIGNID = "Campaign".PYID)
ORDER BY 21 ASC,
22 DESC
這需要將近13秒才能獲取SQl開發人員中的前50條記錄。實時我將一次提取近5千條記錄。
在我爲REMINDERDATE和STAGELASTCHANGED列和位圖連接索引定義了CAST的函數索引之後,時間爲13秒。
你可以請建議我應該如何優化查詢。在大集合上排序可能是我必須面對的一個問題。 :(
向我們解釋計劃並檢查是否使用索引。 –
@SylvainLeroux我們需要獲取排序結果。就像首先通過提醒日期的記錄一樣,然後這些記錄不會超過7天,然後是其他記錄。 – user3210391
讓我看看我是否瞭解它:當你禁用的功能。指數,你有體面的表演。當它啓用時,它太長了?如果是這樣,你能比較兩種執行計劃嗎?另外,有沒有辦法讓你在[最小示例](http://stackoverflow.com/help/mcve)上重現該行爲,以便我們能夠測試它? –