AMashenkov commented on code in PR #3071:
URL: https://github.com/apache/ignite-3/pull/3071#discussion_r1467608206


##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rule/logical/ExposeIndexRule.java:
##########
@@ -71,18 +87,68 @@ 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(CollectionUtils.difference(tblIdxNames, 
idxToUse));

Review Comment:
   This means we can use FORCE_INDEX and NO_INDEX hints together in the same 
query.
   The documentation doesn't says it is valid usage, and contain no example. I 
guess it is invalid case, otherwise what does the query could mean: 
   "SELECT /* FORCE_INDEX('idx'), NOINDEX */
   What hit has a priority? I guess this is invalid case.
   
   
   Also, SQL is declarative language and we shouldn't expect `hints` collection 
is ordered.



-- 
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]

Reply via email to