lower segment heap footprint and fix bug with expression type coercion #14002
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
While working on some other stuff I noticed that we were doing something when loading segments which results in some extra heap usage storing redundant stuff we don't really need. Specifically, the changes in #12279 causes us to make a combined column and dimension list in the form of
Indexed
to pass to theSimpleQueryableIndex
, which it was doing prior to this PR with https://github.com/apache/druid/blob/master/processing/src/main/java/org/apache/druid/segment/IndexIO.java#L648GenericIndexed.fromIterable
which is going to make new heap bytebuffers of the column and dimension lists. The columnsIndexed
is thrown away basically, but the dimensions list is kept around forever.We actually already have to have all of these column names on heap, and are already interning them via the
FileSmooshMapper
https://github.com/apache/druid/blob/master/processing/src/main/java/org/apache/druid/java/util/common/io/smoosh/SmooshedFileMapper.java#L88 which does so whenever it readsmeta.smoosh
to get the internal file list of a smoosh. There is an internal file as the entry point for every column name, so if we re-use this interner for the map ofColumnHolder
suppliers as well as to back theIndexed<String>
for the dimension list then we can save some heap.With my laptop test cluster of ~5k segments it reduces the heap footprint by ~20MB
Before:
After:
Looking specifically at strings, we now have about 1/3 as many on heap (from the map of ColumnHolder suppliers), not counting all of the heap bytebuffers which were backing the dimensions lists.
Completely unrelated, this PR also fixes a bug with native expression type coercion with complex types. The added test would fail where it would return "unknown complex" sometimes when using the
ExpressionTypeCoercion.operator
method. I guess I could have made it its own PR, but both things were small...This PR has: