maedhroz commented on code in PR #3649:
URL: https://github.com/apache/cassandra/pull/3649#discussion_r1833645393


##########
src/java/org/apache/cassandra/index/sai/plan/StorageAttachedIndexSearcher.java:
##########
@@ -400,36 +430,56 @@ private UnfilteredRowIterator applyIndexFilter(PrimaryKey 
key, UnfilteredRowIter
                 {
                     queryContext.rowsFiltered++;
 
-                    if (tree.isSatisfiedBy(partition.partitionKey(), (Row) 
unfiltered, staticRow))
+                    if (tree.isSatisfiedBy(partitionKey, (Row) unfiltered, 
staticRow))
                     {
-                        matchingRows.add(unfiltered);
+                        matches.add(unfiltered);
                         hasMatch = true;
+
+                        if (topK)
+                        {
+                            PrimaryKey shadowed = 
keyFactory.hasClusteringColumns()
+                                                  ? 
keyFactory.create(partitionKey, ((Row) unfiltered).clustering())
+                                                  : 
keyFactory.create(partitionKey);
+                            keysToShadow.remove(shadowed);
+                        }
                     }
                 }
             }
 
+            // If any non-static rows match the filter, there should be no 
need to shadow the static primary key:
+            if (topK && hasMatch && keyFactory.hasClusteringColumns())
+                keysToShadow.remove(keyFactory.create(partitionKey, 
Clustering.STATIC_CLUSTERING));
+
+            // We may not have any non-static row data to filter...
             if (!hasMatch)
             {
                 queryContext.rowsFiltered++;
 
-                if (tree.isSatisfiedBy(key.partitionKey(), staticRow, 
staticRow))
+                if (tree.isSatisfiedBy(partitionKey, staticRow, staticRow))
+                {
                     hasMatch = true;
+
+                    if (topK)
+                        keysToShadow.remove(keyFactory.create(partitionKey, 
staticRow.clustering()));

Review Comment:
   I think you're right...changing...



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