GaussDB(DWS)性能调优:indexscan导致的性能问题识别与优化

gaussdb,dws,性能,indexscan,导致,问题,识别,优化 · 浏览次数 : 77

小编点评

内容生成时需要带简单的排版,并结合以下内容进行生成: 1.华为云新鲜技术介绍 2.华为云新鲜技术功能 3.华为云新鲜技术应用 4.华为云新鲜技术发展 5.华为云新鲜技术未来 内容生成时需要根据以上内容进行排版,并结合其他内容进行生成。

正文

摘要:通常跑批加工场景下,都是大数量做关联操作,通常不建议使用索引。有些时候因为计划误判导致使用索引的可能会导致严重的性能问题。本文从一个典型的索引导致性能的场景重发,剖析此类问题的特征,定位方法和解决方法

本文分享自华为云社区《GaussDB(DWS)性能调优:indexscan导致的性能问题识别与优化 #【玩转PB级数仓GaussDB(DWS)】》,作者: 譡里个檔 。

通常跑批加工场景下,都是大数量做关联操作,通常不建议使用索引。有些时候因为计划误判导致使用索引的可能会导致严重的性能问题。本文从一个典型的索引导致性能的场景重发,剖析此类问题的特征,定位方法和解决方法。

1)在某局点POC测试时发现某SQL语句比较慢,原始SQL如下

WITH 
/**
etl_116583_7960703_994644
**/
LOADABLE as (select "boq_rel_type_id","to_pu_id","to_version","cycle_id",
 "part_offset_flag","to_boq_id","descr","from_contract_id",
 "from_version","from_pu_id","ss_id","to_contract_id",
 "from_boq_id","enable_flag","last_update_date" 
 from (SELECT /*+ PARALLEL(4)*/
    BOQ_REL.FROM_BOQ_ID,
    BOQ_REL.TO_BOQ_ID,
    BOQ_REL.FROM_PU_ID,
    BOQ_REL.TO_PU_ID,
    BOQ_REL.PART_OFFSET_FLAG,
    BOQ_REL.DESCR,
    BOQ_REL.SS_ID,
    BOQ_REL.CYCLE_ID,
 NVL(BOQ_REL.FROM_VERSION, 'SNULL') FROM_VERSION,
 NVL(BOQ_REL.TO_VERSION, 'SNULL') TO_VERSION,
    BOQ_REL.LAST_UPDATE_DATE,
    FROM_CON.CONTRACT_ID AS FROM_CONTRACT_ID,
    TO_CON.CONTRACT_ID AS TO_CONTRACT_ID,
    CLA.CLASS_ID AS BOQ_REL_TYPE_ID,
    BOQ_REL.ENABLE_FLAG
FROM (SELECT A.FROM_BOQ_ID,
                   A.TO_BOQ_ID,
 A.FROM_PU_ID,
                   A.TO_PU_ID,
 A.FROM_CONTRACT_NUMBER,
                   A.TO_CONTRACT_NUMBER,
                   A.BOQ_REL_TYPE_CODE,
                   A.PART_OFFSET_FLAG,
 A.DESCR,
 A.SS_ID,
 A.FROM_VERSION,
                   A.TO_VERSION,
 A.LAST_UPDATE_DATE,
 A.CYCLE_ID,
 A.ENABLE_FLAG,
 DECODE(A.SS_ID, 2820, 2600, A.SS_ID) SS_ID_TMP,
                   ROW_NUMBER() OVER(PARTITION BY FROM_BOQ_ID, TO_BOQ_ID, FROM_PU_ID, TO_PU_ID, FROM_CONTRACT_NUMBER, TO_CONTRACT_NUMBER, BOQ_REL_TYPE_CODE, FROM_VERSION, TO_VERSION
 ORDER BY DECODE(A.SS_ID, 2820, 1, 2600, 2, 3)) RN
 FROM LDB_MD_BOQ_REL A) BOQ_REL,
           (SELECT CONTRACT_ID,
                   HW_CONTRACT_NUM,
                   SS_ID
 FROM DWI_MD_CONTRACT
 WHERE CONTRACT_ID IS NOT NULL
 AND END_TIME = TO_DATE('4712-12-31', 'YYYY-MM-DD')) FROM_CON,
           (SELECT CONTRACT_ID,
                   HW_CONTRACT_NUM,
                   SS_ID
 FROM DWI_MD_CONTRACT
 WHERE CONTRACT_ID IS NOT NULL
 AND END_TIME = TO_DATE('4712-12-31', 'YYYY-MM-DD')) TO_CON,
           (SELECT CLASS_ID,
                   CODE,
                   CLASS_TYPE_ID,
                   SS_ID
 FROM DWI_MD_CLASS
 WHERE CLASS_TYPE_ID = 193) CLA
 WHERE BOQ_REL.RN = 1
 AND BOQ_REL.FROM_CONTRACT_NUMBER = FROM_CON.HW_CONTRACT_NUM
 AND BOQ_REL.SS_ID = FROM_CON.SS_ID
 AND BOQ_REL.TO_CONTRACT_NUMBER = TO_CON.HW_CONTRACT_NUM
 AND BOQ_REL.SS_ID = TO_CON.SS_ID
 AND BOQ_REL.BOQ_REL_TYPE_CODE = CLA.CODE
 AND BOQ_REL.SS_ID_TMP = CLA.SS_ID
    ) t
),
BEFORE_TARGET as (select "from_contract_id","from_pu_id","ss_id","from_boq_id","from_version","to_version",
 "crt_cycle_id","to_pu_id","to_boq_id","del_flag","last_upd_cycle_id","last_update_date",
 "descr","enable_flag","crt_job_instance_id","dq_improve_flag","upd_job_instance_id",
 "to_contract_id","part_offset_flag","boq_rel_type_id" 
 from (SELECT /*+PARALLEL(4)*/
     FROM_BOQ_ID,
     TO_BOQ_ID,
     FROM_PU_ID,
     TO_PU_ID,
     FROM_CONTRACT_ID,
     TO_CONTRACT_ID,
     BOQ_REL_TYPE_ID,
     PART_OFFSET_FLAG,
     DESCR,
     SS_ID,
     CRT_CYCLE_ID,
     LAST_UPD_CYCLE_ID,
     DEL_FLAG,
     DQ_IMPROVE_FLAG,
     CRT_JOB_INSTANCE_ID,
     UPD_JOB_INSTANCE_ID,
 NVL(FROM_VERSION, 'SNULL') FROM_VERSION,
 NVL(TO_VERSION, 'SNULL') TO_VERSION,
     LAST_UPDATE_DATE,
     ENABLE_FLAG
 FROM DWI_MD_BOQ_REL
    ) t
),
CDC as (select LOADABLE."ss_id",LOADABLE."from_version",LOADABLE."from_boq_id",
    LOADABLE."part_offset_flag",LOADABLE."from_pu_id",
 case when BEFORE_TARGET.BOQ_REL_TYPE_ID is null and BEFORE_TARGET.FROM_BOQ_ID is null 
 and BEFORE_TARGET.FROM_CONTRACT_ID is null and BEFORE_TARGET.FROM_PU_ID is null 
 and BEFORE_TARGET.FROM_VERSION is null 
 and BEFORE_TARGET.TO_BOQ_ID is null and BEFORE_TARGET.TO_CONTRACT_ID is null 
 and BEFORE_TARGET.TO_PU_ID is null and BEFORE_TARGET.TO_VERSION is null
 then 1 
 else 3 
 end as "change_code",
    LOADABLE."to_version",LOADABLE."boq_rel_type_id",
    LOADABLE."from_contract_id",LOADABLE."to_contract_id",
    LOADABLE."descr",LOADABLE."last_update_date",
    LOADABLE."to_pu_id",LOADABLE."enable_flag",LOADABLE."cycle_id",
    LOADABLE."to_boq_id" 
from LOADABLE  
left join BEFORE_TARGET on LOADABLE.BOQ_REL_TYPE_ID = BEFORE_TARGET.BOQ_REL_TYPE_ID 
 and LOADABLE.FROM_BOQ_ID = BEFORE_TARGET.FROM_BOQ_ID and LOADABLE.FROM_CONTRACT_ID = BEFORE_TARGET.FROM_CONTRACT_ID 
 and LOADABLE.FROM_PU_ID = BEFORE_TARGET.FROM_PU_ID and LOADABLE.FROM_VERSION = BEFORE_TARGET.FROM_VERSION 
 and LOADABLE.TO_BOQ_ID = BEFORE_TARGET.TO_BOQ_ID and LOADABLE.TO_CONTRACT_ID = BEFORE_TARGET.TO_CONTRACT_ID 
 and LOADABLE.TO_PU_ID = BEFORE_TARGET.TO_PU_ID and LOADABLE.TO_VERSION = BEFORE_TARGET.TO_VERSION
),
TFM_FILTER_DATA_TARGET_OUTPUT_U as (select CDC."to_pu_id",CDC."boq_rel_type_id",CDC."ss_id",
 Current_Timestamp() as "dw_last_update_date",CDC."to_version",
    CDC."from_version",20230104000000 as "last_upd_cycle_id",
    CDC."from_contract_id",CDC."last_update_date",CDC."descr",
 'N' as "del_flag",CDC."from_boq_id",CDC."to_boq_id",
    CDC."enable_flag",CDC."from_pu_id",-1 as "upd_job_instance_id",
 'N' as "dq_improve_flag",CDC."to_contract_id",
    CDC."part_offset_flag" 
from CDC where CDC.change_code=3
)
update DWI_MD_BOQ_REL TARGET_U 
set "dq_improve_flag" = TFM_FILTER_DATA_TARGET_OUTPUT_U."dq_improve_flag",
 "dw_last_update_date" = TFM_FILTER_DATA_TARGET_OUTPUT_U."dw_last_update_date",
 "upd_job_instance_id" = TFM_FILTER_DATA_TARGET_OUTPUT_U."upd_job_instance_id",
 "descr" = TFM_FILTER_DATA_TARGET_OUTPUT_U."descr",
 "part_offset_flag" = TFM_FILTER_DATA_TARGET_OUTPUT_U."part_offset_flag",
 "last_update_date" = TFM_FILTER_DATA_TARGET_OUTPUT_U."last_update_date",
 "del_flag" = TFM_FILTER_DATA_TARGET_OUTPUT_U."del_flag",
 "last_upd_cycle_id" = TFM_FILTER_DATA_TARGET_OUTPUT_U."last_upd_cycle_id",
 "enable_flag" = TFM_FILTER_DATA_TARGET_OUTPUT_U."enable_flag",
 "ss_id" = TFM_FILTER_DATA_TARGET_OUTPUT_U."ss_id" 
from TFM_FILTER_DATA_TARGET_OUTPUT_U
where TARGET_U."boq_rel_type_id" = TFM_FILTER_DATA_TARGET_OUTPUT_U."boq_rel_type_id" 
 and TARGET_U."to_version" = TFM_FILTER_DATA_TARGET_OUTPUT_U."to_version"
 and TARGET_U."to_version" = TFM_FILTER_DATA_TARGET_OUTPUT_U."to_version"
 and TARGET_U."to_pu_id" = TFM_FILTER_DATA_TARGET_OUTPUT_U."to_pu_id"
 and TARGET_U."to_pu_id" = TFM_FILTER_DATA_TARGET_OUTPUT_U."to_pu_id"
 and TARGET_U."to_contract_id" = TFM_FILTER_DATA_TARGET_OUTPUT_U."to_contract_id"
 and TARGET_U."to_contract_id" = TFM_FILTER_DATA_TARGET_OUTPUT_U."to_contract_id"
 and TARGET_U."to_boq_id" = TFM_FILTER_DATA_TARGET_OUTPUT_U."to_boq_id"
 and TARGET_U."to_boq_id" = TFM_FILTER_DATA_TARGET_OUTPUT_U."to_boq_id"
 and TARGET_U."from_version" = TFM_FILTER_DATA_TARGET_OUTPUT_U."from_version"
 and TARGET_U."from_version" = TFM_FILTER_DATA_TARGET_OUTPUT_U."from_version"
 and TARGET_U."from_pu_id" = TFM_FILTER_DATA_TARGET_OUTPUT_U."from_pu_id"
 and TARGET_U."from_pu_id" = TFM_FILTER_DATA_TARGET_OUTPUT_U."from_pu_id"
 and TARGET_U."from_contract_id" = TFM_FILTER_DATA_TARGET_OUTPUT_U."from_contract_id"
 and TARGET_U."from_contract_id" = TFM_FILTER_DATA_TARGET_OUTPUT_U."from_contract_id"
 and TARGET_U."from_boq_id" = TFM_FILTER_DATA_TARGET_OUTPUT_U."from_boq_id"
 and TARGET_U."from_boq_id" = TFM_FILTER_DATA_TARGET_OUTPUT_U."from_boq_id"
 and TARGET_U."boq_rel_type_id" = TFM_FILTER_DATA_TARGET_OUTPUT_U."boq_rel_type_id"
;

2)查询此query的topSQL信息的warning字段,发现SQL自诊断信息中有索引相关告警信息。

3)查询此query的topSQL信息(如下图),分析历史执行信息,发现id=20的CStore Index Scan算子的耗时为90796.980ms,SQL执行总时长137135.658ms。CStore Index Scan算子的耗时占比为 66%

4)找到原始SQL语句,对查询语句中出现的表dwimd.dwi_md_contract 进行hint,强制其走顺序扫描,避免走indexscan(全量语句见附件)

5)对语句进行explain verbose,查看计划,发现计划符合预期(即表dwimd.dwi_md_contract走tablescan,对于列存表计划上显式为CStore Scan)

6)对语句执行EXPLAIN ANALYZE操作(即实际执行语句),查看实际执行时间如下,发现SQL语句性能提升近10倍。全量的执行信息见附件

 

点击关注,第一时间了解华为云新鲜技术~

与GaussDB(DWS)性能调优:indexscan导致的性能问题识别与优化相似的内容:

GaussDB(DWS)性能调优:indexscan导致的性能问题识别与优化

摘要:通常跑批加工场景下,都是大数量做关联操作,通常不建议使用索引。有些时候因为计划误判导致使用索引的可能会导致严重的性能问题。本文从一个典型的索引导致性能的场景重发,剖析此类问题的特征,定位方法和解决方法 本文分享自华为云社区《GaussDB(DWS)性能调优:indexscan导致的性能问题识别

GaussDB(DWS)性能调优,解决DM区大内存占用问题

本文分享自华为云社区《GaussDB(DWS)性能调优:DM区优化案例——维度表关联条件存在会计期》,作者: O泡果奶~。 当前DM(P1、P3、CBGDM)存在维度表与主表关联时使用会计期作为关联条件,会导致出现大内存占用或未识别数据倾斜的问题 【场景一】f.period_id = 维度表.per

GaussDB(DWS)性能调优:Sort+Groupagg聚集引起的性能瓶颈案例

本文针对SQL语句长时间执行不出来,且verbose执行计划中出现Sort+GroupAgg聚集方式的案例进行分析。

数仓性能调优:如何进行函数下推

摘要:本文主要描述下函数在满足特征的前提下可以把函数属性定义为下推属性。 本文分享自华为云社区《GaussDB(DWS)性能调优:函数下推》,作者:譡里个檔 。 DWS作为MPP架构的数仓产品,其性能优势主要在分布式计算上。默认情况下,DWS为了保证结果的正确性,自定义函数默认属性是不下推的,这会导

数仓性能调优:大宽表关联MERGE性能优化

摘要:本文主要为大家讲解在数仓性能调优过程中,关于大宽表关联MERGE性能优化过程。 本文分享自华为云社区《GaussDB(DWS)性能调优:大宽表关联MERGE性能优化》,作者:譡里个檔。 【业务背景】 如下MERGE语句执行耗时长达2034s MERGE INTO sdifin.hah_ae_l

解读数仓常用模糊查询的优化方法

摘要:本文讲解了GaussDB(DWS)上模糊查询常用的性能优化方法,通过创建索引,能够提升多种场景下模糊查询语句的执行速度。 本文分享自华为云社区《GaussDB(DWS) 模糊查询性能优化》,作者: 黎明的风 。 在使用GaussDB(DWS)时,通过like进行模糊查询,有时会遇到查询性能慢的

GaussDB(DWS)案例丨MERGE场景下语句不下推引起的性能瓶颈问题

本文针对MERGE场景下SQL语句因执行不下推而导致执行效率低下的案例进行分析。

带你掌握数仓的作业级监控TopSQL

摘要:目前TopSQL功能被用户广泛使用,是性能定位、劣化分析、审计回溯等重要的基石,为用户提供覆盖内存、耗时、IO、网络、空间等多方面的监控能力。 本文分享自华为云社区《GaussDB(DWS)监控工具指南(一)作业级监控TopSQL》,作者:幕后小黑爪 。 1、引言: 监控系统是智能化管理和自动

sequence:从认识到会使用,今儿给你讲的透透的

摘要:本文简单介绍sequence的使用场景及如何修改sequence的cache值提高性能。 本文分享自华为云社区《GaussDB(DWS)关于sequence的那些事》,作者:Arrow0lf 。 什么是sequence sequence,也称作序列,是用来产生唯一整数的数据库对象。序列的值按照

详解数仓中sequence的应用场景及优化

摘要:本文简单介绍sequence的使用场景及如何修改sequence的cache值提高性能。 本文分享自华为云社区《GaussDB(DWS)关于sequence的那些事》,作者:Arrow0lf 。 什么是sequence sequence,也称作序列,是用来产生唯一整数的数据库对象。序列的值按照