nva commented on code in PR #3071:
URL: https://github.com/apache/ignite-3/pull/3071#discussion_r1465879410
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rule/logical/ExposeIndexRule.java:
##########
@@ -71,18 +86,66 @@ public void onMatch(RelOptRuleCall call) {
.filter(idx -> filter(igniteTable, idx.indexName(),
idx.searchBounds()))
.collect(Collectors.toList());
+ indexes = applyHints(scan, indexes);
+
if (indexes.isEmpty()) {
return;
}
- Map<RelNode, RelNode> equivMap = new HashMap<>(indexes.size());
+ Map<RelNode, RelNode> equivMap =
IgniteUtils.newHashMap(indexes.size());
for (int i = 1; i < indexes.size(); i++) {
equivMap.put(indexes.get(i), scan);
}
call.transformTo(indexes.get(0), equivMap);
}
+ /** Filter actual indexes list and prune-table-scan flag if any index is
forced to use. */
+ private static List<IgniteLogicalIndexScan> applyHints(TableScan scan,
List<IgniteLogicalIndexScan> indexes) {
+ List<RelHint> hints = HintUtils.hints(scan, INDEX_HINTS);
+
+ if (hints.isEmpty()) {
+ return indexes;
+ }
+
+ Set<String> tblIdxNames =
indexes.stream().map(AbstractIndexScan::indexName).collect(Collectors.toSet());
+ Set<String> idxToSkip = new HashSet<>(capacity(tblIdxNames.size()));
+ Set<String> idxToUse = new HashSet<>(capacity(tblIdxNames.size()));
+
+ for (RelHint hint : hints) {
+ Collection<String> hintIdxNames = hint.listOptions;
+ boolean noIndex = hint.hintName.equals(NO_INDEX.name());
+
+ if (hintIdxNames.isEmpty()) {
+ if (noIndex) {
+ idxToSkip.addAll(tblIdxNames);
Review Comment:
There may be `FORCE_INDEX` hints before, this will ignore it.
Added test for this case
`ForceIndexHintPlannerTest#testWithMultipleIndexHints`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]