GBase 8a
性能调优
文章

SQL优化——关联视图查询,视图性能慢类优化

发表于2024-12-06 17:39:1028次浏览2个评论

视图会在查询、关联中大量引起,需要保证视图的高性能,本例中的视图查询性能慢。
SQL语句

SQL总计耗时28秒

视图vw_ehr_emp语法如下:

vw_ehr_emp中两表关联左侧关联字段加了trim()函数,会导致关联列上智能索引失效,走全表扫描,是造成该视图性能低的原因。建议提前将sz_mh_10ehr_ref表里的orgid、depid列的数据进行清洗,避免数据中包含左右空格。
在另外一套环境的testdb_ndty库中新建视图和视图依赖的表,通过以下方式先清洗关联列左右空格,保证库内的高效运算。

drop table if exists testdb_ndty.eoa_staff;
create table  testdb_ndty.eoa_staff distributed by ('depid') as select * from bdmjs10.eoa_staff limit 0;
insert into testdb_ndty.eoa_staff (eoaid,usapid,iden,mob,staffname,orgid,orgname,depid,depnam,c3id,ifarid,bz1,bz2,bz3,bz4,bz5)
select 
eoaid,usapid,iden,mob,staffname,orgid,orgname,trim(depid),depnam,c3id,ifarid,bz1,bz2,bz3,bz4,bz5 from bdmjs10.eoa_staff
 
drop table if exists testdb_ndty.sz_mh_10ehr_ref; 
create table testdb_ndty.sz_mh_10ehr_ref replicated  select * from  bdmjssh.sz_mh_10ehr_ref limit 1;
insert into  testdb_ndty.sz_mh_10ehr_ref (org_name,org_id,org_pid ,org_lvl ,  org_ou)
select org_name,trim(org_id),org_pid ,org_lvl ,  org_ou from  bdmjssh.sz_mh_10ehr_ref;

优化视图后SQL总计耗时21秒。

评论

登录后才可以发表评论
GBase用户31099发表于 8个月前
优秀
用户头像
levvel发表于 2个月前
观点很新颖!