zoukankan      html  css  js  c++  java
  • 奇怪的SQLserver执行

     今天工作遇到,下面这段执行超慢,几乎不出来,在旧服务器上运行是可以的,一样代码,很快,在新虚拟服务器上,超慢。

         select * from 
            (
                select RowNum=row_number() over(order by AutoId desc),StartTime,cast(testtime/1000.00 as decimal(10,2)) as testtime,AutoId
                from dbo.FTMaster M
                 WITH(NOLock) Where StartTime >='2014-01-01 00:00:00.000' and StartTime <'2014-12-31 23:00:00.000' and ModelIc='XXX' and Result=0 and TestType=3            
                and exists
                (    
                    select AutoId from 
                    (
                        select Min(BB.autoid) AutoID 
                from (Select Max(StartTime) as starttime,SN From dbo.FTMaster WITH(NOLock)
                 Where StartTime >='2014-01-01 00:00:00.000' and StartTime <'2014-12-31 23:00:00.000' and ModelIc='XXX' and TestType=3 group by Sn) as AA inner join
                (Select AutoID,SN,StartTime From dbo.FTMaster WITH(NOLock)   
                 Where StartTime >='2014-01-01 00:00:00.000' and StartTime <'2014-12-31 23:00:00.000' and ModelIc='XXX' and TestType=3 ) As BB
                 on AA.SN=BB.SN And AA.StartTime=BB.StartTime group by BB.SN ) t where t.AutoId=M.AutoId ) ) as MasterTable WHERE RowNum between (1 - 1) * 12430 + 1 and 1 * 12430

    执行里面的又很快, 为什么呢。

           select RowNum=row_number() over(order by AutoId desc),StartTime,cast(testtime/1000.00 as decimal(10,2)) as testtime,AutoId
                from dbo.FTMaster M
                 WITH(NOLock) Where StartTime >='2014-01-01 00:00:00.000' and StartTime <'2014-12-31 23:00:00.000' and ModelIc='XXX' and Result=0 and TestType=3            
                and exists
                (    
                    select AutoId from 
                    (
                        select Min(BB.autoid) AutoID 
                from 
                         (Select Max(StartTime) as starttime,SN From dbo.FTMaster WITH(NOLock) 
                 Where StartTime >='2014-01-01 00:00:00.000' and StartTime <'2014-12-31 23:00:00.000' and ModelIc='XXX' and TestType=3 group by Sn) as AA 
                         inner join 
                (Select AutoID,SN,StartTime From dbo.FTMaster WITH(NOLock)   
                 Where StartTime >='2014-01-01 00:00:00.000' and StartTime <'2014-12-31 23:00:00.000' and ModelIc='XXX' and TestType=3 ) As BB 
                 on AA.SN=BB.SN And AA.StartTime=BB.StartTime 
                        group by BB.SN
                    ) t where t.AutoId=M.AutoId 
                )    
  • 相关阅读:
    五种常见的 PHP 设计模式
    转载:php header下载乱码 空格 问题
    PHP程序员最常犯的11个MySQL错误
    启迪人心:10个的有关编程的至理名言
    如何使用搜索技巧来成为一名高效的程序员
    随机验证码
    产生sql表中表示字段, 实现自增列
    在当前页面弹出对话框
    读取页面传入的URL值
    Sql临时表
  • 原文地址:https://www.cnblogs.com/jjoo/p/4271075.html
Copyright © 2011-2022 走看看