jtuglu1 commented on code in PR #20815:
URL: https://github.com/apache/druid/pull/20815#discussion_r4504276305
##########
server/src/main/java/org/apache/druid/query/ResultLevelCachingQueryRunner.java:
##########
@@ -206,6 +209,29 @@ private byte[] fetchResultsFromResultLevelCache(
return null;
}
+ private byte[] computeResultLevelCacheKey()
+ {
+ final byte[] queryCacheKey = strategy.computeResultLevelCacheKey(query);
+ if (!cacheConfig.isIncludeDatasourceAndIntervalsInResultLevelCacheKey()) {
+ return queryCacheKey;
+ }
+ // The cached value still starts with the ETag, which is checked before
the entry is used. Adding the datasource
+ // and intervals to the key gives queries that differ only by interval or
datasource their own entries, instead of
+ // one shared entry that each of them overwrites. The byte arrays are
length-prefixed so that where one ends and the
+ // next begins is unambiguous.
+ final CacheKeyBuilder builder = new
CacheKeyBuilder(RESULT_LEVEL_CACHE_KEY_WITH_DATASOURCE_AND_INTERVALS)
+ .appendInt(queryCacheKey.length)
+ .appendByteArray(queryCacheKey);
+ final byte[] dataSourceCacheKey = query.getDataSource().getCacheKey();
+ if (dataSourceCacheKey != null) {
+
builder.appendInt(dataSourceCacheKey.length).appendByteArray(dataSourceCacheKey);
+ }
+ for (Interval interval : query.getIntervals()) {
Review Comment:
getIntervals() is sorted but might be nice to add a small test to ensure we
get equal cache keys for queries which pass different order intervals :)
and might be worth thinking about appendLongArray() or similar if it exists,
looks like that might shave off some bytes on the cache key 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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]