• sqlserver使用临时表提高速度


    select Distinct
    t8.objname 唯一编码
    ,t8.objjc 名称
    ,t8.objid,t8.parentid,t8.objname,t8.objjc,t8.objorder
    ,case t8.worktype when 'ST' then 0 when 'FR' then 2 when 'WK' then 4 else 6 end xbico
    from cwfsys_work a 
    left join cwfsys_work t1 on a.objid=t1.parentid or a.objid=t1.objid
    left join cwfsys_work t2 on t1.objid=t2.parentid or t1.objid=t2.objid
    left join cwfsys_work t3 on t2.objid=t3.parentid or t2.objid=t3.objid
    left join cwfsys_work t4 on t3.objid=t4.parentid or t3.objid=t4.objid
    left join cwfsys_work t5 on t4.objid=t5.parentid or t4.objid=t5.objid
    left join cwfsys_work t6 on t5.objid=t6.parentid or t5.objid=t6.objid
    left join cwfsys_work t7 on t6.objid=t7.parentid or t6.objid=t7.objid
    left join cwfsys_work t8 on t7.objid=t8.parentid or t7.objid=t8.objid

    where a.objname='#工作分类#'

    原sql ,运行5-6秒

    if object_id('tempdb..#tempwork') is not null drop table #tempwork
    select Distinct
    t4.objname 唯一编码
    ,t4.objjc 名称
    ,t4.objid,t4.parentid,t4.objname,t4.objjc,t4.objorder
    ,case t4.worktype when 'ST' then 0 when 'FR' then 2 when 'WK' then 4 else 6 end xbico
    into #tempwork
    from cwfsys_work a 
    join cwfsys_work t1 on a.objid=t1.parentid or a.objid=t1.objid
    join cwfsys_work t2 on t1.objid=t2.parentid or t1.objid=t2.objid
    join cwfsys_work t3 on t2.objid=t3.parentid or t2.objid=t3.objid
    join cwfsys_work t4 on t3.objid=t4.parentid or t3.objid=t4.objid
    join cwfsys_work t5 on t4.objid=t5.parentid or t4.objid=t5.objid
    join cwfsys_work t6 on t5.objid=t6.parentid or t5.objid=t6.objid
    join cwfsys_work t7 on t6.objid=t7.parentid or t6.objid=t7.objid
    join cwfsys_work t8 on t7.objid=t8.parentid or t7.objid=t8.objid
    where a.objname='#工作分类#'

    select Distinct
    t8.objname 唯一编码
    ,t8.objjc 名称
    ,t8.objid,t8.parentid,t8.objname,t8.objjc,t8.objorder
    ,case t8.worktype when 'ST' then 0 when 'FR' then 2 when 'WK' then 4 else 6 end xbico
    from #tempwork t4
    join cwfsys_work t5 on t4.objid=t5.parentid or t4.objid=t5.objid
    join cwfsys_work t6 on t5.objid=t6.parentid or t5.objid=t6.objid
    join cwfsys_work t7 on t6.objid=t7.parentid or t6.objid=t7.objid
    join cwfsys_work t8 on t7.objid=t8.parentid or t7.objid=t8.objid
    if object_id('tempdb..#tempwork') is not null drop table #tempwork

    修改后sql,采用临时表,运行2-3秒

  • 相关阅读:
    自动化测试-18.selenium之bugFree代码注释
    自动化测试-16.selenium数据的分离之Excel的使用
    自动化测试-15.selenium单选框与复选框状态判断
    自动化测试-14.selenium加载FireFox配置
    自动化测试-13.selenium执行JS处理滚动条
    Lucas-Kanade算法总结
    迟来的2013年总结及算法工程师/研究员找工作总结
    Android从文件读取图像显示的效率问题
    Viola Jones Face Detector
    谈谈Android中的SurfaceTexture
  • 原文地址:https://www.cnblogs.com/cwfsoft/p/1806177.html
Copyright © 2020-2023  润新知