Debian Codegraph @

src/main/org/h2/table/IndexHints.java

raw
1 /*
2 * Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0,
3 * and the EPL 1.0 (https://h2database.com/html/license.html).
4 * Initial Developer: H2 Group
5 */
6 package org.h2.table;
7
8 import java.util.LinkedHashSet;
9 import java.util.Set;
10
11 import org.h2.index.Index;
12
13 /**
14 * Contains the hints for which index to use for a specific table. Currently
15 * allows a list of "use indexes" to be specified.
16 * <p>
17 * Use the factory method IndexHints.createUseIndexHints(listOfIndexes) to limit
18 * the query planner to only use specific indexes when determining which index
19 * to use for a table
20 **/
21 public final class IndexHints {
22
23 private final LinkedHashSet<String> allowedIndexes;
24
25 private IndexHints(LinkedHashSet<String> allowedIndexes) {
26 this.allowedIndexes = allowedIndexes;
27 }
28
29 /**
30 * Create an index hint object.
31 *
32 * @param allowedIndexes the set of allowed indexes
33 * @return the hint object
34 */
35 public static IndexHints createUseIndexHints(LinkedHashSet<String> allowedIndexes) {
36 return new IndexHints(allowedIndexes);
37 }
38
39 public Set<String> getAllowedIndexes() {
40 return allowedIndexes;
41 }
42
43 @Override
44 public String toString() {
45 return "IndexHints{allowedIndexes=" + allowedIndexes + '}';
46 }
47
48 /**
49 * Allow an index to be used.
50 *
51 * @param index the index
52 * @return whether it was already allowed
53 */
54 public boolean allowIndex(Index index) {
55 return allowedIndexes.contains(index.getName());
56 }
57 }