2012-02-23 88 views
1

我有7秒鐘內運行的查詢,在本地SQL Server 2008 R2實例上(非快速)生成12,094條記錄。但是,Sql Server Express實例需要38秒。這可能只是本地8GB Hyper-V機器和具有一半內存的遠程GoGrid機器之間的區別。XML查詢問題 - 在一臺服務器上性能不錯,另一臺服務器性能很差

我的問題是我在做什麼明顯效率低下?

查詢:

declare @FromTimestamp datetime = '2012-02-01' 
declare @ToTimestamp datetime = '2012-02-22' 
DECLARE @to datetime = DATEADD(dd, 1, @ToTimestamp) 
SELECT 
    Data.value('(/LendingTreeAffiliateRequest/Request/@AppID)[1]', 'varchar(50)') AS AppID, 
    Data.value('(/LendingTreeAffiliateRequest/Request/@type)[1]', 'varchar(50)') AS [Type], 
    [Timestamp], 
    Data.value('(/LendingTreeAffiliateRequest/@affid)[1]', 'varchar(50)') AS CDNumber, 
    Data.value('(/LendingTreeAffiliateRequest/Request/SourceOfRequest/VisitorIPAddress)[1]', 'varchar(50)') AS IP, 
    Data.value('(/LendingTreeAffiliateRequest/Request/SourceOfRequest/LendingTreeAffiliateEsourceID)[1]', 'varchar(50)') AS ESourceID, 
    Data.value('(/LendingTreeAffiliateRequest/Request/Applicant/State)[1]', 'char(2)') AS [State], 
    Data.value('(/LendingTreeAffiliateRequest/Request/Applicant/DateOfBirth)[1]', 'varchar(20)') AS DateOfBirth, 
    Data.value('(/LendingTreeAffiliateRequest/Request/Applicant/EmailAddress)[1]', 'varchar(255)') AS Email, 
    Data.value('(/LendingTreeAffiliateRequest/Request/Applicant/IsVeteran)[1]', 'char(1)') AS IsVeteran, 
    Data.value('(/LendingTreeAffiliateRequest/Request/Applicant/CreditHistory/CreditSelfRating)[1]', 'varchar(50)') AS Credit 
FROM 
    WebLogEntry wle 
    INNER JOIN EventType et on wle.EventTypeId=et.Id 
    INNER JOIN [EventData] ed on wle.EventDataId=ed.Id 
WHERE 
    (et.Id=2) 
     AND (Data.exist('/LendingTreeAffiliateRequest/Request/@AppID')=1) 
     AND ([Timestamp] BETWEEN @FromTimestamp AND @to) 
+0

你比較了執行計劃嗎? – 2012-02-23 23:41:34

+0

感謝您的建議。它看起來像是所有的XML ..沒有什麼,但其他地方0%​​。我也注意到sql server express機器沒有超過25%cpu ... – 2012-02-23 23:51:10

回答

1

我看不出有什麼明顯的錯誤以外的事實,SQL服務器將不得不翻騰對非常多的XQuery的。您可能希望嘗試完整返回數據字段,然後在代碼中解析它,以查看特定實現的速度是否更快。測量這兩種方法的時間,並採取更快的方法。

如果你有一個可預測的數據結構,你最好將它存儲在一個表中而不是XML blob中,因爲這會顯着加快速度。

+0

你似乎是正確的,雖然我不是閱讀這些執行計劃的專家。我覺得我應該能夠做一些事實,這些記錄很少編輯..如果我基於我的查詢在一個由觸發器填充的表上也許,所以xquery只發生過一次。我對我的服務器邏輯的簡單性感到非常興奮,只是插入一個XML blob :) – 2012-02-23 23:54:23

+0

@Gabriel如果你有一個可預測的數據結構,你最好將它存儲在一個表中,而不是XML blob,因爲這會加快速度顯著。 – 2012-02-24 00:07:06

+0

我似乎正在學習這種困難的方式,謝謝。 – 2012-02-24 00:08:19

相關問題