2013-07-15 4 views
0

내가 테이블 아래와 같이이 쿼리SQL 성능

PRIMARY KEY CLUSTERED 
(
    idMetalTemprature ASC 
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON PRIMARY 
) ON PRIMARY 

CREATE NONCLUSTERED INDEX NonClusteredIndex1112 ON MetalTemprature 
(
    rawTime DESC 
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON PRIMARY 

나는이 쿼리 그렇게 0 초을 실행하면

SELECT count(*) 
    FROM MetalTemprature 
    where rawTime < 4449449575 and rawTime > (4449449575 -10000000) and metal = 'iron'; 

하지만이 쿼리를 다른 선택 아래에 넣을 때

SELECT 
    SELECT count(*) 
      FROM MetalTemprature 
      where rawTime < other.rawTime and rawTime > (other.rawTime -10000000) and metal = 'iron'; 
from other_table_only_one_row as other; 

약 60 초가 걸립니다 (other.rawTime이 4449449575이고 두 쿼리의 결과가 같을 때) 이유는 무엇입니까? FROM 섹션에

답변

0
SELECT * 
from other_table_only_one_row as other, (SELECT count(*) 
      FROM MetalTemprature 
      where rawTime < other.rawTime and rawTime > (other.rawTime -10000000) and metal = 'iron') as cnt 

장소 그냥 한 번

+0

Thnaks을 실행하되 나는 그것을 시도하지만 난 오류 메시지 4104, 수준 16, 상태 1, 줄 10 다중 부분 식별자 "도착했을 때 other.rawTime "구속 될 수 없었다. –