15.07.2016 Views

MARKLOGIC SERVER

Inside-MarkLogic-Server

Inside-MarkLogic-Server

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Performance of range index operations depends mostly on the size of the result<br />

set—how many items have to be looked up. Performance varies a bit by data type, but<br />

you can get roughly 10 million lookups per second per core. Integers are faster than<br />

floats, which are faster than strings, which are faster when using the simplistic Unicode<br />

Codepoint collation than when using a more advanced collation.<br />

For more information on optimized order by expressions and the exact rules for<br />

applying them, see the Query Performance and Tuning Guide.<br />

USING RANGE INDEXES FOR JOINS<br />

Range indexes turn out to be useful for cross-document joins. Here's the technique:<br />

You get a set of IDs matching the first query, then feed that set into a second query as<br />

a constraint. The ability to use range indexes on both ends makes the work relatively<br />

efficient. (You can perform cross-document joins even more efficiently with RDF triples.<br />

See the "Semantics" section for details.)<br />

Understanding this technique requires a code example. Imagine that you have a set of<br />

tweets, and each tweet has a date, author ID, text, etc. And you have a set of data about<br />

authors, with things like their author ID, when they signed up, their real name, etc. You<br />

want to find authors who've been on Twitter for at least a year and who have mentioned<br />

a specific phrase, and return the tweets with that phrase. That requires joining between<br />

author data and the tweet data.<br />

Here's example XQuery code:<br />

let $author-ids := cts:element-values(<br />

xs:QName("author-id"), "", (),<br />

cts:and-query((<br />

cts:collection-query("authors"),<br />

cts:element-range-query(<br />

xs:QName("signup-date"), "

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!