通过删除不同的关键字优化查询

optimizing query by removing distinct key word

我正在尝试通过删除 distinct 关键字来调整一个查询以提高存储函数的性能。

在查询调优过程中,我在存储函数中遇到了由于性能下降而使用 distinct 关键字的查询,因此我尝试在不使用 distinct 关键字的情况下编写具有相同功能的查询.

具有不同关键字的当前代码:-

select distinct dm.strdatadest 
            from PUBLIC.temp te1
            JOIN PUBLIC.applicationconfiguration AC on AC.intapplicationid = te1.applicationid
            JOIN columnmapping cm on cm.intapplicationid = AC.intapplicationid
            JOIN datamapping dm on lower(dm.strcolumnsource) = lower(cm.strcolumnsource)
            JOIN srctable s on s.applicationid=AC.intapplicationid
            where lower(cm.strtablesource) = lower(s.tablename) and 
            lower(dm.strdatasource) = lower('||quote_literal(rec.status) ||') and lower( dm.strcolumndest ) LIKE ''strstatus'' and te1.applicationid='||quote_literal(rec.applicationid);

通过删除不同的关键字来尝试代码:-

select  dm.strdatadest
from PUBLIC.temp te, 
PUBLIC.applicationconfiguration AC,
            PUBLIC.columnmapping cm,
            PUBLIC.datamapping dm
            where AC.intapplicationid = te.applicationid and cm.intapplicationid = AC.intapplicationid and lower(dm.strcolumnsource) = lower(cm.strcolumnsource)
            and lower(cm.strtablesource) = lower(s.tablename) and 
            lower(dm.strdatasource) = lower('||quote_literal(rec.priority) ||') and lower( dm.strcolumndest ) LIKE ''strpriority'' and te1.applicationid='||quote_literal(rec.applicationid)
            GROUP BY dm.strdatadest;

我需要一些控制权来通过删除不同的关键字来调整查询

关于您的查询,有两点需要提及

  1. 隐式连接与显式连接的性能大致相同。

people often ask if there is a performance difference between implicit and explicit joins. The answer is: “Usually not”

  1. distinct vs group by 其中 distinct 最适合内存使用,group by 最适合速度,因此后者优于前者,但如果需要,需要大量内存。

The distinct approach is executed like:

  • Copy all business_key values to a temporary table

  • Sort the temporary table

  • Scan the temporary table, returning each item that is different from the one before it

The group by could be executed like:

  • Scan the full table, storing each value of business key in a hashtable

  • Return the keys of the hashtable

对以下链接的精明解释。

implicit join vs explicit join

distinct vs group by