From 7119ac9c50c018968c0c2ae5fc277aa02f048373 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Mon, 22 Mar 2021 13:16:16 +0100 Subject: [PATCH 1/3] index estimates flag --- .../java/com/arangodb/entity/IndexEntity.java | 5 ++ .../com/arangodb/model/HashIndexOptions.java | 17 +++- .../model/PersistentIndexOptions.java | 16 +++- .../arangodb/model/SkiplistIndexOptions.java | 17 +++- .../com/arangodb/ArangoCollectionTest.java | 82 ++++++++++++++++++- 5 files changed, 131 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/arangodb/entity/IndexEntity.java b/src/main/java/com/arangodb/entity/IndexEntity.java index 5be2d0b87..b359a5146 100644 --- a/src/main/java/com/arangodb/entity/IndexEntity.java +++ b/src/main/java/com/arangodb/entity/IndexEntity.java @@ -41,6 +41,7 @@ public class IndexEntity implements Entity { private Boolean deduplicate; private Integer expireAfter; private Boolean inBackground; + private Boolean estimates; public IndexEntity() { super(); @@ -102,4 +103,8 @@ public Boolean getDeduplicate() { return deduplicate; } + public Boolean getEstimates() { + return estimates; + } + } diff --git a/src/main/java/com/arangodb/model/HashIndexOptions.java b/src/main/java/com/arangodb/model/HashIndexOptions.java index 992c79281..431a2eb25 100644 --- a/src/main/java/com/arangodb/model/HashIndexOptions.java +++ b/src/main/java/com/arangodb/model/HashIndexOptions.java @@ -33,6 +33,7 @@ public class HashIndexOptions extends IndexOptions { private Boolean unique; private Boolean sparse; private Boolean deduplicate; + private Boolean estimates; public HashIndexOptions() { super(); @@ -91,11 +92,25 @@ public Boolean getDeduplicate() { } /** - * @param deduplicate if false, the deduplication of array values is turned off. + * @param deduplicate + * if false, the deduplication of array values is turned off. * @return options */ public HashIndexOptions deduplicate(final Boolean deduplicate) { this.deduplicate = deduplicate; return this; } + + /** + * FIXME: add doc + */ + public HashIndexOptions estimates(final Boolean estimates) { + this.estimates = estimates; + return this; + } + + public Boolean getEstimates() { + return estimates; + } + } diff --git a/src/main/java/com/arangodb/model/PersistentIndexOptions.java b/src/main/java/com/arangodb/model/PersistentIndexOptions.java index 75ab9fa9c..01aea223e 100644 --- a/src/main/java/com/arangodb/model/PersistentIndexOptions.java +++ b/src/main/java/com/arangodb/model/PersistentIndexOptions.java @@ -33,6 +33,7 @@ public class PersistentIndexOptions extends IndexOptions protected final IndexType type = IndexType.persistent; private Boolean unique; private Boolean sparse; + private Boolean estimates; public PersistentIndexOptions() { super(); @@ -78,7 +79,8 @@ public Boolean getSparse() { } /** - * @param sparse if true, then create a sparse index + * @param sparse + * if true, then create a sparse index * @return options */ public PersistentIndexOptions sparse(final Boolean sparse) { @@ -86,4 +88,16 @@ public PersistentIndexOptions sparse(final Boolean sparse) { return this; } + /** + * FIXME: add doc + */ + public PersistentIndexOptions estimates(final Boolean estimates) { + this.estimates = estimates; + return this; + } + + public Boolean getEstimates() { + return estimates; + } + } diff --git a/src/main/java/com/arangodb/model/SkiplistIndexOptions.java b/src/main/java/com/arangodb/model/SkiplistIndexOptions.java index f99676d2f..299c86d01 100644 --- a/src/main/java/com/arangodb/model/SkiplistIndexOptions.java +++ b/src/main/java/com/arangodb/model/SkiplistIndexOptions.java @@ -33,6 +33,7 @@ public class SkiplistIndexOptions extends IndexOptions { private Boolean unique; private Boolean sparse; private Boolean deduplicate; + private Boolean estimates; public SkiplistIndexOptions() { super(); @@ -91,11 +92,25 @@ public Boolean getDeduplicate() { } /** - * @param deduplicate if false, the deduplication of array values is turned off. + * @param deduplicate + * if false, the deduplication of array values is turned off. * @return options */ public SkiplistIndexOptions deduplicate(final Boolean deduplicate) { this.deduplicate = deduplicate; return this; } + + /** + * FIXME: add doc + */ + public SkiplistIndexOptions estimates(final Boolean estimates) { + this.estimates = estimates; + return this; + } + + public Boolean getEstimates() { + return estimates; + } + } diff --git a/src/test/java/com/arangodb/ArangoCollectionTest.java b/src/test/java/com/arangodb/ArangoCollectionTest.java index a732cbfa2..bd7afd5ec 100644 --- a/src/test/java/com/arangodb/ArangoCollectionTest.java +++ b/src/test/java/com/arangodb/ArangoCollectionTest.java @@ -20,9 +20,38 @@ package com.arangodb; -import com.arangodb.entity.*; -import com.arangodb.model.*; +import com.arangodb.entity.BaseDocument; +import com.arangodb.entity.BaseEdgeDocument; +import com.arangodb.entity.CollectionEntity; +import com.arangodb.entity.CollectionPropertiesEntity; +import com.arangodb.entity.CollectionRevisionEntity; +import com.arangodb.entity.DocumentCreateEntity; +import com.arangodb.entity.DocumentDeleteEntity; +import com.arangodb.entity.DocumentEntity; +import com.arangodb.entity.DocumentImportEntity; +import com.arangodb.entity.DocumentUpdateEntity; +import com.arangodb.entity.IndexEntity; +import com.arangodb.entity.IndexType; +import com.arangodb.entity.MultiDocumentEntity; +import com.arangodb.entity.Permissions; +import com.arangodb.entity.ShardEntity; +import com.arangodb.model.CollectionCreateOptions; +import com.arangodb.model.CollectionPropertiesOptions; +import com.arangodb.model.DocumentCreateOptions; +import com.arangodb.model.DocumentDeleteOptions; +import com.arangodb.model.DocumentExistsOptions; +import com.arangodb.model.DocumentImportOptions; import com.arangodb.model.DocumentImportOptions.OnDuplicate; +import com.arangodb.model.DocumentReadOptions; +import com.arangodb.model.DocumentReplaceOptions; +import com.arangodb.model.DocumentUpdateOptions; +import com.arangodb.model.FulltextIndexOptions; +import com.arangodb.model.GeoIndexOptions; +import com.arangodb.model.HashIndexOptions; +import com.arangodb.model.OverwriteMode; +import com.arangodb.model.PersistentIndexOptions; +import com.arangodb.model.SkiplistIndexOptions; +import com.arangodb.model.TtlIndexOptions; import com.arangodb.util.MapBuilder; import com.arangodb.velocypack.VPackSlice; import com.fasterxml.jackson.core.JsonProcessingException; @@ -33,7 +62,14 @@ import org.junit.runner.RunWith; import org.junit.runners.Parameterized; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -1391,6 +1427,46 @@ public void createPersistentIndexWithOptions() { assertThat(indexResult.getName(), is(name)); } + @Test + public void indexEstimates() { + assumeTrue(isAtLeastVersion(3, 8)); + assumeTrue(isSingleServer()); + + String name = "persistentIndex-" + rnd(); + final PersistentIndexOptions options = new PersistentIndexOptions(); + options.name(name); + options.estimates(true); + + String f1 = "field-" + rnd(); + String f2 = "field-" + rnd(); + + final Collection fields = Arrays.asList(f1, f2); + final IndexEntity indexResult = collection.ensurePersistentIndex(fields, options); + assertThat(indexResult, is(notNullValue())); + assertThat(indexResult.getEstimates(), is(true)); + assertThat(indexResult.getSelectivityEstimate(), is(notNullValue())); + } + + @Test + public void indexEstimatesFalse() { + assumeTrue(isAtLeastVersion(3, 8)); + assumeTrue(isSingleServer()); + + String name = "persistentIndex-" + rnd(); + final PersistentIndexOptions options = new PersistentIndexOptions(); + options.name(name); + options.estimates(false); + + String f1 = "field-" + rnd(); + String f2 = "field-" + rnd(); + + final Collection fields = Arrays.asList(f1, f2); + final IndexEntity indexResult = collection.ensurePersistentIndex(fields, options); + assertThat(indexResult, is(notNullValue())); + assertThat(indexResult.getEstimates(), is(false)); + assertThat(indexResult.getSelectivityEstimate(), is(nullValue())); + } + @Test public void createFulltextIndex() { String f1 = "field-" + rnd(); From 673d4ed52158fe35f8edc9572159aef3b0503bd8 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Mon, 12 Apr 2021 14:25:25 +0200 Subject: [PATCH 2/3] javadoc upd --- ChangeLog.md | 1 + src/main/java/com/arangodb/model/HashIndexOptions.java | 4 +++- src/main/java/com/arangodb/model/PersistentIndexOptions.java | 4 +++- src/main/java/com/arangodb/model/SkiplistIndexOptions.java | 4 +++- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index d544b6806..03f9ce1f5 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a ## [Unreleased] +- added support for index estimates (ArangoDB v3.8) - fixed performance issue when consuming big cursor batches in stream mode (arangodb/arangodb#13476) ## [6.9.0] - 2021-02-04 diff --git a/src/main/java/com/arangodb/model/HashIndexOptions.java b/src/main/java/com/arangodb/model/HashIndexOptions.java index 431a2eb25..a691fb611 100644 --- a/src/main/java/com/arangodb/model/HashIndexOptions.java +++ b/src/main/java/com/arangodb/model/HashIndexOptions.java @@ -102,7 +102,9 @@ public HashIndexOptions deduplicate(final Boolean deduplicate) { } /** - * FIXME: add doc + * @param estimates + * This attribute controls whether index selectivity estimates are maintained for the index. Default: {@code + * true} */ public HashIndexOptions estimates(final Boolean estimates) { this.estimates = estimates; diff --git a/src/main/java/com/arangodb/model/PersistentIndexOptions.java b/src/main/java/com/arangodb/model/PersistentIndexOptions.java index 01aea223e..bbfb68fb2 100644 --- a/src/main/java/com/arangodb/model/PersistentIndexOptions.java +++ b/src/main/java/com/arangodb/model/PersistentIndexOptions.java @@ -89,7 +89,9 @@ public PersistentIndexOptions sparse(final Boolean sparse) { } /** - * FIXME: add doc + * @param estimates + * This attribute controls whether index selectivity estimates are maintained for the index. Default: {@code + * true} */ public PersistentIndexOptions estimates(final Boolean estimates) { this.estimates = estimates; diff --git a/src/main/java/com/arangodb/model/SkiplistIndexOptions.java b/src/main/java/com/arangodb/model/SkiplistIndexOptions.java index 299c86d01..27616ffae 100644 --- a/src/main/java/com/arangodb/model/SkiplistIndexOptions.java +++ b/src/main/java/com/arangodb/model/SkiplistIndexOptions.java @@ -102,7 +102,9 @@ public SkiplistIndexOptions deduplicate(final Boolean deduplicate) { } /** - * FIXME: add doc + * @param estimates + * This attribute controls whether index selectivity estimates are maintained for the index. Default: {@code + * true} */ public SkiplistIndexOptions estimates(final Boolean estimates) { this.estimates = estimates; From 3115d00d3e65ee40122adc211e956d64ed5f2f99 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Mon, 12 Apr 2021 14:44:09 +0200 Subject: [PATCH 3/3] javadoc upd --- src/main/java/com/arangodb/model/HashIndexOptions.java | 1 + src/main/java/com/arangodb/model/PersistentIndexOptions.java | 1 + src/main/java/com/arangodb/model/SkiplistIndexOptions.java | 1 + 3 files changed, 3 insertions(+) diff --git a/src/main/java/com/arangodb/model/HashIndexOptions.java b/src/main/java/com/arangodb/model/HashIndexOptions.java index a691fb611..20eff1d44 100644 --- a/src/main/java/com/arangodb/model/HashIndexOptions.java +++ b/src/main/java/com/arangodb/model/HashIndexOptions.java @@ -105,6 +105,7 @@ public HashIndexOptions deduplicate(final Boolean deduplicate) { * @param estimates * This attribute controls whether index selectivity estimates are maintained for the index. Default: {@code * true} + * @since ArangoDB 3.8 */ public HashIndexOptions estimates(final Boolean estimates) { this.estimates = estimates; diff --git a/src/main/java/com/arangodb/model/PersistentIndexOptions.java b/src/main/java/com/arangodb/model/PersistentIndexOptions.java index bbfb68fb2..25a50a886 100644 --- a/src/main/java/com/arangodb/model/PersistentIndexOptions.java +++ b/src/main/java/com/arangodb/model/PersistentIndexOptions.java @@ -92,6 +92,7 @@ public PersistentIndexOptions sparse(final Boolean sparse) { * @param estimates * This attribute controls whether index selectivity estimates are maintained for the index. Default: {@code * true} + * @since ArangoDB 3.8 */ public PersistentIndexOptions estimates(final Boolean estimates) { this.estimates = estimates; diff --git a/src/main/java/com/arangodb/model/SkiplistIndexOptions.java b/src/main/java/com/arangodb/model/SkiplistIndexOptions.java index 27616ffae..30d000f59 100644 --- a/src/main/java/com/arangodb/model/SkiplistIndexOptions.java +++ b/src/main/java/com/arangodb/model/SkiplistIndexOptions.java @@ -105,6 +105,7 @@ public SkiplistIndexOptions deduplicate(final Boolean deduplicate) { * @param estimates * This attribute controls whether index selectivity estimates are maintained for the index. Default: {@code * true} + * @since ArangoDB 3.8 */ public SkiplistIndexOptions estimates(final Boolean estimates) { this.estimates = estimates;