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


##########
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:
   Let's create a ticket to fix examples in documentation.
   The examples, which mentioned above, should be explained in documentation.
   The example `SELECT /*+ NO_INDEX(TBL1_IDX2), FORCE_INDEX(TBL2_IDX2) */` in 
"Hint Scope" section should be rewritten.
   



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