zhangstar333 commented on code in PR #67650:
URL: https://github.com/apache/doris/pull/67650#discussion_r3975515453


##########
fe/fe-core/src/main/java/org/apache/doris/datasource/lance/source/LanceScalarIndexPlanner.java:
##########
@@ -0,0 +1,139 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you 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 org.apache.doris.datasource.lance.source;
+
+import org.apache.doris.analysis.CompoundPredicate;
+import org.apache.doris.analysis.Expr;
+import org.apache.doris.analysis.SlotRef;
+import org.apache.doris.datasource.lance.LanceFragmentInfo;
+import org.apache.doris.datasource.lance.LanceIndexSegmentInfo;
+import org.apache.doris.datasource.lance.LanceTableMetadata;
+
+import org.lance.index.IndexType;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.stream.Collectors;
+
+/** Assigns one BTree/Bitmap/LabelList segment and a disjoint fragment domain 
to each ordinary scan task. */
+final class LanceScalarIndexPlanner {
+    static final class Plan {
+        final String indexName;
+        final IndexSegmentSplitPlan splits;
+        private final long coveredRows;
+
+        Plan(String indexName, IndexSegmentSplitPlan splits, long coveredRows) 
{
+            this.indexName = indexName;
+            this.splits = splits;
+            this.coveredRows = coveredRows;
+        }
+    }
+
+    static Plan plan(LanceTableMetadata metadata, List<Expr> pushedConjuncts,
+            Map<Long, LanceFragmentInfo> visibleFragments) {
+        if (metadata.getVersion() <= 0) {
+            return null;
+        }
+        Set<Integer> filterFields = collectFilterFields(metadata, 
pushedConjuncts);
+        if (filterFields.isEmpty()) {
+            return null;
+        }
+        // Group all segments of each logical index before checking coverage. 
Name order
+        // provides a stable winner when multiple indices cover the same 
number of rows.
+        Map<String, List<LanceIndexSegmentInfo>> indices = 
metadata.getIndexSegments().stream()
+                
.collect(Collectors.groupingBy(LanceIndexSegmentInfo::getIndexName,
+                        TreeMap::new, Collectors.toList()));
+        Plan selected = null;
+        for (List<LanceIndexSegmentInfo> segments : indices.values()) {
+            // PR #79 supports one top-level key in BTree/Bitmap/LabelList 
indices. Lance
+            // performs the final typed driver selection and falls back within 
the same domain.
+            LanceIndexSegmentInfo index = segments.get(0);
+            if ((index.getIndexType() != IndexType.BTREE && 
index.getIndexType() != IndexType.BITMAP
+                    && index.getIndexType() != IndexType.LABEL_LIST)
+                    || index.getFieldIds().size() != 1 || 
!filterFields.contains(index.getFieldIds().get(0))) {
+                continue;
+            }
+            Plan candidate = groupFragments(metadata, segments, 
visibleFragments);
+            if (candidate != null && (selected == null || 
candidate.coveredRows > selected.coveredRows)) {

Review Comment:
   we chose one filter who covers more rows, it‘s hard to konw which filter is 
more usefully



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to