The Query Service supports the querying of data by means of the N1QL query language. The Query Service depends on both the Index Service and the Data Service.
Query Service Architecture
The architecture of the Query Service is shown by the following illustration:
The principal components are:
Listeners: Concurrent query requests are received on ports 8093 and 18093 (for more information on port-allocation, see Network and Firewall Requirements).
Query Processor: Responsible for applying the Parser to incoming queries, in order to determine whether each is a valid statement. Also employs the Optimizer, which evaluates available execution paths, so determining the path of lowest latency; generates a query-execution plan that uses the lowest-latency path; and assembles the plan into a series of operators. The Execution Engine receives the operators, and executes them — in parallel where possible.
Data Stores: Provides access to various data-sources. The Couchbase Server store is used to access the data and indexes on Couchbase Server, and to handle authentication. Other data stores are also included, such as the store for the local filesystem.
The sequence whereby queries are executed is shown below:
The client’s N1QL 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.
The Query Service supports queries made in the N1QL query language. As well as providing a rich variety of query-options, N1QL allows statements to be prepared, so that the parsing and compiling of plans is completed prior to execution; and permits consistency-levels to be configured. For detailed information, see N1QL Language Reference.