Skip to content

Commit 70f445c

Browse files
Indexes and sans-index
DOC-13529 DOC-13598
1 parent f1483bb commit 70f445c

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

modules/concept-docs/pages/n1ql-query.adoc

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
= Query
2+
:page-toclevels: 2
23
:description: Parallel data management for complex queries over many records, using a familiar SQL-like syntax.
34
:page-aliases: ROOT:n1ql-query.adoc,ROOT:prepared-statements.adoc,ROOT:querying.adoc
45

5-
include::project-docs:partial$attributes.adoc[]
66

77
[abstract]
88
{description}
@@ -23,13 +23,26 @@ include::devguide:example$java/N1qlQueryExample.java[tag=n1ql_query_1,indent=0]
2323

2424
== Indexes
2525

26-
The Couchbase Query Service makes use of xref:7.1@server:learn:services-and-indexes/indexes/indexes.adoc[_indexes_] in order to do its work.
26+
The Couchbase Query Service makes use of xref:{version-server}@server:learn:services-and-indexes/indexes/indexes.adoc[_indexes_] in order to do its work.
2727
Indexes replicate subsets of documents from data nodes over to index nodes,
2828
allowing specific data (for example, specific document properties) to be retrieved quickly,
29-
and to distribute load away from data nodes in xref:7.1@server:learn:services-and-indexes/services/services.adoc[MDS] topologies.
29+
and to distribute load away from data nodes in xref:{version-server}@server:learn:services-and-indexes/services/services.adoc[MDS] topologies.
3030

31-
[IMPORTANT]
32-
In order to make a bucket queryable, it must have at least one index defined.
31+
=== Query without Index
32+
33+
From Couchbase Server 7.6 onwards,
34+
CRUD operations (such as `CREATE`, `INSERT`, and `SELECT`) and `JOIN` can be performed against the Query Service without an index (primary or secondary).
35+
This uses a xref:server:learn:services-and-indexes/indexes/query-without-index.adoc#sequential-scans[sequential scan], relying on a KV range scan to deliver the keys.
36+
37+
Sequential scans are best suited to small collections where key order is unimportant, or where the overhead of maintaining an index can't be justified.
38+
For larger collections and greater performance, define the appropriate indexes to speed up your queries.
39+
For ordered document key operations, a primary index provides the same functionality, and will outperform a sequential scan.
40+
41+
Creating the right index, with the right keys, right order, and right expression is critical to query performance in any database system.
42+
A Primary Index on the document keys will give you better search performance than trying to query without index,
43+
but well-chosen secondary indexes will make all the difference to query performance.
44+
45+
=== Defining an Index
3346

3447
You can define a _primary index_ on a bucket.
3548
When a _primary_ index is defined you can issue non-covered (see below) queries on the bucket as well.
@@ -59,7 +72,7 @@ Indexes help improve the performance of a query.
5972
When an index includes the actual values of all the fields specified in the query,
6073
the index _covers_ the query, and eliminates the need to fetch the actual values from the Data Service.
6174
An index, in this case, is called a _covering index_, and the query is called a _covered_ query.
62-
For more information, see xref:7.1@server:n1ql:n1ql-language-reference/covering-indexes.adoc[Covering Indexes].
75+
For more information, see xref:{version-server}@server:n1ql:n1ql-language-reference/covering-indexes.adoc[Covering Indexes].
6376

6477
You can also create and define indexes in the SDK using:
6578

@@ -125,7 +138,7 @@ and allows optimization on a case-by-case basis.
125138

126139
== Collections and Scopes, and the Query Context
127140

128-
From Couchbase Server release 7.0 the xref:7.1@server:learn:data/scopes-and-collections.adoc[Collections] feature lets you logically group similar documents into Collections.
141+
From Couchbase Server release 7.0 the xref:{version-server}@server:learn:data/scopes-and-collections.adoc[Collections] feature lets you logically group similar documents into Collections.
129142

130143
You can query collections in {sqlpp}, by referring to a fully qualified keyspace.
131144
For example, to list the documents in the `airline` collection in the `inventory` scope:
@@ -135,7 +148,7 @@ For example, to list the documents in the `airline` collection in the `inventory
135148
SELECT * FROM `travel-sample`.inventory.airline;
136149
----
137150

138-
As a convenience, you can also query a partial keyspace from the xref:7.1@server:n1ql:n1ql-intro:sysinfo.adoc#query-context[Query Context] of a specific Scope.
151+
As a convenience, you can also query a partial keyspace from the xref:{version-server}@server:n1ql:n1ql-intro:sysinfo.adoc#query-context[Query Context] of a specific Scope.
139152
For example, from the context of `{backtick}travel-sample{backtick}.inventory`, you could abbreviate the previous query to:
140153

141154
[source,sqlpp]

0 commit comments

Comments
 (0)