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

feat: use u64 hash in buffer index instead of str literal #25883

Merged
merged 2 commits into from
Jan 21, 2025

Conversation

hiltontj
Copy link
Contributor

Closes #25875

@hiltontj hiltontj requested a review from a team January 21, 2025 02:13
@hiltontj hiltontj self-assigned this Jan 21, 2025
@hiltontj hiltontj force-pushed the hiltontj/xxhash-buffer-index branch from 47d7831 to 732874a Compare January 21, 2025 13:26
@hiltontj
Copy link
Contributor Author

I made a couple of QoL improvements in 732874a in addition to moving the call to hash the row value after the check to see if it is an indexed column.

Copy link
Contributor

@praveen-influx praveen-influx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good - I can generally follow the code, I guess because we need to keep a tab on the actual hashes (Hashset<u64>?) outside the HashMap, we are not passing the hasher function through Hashmap::with_hasher?

@hiltontj
Copy link
Contributor Author

Looks good - I can generally follow the code, I guess because we need to keep a tab on the actual hashes (Hashset<u64>?) outside the HashMap, we are not passing the hasher function through Hashmap::with_hasher?

By HashSet<u64> are you referring to the HashSet<usize>? If so, that is the set of row indexes, so we don't use the XX Hasher there - I think we need to use a cryptographically secure hash on that, because the row indices that a given value falls into needs to be correct.

The XX hasher is only for taking the values, which are originally string literals, and converting them to a u64, so that they are moved around, stored, and compared more cheaply.

The previous structure of BufferIndex was:

BufferIndex {
    Column ID -> string literal -> Set of Indexes from the table buffer
}

This changes it to

BufferIndex {
    Column ID -> u64 hash of string literal -> Set of Indexes from the table buffer
}

Consequently, by using XX Hash, there is a chance of hash collisions (though unlikely), but that is acceptable in this case, because the result would be that the buffer produces excess rows, which DataFusion will filter out.

@praveen-influx
Copy link
Contributor

The XX hasher is only for taking the values, which are originally string literals, and converting them to a u64

I see - got it. Happy for it to be merged.

@hiltontj hiltontj merged commit d1fd155 into main Jan 21, 2025
13 checks passed
@hiltontj hiltontj deleted the hiltontj/xxhash-buffer-index branch January 21, 2025 14:09
@pauldix
Copy link
Member

pauldix commented Jan 21, 2025

We shouldn't be hashing the row indexes, they're already in the optimal type for doing set union and intersections on them, as long as they're sorted.

@hiltontj
Copy link
Contributor Author

We shouldn't be hashing the row indexes, they're already in the optimal type for doing set union and intersections on them, as long as they're sorted.

@pauldix Ah, my changing to a HashSet<usize> to hold row indices in #25866 could be an issue if keeping them in sorted order is important. Previously it was a Vec<usize> which would keep the rows in the order in which they are added - which would be sorted order.

If that is important, we could switch to use an IndexSet.

@pauldix
Copy link
Member

pauldix commented Jan 21, 2025

Yeah, since the rows always arrive in order (i.e. every row added is always > than any row before) and they're never added to an entry more than once, it's wasteful to use a set rather than just appending to a vec. And doing set operations on two sorted vecs is generally as fast as it gets. No reason to use a hash set.

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

Successfully merging this pull request may close these issues.

Use a XXHash of literals in BufferFilter and BufferIndex
3 participants