Oracle xpath 的性能:两个选择场景
我正在使用 oracle 11g 并且有一个带有 XMLType 的表。该表中有很多记录,每个 XML 包含 0 到 n 个答案的列表,如下所示:
<section>
<answer id="100">
<value>Something</value>
</answer>
...
</section>
有两种方法对值进行 xpath。
示例 1:
extract(table.column, '//answer[@id=100]').getStringVal()
返回
<answer id="100">
<value>Something</value>
</answer>
示例 2:
extractvalue(table.column, '//answer[@id=100]/value/text()')
返回
Something
为复杂查询提取许多 text() 值时性能会受到影响,这让我提出以下问题。如果我使用像 xstream 这样的库来解析 java 中的这些值(示例 1),我会获得更好的性能吗?还是让 Oracle 为我解析这些值更好(示例 2)?
在我投入时间重写大量 daos 和查询之前,我正在尝试从其他人的经验或者可能是一些白皮书中学习,所以非常感谢,谢谢!
================== 编辑
开始研究使用 Scala 作为在 JVM 中解析 xml 的替代方案。请随意添加 Scala 示例。
I am using oracle 11g and have a table with an XMLType. There are many records in this table and each XML contains a list of 0 to n answers as follows:
<section>
<answer id="100">
<value>Something</value>
</answer>
...
</section>
There are two ways to xpath for values.
Example 1:
extract(table.column, '//answer[@id=100]').getStringVal()
which returns
<answer id="100">
<value>Something</value>
</answer>
Example 2:
extractvalue(table.column, '//answer[@id=100]/value/text()')
which returns
Something
There is a hit in performance extracting many text() values for a complex query, which has me asking the following question. Would I gain better performance if I utilized a library like xstream to parse out those values in java (example 1), or is it better to let oracle parse those values for me (example 2)?
I am trying to learn from other people's experiences or maybe some whitepapers before I commit time to rewrite a lot of daos and queries, so anything is much appreciated, thanks!
================== EDIT
Started looking into using Scala as an alternative to parsing xml in the JVM. Feel free to add Scala examples to the mix.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想示例 2 应该更快。
如果您需要更快的速度,我建议对此表进行规范化并摆脱 XML 或使用物化视图。
I suppose Example 2 should be faster.
If you need more more speed, I recommend to do normalization for this table and get rid from XML or use materialized view.
我终于开始进行测试,这就是我的发现。
对于使用表的简单“报告”jsp 视图,我运行了一个查询来填充 850 行。
根据我的代码库,我首先按如下方式运行查询:
这总共花费了:
然后我更改了查询以执行以下操作:
这总共花费了:
这当然是我的代码库,但我认为我可以排除使用 XStream 作为提高效率的手段。但似乎 XMLType 和 xpathing 一开始就不是很有效。
I finally got around to testing and here is what I found.
For a simple "reporting" jsp view using a table, I ran a query to populate 850 rows.
Given my codebase, I ran the query first as follows:
This took a total of:
I then altered the query to do following:
This took a total of:
This is of course my codebase, but I think I can rule out the use of XStream as a mean of efficiency. But it seems that the XMLType and xpathing is not very efficient in the first place.