QueryEngine

class QueryEngine(store: DocumentStore, indexes: IndexCatalog, schema: InferredSchema? = null)

Answers queries against a store, using the indexes that exist and scanning what they do not cover.

val engine = QueryEngine(store, indexes)
engine.execute(Query.where(path("$.team") eq "analytics")).use { rows ->
while (rows.next()) println(rows.key)
println(rows.stats)
}

An index changes how fast this runs, never what it returns. That is not a hope about the planner; it is a property of how a plan is put together. An index yields candidates over the segments it can answer for at this snapshot, everything else is scanned, and every candidate is rechecked against the version the snapshot sees by the same walk that built the index. A store whose index is half built, or stale for this snapshot, or has unflushed writes, is not a special case: it is a plan with more segments in the scanned half.

The engine holds nothing and owns nothing. It is safe to make one per query or one per store, and to use one from several threads at once — the state of a query lives in its QueryCursor.

Constructors

Link copied to clipboard
constructor(store: DocumentStore, indexes: IndexCatalog, schema: InferredSchema? = null)

Functions

Link copied to clipboard
fun execute(query: Query, snapshot: Snapshot? = null): QueryCursor

Runs query and returns its rows.

Link copied to clipboard
fun explain(query: Query, snapshot: Snapshot? = null): Explain

How query would be answered, and why.

Link copied to clipboard
fun keys(query: Query, snapshot: Snapshot? = null): List<Key>

The keys query matches, materialised. Convenient where the result is known to be small.