diff --git a/CHANGES.txt b/CHANGES.txt index 4f5e8a72cc..560472ab74 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -5,6 +5,7 @@ * Deprecate Pig support (CASSANDRA-10542) * Reduce contention getting instances of CompositeType (CASSANDRA-10433) Merged from 2.1: + * Fix potential NPE from handling result of SIM.highestSelectivityIndex (CASSANDRA-10550) * Fix paging issues with partitions containing only static columns data (CASSANDRA-10381) * Fix conditions on static columns (CASSANDRA-10264) * AssertionError: attempted to delete non-existing file CommitLog (CASSANDRA-10377) diff --git a/src/java/org/apache/cassandra/db/index/SecondaryIndexManager.java b/src/java/org/apache/cassandra/db/index/SecondaryIndexManager.java index 5edcf2e214..b0c31b6b7f 100644 --- a/src/java/org/apache/cassandra/db/index/SecondaryIndexManager.java +++ b/src/java/org/apache/cassandra/db/index/SecondaryIndexManager.java @@ -849,11 +849,14 @@ public class SecondaryIndexManager for (SecondaryIndexSearcher searcher : indexSearchers) { SecondaryIndex highestSelectivityIndex = searcher.highestSelectivityIndex(clause); - long estimate = highestSelectivityIndex.estimateResultRows(); - if (estimate <= bestEstimate) + if (highestSelectivityIndex != null) { - bestEstimate = estimate; - mostSelective = searcher; + long estimate = highestSelectivityIndex.estimateResultRows(); + if (estimate <= bestEstimate) + { + bestEstimate = estimate; + mostSelective = searcher; + } } } diff --git a/src/java/org/apache/cassandra/service/StorageProxy.java b/src/java/org/apache/cassandra/service/StorageProxy.java index ec2229ea91..3a626407c8 100644 --- a/src/java/org/apache/cassandra/service/StorageProxy.java +++ b/src/java/org/apache/cassandra/service/StorageProxy.java @@ -1633,7 +1633,7 @@ public class StorageProxy implements StorageProxyMBean { // use our own mean column count as our estimate for how many matching rows each node will have SecondaryIndex highestSelectivityIndex = searcher.highestSelectivityIndex(command.rowFilter); - resultRowsPerRange = Math.min(resultRowsPerRange, highestSelectivityIndex.estimateResultRows()); + resultRowsPerRange = highestSelectivityIndex == null ? resultRowsPerRange : Math.min(resultRowsPerRange, highestSelectivityIndex.estimateResultRows()); } } }