Marklogic date comparison in XQuery with or without index

M_breeb

I need to filter documents by date (last week, last month, etc.) with Marklogic 8. The database contains 1.3 million XML documents.

The documents look like this:

<work datum_gegenereerd="2015-06-10" gegenereerd="2015-06-10T14:28:48" label="gmb-2015-12000">
 ...

I've created a range element attribute index on work/@datum_gegenereerd (scalar type date).

The following query works but is slow (3 seconds):

xquery version "1.0-ml";
for $a in //work
where xs:date($a/@datum_gegenereerd) > current-date()-   5*xs:dayTimeDuration('P1D')
return
<hit>{base-uri($a)}</hit>

After a lot of experimenting, it turns out that I can get the performance down to 0.02 seconds by removing the xs:date cast from the where statement.

xquery version "1.0-ml";
for $a in //work
where $a/@datum_gegenereerd > current-date()-   5*xs:dayTimeDuration('P1D')
return
<hit>{base-uri($a)}</hit>

Can anyone explain this behaviour?


Update:
when I delete the attribute range index, the performance for the second variant goes down to 3+ seconds as well. And recreating the index brings the performance back up. This makes me wonder how to read David's statement below that there is no way to use a custom index from plain xquery. (BTW: the query returns 1267 XML documents, out of a possible 450000 documents with root element work in a total database of 1.35 million documents)
Update 2:
I messed up with the performance metric of 0.02 seconds. But it is very fast in the query console. Of the 3 versions, the cts-search seems a tiny bit faster.

David Ennis

You may have created an index, but you are not using it. You need to use an element-attribute-range-query to find all of the fragments that have dates in the range in question.

something like

cts:search(doc(), cts:element-attribute-range-query(xs:QName("work"), xs:QName("datum_gegenereerd"), ">" current-date()-   5*xs:dayTimeDuration('P1D'))

BUT: if you really just want the URIS, then the element-range-query would be used with cts:uris (sometihng like this - but check the docs)

cts:uris('', (), cts:element-attribute-range-query(xs:QName("work"), xs:QName("datum_gegenereerd"), ">" current-date()-   5*xs:dayTimeDuration('P1D'))

The second one does everything in memory and just pulls the URIs from the URI lexicon that point to document fragments where the date query matches.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I get an XQuery map of MarkLogic document URIs to lexicon (range index) values in the document?

From Dev

PHP/MySQL Date and Time comparison (without seconds)

From Dev

Implementing natural sort in XQuery on MarkLogic

From Dev

Regular Expressions in MarkLogic's xQuery

From Dev

Updating JSON in XQuery and Marklogic 8

From Dev

XQuery Comparison Expressions in SQL Column

From Java

XQuery to get a multi-valued field in MarkLogic

From Dev

declareUpdate in JavaScript calling XQuery in MarkLogic 8

From Dev

Updating embedded triples using xquery in MarkLogic

From Dev

MarkLogic: XQuery to Get Values from XML Documents?

From Dev

Updating embedded triples using xquery in MarkLogic

From Dev

Creating a filter view in Jspresso containing a date picker without comparison operators

From Dev

Creating a filter view in Jspresso containing a date picker without comparison operators

From Dev

Marklogic 6 Index creation?

From Dev

Marklogic index trouble

From Dev

Marklogic index trouble

From Dev

XQuery expression to reutrn items based on comparison on their attributes

From Dev

Date format in Marklogic for JSON Documents

From Dev

Date format in Marklogic for JSON Documents

From Dev

MarkLogic: Converting an XML document into an XML string using XQuery

From Dev

xquery api to upload data from marklogic to amazon s3

From Dev

XQuery sequence equivalent in MarkLogic Server-Side JavaScript

From Dev

How do I programmatically create JSON in XQuery in MarkLogic?

From Dev

Calling xquery libraries with dependencies from rest endpoints in MarkLogic 8

From Dev

Creating a global map variable in xquery library module in Marklogic

From Dev

MarkLogic 8 - XQuery - cts query to find document property by value

From Dev

Is there a way to get all database names in MarkLogic server in XQuery?

From Dev

MarkLogic: XQuery to Get Distinct Names from XML Document?

From Dev

MarkLogic: Converting an XML document into an XML string using XQuery

Related Related

  1. 1

    How can I get an XQuery map of MarkLogic document URIs to lexicon (range index) values in the document?

  2. 2

    PHP/MySQL Date and Time comparison (without seconds)

  3. 3

    Implementing natural sort in XQuery on MarkLogic

  4. 4

    Regular Expressions in MarkLogic's xQuery

  5. 5

    Updating JSON in XQuery and Marklogic 8

  6. 6

    XQuery Comparison Expressions in SQL Column

  7. 7

    XQuery to get a multi-valued field in MarkLogic

  8. 8

    declareUpdate in JavaScript calling XQuery in MarkLogic 8

  9. 9

    Updating embedded triples using xquery in MarkLogic

  10. 10

    MarkLogic: XQuery to Get Values from XML Documents?

  11. 11

    Updating embedded triples using xquery in MarkLogic

  12. 12

    Creating a filter view in Jspresso containing a date picker without comparison operators

  13. 13

    Creating a filter view in Jspresso containing a date picker without comparison operators

  14. 14

    Marklogic 6 Index creation?

  15. 15

    Marklogic index trouble

  16. 16

    Marklogic index trouble

  17. 17

    XQuery expression to reutrn items based on comparison on their attributes

  18. 18

    Date format in Marklogic for JSON Documents

  19. 19

    Date format in Marklogic for JSON Documents

  20. 20

    MarkLogic: Converting an XML document into an XML string using XQuery

  21. 21

    xquery api to upload data from marklogic to amazon s3

  22. 22

    XQuery sequence equivalent in MarkLogic Server-Side JavaScript

  23. 23

    How do I programmatically create JSON in XQuery in MarkLogic?

  24. 24

    Calling xquery libraries with dependencies from rest endpoints in MarkLogic 8

  25. 25

    Creating a global map variable in xquery library module in Marklogic

  26. 26

    MarkLogic 8 - XQuery - cts query to find document property by value

  27. 27

    Is there a way to get all database names in MarkLogic server in XQuery?

  28. 28

    MarkLogic: XQuery to Get Distinct Names from XML Document?

  29. 29

    MarkLogic: Converting an XML document into an XML string using XQuery

HotTag

Archive