clickhouse-rs icon indicating copy to clipboard operation
clickhouse-rs copied to clipboard

Questions about whether the with_capacity method of the Block interface is valid

Open monadbobo opened this issue 4 years ago • 2 comments

I read the code of clickhouse-rs and found that after setting the capacity in Block::with_capacity, the later code does not use it. Shouldn't this be changed here?

    /// Constructs a new, empty `Block` with the specified capacity.
    pub fn with_capacity(capacity: usize) -> Self {
        Self {
            info: Default::default(),
            columns: Vec::with_capacity(capacity),
            capacity
        }
    }

monadbobo avatar Nov 03 '21 07:11 monadbobo

The size field stores the estimated number of rows, not columns. This is reasonable because, in practice, the number of rows in blocks is usually much larger than the number of columns, and reducing unnecessary allocations when adding rows can significantly improve performance. These are the places where this field is used:

suharev7 avatar Nov 03 '21 16:11 suharev7

Thank you very much for your answer.

monadbobo avatar Nov 04 '21 12:11 monadbobo