Skip to content

Commit ba8ec91

Browse files
committed
Add Vector Index syntax (WIP)
1 parent 904f50b commit ba8ec91

File tree

3 files changed

+141
-43
lines changed

3 files changed

+141
-43
lines changed

modules/n1ql/pages/n1ql-language-reference/alterindex.adoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ image::n1ql-language-reference/alter-index.png["Syntax diagram: refer to source
6262
The ALTER INDEX statement provides two possible syntaxes for specifying the index and the keyspace where the index is located.
6363

6464
// TODO: Automatic links in EBNF.
65+
// FIXME: Maybe try to make consistent with DROP INDEX
6566

6667
[horizontal]
6768
index-name:: (Required) A unique name that identifies the index.
@@ -78,6 +79,13 @@ Refer to <<index-using>> below.
7879
index-with:: (Required) Specifies options for the index.
7980
Refer to <<index-with>> below.
8081

82+
[[vector]]
83+
=== VECTOR Keyword
84+
85+
FIXME: The optional VECTOR keyword indicates that you are altering a vector index.
86+
The VECTOR keyword is purely a visual mnemonic.
87+
There is no syntactic requirement to include the VECTOR keyword when altering a vector index.
88+
8189
[[index-path]]
8290
=== Index Path
8391

modules/n1ql/pages/n1ql-language-reference/createindex.adoc

Lines changed: 66 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
:page-topic-type: reference
33
:imagesdir: ../../assets/images
44
:keywords: secondary, index, placement
5-
:description: The CREATE INDEX statement allows you to create a secondary index. \
5+
:description: FIXME: The CREATE INDEX statement allows you to create a secondary index. \
66
Secondary indexes contain a filtered or a full set of keys in a given keyspace.
77

88
:authorization-overview: xref:learn:security/authorization-overview.adoc
@@ -23,7 +23,7 @@ Secondary indexes contain a filtered or a full set of keys in a given keyspace.
2323
// TEMP
2424
include::partial$n1ql-language-reference/horizontal-style.adoc[]
2525

26-
The `CREATE INDEX` statement allows you to create a secondary index.
26+
FIXME: The `CREATE INDEX` statement allows you to create a secondary index.
2727
Secondary indexes contain a filtered or a full set of keys in a given keyspace.
2828
Secondary indexes are optional but increase query efficiency on a keyspace.
2929

@@ -75,14 +75,12 @@ When querying, if the index name contains a `&num;` or `&lowbar;` character, you
7575
keyspace-ref:: (Required) Specifies the keyspace where the index is created.
7676
Refer to <<keyspace-ref>> below.
7777

78-
index-key:: (Required) Specifies an index key.
79-
Refer to <<index-key>> below.
80-
81-
lead-key-attribs:: (Optional) Specifies attributes for the leading index key.
82-
Refer to <<index-key-attrib>> below.
78+
index-keys-and-attribs:: (Required) Specified the index keys and index key attributes.
79+
Refer to <<index-keys-and-attribs>> below.
8380

84-
key-attribs:: (Optional) Specifies attributes for a non-leading index key.
85-
Refer to <<index-key-attrib>> below.
81+
index-include:: (Optional) Specifies non-key fields to include in the index.
82+
For use with vector indexes and secondary indexes with a vector field.
83+
Refer to <<index-include>> below.
8684

8785
index-partition:: (Optional) Specifies index partitions.
8886
Refer to <<index-partition>> below.
@@ -96,6 +94,12 @@ Refer to <<index-using>> below.
9694
index-with:: (Optional) Specifies options for the index.
9795
Refer to <<index-with>> below.
9896

97+
[[vector]]
98+
=== VECTOR Keyword
99+
100+
FIXME: The optional `VECTOR` keyword indicates that the index is a vector index.
101+
For details, see Vector Indexes.
102+
99103
[[if-not-exists]]
100104
=== IF NOT EXISTS Clause
101105

@@ -179,8 +183,31 @@ collection::
179183
For example, `airline` indicates the `airline` collection, assuming the query context is set.
180184
====
181185

186+
[[index-keys-and-attribs]]
187+
=== Index Keys and Attributes
188+
189+
[source,ebnf]
190+
----
191+
include::partial$grammar/ddl.ebnf[tag=index-keys-and-attribs]
192+
----
193+
194+
image::n1ql-language-reference/index-keys-and-attribs.png["Syntax diagram: refer to source code listing", align=left]
195+
196+
TODO: Secondary indexes can have many keys.
197+
Vector indexes can only have one key, which must be a vector field.
198+
199+
[horizontal]
200+
index-key:: (Required) Specifies an index key.
201+
Refer to <<index-key>> below.
202+
203+
lead-key-attribs:: (Optional) Specifies attributes for the leading index key.
204+
Refer to <<index-key-attrib>> below.
205+
206+
key-attribs:: (Optional) Specifies attributes for a non-leading index key.
207+
Refer to <<index-key-attrib>> below.
208+
182209
[[index-key]]
183-
=== Index Key
210+
==== Index Key
184211

185212
[source,ebnf]
186213
----
@@ -203,7 +230,7 @@ Array indexing enables you to create global indexes on array elements and optimi
203230
For details, refer to {indexing-arrays}[Array Indexing].
204231

205232
[[index-key-attrib]]
206-
=== Index Key Attributes
233+
==== Index Key Attributes
207234

208235
[source,ebnf]
209236
----
@@ -228,8 +255,11 @@ Refer to <<index-order>> below.
228255
include-missing:: (Optional) The leading index key may also include `INCLUDE MISSING` clause.
229256
Refer to <<include-missing>> below.
230257

258+
include-vector:: (Optional) The leading index key may also include `INCLUDE MISSING` clause.
259+
Refer to <<include-vector>> below.
260+
231261
[[index-order]]
232-
==== Index Order
262+
===== Index Order
233263

234264
[source,ebnf]
235265
----
@@ -250,7 +280,7 @@ The index key is sorted in descending order.
250280
This clause is optional; if omitted, the default is `ASC`.
251281

252282
[[include-missing]]
253-
==== INCLUDE MISSING Clause
283+
===== INCLUDE MISSING Clause
254284

255285
[source,ebnf]
256286
----
@@ -265,6 +295,26 @@ If this clause is not present, then documents without the index key field are no
265295
The `INCLUDE MISSING` clause can only be applied to the leading index key.
266296
The `INCLUDE MISSING` clause may be included before or after the `ASC` or `DESC` keyword.
267297

298+
[[include-vector]]
299+
===== VECTOR Field
300+
301+
[source,ebnf]
302+
----
303+
include::partial$grammar/ddl.ebnf[tag=index-vector]
304+
----
305+
306+
image::n1ql-language-reference/index-vector.png["Syntax diagram: refer to source code listing", align=left]
307+
308+
FIXME: Indicates that the index key is a vector field.
309+
For details, see Vector Indexes and Secondary Indexes with a Vector Field.
310+
311+
[[index-include]]
312+
=== INCLUDE Clause
313+
314+
FIXME: Used to include non-key fields in the index.
315+
This is used for vector indexes and secondary indexes with a vector field.
316+
For details, see Vector Indexes and Secondary Indexes with a Vector Field.
317+
268318
[[index-partition]]
269319
=== PARTITION BY HASH Clause
270320

@@ -378,6 +428,9 @@ If the value of this property is not less than the number of index nodes in the
378428
|Integer
379429
|===
380430

431+
TODO: Vector indexes and secondary indexes with a vector field support further options.
432+
See Vector Indexes and Secondary Indexes with a Vector Field.
433+
381434
== Usage
382435

383436
NOTE: It is not recommended to create (or drop) secondary indexes when any node with a secondary index role is down, as this may result in duplicate index names.

modules/n1ql/pages/n1ql-language-reference/dropindex.adoc

Lines changed: 67 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
= DROP INDEX
2-
:description: The DROP INDEX statement allows you to drop a named primary index or a secondary index.
2+
:description: The DROP INDEX statement allows you to drop a secondary index or a vector index.
33
:page-topic-type: reference
44
:imagesdir: ../../assets/images
55

@@ -42,29 +42,45 @@ The DROP INDEX statement provides two possible syntaxes for specifying the index
4242
// TODO: Automatic links in EBNF.
4343

4444
[horizontal]
45-
index-name:: (Required) A unique name that identifies the index.
45+
index-path-and-name:: (Optional) One possible syntax for specifying the index and keyspace.
46+
Refer to <<index-path-and-name>> below.
4647

47-
index-path:: (Optional) One possible syntax for specifying the the keyspace.
48-
Refer to <<index-path>> below.
48+
index-name-on-keyspace:: (Optional) The other possible syntax for specifying the index and keyspace.
49+
Refer to <<index-name-on-keyspace>> below.
4950

50-
keyspace-ref:: (Optional) The other possible syntax for specifying the keyspace.
51-
Refer to <<keyspace-ref>> below.
51+
index-using:: (Optional) Specifies the index type.
52+
Refer to <<index-using>> below.
5253

53-
index-using:: Specifies the index type.
54-
(Optional) Refer to <<index-using>> below.
54+
[[vector]]
55+
=== VECTOR Keyword
5556

56-
[[if-exists]]
57-
=== IF EXISTS Clause
57+
FIXME: The optional VECTOR keyword indicates that you are deleting a vector index.
58+
The VECTOR keyword is purely a visual mnemonic.
59+
There is no syntactic requirement to include the VECTOR keyword when deleting a vector index.
5860

59-
The optional `IF EXISTS` clause enables the statement to complete successfully when the specified index doesn't exist.
60-
If the index does not exist within the specified keyspace, then:
61+
[[index-path-and-name]]
62+
=== Index Path and Name
6163

62-
* If this clause is not present, an error is generated.
64+
[source,ebnf]
65+
----
66+
include::partial$grammar/ddl.ebnf[tag=index-path-and-name]
67+
----
6368

64-
* If this clause is present, the statement does nothing and completes without error.
69+
image::n1ql-language-reference/index-path-and-name.png["Syntax diagram: refer to source code listing", align=left]
70+
71+
You can use a dotted notation to specify the index and the keyspace on which the index is built.
72+
This syntax provides compatibility with legacy versions of Couchbase Server.
73+
74+
[horizontal]
75+
index-name:: (Required) A unique name that identifies the index.
76+
77+
index-path:: (Required) Refer to <<index-path>> below.
78+
79+
NOTE: If there is a hyphen (-) inside the index name or any part of the index path, you must wrap the index name or that part of the index path in backticks ({backtick}{nbsp}{backtick}).
80+
Refer to the examples below.
6581

6682
[[index-path]]
67-
=== Index Path
83+
==== Index Path
6884

6985
[source,ebnf]
7086
----
@@ -73,15 +89,10 @@ include::partial$grammar/ddl.ebnf[tag=index-path]
7389

7490
image::n1ql-language-reference/index-path.png["Syntax diagram: refer to source code listing", align=left]
7591

76-
You can use a dotted notation to specify the index and the keyspace on which the index is built.
77-
This syntax provides compatibility with legacy versions of Couchbase Server.
7892
The index path may be a <<keyspace-full-index>>, a <<keyspace-prefix-index>>, or a <<keyspace-partial-index>>.
7993

80-
NOTE: If there is a hyphen (-) inside the index name or any part of the index path, you must wrap the index name or that part of the index path in backticks ({backtick}{nbsp}{backtick}).
81-
Refer to the examples below.
82-
8394
[[keyspace-full-index,full keyspace path]]
84-
==== Index Path: Full Keyspace
95+
===== Index Path: Full Keyspace
8596

8697
[source,ebnf]
8798
----
@@ -112,7 +123,7 @@ For example, `default:{backtick}travel-sample{backtick}.inventory.airline.{backt
112123
====
113124

114125
[[keyspace-prefix-index,keyspace prefix]]
115-
==== Index Path: Keyspace Prefix
126+
===== Index Path: Keyspace Prefix
116127

117128
[source,ebnf]
118129
----
@@ -138,7 +149,7 @@ For example, `default:{backtick}travel-sample{backtick}.def_type` indicates the
138149
====
139150

140151
[[keyspace-partial-index,keyspace partial]]
141-
==== Index Path: Keyspace Partial
152+
===== Index Path: Keyspace Partial
142153

143154
[source,ebnf]
144155
----
@@ -158,24 +169,40 @@ collection::
158169
For example, `airline.{backtick}idx-name{backtick}` indicates the `idx-name` index on the `airline` collection, assuming that the query context is set.
159170
====
160171

161-
[[keyspace-ref]]
172+
[[index-name-on-keyspace]]
162173
=== Index Name ON Keyspace Reference
163174

164175
[source,ebnf]
165176
----
166-
include::partial$grammar/dql.ebnf[tag=keyspace-ref]
177+
include::partial$grammar/dql.ebnf[tag=index-name-on-keyspace]
167178
----
168179

169-
image::n1ql-language-reference/keyspace-ref.png["Syntax diagram: refer to source code listing", align=left]
180+
image::n1ql-language-reference/index-name-on-keyspace.png["Syntax diagram: refer to source code listing", align=left]
170181

171-
You can use the index name with the `ON` keyword and a keyspace reference to specify the keyspace on which the index is built.
172-
The keyspace reference may be a <<keyspace-path>> or a <<keyspace-partial>>.
182+
You can use the index name with the `ON` keyword and a keyspace reference to specify the index and the keyspace on which the index is built.
183+
184+
[horizontal]
185+
index-name:: (Required) A unique name that identifies the index.
186+
187+
keyspace-ref:: (Required) Refer to <<keyspace-ref>> below.
173188

174189
NOTE: If there is a hyphen (-) inside the index name or any part of the keyspace reference, you must wrap the index name or that part of the keyspace reference in backticks ({backtick}{nbsp}{backtick}).
175190
Refer to the examples below.
176191

192+
[[keyspace-ref]]
193+
==== Keyspace Reference
194+
195+
[source,ebnf]
196+
----
197+
include::partial$grammar/dql.ebnf[tag=keyspace-ref]
198+
----
199+
200+
image::n1ql-language-reference/keyspace-ref.png["Syntax diagram: refer to source code listing", align=left]
201+
202+
The keyspace reference may be a <<keyspace-path>> or a <<keyspace-partial>>.
203+
177204
[[keyspace-path,keyspace path]]
178-
==== Keyspace Reference: Keyspace Path
205+
===== Keyspace Reference: Keyspace Path
179206

180207
[source,ebnf]
181208
----
@@ -211,7 +238,7 @@ Similarly, `{backtick}idx-name{backtick} ON default:{backtick}travel-sample{back
211238
====
212239

213240
[[keyspace-partial,keyspace partial]]
214-
==== Keyspace Reference: Keyspace Partial
241+
===== Keyspace Reference: Keyspace Partial
215242

216243
[source,ebnf]
217244
----
@@ -231,6 +258,16 @@ collection::
231258
For example, `{backtick}idx-name{backtick} ON airline` indicates the `idx-name` index on the `airline` collection, assuming the query context is set.
232259
====
233260

261+
[[if-exists]]
262+
=== IF EXISTS Clause
263+
264+
The optional `IF EXISTS` clause enables the statement to complete successfully when the specified index doesn't exist.
265+
If the index does not exist within the specified keyspace, then:
266+
267+
* If this clause is not present, an error is generated.
268+
269+
* If this clause is present, the statement does nothing and completes without error.
270+
234271
[[index-using]]
235272
=== USING Clause
236273

0 commit comments

Comments
 (0)