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

RowInterner::size() much too low for high cardinality dictionary columns #4645

Closed
alamb opened this issue Aug 4, 2023 · 2 comments · Fixed by #4646
Closed

RowInterner::size() much too low for high cardinality dictionary columns #4645

alamb opened this issue Aug 4, 2023 · 2 comments · Fixed by #4646
Assignees
Labels
arrow Changes to the arrow crate bug

Comments

@alamb
Copy link
Contributor

alamb commented Aug 4, 2023

Describe the bug
When merging GB of high cardinality dictionary data, the size reported by the RowInterner is a signficiant (GB) undercount

This leads to our system to significant exceed its configured memory limit in several cases.

I believe the bug is that the Bucket::size() does not account for size of embedded Bucket in Slot. I will make a PR shortly

To Reproduce
I can reproduce this when merge GB of high cardinality proprietary dictionary encoded data

I tried to make a unit test but I could not figure out how to. Any thoughts would be appreciated

    #[test]
    fn test_intern_sizes() {
        let mut interner = OrderPreservingInterner::default();

        // Intern a 1M values each 10 bytes large, and the interner
        // should report at least 10MB bytes
        // ...
        let num_items = 3000;
        let mut values: Vec<usize> = (0..num_items).collect();
        values.reverse();

        interner.intern(values.iter().map(|v| Some(v.to_be_bytes())));
        let actual_size = interner.size();
        let min_expected_size =
            // at least space for each item
            num_items * std::mem::size_of::<usize>()
            // at least one slot for each item
            + num_items * std::mem::size_of::<Slot>();

        println!("Actual size: {actual_size}, min {min_expected_size}");

        assert!(actual_size > min_expected_size,
                "actual_size {actual_size} not larger than min_expected_size: {min_expected_size}")
    }

Expected behavior

Additional context
I found this while testing apache/datafusion#7130 with our internal data -- it did not reduce memory requirements the way I expected. I tracked the root cause down to this

@alamb alamb added bug arrow Changes to the arrow crate labels Aug 4, 2023
@alamb alamb changed the title RowInterner::size() too low for high cardinality dictionary columns RowInterner::size() much too low for high cardinality dictionary columns Aug 4, 2023
@tustvold
Copy link
Contributor

tustvold commented Aug 5, 2023

Intern will sort the input data, so if you're trying to get it to fail to allocate keys efficiently, you likely will need to make separate calls to intern with out of order data

@alamb
Copy link
Contributor Author

alamb commented Aug 5, 2023

you likely will need to make separate calls to intern with out of order data

Ah, this is probably what I missed -- I passed in non ordered data but a a single call to intern -- I will try with different calls

@alamb alamb self-assigned this Aug 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants