我有以下查询,它在 XS/S 上运行的时间太长,并且出现错误,错误代码建议将 WH 升级到更高的尺寸。我们做到了(M),它在 10 分钟内运行。有什么建议可以微调这个查询吗?请注意,这只是实际查询的几行。实际查询对于其他列有 20 多个重复行(对于 windows 函数 - first_value(CAT) over (partition by DATE_VAL, CAM_ID, GRP_ID order by CAT nulls last) as CATEGORY)
。基于查询配置文件,它花费了 89% 的精力来评估/处理 windows 函数代码。
select * from (
select
DATE_VAL,
CAM_ID,
GRP_ID,
first_value(CAT) over (partition by DATE_VAL, CAM_ID, GRP_ID order by CAT nulls last) as CATEGORY,
ROW_NUMBER() OVER ( partition by DATE_VAL, CAM_ID, GRP_ID order by TRCK nulls last ) as rnk
from (
select distinct
REPLACE(DATE, '-', '') as DATE_VAL,
CAM_ID,
GRP_ID,
TRCK,
case when D.CAT = 'T' then NULL else D.CAT end as CAT,
from DB.SCHEMA.TAB D )
) where rnk = 1