[MarkLogic Dev General] How to get accurate fragment counts using xdmp:estimate when the QName is a variable
mary.holstege at marklogic.com
Wed Sep 15 08:39:47 PDT 2010
On Wed, 15 Sep 2010 08:02:54 -0700, McBeath, Darin W (ELS-STL)
<D.McBeath at elsevier.com> wrote:
> Thanks Mary. That was pretty dumb on my part. But, I still do have a
> question based on my more complex example.
> Basically, I want to get fragment counts where a fragment contains a
> given element, attribute, and value for that attribute. I was thinking
> that I could do XPath such as below wrapped in a xdmp:estimate.
> xdmp:estimate(//*[node-name(.)=$eQName and string(./@*[node-name(.) =
> $aQName]) = $value])
> But, this always seems to return me the number of fragments in the DB.
> I did verify that
> //*[node-name(.)=$eQName and string(./@*[node-name(.) = $aQName]) =
> Only returns the nodes which I want ... so, unlike last time it would
> appear the query is at least written correctly. Perhaps, what I'm
> trying to do with XPath and an accurate estimate is not currently
> possible. I believe that I have the necessary indexes enabled that
> should support an accurate estmate.
I don't think you'll be able to get there with an XPath: I don't think
the optimizer is smart enough to fold the attribute in with the
element when it is indirected in this way, and the indices only
index attributes in the context of specific elements. The string()
wrapping will also throw off the optimizer, but unless you have
a type-mismatch issue, you probably don't need it anyhow -- atomization
will take care of it. So, yeah, element-attribute-value-query is
the way to go.
More information about the General