如何优化此查询的速度?

How can this query be optimized for speed?

此查询从递送历史记录中为 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 优化此查询的速度?

可能这个查询每天最多 运行 一次,因为 deliverydate 不包含时间。因此,从 ExactOnlineREST..GoodsDeliveries 编辑的行数 select 有数百行。据统计,账号、收货地址、联系方式也有数百个左右。

通常,这样的查询会通过 等解决方案进行优化,但该解决方案在这里不起作用:join_set(soe, orderid, 100) 的第三个值是左侧与索引连接一起使用。此时,基于对 Exact Online 的 OData 请求的 URL 长度的限制,左侧的最大数字约为 125。请记住,实际的 OData 查询是使用 URL 的 GET,而不是过滤器大小不受限制的 POST。

备选方案是:

  1. 分卷
  2. 数据缓存
  3. 数据复制器
  4. 有 SQL 引擎或 Exact Online 改编:-)

拆分音量

在单独的查询中 select 符合条件的 GoodsDeliveries 并将它们放入内存或数据库中 table 使用例如:

create or replace table gdy@inmemorystorage as select ... from ...

然后每 100 行或类似的行创建一个临时的 table,例如:

create or replace table gdysubpartition1@inmemorystorage as select ... from ... where rowidx$ between 0 and 99
... etc for 100, 200, 300, 400, 500

然后 运行 多次查询,每次使用不同的 gdysubpartition1..gdysubpartition5 而不是原来的 ExactOnlineREST..GoodsDeliveries

当然,您也可以通过使用内联视图来避免使用中间 tables:

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

或类似。

数据缓存

当您每天 运行 多次查询(不太可能,但我不知道)时,您可能希望将帐户缓存在关系数据库中并每天更新。

您还可以使用'本地记忆结果剪贴板and本地保存结果剪贴板到to save the last results to a file manually and later restore them using本地加载结果剪贴板...and本地插入结果剪贴板在table . And maybe then从 exactonlinerest..accounts 插入,其中 datecreated > t运行c(sysdate)`.

数据复制器

启用 Data Replicator 后,您可以在本地或云关系数据库中为 Exact Online API 实体自动创建和维护副本。对于低延迟,您需要启用 Exact webhooks。

已SQL 引擎或精确调整

您还可以注册一个请求,让 SQL 引擎在 join_set 提示中允许更高的数字,这将需要以另一种方式解决 EOL API。或者在 Exact 注册一个请求,以允许 POST 向 API 请求,并在正文中添加过滤器。