Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ The Query Service depends on both the _Index Service_ and the _Data Service_.
The architecture of the _Query Service_ is shown by the following illustration:

[#query_service_architecture]
image::services-and-indexes/services/queryServiceArchitecture.png[,700,align=left]
.Query Service Architecture
image::services-and-indexes/services/queryServiceArchitecture.png[,700,align=centre]

The principal components are:

Expand All @@ -26,17 +27,27 @@ Other data stores are also included, such as the store for the local filesystem.

== Query Execution

The sequence whereby queries are executed is shown below:
The following diagram shows the sequence of operations during query execution.

[#query_sequence]
image::services-and-indexes/services/querySequence.png[,820,align=left]

The client's {sqlpp} query is shown entering the Query Service at the left-hand side.
The Query Processor performs its *Parse* routine, to validate the submitted statement, then creates the execution *Plan*.
*Scan* operations are then performed on the relevant index, by accessing the *Index Service* or the *Search Service*.
Next, *Fetch* operations are performed by accessing the *Data Service*, and the data duly returned is used in *Join* operations.
The Query Service continues by performing additional processing, which includes *Filter*, *Aggregate*, and *Sort* operations.
Note the degree of parallelism with which operations are frequently performed, represented by the vertically aligned groups of right-pointing arrows.
.Query Execution Sequence
[plantuml,query-execution,svg]
....
include::indexes:partial$diagrams/query-service.puml[]
....

When the Query Service receives the client's {sqlpp} query, it immediately passes it to the Query Processor.
The Query Processor first parses the query to validate the statement and then creates an execution plan for the request.

The Execution Engine then begins executing the plan.
It performs Scan operations on the relevant index, using either the Index Service or the Search Service.
Next, it performs Fetch operations to get the actual data from the Data Service, and then uses this data for Join operations.

The Query Service processes the data further by applying Filter, Aggregate, Project, and Sort operations.
These operations often run in parallel, as represented by the vertically aligned groups of right-pointing arrows.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parallelism is represented by the little boxes within each operation

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't merge this until someone from Query has reviewed the diagram at

Finally, it executes Offset and Limit operations to set the result size and starting point, and then streams the results back to the client.

For more information about each of these operations, see xref:n1ql:n1ql-language-reference/selectintro.adoc#query-execution-phases[Query Phases].

== Using {sqlpp}

Expand Down
3 changes: 3 additions & 0 deletions preview/DOC-12349-query-execution-diagram.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sources:
docs-devex:
branches: [DOC-12349-query-execution-diagram]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete this before merging!