Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prepared_statement: fix deserialization of compound partition keys
When PartitionKeyDeserializer wants to deserialize i-th column of the partition key, it needs to know the type of that column. It has access to PreparedMetadata of the prepared query the partition key was constructed from, which has a mapping between bind markers and types. Hence, it needs to learn to which bind marker the i-th pk column corresponds to. The `self.pk_indexes` of type `Vec<PartitionKeyIndex>` is supposed to help with that. The PartitionKeyIndex structure looks like this: pub struct PartitionKeyIndex { /// index in the serialized values pub index: u16, /// sequence number in partition key pub sequence: u16, } So, we need to find an entry `pki` with `pki.sequence == i` and `pki.index` will be the desired bind marker index. Currently, we naively look at the `self.pk_indexes[i]` entry - which is wrong. The `pk_indexes` vec is actually ordered by `index`, so we might accidentally obtain an index of the wrong partition key column this way. Although there was a test that was supposed to check this scenario, it constructed `PreparedMetadata` manually and didn't sort the `pk_indexes` by `index` field, which resulted in it accidentally passing. In order to fix this, the `PartitionKeyIndex` is now doing a linear lookup in order to find a `pki` with `pki.sequence == i`. This lookup should be fine as partition keys usually have a little number of fields. Fixes: #793
- Loading branch information