我确实期望doc()函数即使在较大的数据库中也应该具有非常低的成本,但事实证明它没有。
或者我一直在做错误的查询? ia:if-doc-available()
正在进行doc()
调用,因为内置的doc-available()
正在投放' ..不会产生任何文档错误。'
import module namespace ia = 'http://my.tld/ia';
let $__result__ := (let $locTpl := <Item><Location><Province /><PostalCode /></Location></Item>
let $items := (for $item in collection('item_MyCar')/node()
let $location := ia:if-doc-available(concat('rootnamespace/item_Location/', $item/Location/@Id), $locTpl)/node()
where not($item/@IsDeleted='True')
order by $item/Updated/text() descending
return <Item>{$item}{$location}</Item>)[position() = 1 to 6]
return <Results>{$items}</Results>)
return <Result Count="{count($__result__/node())}">{$__result__}</Result>
这样我当然会变得更好,但对于只有doc()加入的路径来说仍然很慢:
import module namespace ia = 'http://my.tld/ia';
let $__result__ := (let $locTpl := <Item><Location><Province /><PostalCode /></Location></Item>
let $items := (for $item in collection('item_MyCar')/node()
where not($item/@IsDeleted='True')
order by $item/Updated/text() descending
return <Item>{$item}{ia:if-doc-available(concat('rootnamespace/item_Location/', $item/Location/@Id), $locTpl)/node()}</Item>)[position() = 1 to 6]
return <Results>{$items}</Results>)
return <Result Count="{count($__result__/node())}">{$__result__}</Result>
自定义ia:if-doc-available()函数:
declare function ia:if-doc-available
( $arg as xs:string?,
$value as item()* ) as item()* {
try {
doc($arg)
} catch * {
$value
}
};