Repository: cassandra Updated Branches: refs/heads/trunk 40d1425a1 -> 9c9e39263
Exclude sstable based on clustering in query by name path patch by slebresne; reviewed by iamaleksey for CASSANDRA-10571 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/1e8007b1 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/1e8007b1 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/1e8007b1 Branch: refs/heads/trunk Commit: 1e8007b1a0a1baac6282d142fbb54a7d0860e751 Parents: cba5ef6 Author: Sylvain Lebresne <sylv...@datastax.com> Authored: Fri Oct 23 12:20:28 2015 +0200 Committer: Sylvain Lebresne <sylv...@datastax.com> Committed: Mon Nov 2 15:35:20 2015 +0100 ---------------------------------------------------------------------- CHANGES.txt | 1 + .../db/SinglePartitionReadCommand.java | 22 ++++++++++++++++++++ .../db/filter/ClusteringIndexNamesFilter.java | 14 +++++++++++-- 3 files changed, 35 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/1e8007b1/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index 1724f01..080cc51 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 3.0 + * Skip sstables by clustering in query by names path (10571) * Fix implementation of LegacyLayout.LegacyBoundComparator (CASSANDRA-10602) * Don't use 'names query' read path for counters (CASSANDRA-10572) * Fix backward compatibility for counters (CASSANDRA-10470) http://git-wip-us.apache.org/repos/asf/cassandra/blob/1e8007b1/src/java/org/apache/cassandra/db/SinglePartitionReadCommand.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/db/SinglePartitionReadCommand.java b/src/java/org/apache/cassandra/db/SinglePartitionReadCommand.java index 4d7d93c..065a247 100644 --- a/src/java/org/apache/cassandra/db/SinglePartitionReadCommand.java +++ b/src/java/org/apache/cassandra/db/SinglePartitionReadCommand.java @@ -675,6 +675,28 @@ public class SinglePartitionReadCommand extends ReadCommand if (filter == null) break; + if (!filter.shouldInclude(sstable)) + { + // This mean that nothing queried by the filter can be in the sstable. One exception is the top-level partition deletion + // however: if it is set, it impacts everything and must be included. Getting that top-level partition deletion costs us + // some seek in general however (unless the partition is indexed and is in the key cache), so we first check if the sstable + // has any tombstone at all as a shortcut. + if (sstable.getSSTableMetadata().maxLocalDeletionTime == Integer.MAX_VALUE) + continue; // Means no tombstone at all, we can skip that sstable + + // We need to get the partition deletion and include it if it's live. In any case though, we're done with that sstable. + sstable.incrementReadCount(); + try (UnfilteredRowIterator iter = sstable.iterator(partitionKey(), columnFilter(), filter.isReversed(), isForThrift())) + { + if (iter.partitionLevelDeletion().isLive()) + { + sstablesIterated++; + result = add(UnfilteredRowIterators.noRowsIterator(iter.metadata(), iter.partitionKey(), Rows.EMPTY_STATIC_ROW, iter.partitionLevelDeletion(), filter.isReversed()), result, filter, sstable.isRepaired()); + } + } + continue; + } + Tracing.trace("Merging data from sstable {}", sstable.descriptor.generation); sstable.incrementReadCount(); try (UnfilteredRowIterator iter = filter.filter(sstable.iterator(partitionKey(), columnFilter(), filter.isReversed(), isForThrift()))) http://git-wip-us.apache.org/repos/asf/cassandra/blob/1e8007b1/src/java/org/apache/cassandra/db/filter/ClusteringIndexNamesFilter.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/db/filter/ClusteringIndexNamesFilter.java b/src/java/org/apache/cassandra/db/filter/ClusteringIndexNamesFilter.java index 388cd50..a81a7a6 100644 --- a/src/java/org/apache/cassandra/db/filter/ClusteringIndexNamesFilter.java +++ b/src/java/org/apache/cassandra/db/filter/ClusteringIndexNamesFilter.java @@ -18,6 +18,7 @@ package org.apache.cassandra.db.filter; import java.io.IOException; +import java.nio.ByteBuffer; import java.util.*; import org.apache.cassandra.config.CFMetaData; @@ -201,8 +202,17 @@ public class ClusteringIndexNamesFilter extends AbstractClusteringIndexFilter public boolean shouldInclude(SSTableReader sstable) { - // TODO: we could actually exclude some sstables - return true; + ClusteringComparator comparator = sstable.metadata.comparator; + List<ByteBuffer> minClusteringValues = sstable.getSSTableMetadata().minClusteringValues; + List<ByteBuffer> maxClusteringValues = sstable.getSSTableMetadata().maxClusteringValues; + + // If any of the requested clustering is within the bounds covered by the sstable, we need to include the sstable + for (Clustering clustering : clusterings) + { + if (Slice.make(clustering).intersects(comparator, minClusteringValues, maxClusteringValues)) + return true; + } + return false; } public String toString(CFMetaData metadata)