我有一個歷史表,它具有主表的事務記錄信息,在此表中我使用了XML列來存儲該事務信息。包含數據的表結構看起來像。使用Xquery從XMLAttribute獲取數據時的性能問題
在內容的XML數據被存儲爲象下面的XML。
<Answers>
<AnswerSet>
<Answer questionId="ProductCode">S3404</Answer>
<Answer questionId="ProductName">Parabolic Triple</Answer>
<Answer questionId="LegacyOptionID" selectedvalue="1389">1389</Answer>
<Answer questionId="LegacyContentID" selectedvalue="624">624</Answer>
<Answer questionId="LegacyPageID" selectedvalue="355">355</Answer>
<Answer questionId="LegacyParentID" selectedvalue="760">760</Answer>
</AnswerSet>
</Answers>
在所有行結構是相同的,但數據是在回答節點不同,我想其中有產品代碼=「S3404」和CreatedDate是新的數據。像
select n2.* from nodehistory n2 CROSS APPLY n2.content.nodes('Answers/AnswerSet') T(c) WHERE c.value('./Answer[@questionId="ProductCode"][1]','varchar(100)') ='J154'
產品代碼
我已創建的查詢必須爲每一個NODEID獨特的數據,但這是同樣的NODEID返回多行,因爲這是交易表,以便同XML可以存儲多個時間,爲這需要像Created by desc命令那樣的條件,但由於我認爲XML處理,執行此查詢需要更多的時間。
我們可以這樣做嗎?首先通過CreatedDate desc從NodeHistory順序獲取Select Top 1 nodeid,然後搜索XML部分。
請建議你獲得更好的性能