Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,10 @@ public NavigableSet<Clustering<?>> valuesAsClustering(QueryOptions options, Clie
public Slices slices(QueryOptions options) throws InvalidRequestException
{
MultiCBuilder builder = new MultiCBuilder(comparator);
int keyPosition = 0;
if (restrictions.isEmpty()) // to avoid an iterator allocation for restrictions
return builder.buildSlices();

int keyPosition = 0;
for (SingleRestriction r : restrictions)
{
if (handleInFilter(r, keyPosition))
Expand Down
19 changes: 14 additions & 5 deletions src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@
import org.apache.cassandra.transport.Dispatcher;
import org.apache.cassandra.transport.ProtocolVersion;
import org.apache.cassandra.transport.messages.ResultMessage;
import org.apache.cassandra.utils.ByteBufferUtil;
import org.apache.cassandra.utils.FBUtilities;
import org.apache.cassandra.utils.NoSpamLogger;

Expand Down Expand Up @@ -802,7 +801,7 @@ public boolean isPartitionRangeQuery()
private ReadQuery getSliceCommands(QueryOptions options, ClientState state, ColumnFilter columnFilter,
RowFilter rowFilter, DataLimits limit, long nowInSec, PotentialTxnConflicts potentialTxnConflicts)
{
Collection<ByteBuffer> keys = restrictions.getPartitionKeys(options, state);
List<ByteBuffer> keys = restrictions.getPartitionKeys(options, state);
if (keys.isEmpty())
return ReadQuery.empty(table);

Expand All @@ -815,11 +814,21 @@ private ReadQuery getSliceCommands(QueryOptions options, ClientState state, Colu
if (filter == null || filter.isEmpty(table.comparator))
return ReadQuery.empty(table);

List<DecoratedKey> decoratedKeys = new ArrayList<>(keys.size());
for (ByteBuffer key : keys)
List<DecoratedKey> decoratedKeys;
if (keys.size() == 1) // reduce allocations in collections for keys
{
ByteBuffer key = keys.get(0);
QueryProcessor.validateKey(key);
decoratedKeys.add(table.partitioner.decorateKey(ByteBufferUtil.clone(key)));
decoratedKeys = Collections.singletonList(table.partitioner.decorateKey(key));
}
else
{
decoratedKeys = new ArrayList<>(keys.size());
for (ByteBuffer key : keys)
{
QueryProcessor.validateKey(key);
Comment thread
netudima marked this conversation as resolved.
decoratedKeys.add(table.partitioner.decorateKey(key));
}
}

SinglePartitionReadQuery.Group<? extends SinglePartitionReadQuery> group =
Expand Down
11 changes: 11 additions & 0 deletions src/java/org/apache/cassandra/db/SinglePartitionReadCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -1388,6 +1388,17 @@ public static Group create(TableMetadata metadata,
ClusteringIndexFilter clusteringIndexFilter,
PotentialTxnConflicts potentialTxnConflicts)
{
if (partitionKeys.size() == 1)
{
return one(SinglePartitionReadCommand.create(metadata,
nowInSec,
columnFilter,
rowFilter,
limits,
partitionKeys.get(0),
clusteringIndexFilter,
potentialTxnConflicts));
}
List<SinglePartitionReadCommand> commands = new ArrayList<>(partitionKeys.size());
for (DecoratedKey partitionKey : partitionKeys)
{
Expand Down