Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1638 from pengpeng-lu/hint
resolves #1671: match index hints in a query
- Loading branch information
Showing
10 changed files
with
444 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...ayer-core/src/main/java/com/apple/foundationdb/record/query/plan/cascades/AccessHint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* AccessHint.java | ||
* | ||
* This source file is part of the FoundationDB open source project | ||
* | ||
* Copyright 2015-2022 Apple Inc. and the FoundationDB project authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.apple.foundationdb.record.query.plan.cascades; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
/** | ||
* Interface to represent an access hint. An access hint can be of type INDEX and PRIMARY. | ||
*/ | ||
public interface AccessHint { | ||
|
||
/** | ||
* Gets the type of the access hint. | ||
* @return the type of the access hint | ||
*/ | ||
@Nonnull | ||
String getAccessHintType(); | ||
} | ||
|
59 changes: 59 additions & 0 deletions
59
...yer-core/src/main/java/com/apple/foundationdb/record/query/plan/cascades/AccessHints.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* AccessHints.java | ||
* | ||
* This source file is part of the FoundationDB open source project | ||
* | ||
* Copyright 2015-2022 Apple Inc. and the FoundationDB project authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.apple.foundationdb.record.query.plan.cascades; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.util.Arrays; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
/** | ||
* Represents a set of AccessHint a query or a match candidate has. | ||
*/ | ||
public class AccessHints { | ||
@Nonnull | ||
private final Set<AccessHint> accessHintSet = new HashSet<>(); | ||
|
||
public AccessHints(AccessHint... accessHints) { | ||
this.accessHintSet.addAll(Arrays.asList(accessHints)); | ||
} | ||
|
||
@Nonnull | ||
public Set<AccessHint> getAccessHintSet() { | ||
return accessHintSet; | ||
} | ||
|
||
public int size() { | ||
return accessHintSet.size(); | ||
} | ||
|
||
public boolean satisfies(@Nonnull AccessHints other) { | ||
// if no hint is set, it's considered to include all possible hints | ||
if (size() == 0) { | ||
return true; | ||
} | ||
// if other is empty, this does not include other | ||
if (other.size() == 0) { | ||
return false; | ||
} | ||
return accessHintSet.containsAll(other.getAccessHintSet()); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
...core/src/main/java/com/apple/foundationdb/record/query/plan/cascades/IndexAccessHint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* IndexAccessHint.java | ||
* | ||
* This source file is part of the FoundationDB open source project | ||
* | ||
* Copyright 2015-2022 Apple Inc. and the FoundationDB project authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.apple.foundationdb.record.query.plan.cascades; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Represents an index hint. | ||
*/ | ||
public class IndexAccessHint implements AccessHint { | ||
@Nonnull | ||
private final String indexName; | ||
|
||
public IndexAccessHint(@Nonnull final String indexName) { | ||
this.indexName = indexName; | ||
} | ||
|
||
@Override | ||
@Nonnull | ||
public String getAccessHintType() { | ||
return "INDEX"; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (this == other) { | ||
return true; | ||
} | ||
if (other == null || getClass() != other.getClass()) { | ||
return false; | ||
} | ||
return indexName.equals(((IndexAccessHint)other).getIndexName()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(indexName); | ||
} | ||
|
||
@Nonnull | ||
public String getIndexName() { | ||
return indexName; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...re/src/main/java/com/apple/foundationdb/record/query/plan/cascades/PrimaryAccessHint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* PrimaryAccessHint.java | ||
* | ||
* This source file is part of the FoundationDB open source project | ||
* | ||
* Copyright 2015-2022 Apple Inc. and the FoundationDB project authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.apple.foundationdb.record.query.plan.cascades; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
/** | ||
* Represents reading a table directly without using an index plus fetch. | ||
*/ | ||
public class PrimaryAccessHint implements AccessHint { | ||
@Override | ||
@Nonnull | ||
public String getAccessHintType() { | ||
return "PRIMARY"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.