2017-06-03 85 views
1

此查詢創建從交付歷史UPS出口:這個查詢如何針對速度進行優化?

select 'key' 
,  ACC.Name 
,  CON.FullName 
,  CON.Phone 
,  ADR.AddressLine1 
,  ADR.AddressLine2 
,  ADR.AddressLine3 
,  ACC.Postcode 
,  ADR.City 
,  ADR.Country 
,  ACC.Code 
,  DEL.DeliveryNumber 
,  CON.Email 
,  case 
     when CON.Email is not null 
     then 'Y' 
     else 'N' 
     end 
     Ship_Not_Option 
,  'Y' Ship_Not 
,  'ABCDEFG' Description_Goods 
,  '1' numberofpkgs 
,  'PP' billing 
,  'CP' pkgstype 
,  'ST' service 
,  '1' weight 
,  null Shippernr 
from ExactOnlineREST..GoodsDeliveries del 
join ExactOnlineREST..Accounts acc 
on  ACC.ID = del.DeliveryAccount 
join ExactOnlineREST..Addresses ADR 
on  ADR.ID = DEL.DeliveryAddress 
join ExactOnlineREST..Contacts CON 
on  CON.ID = DEL.DeliveryContact 
where DeliveryDate between $P{P_SHIPDATE_FROM} and $P{P_SHIPDATE_TO} 
order 
by  DEL.DeliveryNumber 

這需要多少分鐘來運行。交付和賬戶的數量每天增長數百。地址和聯繫人大多是1:1的賬戶。如何針對Excel的Invantive Control中的速度優化此查詢?

回答

1

也許這個查詢每天至多運行一次,因爲deliverydate不包含時間。因此,從ExactOnlineREST..GoodsDeliveries中選擇的行數是幾百。根據統計數據,帳戶數量,交付地址和聯繫人數量也大約有數百個。

通常情況下,這樣的查詢將通過諸如Exact Online query with joins runs more than 15 minutes之類的解決方案進行優化,但該解決方案在此處不起作用:join_set(soe, orderid, 100)的第三個值是與索引一起使用的左側的最大行數連接。此時,根據對Exact Online的OData請求的URL長度限制,左側的最大數量類似於125。請記住,實際的OData查詢是使用URL的GET,而不是過濾器的無限大小的POST。

的替代方案是:

  1. 拆分容積
  2. 數據緩存
  3. 數據複製
  4. 具有SQL引擎或精確在線適應:-)

分割卷

在單獨的查詢中選擇符合條件的GoodsDeliveries,並把它們在內存中,或使用例如數據庫表:

create or replace table [email protected] as select ... from ... 

然後創建每100個或類似行的臨時表,例如:

create or replace table [email protected] as select ... from ... where rowidx$ between 0 and 99 
... etc for 100, 200, 300, 400, 500 

然後運行查詢幾次,每次用不同的gdysubpartition1 .. gdysubpartition5代替原來的ExactOnlineREST..GoodsDeliveries

from (select * from goodsdeliveries where date... limit 100) 

或相似:

當然,也可以通過使用內嵌視圖像避免使用中間表。

數據緩存

當你每天運行查詢多次(不太可能,但我不知道),你可能想緩存帳戶在關係數據庫中,並每天更新。

您還可以使用「本地背誦結果剪貼板and本地保存結果剪貼板to save the last results to a file manually and later restore them using本地負載結果剪貼板從... and本地插入結果表剪貼板. And maybe then INSERT INTO從exactonlinerest..accounts其中dateCreated會> TRUNC(SYSDATE )`。

數據複製

啓用數據複製,您可以創建副本和內自動維護的內部部署或雲關係數據庫的精確在線API實體。對於低延遲,您需要啓用Exact webhook。

具有SQL引擎或精確調整

您還可以註冊有SQL引擎允許在join_set暗示,這將需要解決以另一種方式EOL的API人數較多的請求。或者在Exact中註冊一個請求,以允許POST請求通過正文中的過濾器提供給API。