Fix sparse nullable serialization inconsistency in Tuple subcolumns#91932
Fix sparse nullable serialization inconsistency in Tuple subcolumns#91932Algunenano merged 8 commits intoClickHouse:masterfrom
Conversation
|
Workflow [PR], commit [642bad1] Summary: ❌
|
| namespace DB | ||
| { | ||
|
|
||
| bool SerializationInfoSettings::supportsSparseSerialization(const IDataType & type) const |
There was a problem hiding this comment.
Let's find a different name, either for this one or for IDataType(). Otherwise it will be really easy to mess up again.
Not sure 100%, but maybe we could call this SerializationInfoSettings::shouldUseSparseSerialization. Another option is to keep only IDataType and make SerializationInfoSettings a mandatory parameter. WDTY?
There was a problem hiding this comment.
Let's find a different name, either for this one or for IDataType(). Otherwise it will be really easy to mess up again.
Sure.
Another option is to keep only IDataType and make SerializationInfoSettings a mandatory parameter.
I did try that approach, but the required changes were large: every derivative type would need to be updated. Also, the semantics feel a bit off: whether a data type supports sparse encoding shouldn't really be governed by SerializationInfoSettings. That setting should describe limitations of a particular serialization pipeline (e.g. MergeTree serialization, or Native reader/writer), not the capabilities of the type system itself. DataTypeNullable should fundamentally support sparse encoding. It's the specific serialization path that may decide sparse is not allowed under certain SerializationInfoSettings.
There was a problem hiding this comment.
I'll rename to SerializationInfoSettings::canUseSparseSerialization
|
The crash seems related: |
Yes, it looks related. I'm digging into it now. |
|
This also closes #91380. We can add a test later on |
| if (supportsSparseSerialization() && kind == ISerialization::Kind::SPARSE) | ||
| if (settings.canUseSparseSerialization(*this) && kind == ISerialization::Kind::SPARSE) | ||
| serialization = std::make_shared<SerializationSparse>(serialization); | ||
| else if (kind == ISerialization::Kind::DETACHED) |
There was a problem hiding this comment.
Any reason for removing the else except that if you take the previous if you won't take the second one?
There was a problem hiding this comment.
This is definitely an unintended change. It was probably introduced during some local debugging and not fully cleaned up. Good catch!
src/Formats/NativeReader.cpp
Outdated
| /// NativeReader must enable nullable sparse support here. Since it operates on in-memory state, it should | ||
| /// be able to handle all possible serialization variants. | ||
| SerializationInfoSettings settings; | ||
| settings.allowNullableSparse(); |
There was a problem hiding this comment.
Is this necessary only if server >= DBMS_MIN_REVISION_WITH_NULLABLE_SPARSE_SERIALIZATION or it doesn't matter?
There was a problem hiding this comment.
It doesn't matter. The newest reader should be able to handle all serialization variants.
|
|
||
| bool canUseSparseSerialization(const IDataType & type) const; | ||
|
|
||
| void allowNullableSparse() { nullable_serialization_version = MergeTreeNullableSerializationVersion::ALLOW_SPARSE; } |
There was a problem hiding this comment.
Minor, but creating object and call a method on it later looks adhoc, maybe adding separate method to create an object with nullable_serialization_version = MergeTreeNullableSerializationVersion::ALLOW_SPARSE will be better? i.e. createSerializationInfoSettingsWithNullableSparse (or a static function)? And the comment can be put there with an explanation
There was a problem hiding this comment.
Yes. I’ll add a method that builds this setting with the widest serialization capability, so it can be extended in the future, along with proper documentation.
e277cb3
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a serialization inconsistency between sparse and nullable substreams in Tuple columns that could lead to corrupted parts or crashes during reading. This addresses #91851 . @Algunenano Could you please help check if this can fix the stress test in private repo? @CurtizJ Could you also help take a look please? Thanks!
Documentation entry for user-facing changes