实用教程(Teradata).ppt

上传人:wuy****n92 文档编号:63793080 上传时间:2022-11-26 格式:PPT 页数:81 大小:681.50KB
返回 下载 相关 举报
实用教程(Teradata).ppt_第1页
第1页 / 共81页
实用教程(Teradata).ppt_第2页
第2页 / 共81页
点击查看更多>>
资源描述

《实用教程(Teradata).ppt》由会员分享,可在线阅读,更多相关《实用教程(Teradata).ppt(81页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、实用教程(Teradata)陆世潮2008年9月2 11/26/2022问题总结常见问题分类:常见问题分类:1.表属性不对:Set/Multiset问题:INSERT操作慢2.主索引(PI)设置不合理问题1:数据倾斜度大,空间爆满。问题2:JOIN操作,数据需要重分布。3.分区索引(PPI)设置不合理问题:全表扫描4.连接条件过于复杂问题:系统无法优化执行计划5.缺乏统计信息问题:系统无法找到最优化的执行计划SQL跑得慢哈!跑得慢哈!3 11/26/2022提纲Teradata架构常见问题,及解决方法Teradata工具实用小技巧JOIN的实现机制JOIN的优化4 11/26/2022Tera

2、data 体系架构Teradata and MPP SystemsRDBMS ARCH5 11/26/2022Logical Example of NPPI versus PPI4 AMPs with Orders Table defined with PPI on O_Date.RHO_#O_DateRHO_#O_DateRHO_#O_DateRHO_#O_Date35100706/0126100206/0124100406/0120100506/0139101106/0136101206/0132100306/0143101006/0114100106/0106100906/0104100

3、806/0108100606/0103101606/0217101306/0248102306/0207101706/0216102106/0245101506/0209101806/0227101406/0244102206/0202102406/0211101906/0222102006/0201102806/0312103106/0328103206/0310103406/0329103306/0334102906/0319102506/0340103506/0347102706/0325103606/0331102606/0346103006/0323104006/0430103806

4、/0442104706/0413103706/0421104506/0436104306/0405104806/0415104206/0433103906/0418104106/0438104606/0441104406/04 4 AMPs with Orders Table defined with NPPI.01102806/0312103106/0328103206/0310103406/0329103306/0334102906/0319102506/0340103506/0347102706/0325103606/0331102606/0346103006/0303101606/02

5、17101306/0248102306/0207101706/0216102106/0245101506/0209101806/0227101406/0244102206/0202102406/0211101906/0222102006/0214100106/0135100706/0139101106/0106100906/0126100206/0136101206/0104100806/0124100406/0132100306/0108100606/0120100506/0143101006/0123104006/0430103806/0442104706/0413103706/04211

6、04506/0436104306/0405104806/0415104206/0433103906/0418104106/0438104606/0441104406/04RHO_#O_DateRHO_#O_DateRHO_#O_DateRHO_#O_Date 6 11/26/2022提纲Teradata架构常见问题,及解决方法Teradata工具实用小技巧JOIN的实现机制JOIN的优化7 11/26/2022表属性:Set&MultiSetSet Table不允许记录重复MultiSet Table允许记录重复默认值:Set TableCreate Table.AS.生成的目标表属性默认为S

7、et Table对SET Table进行INSERT操作,需要检查是否存在重复记录相当的耗资源若真要限定唯一性,可以通过UPI或USI实现CREATE SET TABLE pmart.RPT_NM_GRP_PRE_WARN_MON,(CAL_Month INTEGER TITLE 统计月份,ORG_NUM CHAR(12)TITLE 集团编号,City_ID CHAR(3)TITLE 地市标识,ORG_SUBS_GRP_NUM CHAR(10)TITLE 集团用户群编号,ORG_Title VARCHAR(200)TITLE 集团名称,ORG_Level CHAR(2)TITLE 集团级别,S

8、TAT_Item_Code CHAR(2)TITLE 统计项,STAT_Value DECIMAL(18,2)TITLE 统计值)PRIMARY INDEX(ORG_NUM);例子:pmart.RPT_NM_GRP_PRE_WARN_MON 内蒙移动集团客户预警指标月报表假设原有1286449条记录插入:152853条记录耗时:15秒8 11/26/2022表属性:Set&MultiSet(cont.)CREATE MULTISET TABLE pmart.RPT_NM_GRP_PRE_WARN_MON(CAL_Month INTEGER TITLE 统计月份,ORG_NUM CHAR(12)

9、TITLE 集团编号,City_ID CHAR(3)TITLE 地市标识,ORG_SUBS_GRP_NUM CHAR(10)TITLE 集团用户群编号,ORG_Title VARCHAR(200)TITLE 集团名称,ORG_Level CHAR(2)TITLE 集团级别,STAT_Item_Code CHAR(2)TITLE 统计项,STAT_Value DECIMAL(18,2)TITLE 统计值)PRIMARY INDEX(ORG_NUM);例子:pmart.RPT_NM_GRP_PRE_WARN_MON 内蒙移动集团客户预警指标月报表建议:建议:Teradata中都用中都用 Multi

10、Set假设原有1286449条记录插入:152853条记录耗时:1秒例子:CREATE MULTISET TABLE tttemp.VT_SUBS_VIOC_QUAN as(SELECT*FROM tttemp.MID_SUBS_VIOC_QUAN WHERE CAL_MONTH=200802 AND*)WITH DATA PRIMARY INDEX(subs_id);临时表临时表,默认为默认为:Set需要指定为需要指定为:Multiset字段越多,记录越多字段越多,记录越多差别越明显差别越明显9 11/26/2022PI(Primary Index 主索引)的选择PI影响数据的存储与访问影响

11、数据的存储与访问,其选择标准:不同值尽量多的字段(More Unique Values)使用频繁的字段:包括值访问和连接访问少更新PI字段不宜太多最好是手动指定PI 例子:用户语音业务量中间表用户语音业务量中间表CREATE MULTISET TABLE tttemp.MID_SUBS_VIOC_QUAN(CAL_Month INTEGER TITLE 统计月份,City_ID CHAR(4)TITLE 地市标识,Channel_ID CHAR(8)TITLE 渠道标识,Subs_id CHAR(12)TITLE 用户标识,。)PRIMARY INDEX(subs_id);例子:用户语音业务量

12、临时表用户语音业务量临时表CREATE MULTISET TABLE tttemp.VT_SUBS_VIOC_QUAN as(SELECT*FROM tttemp.MID_SUBS_VIOC_QUAN WHERE CAL_MONTH=200802 AND*)WITH DATA PRIMARY INDEX(subs_id);Subs_ID:频繁使用频繁使用 Unique Value多多如果不指定如果不指定PI,系统默认为系统默认为:Cal_Month10 11/26/2022PI(Primary Index 主索引)的选择(cont.)例子:梦网客户活跃客户分析梦网客户活跃客户分析CREATE

13、MULTISET TABLE PMART.FCT_DATA_MONNET_ACTIVE_MON(CAL_Month INTEGER TITLE 统计月份,City_ID CHAR(4)TITLE 地市标识,Channel_ID CHAR(8)TITLE 渠道标识,Mont_SVC_Type_Cod CHAR(3)TITLE 梦网业务类型编码,Mont_SVC_CAT_MicroCls_Cod CHAR(3)TITLE 梦网业务分类小类编码,Mont_SVC_CHRG_Type_Cod CHAR(2)TITLE 梦网业务计费类型编码,THR_Brand_Cod CHAR(1)TITLE 三大品牌

14、编码,Mont_Consume_Level_Cod CHAR(2)TITLE 梦网消费层次编码,Consume_Level_Cod CHAR(2)TITLE 消费层次编码,。)PRIMARY INDEX(CAL_Month,City_ID,Channel_ID,Mont_SVC_Type_Cod,Mont_SVC_CAT_MicroCls_Cod,Mont_SVC_CHRG_Type_Cod,THR_Brand_Cod,Mont_Consume_Level_Cod,Consume_Level_Cod);PI:9字段 2字段:City_ID,Channel_ID 调整PI后,在右边的SQL中,P

15、I是否起作用?以下以下SQL,PI是否起作用?:是否起作用?:1.值访问Select*From FCT_DATA_MONNET_ACTIVE_MONWhere City_ID=070010 and Channel_ID=0100 and cal_month=2007072.连接访问Select*From FCT_DATA_MONNET_ACTIVE_MON ALEFT JOIN MID_CHANNEL_INFO_DAILY B ON A.Channel_ID=B.Channel_ID and A.City_ID =b.City_ID LEFT JOIN VW_CDE_REGION_TYPE C

16、 ON A.City_ID =C.City_ID 3、值访问连接访问Select*From FCT_DATA_MONNET_ACTIVE_MON A,VT_INFO BWHERE A.Channel_ID=B.Channel_ID AND A.City_ID =B.City_ID AND A.CAL_MONTH=200707 AND A.Consume_Level_Cod=B.Consume_Level_Cod11 11/26/2022PPI的使用PPI(Partition Primary Index,分区索引),把具有相同分区值的数据聚簇存放在一起;类似于SQL Server的聚簇索引(Cl

17、uster Index),Oracle的聚簇表(Cluster Table)。利用PPI,可以快速插入/访问同一个Partition(分区)的数据。CREATE MULTISET TABLE qdata.TB_DQC_KPI_CHECK_RESULT (TX_DATE DATE FORMAT YYYYMMDD TITLE 数据日期 NOT NULL,KPI_CODE INTEGER TITLE 指标代码 NOT NULL,。)PRIMARY INDEX(KPI_CODE)PARTITION BY RANGE_N(TX_DATE BETWEEN CAST(20030101)AS DATE FOR

18、MAT YYYYMMDD)AND CAST(20191231)AS DATE FORMAT YYYYMMDD)EACH INTERVAL 1 DAY,NO RANGE OR UNKNOWN);Select*From TB_DQC_KPI_CHECK_RESULTWhere tx_date=20070701;或Where tx_date between 20070701 and 20070731;或Where tx_date 20070701;但Where tx_date like 200707%;不起作用12 11/26/2022PPI的使用(cont.)Partition上不要使用表达式,否

19、则Partition不能被正确使用。T1.tx_date/100=CAST(20070917AS DATE FORMAT YYYYMMDD)/100Substring(T1.tx_date from 1 for 6)=200709应该修改为 T1.tx_date=CAST(20070901 AS DATE FORMAT YYYYMMDD)13 11/26/2022PPI的使用(cont.)脚本:tb_030040270.pl/*删除当月*/2小时 del BASS1.tb_03004 where proc_dt=200709;insert into BASS1.tb_03004 7小时。sel

20、.from pview.vw_evt_cust_so cust where acpt_date=cast(200710|01 as date)cast(200710|01 as date)写法错误,PPI不起作用日期的正确写法日期的正确写法:Cast(20071001 as date format YYYYMMDD)在proc_dt建立PPIPPI字段从Load_Date调整为acpt_date14 11/26/2022创建可变临时表它仅存活于同一个Session之内注意指定可变临时表为multiset(通常也要指定PI)可变临时表不能带有PPI例子1:create volatile mult

21、iset table vt_RETAIN_ANLY_MON as(select col1,col2,from where group by.)with data PRIMARY INDEX(PI_Cols)ON COMMIT PRESERVE ROWS;例子2:create volatile multiset table vt_RETAIN_ANLY_MON(col1 char(2),col2 varchar(12)NOT NULL)PRIMARY INDEX(PI_Cols)ON COMMIT PRESERVE ROWS;15 11/26/2022创建可变临时表(cont.)例子3:crea

22、te volatile multiset table vt_RETAIN_ANLY_MON as(select col1,cast(adc as varchar(12)col2 from where )with no data PRIMARY INDEX(col1)ON COMMIT PRESERVE ROWS;例子4:create volatile multiset table vt_net_gsm_nl as pdata.tb_net_gsm_nl with no data ON COMMIT PRESERVE ROWS;字段col2将用unicode字符集;当跟普通字段(latin字符集

23、)join时,需要进行数据重新分布。不建议不建议失败:因为pdata.tb_net_gsm_nl 有PPI而可变临时表不允许有PPI16 11/26/2022固化临时表固化临时表,就是把查询结果存放到一张物理表。固化临时表,就是把查询结果存放到一张物理表。共下次分析或他人使用共下次分析或他人使用Session断开之后,仍然可以使用。断开之后,仍然可以使用。示例1:CREATE MULTISET TABLE tttemp.TMP_BOSS_VOIC as(select*from pview.vw_net_gsm_nl)WITH no DATA PRIMARY INDEX(subs_id);INS

24、ERT INTO tttemp.TMP_BOSS_VOICSELECT*FROM pview.vw_net_gsm_nl WHERE*;示例2:CREATE MULTISET TABLE tttemp.TMP_BOSS_VOIC as(select*from pview.vw_net_gsm_nl WHERE*)WITH DATA PRIMARY INDEX(subs_id);示例3:(复制表,数据备份)CREATE MULTISET TABLE tttemp.TMP_BOSS_VOIC AS pdata.tb_net_gsm_nl WITH DATA ;17 11/26/2022数据类型注意

25、非日期字段与日期字段char&date的转换与关联:如果数据类型一致可以直接使用;在CASE WHEN or COALESCE一定要使用显式的类型转换(CAST)CASE WHEN A=B THEN DATE1 ELSE 20061031 END应写成CASE WHEN A=B THEN DATE1 ELSE CAST(20061031 AS DATE)END数值运算时,确保运算过程中不丢失计算精度。CAST(100/3 AS DEC(5,2)应该写成CAST(100/3.00 AS DEC(5,2)18 11/26/2022字符(串)与数字相比较比较规则比较规则:1)比较两个值比较两个值(字

26、段字段),它们的类型必须一样!,它们的类型必须一样!2)当字符当字符(串串)与数字相比较时,先把字符与数字相比较时,先把字符(串串)转换成数字,再进行比较。转换成数字,再进行比较。3)经分系统中容易出错的,有经分系统中容易出错的,有Cal_Month字段字段Case 1Table 1CREATE TABLE Emp1(Emp_noCHAR(6),Emp_nameCHAR(20)PRIMARY INDEX(Emp_no);Statement 1SELECT*FROMEmp1WHEREEmp_no=1234;Statement 2SELECT*FROMEmp1WHEREEmp_no=1234;Ta

27、ble 1CREATE TABLE Emp2(Emp_noINTEGER,Emp_nameCHAR(20)PRIMARY INDEX(Emp_no);Statement 1SELECT*FROMEmp2WHEREEmp_no=1234;Statement 2SELECT*FROMEmp2WHEREEmp_no=1234;Case 2Results in Full Table ScanResults in unnecessary conversion 19 11/26/2022目标列的选择减少目标列,可以少消耗SPOOL空间,从而提高SQL的效率当系统任务繁忙,系统内存少的时候,效果尤为明显。举

28、例:GSM语言话单表,PDATA.TB_NET_GSM_NL共有73字段,以下SQL供返回1.6亿条记录左边的SQL,记录最长为:698字节,平均399字节右边的SQL,记录最长为:59字节,平均30字节两者相差两者相差400多多GB的的SPOOL空间,空间,IO次数也随着相差甚大!次数也随着相差甚大!SPOOL空间估计:497 GBSPOOL空间估计:42 GBSELECT SUBS_ID ,MSISDN ,Begin_Date ,Begin_Time ,Call_DUR ,CHRG_DURFROM PDATA.TB_NET_GSM_NLWHERE PROC_DATE BETWEEN 200

29、70701 AND 20070731 SELECT*FROM PDATA.TB_NET_GSM_NLWHERE PROC_DATE BETWEEN 20070701 AND 2007073120 11/26/2022Where条件的限定根据Where条件先进行过滤数据集,再进行连接(JOIN)等操作这样,可以减少参与连接操作的数据集大小,从而提高效率好的查询引擎,可以自动优化;但有些复杂SQL,查询引擎优化得并不好。注意:系统的系统的SQL优化,只是避免最差的,选择相对优的,未必能够优化,只是避免最差的,选择相对优的,未必能够得到最好的优化结果。得到最好的优化结果。SELECT A.TX_DA

30、TE,A.KPI_CODE ,B.SRC_NAME,A.KPI_VALUEFROM(select *from qdata.tb_dqc_kpi_check_result where TX_DATE=20070701 AND KPI_CODE=65)ALEFT JOIN(SELECT*FROM qdata.tb_dqc_kpi_def where KPI_CODE=65 and N_TYPE=M)BON A.KPI_CODE=B.KPI_CODE SELECT A.TX_DATE,A.KPI_CODE ,coalesce(B.SRC_NAME,no name),A.KPI_VALUEFROM q

31、data.tb_dqc_kpi_check_result ALEFT JOIN qdata.tb_dqc_kpi_def BON A.KPI_CODE=B.KPI_CODE WHERE A.TX_DATE=20070701 AND A.KPI_CODE=65 AND B.N_TYPE=M rewrite21 11/26/2022用Case When替代UNION sel city_id,channel_id,cust_brand_id,sum(stat_values)as stat_valuesfrom(.select t.city_id-语音杂志计费量 ,coalesce(v.channel

32、_id,b.channel_id,-)as channel_id ,cust_brand_id ,sum(case when SMS_SVC_Type_Level_SECND=017 and Call_Type_Code in(00,10,01,11)then sms_quan else 0 END)as stat_values from PVIEW.vw_mid_sms_svc_quan_daily t left join VT_SUBS v on t.subs_id=v.subs_id left join PVIEW.vw_FCT_CDE_BUSN_CITY_TYPE b on t.cit

33、y_id=b.City_ID where cal_date=20070914 group by 1,2,3 union all select t.city_id -梦网短信计费量 ,coalesce(v.channel_id,b.channel_id,-)as channel_id ,cust_brand_id ,sum(sms_quan)as stat_values from PVIEW.vw_mid_sms_svc_quan_daily t left join VT_SUBS v on t.subs_id=v.subs_id left join PVIEW.vw_FCT_CDE_BUSN_

34、CITY_TYPE b on t.city_id=b.City_ID where cal_date=20070914 and SMS_SVC_Type_Level_SECND like 02%and SMS_SVC_Type_Level_SECND not in(021,022)group by 1,2,3 .)tmpGroup by 1,2,3两个子查询的表连接部分完全一样两个子查询除了取数据条件,其它都一样。Union all是多余的,它需要重复扫描数据,进行重复的JOIN可以用Case when替代union 作业:KPI_NWR_SMS_BILL_QUAN描述:点对点短信计费量脚本:k

35、pi_nwr_sms_bill_quan0600.pl22 11/26/2022用Case When替代UNION(cont.)sel city_id,channel_id,cust_brand_id,sum(stat_values)as stat_valuesfrom(select t.city_id ,coalesce(v.channel_id,b.channel_id,-)as channel_id ,cust_brand_id ,sum(CASE WHEN SMS_SVC_Type_Level_SECND=017 and Call_Type_Code in(00,10,01,11)TH

36、EN sms_quan -语音杂志计费量语音杂志计费量 WHEN SMS_SVC_Type_Level_SECND like 02%and SMS_SVC_Type_Level_SECND not in(021,022)THEN sms_quan -梦网短信计费量梦网短信计费量 ELSE 0 END)as stat_values from PVIEW.vw_mid_sms_svc_quan_daily t left join VT_SUBS v on t.subs_id=v.subs_id left join PVIEW.vw_FCT_CDE_BUSN_CITY_TYPE b on t.cit

37、y_id=b.City_ID where cal_date=20070914.)tmpGroup by 1,2,3SQL优化重写优化重写23 11/26/2022用OR替代UNION Select city_id,channel_id,cust_brand_id,sum(sms_quan)stat_valuesfrom(select t.city_id-语音杂志计费量 ,coalesce(v.channel_id,b.channel_id,-)as channel_id ,cust_brand_id ,sum(sms_quan)stat_values from PVIEW.vw_mid_sms

38、_svc_quan_daily t left join VT_SUBS v on t.subs_id=v.subs_id left join PVIEW.vw_FCT_CDE_BUSN_CITY_TYPE b on t.city_id=b.City_ID where cal_date=20070914 and SMS_SVC_Type_Level_SECND=017 and Call_Type_Code in(00,10,01,11)group by 1,2,3 union all select t.city_id -梦网短信计费量 ,coalesce(v.channel_id,b.chann

39、el_id,-)as channel_id ,cust_brand_id ,sum(sms_quan)as stat_values from PVIEW.vw_mid_sms_svc_quan_daily t left join VT_SUBS v on t.subs_id=v.subs_id left join PVIEW.vw_FCT_CDE_BUSN_CITY_TYPE b on t.city_id=b.City_ID where cal_date=20070914 and SMS_SVC_Type_Level_SECND like 02%and SMS_SVC_Type_Level_S

40、ECND not in(021,022)group by 1,2,3)T Group by 1,2,3两个子查询的表连接部分完全一样两个子查询除了取数据条件,其它都一样。Union all是多余的,它需要重复扫描数据,进行重复的JOIN可以用OR替代union 此类的问题,在脚本中经常见到。24 11/26/2022用OR替代UNION(cont.)select t.city_id ,coalesce(v.channel_id,b.channel_id,-)as channel_id ,cust_brand_id ,sum(sms_quan)as stat_values from PVIEW.

41、vw_mid_sms_svc_quan_daily t left join VT_SUBS v on t.subs_id=v.subs_id left join PVIEW.vw_FCT_CDE_BUSN_CITY_TYPE b on t.city_id=b.City_ID where cal_date=20070914 and (SMS_SVC_Type_Level_SECND=017 -语音杂志计费量语音杂志计费量 and Call_Type_Code in(00,10,01,11))OR(SMS_SVC_Type_Level_SECND like 02%-梦网短信计费量梦网短信计费量 a

42、nd SMS_SVC_Type_Level_SECND not in(021,022)Group by 1,2,3SQL优化重写优化重写25 11/26/2022去掉多余的Distinct与Group by sel t.operator,t.acpt_channel_id ,t.acpt_city_id ,t.subs_id ,t.acpt_date as evt_date From(sel operator,ACPT_Channel_ID,acpt_city_id,subs_id,acpt_date from pview.vw_evt_cust_so cust where acpt_date

43、=20071007 and so_meth_code in(0,1,2)and PROC_STS_Code=-1 group by 1,2,3,4,5union all sel operator_num as operator,ACPT_Channel_ID,acpt_city_id,subs.subs_id,charge_date as acpt_date from pview.vw_fin_busi_rec bus join crmmart.subs_day_info_daily subs on subs.msisdn=bus.msisdn where charge_date=200710

44、07 group by 1,2,3,4,5)t group by 1,2,3,4,5;既然t查询外层有group by操作去重,那么子查询内的Group by去重是多余的。而且,两个子查询group by后再用union all,就可能再产生重复记录,那么group by也失去意义了。解决方法:把把t查询内部的两个查询内部的两个group by去掉即可去掉即可 类似的类似的Distinct问题,可效仿解决。问题,可效仿解决。去重去重去重26 11/26/2022Group by vs.DistinctDistinct是去除重复的操作Group by是聚集操作某些情况下,两者可以起到相同的作用。

45、两者的执行计划不一样,效率也不一样建议:使用建议:使用Group byselect subs_id ,acct_idfrom PVIEW.VW_FIN_ACCT_SUBS_HISwhere efct_date 20070701 group by 1,2select DISTINCT subs_id ,acct_idfrom PVIEW.VW_FIN_ACCT_SUBS_HISwhere efct_date 20070701 27 11/26/2022Union vs.Union all Union与Union all的作用是将多个SQL的结果进行合并。Union将自动剔除集合操作中的重复记录;

46、需要耗更多资源。Union all则保留重复记录,一般建议使用Union all。第一个SELECT语句,决定输出的字段名称,标题,格式等要求所有的SELECT语句:1)必须要有同样多的表达式数目;2)相关表达式的域必须兼容select*from(select a)T1(col1)unionselect*from(select bc)T2(col2)select*from(select bc)T3(col3)union allselect*from(select a)T1(col1)union allselect*from(select bc)T2(col2)col3-abcbccol1-ab

47、28 11/26/2022先Group by再join脚本:脚本:rpt_mart_new_comm_mon0400.pl 11小时小时Select case when b.CUST_Brand_ID is null then 5020 when b.CUST_Brand_ID in(2000,5010)then 5020 else b.CUST_Brand_ID end ,sum(COALESCE(b.Bas_CHRG_DUR_Unit,0)as Thsy_Accum_New_SUBS_CHRG_DUR ,sum(case when b.call_type_code=20 then b.Ba

48、s_CHRG_DUR_Unit else 0 END)from VTNEW_SUBS_THISYEAR t inner join VTDUR_MON b on t.Subs_ID=b.Subs_ID left join PVIEW.vw_MID_CDE_LONG_CALL_TYPE_LVL c on b.Long_Type_Level_SECND=c.Long_Type_Level_SECND left join PVIEW.vw_MID_CDE_ROAM_TYPE_LVL d on b.Roam_Type_Level_SECND=d.Roam_Type_Level_SECND group b

49、y 1;记录数情况:记录数情况:t:580万,万,b:9400万万,c:8,d:8 主要问题:主要问题:假如连接顺序为:(b join c)join d)join t)则是(9400万 join 8)join 8)join 580万)数据分布时间长数据分布时间长(IO多多),连接次数多,连接次数多解决方法:解决方法:先执行先执行(t join b),然后,然后groupby,再,再join c,d29 11/26/2022先Group by再join(cont.)脚本:脚本:rpt_mart_new_comm_mon0400.pl40秒秒Select case when b.CUST_Bran

50、d_ID is null then 5020 when b.CUST_Brand_ID in(2000,5010)then 5020 else b.CUST_Brand_ID end ,sum(COALESCE(b.Bas_CHRG_DUR_Unit,0)as Thsy_Accum_New_SUBS_CHRG_DUR ,sum(case when b.call_type_code=20 then b.Bas_CHRG_DUR_Unit else 0 END)from (select CUST_Brand_ID,call_type_code,Long_Type_Level_SECND,Roam_

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 大学资料

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁