2010-03-04 2 views
5

일일 티켓 유효성 검증 (Unix datetime)의 3 천만 레코드 (한 달 값)를 조사해야하고 211 스테이션에 대해 1 시간 24 시간으로 나누어야합니다.3000 만 레코드. 그들을 24 시간 단위로 나누십시오. 1 개월 씩합시다. 린스 및 반복

먼저 내가 찾고있는 달을 선택하는보기를 만들었고 (장비 유형) 각 Unix datetime에 대해 Windows Datetime 값을 만듭니다.

SELECT TOP (100) PERCENT StationName AS Station, MainTable.UnixDateTime AS ValTime, 
DATEADD(s, MainTable.UnixDateTime, CONVERT(DATETIME, '1970-01-01 00:00:00', 102)) AS WinTime 
FROM MainTable 
INNER JOIN StationName ON MainTable.StationID = StationName.StationID 
WHERE (StationName.ValidStationCode = 32767) [use only valid stations] 
AND (MainTable. UnixDateTime >= 1264996800) 
AND (MainTable. UnixDateTime < 1267416000) 
AND (MainTable.EquipmentCode IN (33, 36)) [examine only this equipment] 
ORDER BY Station 

난 후 한 시간 기간의 각각에 대해이보기에 SELECT 문을 사용하는 기본 절차를 실행합니다. 그것은 211 개의 각 스테이션에 대한 24 개의 선택 진술입니다.

예 1)

Update table Set [0102]= (select count(ValTime) 
from view 
where Station = @thisStation and DatePart (Hour, WinTime)>= 1 and DatePart (Hour, WinTime)< 2) 
from view 
where table.Station = @thisStation 

예 2)

Update table Set [0203]= (select count(ValTime) 
from view 
where Station = @thisStation and DatePart (Hour, WinTime)>= 2 and DatePart (Hour, WinTime)< 3) 
from view 
where table.Station = @thisStation 

절차는 작동 - 야호! ,

가 빠른이이 일을 더 나은 방법을

  0001 0102 0203 0304...2324 
Station1 27 34 567 231... 123 
Station2 245 57 23 198... 21 
etc. 

출력 테이블이 25 열하지만 난 모르겠어요. :(

출력 예 우우 - 이 11 시간이 소요 (슈퍼 컴퓨터를 구입 하시겠습니까?) 순위 및 파티션에 대해 생각해 보았지만 어떻게 작동하는지 시각화 할 수 없었습니다. 전문가가 있습니까?

답변

3

DatePart 기능이 성능을 죽인 것 같습니다. 잉크를 사용하면 날짜를 일, 시간, 분 열로 구분하는 속도를 크게 높일 수 있습니다. 이러한 열에 인덱스를 추가하면 계산 된 값 대신 리터럴 값을 쿼리 할 수 ​​있습니다.

+0

열을 작성하는 대신 기능 색인을 작성할 수 있습니다 (즉, oracle이 SQL Server를 호출하는 것으로 가정합니다) –

3

유닉스 시간은 정수로 저장됩니다. DateTime으로 변환하는 대신 정수로 처리하면 더 나은 성능을 얻을 것이라고 생각합니다.

예를 들어,

Select (UnixDateTime % 86400)/3600 As Hour 

난 당신이 쿼리를 실행 한 경우처럼 성능이 될 것을 보는 것은 매우 궁금합니다 .... 유닉스 날짜 시간의 시간, 당신은이 작업을 수행 할 수 있습니다 얻을 수 있습니다

Select StationName As Station, 
     Count(Case When (MainTable.UnixDateTime % 86400)/3600 = 0 Then MainTable.UnixDateTime End) As [0001], 
     Count(Case When (MainTable.UnixDateTime % 86400)/3600 = 1 Then MainTable.UnixDateTime End) As [0102], 
     Count(Case When (MainTable.UnixDateTime % 86400)/3600 = 2 Then MainTable.UnixDateTime End) As [0203], 
     Count(Case When (MainTable.UnixDateTime % 86400)/3600 = 3 Then MainTable.UnixDateTime End) As [0304], 
     Count(Case When (MainTable.UnixDateTime % 86400)/3600 = 4 Then MainTable.UnixDateTime End) As [0405], 
     Count(Case When (MainTable.UnixDateTime % 86400)/3600 = 5 Then MainTable.UnixDateTime End) As [0506], 
     Count(Case When (MainTable.UnixDateTime % 86400)/3600 = 6 Then MainTable.UnixDateTime End) As [0607], 
     Count(Case When (MainTable.UnixDateTime % 86400)/3600 = 7 Then MainTable.UnixDateTime End) As [0708], 
     Count(Case When (MainTable.UnixDateTime % 86400)/3600 = 8 Then MainTable.UnixDateTime End) As [0809], 
     Count(Case When (MainTable.UnixDateTime % 86400)/3600 = 9 Then MainTable.UnixDateTime End) As [0910], 
     Count(Case When (MainTable.UnixDateTime % 86400)/3600 = 10 Then MainTable.UnixDateTime End) As [1011], 
     Count(Case When (MainTable.UnixDateTime % 86400)/3600 = 11 Then MainTable.UnixDateTime End) As [1112], 
     Count(Case When (MainTable.UnixDateTime % 86400)/3600 = 12 Then MainTable.UnixDateTime End) As [1213], 
     Count(Case When (MainTable.UnixDateTime % 86400)/3600 = 13 Then MainTable.UnixDateTime End) As [1314], 
     Count(Case When (MainTable.UnixDateTime % 86400)/3600 = 14 Then MainTable.UnixDateTime End) As [1415], 
     Count(Case When (MainTable.UnixDateTime % 86400)/3600 = 15 Then MainTable.UnixDateTime End) As [1516], 
     Count(Case When (MainTable.UnixDateTime % 86400)/3600 = 16 Then MainTable.UnixDateTime End) As [1617], 
     Count(Case When (MainTable.UnixDateTime % 86400)/3600 = 17 Then MainTable.UnixDateTime End) As [1718], 
     Count(Case When (MainTable.UnixDateTime % 86400)/3600 = 18 Then MainTable.UnixDateTime End) As [1819], 
     Count(Case When (MainTable.UnixDateTime % 86400)/3600 = 19 Then MainTable.UnixDateTime End) As [1920], 
     Count(Case When (MainTable.UnixDateTime % 86400)/3600 = 20 Then MainTable.UnixDateTime End) As [2021], 
     Count(Case When (MainTable.UnixDateTime % 86400)/3600 = 21 Then MainTable.UnixDateTime End) As [2122], 
     Count(Case When (MainTable.UnixDateTime % 86400)/3600 = 22 Then MainTable.UnixDateTime End) As [2223], 
     Count(Case When (MainTable.UnixDateTime % 86400)/3600 = 23 Then MainTable.UnixDateTime End) As [2324] 
FROM MainTable 
INNER JOIN StationName ON MainTable.StationID = StationName.StationID 
WHERE (StationName.ValidStationCode = 32767) --[use only valid stations] 
AND (MainTable.UnixDateTime >= 1264996800) 
AND (MainTable.UnixDateTime < 1267416000) 
AND (MainTable.EquipmentCode IN (33, 36)) --[examine only this equipment] 
Group By StationName 
ORDER BY Station 
관련 문제