[英]exist-db update insert very slow
我是exists-db的初學者。 我正在通過Java構建一個xml文檔。 我通過JAXB處理數據,然后通過插入更新插入到exists-db資源。 我目前正在測試大約500個節點,並且在執行了幾十個節點后,每個插件開始需要10秒鍾。 我的XML具有以下一般結構。
<realestatedata>
<agents>
<author id="1">
<name>Author_A</name>
</author>
<author id="2">
<name>Author_B</name>
</author>
<portal id="1">
<name>Portal_A</name>
</portal>
</agents>
<artifacts>
<document id="1">
<latitude>51.37392</latitude>
<longitude>-0.00866</longitude>
<bathroom_number>1</bathroom_number>
<bedroom_number>3</bedroom_number>
<price>365000</price>
</document>
<theme id="1">
<name>Garden</name>
</theme>
<place id="1">
<name>BR4</name>
<location>
<lat>51.37392</lat>
<lon>-0.00866</lon>
</location>
</place>
</artifacts>
</realestatedata>
為了確保元素按正確順序放置,我使用以下代碼進行插入更新,因此其類型的新記錄要么是第一個,要么基於ids附加在類似元素的末尾。
public void saveAuthor(Author author) {
XQueryService xQueryService = null;
CompiledExpression compiled = null;
int currentId = authorIdSequence.get();
StringWriter authorXml = new StringWriter();
try {
xQueryService = Utils.getXQeuryService();
if (getAuthorByName(author.getName()) == null) {
author.setId(String.valueOf(authorIdSequence.incrementAndGet()));
marshaller.marshal(author, authorXml);
if(currentId == 0){
compiled = xQueryService
.compile("update insert " + authorXml.toString()
+ " into //agents");
}
else{
compiled = xQueryService
.compile("update insert " + authorXml.toString()
+ " following //author[@id = '"+String.valueOf(currentId)+"']");
}
xQueryService.execute(compiled);
}
} catch (XMLDBException e) {
e.printStackTrace();
} catch (JAXBException e) {
e.printStackTrace();
}
}
對文檔,地點等其他元素執行相同的方法。經過一些更新后,它變得非常慢。 插入一條記錄開始需要十秒鍾。
只有我能找到的相關鏈接沒有回復。
一些想法:
[@id=…]
)可能會非常慢。 考慮到你發布的代碼將要求eXist檢查每個先前插入的作者的@id
,然后找到插入新的代碼的正確位置。 我可以想辦法解決這個問題:
@id
的范圍索引會大大加快速度。 @xml:id
代替@id
可以讓你使用id(…)
,它會更快。 這需要將您的ID更改為唯一(例如“author_1”和“portal_1”) @id
值,新節點總是會有最大的@id
。 在這種情況下, following //author[last()]
或甚into //agents
將工作得很好。 XQueryService
在完成后正確發布。 Utils.getXQueryService()
可能保留引用它不應該? XQueryService
嗎? 如果getAuthorByName()
正在查詢eXist,它是否可以與更新查詢結合使用? 您是否可以通過變量綁定提供節點而不是查詢中的文字插入,以便每次都可以重用相同的編譯查詢? 盡管如此,如果你只有500個節點,10s對於單個插入來說是非常長的時間。 在我的機器上使用未編制索引的“跟隨”語法在單個查詢中運行批量更新的快速測試可以在整個500個時間內完成整個500。 在您的問題中,很可能出現更大的錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.