Hello community,
I stumbled over a use case where the total result count of a query is wrong.
Here or set of test data
declareUpdate();
for (i = 0; i < 10; i++) {
xdmp.documentInsert(
"/a" + i + ".json",
{
"project": {
"stages": [{"stageId": 9999, "status": "CURRENT"},
{"stageId": 9999, "status": "CLOSED"}]
}
}
);
xdmp.documentInsert(
"/b" + i + ".json",
{
"project": {
"stages": [{"stageId": 9998, "status": "CURRENT"},
{"stageId": 9999, "status": "CLOSED"}]
}
}
);
};
fn.count(
cts.search(
cts.jsonPropertyScopeQuery("stages",
cts.andQuery(
(cts.jsonPropertyValueQuery("status", "CURRENT"),
cts.jsonPropertyValueQuery("stageId", 9999))
)
)
, 'filtered')
);
Returns 20 but in xquery
fn:count(
cts:search(/,
cts:json-property-scope-query("stages",
cts:and-query(
(cts:json-property-value-query("status", "CURRENT"),
cts:json-property-value-query("stageId", 9999))
)
)
)
)
correctly returns 10
I guess cts.search uses the search:* module behind the scenes because
search:resolve gives me the same result doing an equivalent query. So it seems
the problem is result estimation ... I know search:resolve uses xdmp:estimate
and xdmp:remainder and replacing fn:count with xdmp:estimate
xdmp:estimate(
cts:search(/,
cts:json-property-scope-query("stages",
cts:and-query(
(cts:json-property-value-query("status", "CURRENT"),
cts:json-property-value-query("stageId", 9999))
)
)
)
)
also gives me the 20.
In our use case the data set is rather small so the wrong estimates are very
noticeable and not acceptable.
So my questions: is there a way to get the right count?
* By tuning some indexes
* Using additional query-options
* Changing our query or even data model if there is no other way
Any hint is welcome
holger apel
software manager | information technology and electronic services | iso central
secretariat<http://www.iso.org/iso/contact_iso>
_______________________________________________
General mailing list
[email protected]
Manage your subscription at:
http://developer.marklogic.com/mailman/listinfo/general