BaseX:慢速 XQuery [英] BaseX: Slow XQuery
问题描述
我有一个包含大约 20 个 XML 文件的 BaseX XML 数据库.这些文件的大小和结构各不相同.最大的文件有 524 MB.它由一个带有 267685 个 ART 子标签的父 ARTICLE 标签组成.
I've got a BaseX XML database with ~20 XML files. These files are different in size and structure. The biggest file has got 524 MB. It consists of a parent ARTICLE tag with 267685 ART subtags.
这是我的 XQuery:/ARTICLE/ART[PRDNO=12345]"(非常简单;为清楚起见省略了正确的名称空间).PRDNO 是 PRODUCT/PRD XML 结构的外键,每篇文章有多个(平均约 10 个)产品.
This is my XQuery: "/ARTICLE/ART[PRDNO=12345]" (pretty straightforward; proper namespaces omitted for clarity). PRDNO is a foreign key to the PRODUCT/PRD XML structure, there are multiple (in average ~10) products per article.
一切正常,但是这个查询很慢 - 执行大约需要 1 秒.对数据库中其他对象(数据量较小)的类似查询要快得多.
Everything works as it is supposed to, but this query is quite slow - it takes approximately 1s to execute. Similar queries for other objects in the database (where the data amount is smaller) are much faster.
我可以做些什么来优化此查询?
What can I do to optimize this query?
我运行了优化"(花了几分钟),我确保 TEXT 索引到位.
I ran "optimize" (which took some minutes), I ensured the TEXT index is in place.
这是信息数据库"的输出:
This is the output of "info database":
> info database
Database Properties
Name: hospindex
Size: 1740 MB
Nodes: 69360063
Documents: 22
Binaries: 0
Timestamp: 2014-09-03-09-34-07
Resource Properties
Timestamp: 2014-09-03-09-21-14
Encoding: UTF-8
CHOP: true
Indexes
Up-to-date: true
TEXTINDEX: true
ATTRINDEX: true
FTINDEX: false
LANGUAGE: English
STEMMING: false
CASESENS: false
DIACRITICS: false
STOPWORDS:
UPDINDEX: false
MAXCATS: 100
MAXLEN: 96
EDIT:这是查询执行计划:
Compiling:
- adding text() step
Query:
/*:ARTICLE/*:ART[*:PRDNO=1005935]
Optimized Query:
(db:open-pre("hospindex",0), db:open-pre("hospindex",32884731), ...)/*:ARTICLE/*:ART[(*:PRDNO/text() = 1005935)]
Result:
- Hit(s): 1 Item
- Updated: 0 Items
- Printed: 2078 Bytes
- Read Locking: local [hospindex]
- Write Locking: none
Timing:
- Parsing: 1.12 ms
- Compiling: 0.46 ms
- Evaluating: 1684.35 ms
- Printing: 0.35 ms
- Total Time: 1686.3 ms
Query plan:
<QueryPlan>
<IterPath>
<DBNodeSeq size="22">
<DBNode name="hospindex" pre="0"/>
<DBNode name="hospindex" pre="32884731"/>
<DBNode name="hospindex" pre="33685448"/>
<DBNode name="hospindex" pre="38260847"/>
<DBNode name="hospindex" pre="38358876"/>
</DBNodeSeq>
<IterStep axis="child" test="*:ARTICLE"/>
<IterStep axis="child" test="*:ART">
<CmpG op="=">
<CachedPath>
<IterStep axis="child" test="*:PRDNO"/>
<IterStep axis="child" test="text()"/>
</CachedPath>
<Int value="1005935" type="xs:integer"/>
</CmpG>
</IterStep>
</IterPath>
</QueryPlan>
推荐答案
在搜索值周围使用引号时,您的查询的评估速度会快得多:
Your query will be evaluated much faster when using quotes around your search value:
/ARTICLE/ART[PRDNO = "12345"]
原因是当前版本的 BaseX 没有提供数值索引(可能包含在 BaseX 8.0 中).
The reason is that the current version of BaseX does not provide a numeric value index (it may be included in BaseX 8.0).
通过打开 QUERYINFO 选项,您可以更深入地了解查询编译步骤.
You get more insight into the query compilation steps by turning on the QUERYINFO option.
这篇关于BaseX:慢速 XQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!