You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by "clohfink (via GitHub)" <gi...@apache.org> on 2026/02/05 01:46:34 UTC

Re: [PR] [CASSANDRA-21141][trunk] Reduce memory allocation during transformation of BatchStatement to Mutation [cassandra]

clohfink commented on code in PR #4589:
URL: https://github.com/apache/cassandra/pull/4589#discussion_r2766638173


##########
src/java/org/apache/cassandra/cql3/restrictions/PartitionKeyRestrictions.java:
##########
@@ -191,6 +193,17 @@ public AbstractBounds<PartitionPosition> bounds(IPartitioner partitioner, QueryO
      */
     private List<ByteBuffer> nonTokenRestrictionValues(QueryOptions options, ClientState state)
     {
+        // fast path, a typical case when a single full restriction is used
+        // for example, when we specify a single partition key to modify
+        if (restrictions.size() == 1 && !restrictions.hasIN())
+        {
+            SingleRestriction r = restrictions.lastRestriction();
+            List<ClusteringElements> values = r.values(options);
+            if (values.size() == 1)
+                return toByteBuffers(Clustering.make(values.get(0).toArray(new ByteBuffer[comparator.size()])));

Review Comment:
   Minor additional possible improvement? For the single-column partition key case this is allocating:
     - 1 × ByteBuffer[] array (unnecessary)
     - 1 × BufferClustering object (unnecessary)
   
   to ultimately call get(0) and return the original ByteBuffer. Maybe bypass Clustering entirely and use ClusteringElements which has it
   
   
   ```          if (values.size() == 1)
             {
                 ClusteringElements elements = values.get(0);
                 ByteBuffer pk = serializePartitionKey(elements);
                 validatePartitionKey(pk);
                 return Collections.singletonList(pk);
             }
             return toByteBuffers(MultiCBuilder.build(comparator, values));
   
   ...
   
     private ByteBuffer serializePartitionKey(ClusteringElements elements)
     {
         // Single-column partition key: just return the value directly
         if (elements.size() == 1)
             return elements.get(0);
   
         // Composite partition key: need to build composite
         return CompositeType.build(ByteBufferAccessor.instance,
                                    elements.toArray(new ByteBuffer[elements.size()]));
     }
   
   ```
   
   



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org