michaeljmarshall commented on code in PR #4353:
URL: https://github.com/apache/cassandra/pull/4353#discussion_r2684018044


##########
src/java/org/apache/cassandra/index/sai/plan/StorageAttachedIndexSearcher.java:
##########
@@ -120,24 +132,45 @@ public PartitionIterator 
filterReplicaFilteringProtection(PartitionIterator full
     public UnfilteredPartitionIterator search(ReadExecutionController 
executionController) throws RequestTimeoutException
     {
         if (!command.isTopK())
+        {
             return new ResultRetriever(executionController, false);
+        }
         else
         {
-            Supplier<ResultRetriever> resultSupplier = () -> new 
ResultRetriever(executionController, true);
-
-            // VSTODO performance: if there is shadowed primary keys, we have 
to at least query twice.
-            //  First time to find out there are shadow keys, second time to 
find out there are no more shadow keys.
-            while (true)
+            // Need a consistent view of the memtables/sstables and their 
associated index, so we get the view now
+            // and propagate it as needed.
+            QueryViewBuilder.QueryView queryView = buildAnnQueryView();
+            try
+            {
+                queryController.maybeTriggerGuardrails(queryView);
+                ScoreOrderedResultRetriever result = new 
ScoreOrderedResultRetriever(queryController, executionController, queryContext, 
queryView, command.limits().count());
+                return (UnfilteredPartitionIterator) new 
VectorTopKProcessor(command).takeTopKThenSortByPrimaryKey(result);
+            }
+            finally
             {
-                long lastShadowedKeysCount = 
queryContext.vectorContext().getShadowedPrimaryKeys().size();
-                ResultRetriever result = resultSupplier.get();
-                UnfilteredPartitionIterator topK = 
(UnfilteredPartitionIterator) new VectorTopKProcessor(command).filter(result);
+                
queryView.referencedIndexes.forEach(SSTableIndex::releaseQuietly);
+            }
+        }
+    }
 
-                long currentShadowedKeysCount = 
queryContext.vectorContext().getShadowedPrimaryKeys().size();
-                if (lastShadowedKeysCount == currentShadowedKeysCount)
-                    return topK;
+    private QueryViewBuilder.QueryView buildAnnQueryView()
+    {
+        RowFilter.Expression annExpression = null;
+        for (RowFilter.Expression expression : 
queryController.indexFilter().getExpressions())
+        {
+            if (expression.operator() == Operator.ANN)
+            {
+                if (annExpression != null)
+                    throw new IllegalStateException("Multiple ANN expressions 
in a single query are not supported");
+                annExpression = expression;
             }
         }
+        if (annExpression == null)
+            throw new IllegalStateException("No ANN expression found in 
query");
+
+        StorageAttachedIndex index = queryController.indexFor(annExpression);
+        Expression planExpression = Expression.create(index).add(Operator.ANN, 
annExpression.getIndexValue().duplicate());
+        return new QueryViewBuilder(Collections.singleton(planExpression), 
queryController.mergeRange()).build();
     }
 
     private class ResultRetriever extends 
AbstractIterator<UnfilteredRowIterator> implements UnfilteredPartitionIterator

Review Comment:
   Removed it



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