|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册账号
×
某屠宰项目:运输单参照发货单拉单,查询极慢。由于客户要求限定1个发货单只能拉1次运输单,故在参照查询中,客开了段逻辑。完整SQL如下:
- select so_delivery.approver,
- so_delivery_b.badvfeeflag,
- so_delivery_b.bbarsettleflag,
- so_delivery_b.bcheckflag,
- so_delivery.billmaker,
- so_delivery_b.blargessflag,
- so_delivery_b.boutendflag,
- so_delivery_b.bqualityflag,
- so_delivery_b.btransendflag,
- so_delivery_b.btriatradeflag,
- so_delivery_b.busecheckflag,
- so_delivery_b.carorgid,
- so_delivery_b.carorgvid,
- so_delivery_b.castunitid,
- so_delivery.cbiztypeid,
- so_delivery_b.cchanneltypeid,
- so_delivery_b.cchauffeurid,
- so_delivery_b.ccurrencyid,
- so_delivery_b.ccustmaterialid,
- so_delivery_b.cdeliverybid,
- so_delivery_b.cdeliveryid,
- so_delivery_b.cdeptid,
- so_delivery_b.cdeptvid,
- so_delivery_b.cemployeeid,
- so_delivery_b.cfirstbid,
- so_delivery_b.cfirstid,
- so_delivery_b.cfreecustid,
- so_delivery_b.cinstockorgid,
- so_delivery_b.cinstockorgvid,
- so_delivery_b.cinstordocid,
- so_delivery_b.cinvoicecustid,
- so_delivery_b.cmaterialid,
- so_delivery_b.cmaterialvid,
- so_delivery_b.cmffileid,
- so_delivery_b.cordercustid,
- so_delivery_b.corigareaid,
- so_delivery_b.corigcountryid,
- so_delivery_b.corigcurrencyid,
- so_delivery_b.cpriceformid,
- so_delivery_b.cprodlineid,
- so_delivery_b.cproductorid,
- so_delivery_b.cprofitcenterid,
- so_delivery_b.cprofitcentervid,
- so_delivery_b.cprojectid,
- so_delivery_b.cqtunitid,
- so_delivery_b.cqualitylevelid,
- so_delivery.creationtime,
- so_delivery.creator,
- so_delivery_b.crececountryid,
- so_delivery_b.creceiveadddocid,
- so_delivery_b.creceiveaddrid,
- so_delivery_b.creceiveareaid,
- so_delivery_b.creceivecustid,
- so_delivery_b.creceivepersonid,
- so_delivery_b.cretreasonid,
- so_delivery_b.crowno,
- so_delivery_b.crprofitcenterid,
- so_delivery_b.crprofitcentervid,
- so_delivery_b.csaleorgid,
- so_delivery_b.csaleorgvid,
- so_delivery_b.csendadddocid,
- so_delivery_b.csendaddrid,
- so_delivery_b.csendareaid,
- so_delivery_b.csendcountryid,
- so_delivery.csenddeptid,
- so_delivery.csenddeptvid,
- so_delivery.csendemployeeid,
- so_delivery_b.csendpersonid,
- so_delivery_b.csendstockorgid,
- so_delivery_b.csendstockorgvid,
- so_delivery_b.csendstordocid,
- so_delivery_b.csettleorgid,
- so_delivery_b.csettleorgvid,
- so_delivery_b.cspaceid,
- so_delivery_b.csprofitcenterid,
- so_delivery_b.csprofitcentervid,
- so_delivery_b.csrcbid,
- so_delivery_b.csrcid,
- so_delivery_b.csupercargoid,
- so_delivery_b.ctaxcodeid,
- so_delivery_b.ctaxcountryid,
- so_delivery.ctradewordid,
- so_delivery_b.ctranscustid,
- so_delivery.ctransportrouteid,
- so_delivery.ctransporttypeid,
- so_delivery.ctrantypeid,
- so_delivery_b.cunitid,
- so_delivery_b.cvehicleid,
- so_delivery_b.cvehicletypeid,
- so_delivery_b.cvendorid,
- so_delivery_b.dbilldate,
- so_delivery_b.dhm_f_nreqrsnum,
- so_delivery_b.dhm_f_ntotalarnum,
- so_delivery_b.dhm_f_ntotalelignum,
- so_delivery_b.dhm_f_ntotalestarnum,
- so_delivery_b.dhm_f_ntotalnotoutnum,
- so_delivery_b.dhm_f_ntotaloutnum,
- so_delivery_b.dhm_f_ntotalreportnum,
- so_delivery_b.dhm_f_ntotalrushnum,
- so_delivery_b.dhm_f_ntotaltransnum,
- so_delivery_b.dhm_f_ntotalunelignum,
- so_delivery_b.dhm_f_ntranslossnum,
- so_delivery.dmakedate,
- so_delivery_b.dreceivedate,
- so_delivery_b.dsenddate,
- so_delivery_b.fbuysellflag,
- so_delivery_b.frownote,
- so_delivery.fstatusflag,
- so_delivery_b.ftaxtypeflag,
- so_delivery.ts,
- so_delivery.iprintcount,
- so_delivery.modifiedtime,
- so_delivery.modifier,
- so_delivery_b.nastnum,
- so_delivery_b.ncaltaxmny,
- so_delivery_b.ndiscount,
- so_delivery_b.ndiscountrate,
- so_delivery_b.nexchangerate,
- so_delivery_b.nglobalexchgrate,
- so_delivery_b.nglobalmny,
- so_delivery_b.nglobaltaxmny,
- so_delivery_b.ngroupexchgrate,
- so_delivery_b.ngroupmny,
- so_delivery_b.ngrouptaxmny,
- so_delivery_b.nitemdiscountrate,
- so_delivery_b.nmny,
- so_delivery_b.nnetprice,
- so_delivery_b.nnum,
- so_delivery_b.norigdiscount,
- so_delivery_b.norigmny,
- so_delivery_b.norignetprice,
- so_delivery_b.norigprice,
- so_delivery_b.norigtaxmny,
- so_delivery_b.norigtaxnetprice,
- so_delivery_b.norigtaxprice,
- so_delivery_b.npiece,
- so_delivery_b.nprice,
- so_delivery_b.nqtnetprice,
- so_delivery_b.nqtorignetprice,
- so_delivery_b.nqtorigprice,
- so_delivery_b.nqtorigtaxnetprc,
- so_delivery_b.nqtorigtaxprice,
- so_delivery_b.nqtprice,
- so_delivery_b.nqttaxnetprice,
- so_delivery_b.nqttaxprice,
- so_delivery_b.nqtunitnum,
- so_delivery_b.nreqrsnum,
- so_delivery_b.ntax,
- so_delivery_b.ntaxmny,
- so_delivery_b.ntaxnetprice,
- so_delivery_b.ntaxprice,
- so_delivery_b.ntaxrate,
- so_delivery_b.ntotalarnum,
- so_delivery.ntotalastnum,
- so_delivery_b.ntotalelignum,
- so_delivery_b.ntotalestarnum,
- so_delivery_b.ntotalnotoutnum,
- so_delivery_b.ntotaloutnum,
- so_delivery.ntotalpiece,
- so_delivery_b.ntotalreportnum,
- so_delivery_b.ntotalrushnum,
- so_delivery_b.ntotaltransnum,
- so_delivery_b.ntotalunelignum,
- so_delivery.ntotalvolume,
- so_delivery.ntotalweight,
- so_delivery_b.ntranslossnum,
- so_delivery_b.nvolume,
- so_delivery_b.nweight,
- so_delivery_b.pk_batchcode,
- so_delivery_b.pk_group,
- so_delivery_b.pk_org,
- so_delivery.pk_org_v,
- so_delivery.taudittime,
- so_delivery_b.ts,
- so_delivery_b.vbatchcode,
- so_delivery_b.vbdef1,
- so_delivery_b.vbdef10,
- so_delivery_b.vbdef11,
- so_delivery_b.vbdef12,
- so_delivery_b.vbdef13,
- so_delivery_b.vbdef14,
- so_delivery_b.vbdef15,
- so_delivery_b.vbdef16,
- so_delivery_b.vbdef17,
- so_delivery_b.vbdef18,
- so_delivery_b.vbdef19,
- so_delivery_b.vbdef2,
- so_delivery_b.vbdef20,
- so_delivery_b.vbdef21,
- so_delivery_b.vbdef22,
- so_delivery_b.vbdef23,
- so_delivery_b.vbdef24,
- so_delivery_b.vbdef25,
- so_delivery_b.vbdef26,
- so_delivery_b.vbdef27,
- so_delivery_b.vbdef28,
- so_delivery_b.vbdef29,
- so_delivery_b.vbdef3,
- so_delivery_b.vbdef30,
- so_delivery_b.vbdef31,
- so_delivery_b.vbdef32,
- so_delivery_b.vbdef33,
- so_delivery_b.vbdef34,
- so_delivery_b.vbdef35,
- so_delivery_b.vbdef36,
- so_delivery_b.vbdef37,
- so_delivery_b.vbdef38,
- so_delivery_b.vbdef39,
- so_delivery_b.vbdef4,
- so_delivery_b.vbdef40,
- so_delivery_b.vbdef5,
- so_delivery_b.vbdef6,
- so_delivery_b.vbdef7,
- so_delivery_b.vbdef8,
- so_delivery_b.vbdef9,
- so_delivery.vbillcode,
- so_delivery_b.vchangerate,
- so_delivery.vdef1,
- so_delivery.vdef10,
- so_delivery.vdef11,
- so_delivery.vdef12,
- so_delivery.vdef13,
- so_delivery.vdef14,
- so_delivery.vdef15,
- so_delivery.vdef16,
- so_delivery.vdef17,
- so_delivery.vdef18,
- so_delivery.vdef19,
- so_delivery.vdef2,
- so_delivery.vdef20,
- so_delivery.vdef3,
- so_delivery.vdef4,
- so_delivery.vdef5,
- so_delivery.vdef6,
- so_delivery.vdef7,
- so_delivery.vdef8,
- so_delivery.vdef9,
- so_delivery_b.vfirstbilldate,
- so_delivery_b.vfirstcode,
- so_delivery_b.vfirstrowno,
- so_delivery_b.vfirsttrantype,
- so_delivery_b.vfirsttype,
- so_delivery_b.vfree1,
- so_delivery_b.vfree10,
- so_delivery_b.vfree2,
- so_delivery_b.vfree3,
- so_delivery_b.vfree4,
- so_delivery_b.vfree5,
- so_delivery_b.vfree6,
- so_delivery_b.vfree7,
- so_delivery_b.vfree8,
- so_delivery_b.vfree9,
- so_delivery.vnote,
- so_delivery_b.vqtunitrate,
- so_delivery_b.vreceivetel,
- so_delivery_b.vreturnmode,
- so_delivery_b.vsendtel,
- so_delivery_b.vsrccode,
- so_delivery_b.vsrcrowno,
- so_delivery_b.vsrctrantype,
- so_delivery_b.vsrctype,
- so_delivery.vtrantypecode
- from so_delivery so_delivery
- left outer join so_delivery_b so_delivery_b
- on so_delivery_b.cdeliveryid = so_delivery.cdeliveryid
- where (so_delivery.pk_org = '0001A1100000000HB9JI' AND
- (so_delivery.dbilldate >= '2022-02-21 00:00:00' and
- so_delivery.dbilldate <= '2022-02-21 23:59:59'))
- and so_delivery.dr = 0
- and so_delivery_b.dr = 0
- and (so_delivery.cbiztypeid in
- ('0001A1100000000017XB',
- '1001A1100000000020MH',
- '1001A110000000002ONY',
- '1001A11000000000F0WG',
- '1001A11000000000F0XZ',
- '1001A11000000000F0YQ',
- '1001A110000000BNTAF4',
- '1001A110000000BNYMRL',
- '1001A110000000BPS90H',
- '1001A110000000BRIM5M',
- '1001A110000000BRIMRT',
- '1001A110000000BRIU28'))
- --and (so_delivery.fstatusflag in (1))
- and ((VDEF4 = 'Y') OR (ctrantypeid in ('1001A110000000BB2T8N')))
- and (so_delivery_b.btransendflag = 'N')
- and nvl(so_delivery_b.nnum, 0) - nvl(so_delivery_b.ntotaltransnum, 0) > 0
- <b>and so_delivery.cdeliveryid not in
- (select distinct csrcid
- from dm_delivbill_b
- where nvl(dr, 0) = 0
- and vsrctrantype in
- (select pk_billtypeid
- from bd_billtype
- where nvl(dr, 0) = 0
- and parentbilltype = '4331'))</b>
- and so_delivery.ctransporttypeid not in
- (select distinct pk_transporttype
- from bd_transporttype
- where nvl(dr, 0) = 0
- and code = '4')
- and so_delivery.pk_group = '0001A110000000000MDY'
- order by so_delivery.vbillcode, so_delivery_b.crowno
复制代码 以上标粗的部分,即为增加的逻辑。
前期影响不大,能正常使用。经过两年运行,背景数据达到500万时,性能就很差了。
原因:如下查询子句,无法利用索引,每次全表扫描:
- and so_delivery.cdeliveryid not in
- (select distinct csrcid
- from dm_delivbill_b
- where nvl(dr, 0) = 0
- and vsrctrantype in
- (select pk_billtypeid
- from bd_billtype
- where nvl(dr, 0) = 0
- and parentbilltype = '4331'))
复制代码 将以上通过not exists 做等价替代,如下:csrcid = so_delivery.cdeliveryid 能利用来源线索的索引:
- and not exists (select 1 from dm_delivbill_b where <b>csrcid = so_delivery.cdeliveryid </b> and nvl(dr,0)=0 and vsrctrantype in
- (select pk_billtypeid
- from bd_billtype
- where nvl(dr, 0) = 0
- and parentbilltype = '4331'))
复制代码
改造后性能情况:从4分多种到2秒。
|
|