Strange SQL Server execution

Source: Internet
Author: User

Today work encountered, the following this section of the implementation of ultra-slow, hardly come out, run on the old server is possible, the same code, soon, on the new virtual server, super slow.

       Select *  from         (            SelectRowNum=Row_number () Over(Order  byAutoiddesc), StartTime,cast(Testtime/1000.00  as decimal(Ten,2)) astesttime,autoid fromdbo. Ftmaster M with(NOLock)WhereStartTime>='2014-01-01 00:00:00.000'  andStartTime<'2014-12-31 23:00:00.000'  andModelic='XXX'  andResult=0  andTesttype=3                         and exists            (                    SelectAutoid from                 (                    Select Min(bb.autoid) autoid
             from (Select Max(StartTime) asStarttime,sn fromdbo. Ftmaster with(NOLock)
             WhereStartTime>='2014-01-01 00:00:00.000' andStartTime<'2014-12-31 23:00:00.000' andModelic='XXX' andTesttype=3 Group bySn) asAAInner Join
(SelectAutoid,sn,starttime fromDbo. Ftmaster with(NOLock)
WhereStartTime>='2014-01-01 00:00:00.000' andStartTime<'2014-12-31 23:00:00.000' andModelic='XXX' andTesttype=3) asBB
onAa. SN=Bb. SN andAa. StartTime=BB. StartTimeGroup byBB. SN) TwhereT.autoid=m.autoid)) asmastertableWHERERowNumbetween(1 - 1)* 12430 + 1 and 1 * 12430

The execution of the inside is quick and why.

SelectRowNum=Row_number () Over(Order  byAutoiddesc), StartTime,cast(Testtime/1000.00  as decimal(Ten,2)) astesttime,autoid fromdbo. Ftmaster M with(NOLock)WhereStartTime>='2014-01-01 00:00:00.000'  andStartTime<'2014-12-31 23:00:00.000'  andModelic='XXX'  andResult=0  andTesttype=3                         and exists            (                    SelectAutoid from                 (                    Select Min(bb.autoid) autoid from                      (Select Max(StartTime) asStarttime,sn fromDbo. Ftmaster with(NOLock)WhereStartTime>='2014-01-01 00:00:00.000'  andStartTime<'2014-12-31 23:00:00.000'  andModelic='XXX'  andTesttype=3 Group  bySn) asAAInner Join(SelectAutoid,sn,starttime fromDbo. Ftmaster with(NOLock)WhereStartTime>='2014-01-01 00:00:00.000'  andStartTime<'2014-12-31 23:00:00.000'  andModelic='XXX'  andTesttype=3) asBB onAa. SN=Bb. SN andAa. StartTime=BB. StartTimeGroup  byBB. SN) TwhereT.autoid=m.autoid)

Strange SQL Server execution

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.