以下是示例场景
SELECT * FROM
(SELECT RId,rCode,OCode,PClass,MType,ECode,Status,FType,
CTimeStamp, Id,asofdate,datime,
MIN(rid) KEEP (DENSE_RANK LAST ORDER BY CTimeStamp DESC, asofdate DESC, da_time DESC, id) OVER (PARTITION BY RId,rCode,OCode,PClass,MType,ECode,Status,FType) Min_rid,
MIN(sdate) KEEP (DENSE_RANK LAST ORDER BY CTimeStamp DESC, asofdate DESC, da_time DESC, id) OVER (PARTITION BY RId,rCode,OCode,PClass,MType,ECode,Status,FType) Min_Sub_Date,
DENSE_RANK() OVER (PARTITION BY RId,rCode,OCode,PClass,MType,ECode,Status,FType) ORDER BY CTimeStamp DESC, asofdate DESC, datime DESC, id) rank
FROM sometable aaa
) rn1
WHERE rn1.rank = 1
如果表的记录超过百万,则需要更长的执行时间。
我想知道如何优化它。
答案 0 :(得分:0)
尝试使用PARALLEL
选项so we have multiple process doing the work in parallel.
SELECT /*+ parallel(4) */
...
...
FROM
sometable aaa
来自Oracle Docs,
如果要查询的对象具有parallel属性,并且如果您有 使用query_partition_clause指定分析函数,然后使用 函数计算也是并行化的。
注意:在生产环境中选择PARALLEL
选项时请小心,因为它可能会占用大量CPU,这会阻碍其他在线adhoc查询的性能。