Skip to content

Commit bfc4b0b

Browse files
committed
Avoid allocation by getFunctions in SelectStatement.authorize
Memorize the result of getFunctions in SelectStatement constructor patch by Dmitry Konstantinov; reviewed by Francisco Guerrero for CASSANDRA-21347
1 parent e64e119 commit bfc4b0b

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
6.0-alpha2
2+
* Avoid allocation by getFunctions in SelectStatement.authorize (CASSANDRA-21347)
23
* Avoid unit conversion in DatabaseDescriptor.getMaxValueSize() for every deserializing Cell (CASSANDRA-21295)
34
* Fix single token batch atomicity with Accord/non-Accord batches by using the batch log (CASSANDRA-20588)
45
* Avoid CompactionOptions parsing for every read by WithoutPurgeableTombstones (CASSANDRA-21294)

src/java/org/apache/cassandra/cql3/statements/SelectStatement.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ public class SelectStatement implements CQLStatement.SingleKeyspaceCqlStatement,
194194
*/
195195
private final ColumnComparator<List<ByteBuffer>> orderingComparator;
196196

197+
private final List<Function> functions;
198+
197199
public final StatementSource source;
198200

199201
// Used by forSelection below
@@ -228,6 +230,7 @@ public SelectStatement(TableMetadata table,
228230
this.perPartitionLimit = perPartitionLimit;
229231
this.source = source;
230232
this.selectOptions = selectOptions;
233+
this.functions = findAllFunctions();
231234
}
232235

233236
@Override
@@ -244,9 +247,19 @@ public short[] getPartitionKeyBindVariableIndexes()
244247

245248
@Override
246249
public Iterable<Function> getFunctions()
250+
{
251+
return functions;
252+
}
253+
254+
private List<Function> findAllFunctions()
247255
{
248256
List<Function> functions = new ArrayList<>();
249257
addFunctionsTo(functions);
258+
if (functions.isEmpty())
259+
{
260+
functions = Collections.emptyList(); // to avoid a new Iterator object creation during each authorization
261+
}
262+
250263
return functions;
251264
}
252265

0 commit comments

Comments
 (0)