How to write fast queries (by leveraging indexes)

by Evan Lenz

In my last article on how indexing makes XPath fast, I described the general role that MarkLogic's Universal Index plays. I also promised to show you how to write searchable (and thus fast) expressions. That's what this post is about.

For the Developer Lounge at MLUC '11, I created a tutorial on "Query Tuning Basics" which walks you through a series of simple XQuery examples (27, to be precise) that you can enter into CQ, using XML data from

In this tutorial, you'll learn about these closely related tools:

  • xdmp:query-meters()
  • xdmp:estimate()
  • xdmp:plan()
  • xdmp:query-trace()

Most importantly, you'll see how these tools make it easy for you to ensure that the expressions you write are evaluated by MarkLogic Server in a way that fully leverages its indexes. In other words, you'll learn how to write scalable, blazing fast queries. Just remember: with great power comes great responsibility.

Are you ready to get started? Then download the PDF tutorial and come back here to post any questions you might have (as a comment on this post).