Skip to content

Commit a5fd1c2

Browse files
authored
GT-570 MDI and MDI-Prefixed indexes. Deprecate ZKD index (#591)
1 parent 4e2a90e commit a5fd1c2

13 files changed

+320
-46
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Remove graph with all collections
88
- Allow skipping validation for Database and Collection existence
99
- Deprecate Pregel Job API
10+
- `MDI` and `MDI-Prefixed` indexes. Deprecate `ZKD` index
1011

1112
## [1.6.1](https://github.com/arangodb/go-driver/tree/v1.6.1) (2023-10-31)
1213
- Add support for getting license

collection_indexes.go

+36-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2017 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2017-2024 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -17,8 +17,6 @@
1717
//
1818
// Copyright holder is ArangoDB GmbH, Cologne, Germany
1919
//
20-
// Author Ewout Prangsma
21-
//
2220

2321
package driver
2422

@@ -76,6 +74,16 @@ type CollectionIndexes interface {
7674
// Note that zkd indexes are an experimental feature in ArangoDB 3.9.
7775
EnsureZKDIndex(ctx context.Context, fields []string, options *EnsureZKDIndexOptions) (Index, bool, error)
7876

77+
// EnsureMDIIndex creates a multidimensional index for the collection, if it does not already exist.
78+
// The index is returned, together with a boolean indicating if the index was newly created (true) or pre-existing (false).
79+
// Available in ArangoDB 3.12 and later.
80+
EnsureMDIIndex(ctx context.Context, fields []string, options *EnsureMDIIndexOptions) (Index, bool, error)
81+
82+
// EnsureMDIPrefixedIndex creates is an additional index variant of mdi index that lets you specify additional
83+
// attributes for the index to narrow down the search space using equality checks.
84+
// Available in ArangoDB 3.12 and later.
85+
EnsureMDIPrefixedIndex(ctx context.Context, fields []string, options *EnsureMDIPrefixedIndexOptions) (Index, bool, error)
86+
7987
// EnsureInvertedIndex creates an inverted index in the collection, if it does not already exist.
8088
// Available in ArangoDB 3.10 and later.
8189
EnsureInvertedIndex(ctx context.Context, options *InvertedIndexOptions) (Index, bool, error)
@@ -197,10 +205,32 @@ type EnsureZKDIndexOptions struct {
197205
Name string
198206
// fieldValueTypes is required and the only allowed value is "double". Future extensions of the index will allow other types.
199207
FieldValueTypes string
208+
}
200209

201-
// If true, then create a sparse index.
202-
// TODO: The sparse property is not supported yet
203-
// Sparse bool
210+
// EnsureMDIIndexOptions provides specific options for creating a MDI index
211+
type EnsureMDIIndexOptions struct {
212+
// If true, then create a unique index.
213+
Unique bool
214+
// InBackground if true will not hold an exclusive collection lock for the entire index creation period (rocksdb only).
215+
InBackground bool
216+
// Name optional user defined name used for hints in AQL queries
217+
Name string
218+
// fieldValueTypes is required and the only allowed value is "double". Future extensions of the index will allow other types.
219+
FieldValueTypes string
220+
// Sparse If `true`, then create a sparse index to exclude documents from the index that do not have the defined
221+
// attributes or are explicitly set to `null` values. If a non-value is set, it still needs to be numeric.
222+
Sparse bool
223+
// StoredValues The optional `storedValues` attribute can contain an array of paths to additional attributes to
224+
// store in the index.
225+
StoredValues []string
226+
}
227+
228+
type EnsureMDIPrefixedIndexOptions struct {
229+
EnsureMDIIndexOptions
230+
231+
// PrefixFields is required and contains nn array of attribute names used as search prefix.
232+
// Array expansions are not allowed.
233+
PrefixFields []string
204234
}
205235

206236
// InvertedIndexOptions provides specific options for creating an inverted index

collection_indexes_impl.go

+45-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2017 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2017-2024 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -17,8 +17,6 @@
1717
//
1818
// Copyright holder is ArangoDB GmbH, Cologne, Germany
1919
//
20-
// Author Ewout Prangsma
21-
//
2220

2321
package driver
2422

@@ -50,6 +48,7 @@ type indexData struct {
5048
LegacyPolygons *bool `json:"legacyPolygons,omitempty"`
5149
CacheEnabled *bool `json:"cacheEnabled,omitempty"`
5250
StoredValues []string `json:"storedValues,omitempty"`
51+
PrefixFields []string `json:"prefixFields,omitempty"`
5352

5453
ArangoError `json:",inline"`
5554
}
@@ -320,6 +319,49 @@ func (c *collection) EnsureZKDIndex(ctx context.Context, fields []string, option
320319
return idx, created, nil
321320
}
322321

322+
func (c *collection) EnsureMDIIndex(ctx context.Context, fields []string, options *EnsureMDIIndexOptions) (Index, bool, error) {
323+
input := indexData{
324+
Type: string(MDIIndex),
325+
Fields: fields,
326+
// fieldValueTypes is required and the only allowed value is "double". Future extensions of the index will allow other types.
327+
FieldValueTypes: "double",
328+
}
329+
if options != nil {
330+
input.InBackground = &options.InBackground
331+
input.Name = options.Name
332+
input.Unique = &options.Unique
333+
input.Sparse = &options.Sparse
334+
input.StoredValues = options.StoredValues
335+
}
336+
idx, created, err := c.ensureIndex(ctx, input)
337+
if err != nil {
338+
return nil, false, WithStack(err)
339+
}
340+
return idx, created, nil
341+
}
342+
343+
func (c *collection) EnsureMDIPrefixedIndex(ctx context.Context, fields []string, options *EnsureMDIPrefixedIndexOptions) (Index, bool, error) {
344+
input := indexData{
345+
Type: string(MDIPrefixedIndex),
346+
Fields: fields,
347+
// fieldValueTypes is required and the only allowed value is "double". Future extensions of the index will allow other types.
348+
FieldValueTypes: "double",
349+
}
350+
if options != nil {
351+
input.InBackground = &options.InBackground
352+
input.Name = options.Name
353+
input.Unique = &options.Unique
354+
input.Sparse = &options.Sparse
355+
input.StoredValues = options.StoredValues
356+
input.PrefixFields = options.PrefixFields
357+
}
358+
idx, created, err := c.ensureIndex(ctx, input)
359+
if err != nil {
360+
return nil, false, WithStack(err)
361+
}
362+
return idx, created, nil
363+
}
364+
323365
type invertedIndexData struct {
324366
InvertedIndexOptions
325367
Type string `json:"type"`

edge_collection_indexes_impl.go

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2017 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2017-2024 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -17,8 +17,6 @@
1717
//
1818
// Copyright holder is ArangoDB GmbH, Cologne, Germany
1919
//
20-
// Author Ewout Prangsma
21-
//
2220

2321
package driver
2422

@@ -137,6 +135,22 @@ func (c *edgeCollection) EnsureZKDIndex(ctx context.Context, fields []string, op
137135
return result, created, nil
138136
}
139137

138+
func (c *edgeCollection) EnsureMDIIndex(ctx context.Context, fields []string, options *EnsureMDIIndexOptions) (Index, bool, error) {
139+
result, created, err := c.rawCollection().EnsureMDIIndex(ctx, fields, options)
140+
if err != nil {
141+
return nil, false, WithStack(err)
142+
}
143+
return result, created, nil
144+
}
145+
146+
func (c *edgeCollection) EnsureMDIPrefixedIndex(ctx context.Context, fields []string, options *EnsureMDIPrefixedIndexOptions) (Index, bool, error) {
147+
result, created, err := c.rawCollection().EnsureMDIPrefixedIndex(ctx, fields, options)
148+
if err != nil {
149+
return nil, false, WithStack(err)
150+
}
151+
return result, created, nil
152+
}
153+
140154
// EnsureInvertedIndex creates an inverted index in the collection, if it does not already exist.
141155
// Available in ArangoDB 3.10 and later.
142156
func (c *edgeCollection) EnsureInvertedIndex(ctx context.Context, options *InvertedIndexOptions) (Index, bool, error) {

index.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2017 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2017-2024 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -17,8 +17,6 @@
1717
//
1818
// Copyright holder is ArangoDB GmbH, Cologne, Germany
1919
//
20-
// Author Ewout Prangsma
21-
//
2220

2321
package driver
2422

@@ -29,16 +27,18 @@ type IndexType string
2927

3028
// Symbolic constants for index types
3129
const (
32-
PrimaryIndex = IndexType("primary")
33-
FullTextIndex = IndexType("fulltext") // Deprecated: since 3.10 version. Use ArangoSearch view instead.
34-
HashIndex = IndexType("hash")
35-
SkipListIndex = IndexType("skiplist")
36-
PersistentIndex = IndexType("persistent")
37-
GeoIndex = IndexType("geo")
38-
EdgeIndex = IndexType("edge")
39-
TTLIndex = IndexType("ttl")
40-
ZKDIndex = IndexType("zkd")
41-
InvertedIndex = IndexType("inverted")
30+
PrimaryIndex = IndexType("primary")
31+
FullTextIndex = IndexType("fulltext") // Deprecated: since 3.10 version. Use ArangoSearch view instead.
32+
HashIndex = IndexType("hash") // Deprecated use PersistentIndexType instead
33+
SkipListIndex = IndexType("skiplist") // Deprecated use PersistentIndexType instead
34+
PersistentIndex = IndexType("persistent")
35+
GeoIndex = IndexType("geo")
36+
EdgeIndex = IndexType("edge")
37+
TTLIndex = IndexType("ttl")
38+
ZKDIndex = IndexType("zkd") // Deprecated: since 3.12 version use MDIIndexType instead.
39+
InvertedIndex = IndexType("inverted")
40+
MDIIndex = IndexType("mdi")
41+
MDIPrefixedIndex = IndexType("mdi-prefixed")
4242
)
4343

4444
// Index provides access to a single index in a single collection.

index_impl.go

+4
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ func indexStringToType(indexTypeString string) (IndexType, error) {
5050
return TTLIndex, nil
5151
case string(ZKDIndex):
5252
return ZKDIndex, nil
53+
case string(MDIIndex):
54+
return MDIIndex, nil
55+
case string(MDIPrefixedIndex):
56+
return MDIPrefixedIndex, nil
5357
case string(InvertedIndex):
5458
return InvertedIndex, nil
5559
default:

test/indexes_test.go

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2017-2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2017-2024 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -408,6 +408,29 @@ var namedIndexTestCases = []struct {
408408
return idx, err
409409
},
410410
},
411+
{
412+
Name: "MDI",
413+
MinVersion: newVersion("3.12"),
414+
CreateCallback: func(col driver.Collection, name string) (driver.Index, error) {
415+
idx, _, err := col.EnsureMDIIndex(nil, []string{"mdi"}, &driver.EnsureMDIIndexOptions{
416+
Name: name,
417+
})
418+
return idx, err
419+
},
420+
},
421+
{
422+
Name: "MDI-Prefixed",
423+
MinVersion: newVersion("3.12"),
424+
CreateCallback: func(col driver.Collection, name string) (driver.Index, error) {
425+
idx, _, err := col.EnsureMDIPrefixedIndex(nil, []string{"mdi"}, &driver.EnsureMDIPrefixedIndexOptions{
426+
EnsureMDIIndexOptions: driver.EnsureMDIIndexOptions{
427+
Name: name,
428+
},
429+
PrefixFields: []string{"prefix"},
430+
})
431+
return idx, err
432+
},
433+
},
411434
}
412435

413436
func TestNamedIndexes(t *testing.T) {

v2/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
- Add support for Graph API - Vertex
99
- Add support for Graph API - Edge
1010
- Align ArangoSearchView and ArangoSearchAliasView with API
11+
- `MDI` and `MDI-Prefixed` indexes. Deprecate `ZKD` index
12+
1113

1214
## [2.0.3](https://github.com/arangodb/go-driver/tree/v2.0.3) (2023-10-31)
1315
- Add optional status code checks. Consistent return of response

v2/arangodb/collection_indexe_inverted.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -17,8 +17,6 @@
1717
//
1818
// Copyright holder is ArangoDB GmbH, Cologne, Germany
1919
//
20-
// Author Jakub Wierzbowski
21-
//
2220

2321
package arangodb
2422

@@ -105,6 +103,11 @@ type InvertedIndexOptions struct {
105103
// OptimizeTopK is an array of strings defining optimized sort expressions.
106104
// Introduced in v3.11.0, Enterprise Edition only.
107105
OptimizeTopK []string `json:"optimizeTopK,omitempty"`
106+
107+
// InBackground You can set this option to true to create the index in the background,
108+
// which will not write-lock the underlying collection for as long as if the index is built in the foreground.
109+
// The default value is false.
110+
InBackground *bool `json:"inBackground,omitempty"`
108111
}
109112

110113
// InvertedIndexField contains configuration for indexing of the field

0 commit comments

Comments
 (0)