Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
monadbobo opened this issue Nov 3, 2021 · 2 comments

Comments

@monadbobo
Copy link

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
        }
    }
@suharev7
Copy link
Owner

suharev7 commented Nov 3, 2021

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:

@monadbobo
Copy link
Author

Thank you very much for your answer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants