MDEV-39603 Convert HASH interface from uchar* to void*#5098
Conversation
|
Alexey Botchkov seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
There was a problem hiding this comment.
Code Review
This pull request refactors various hash-related functions across the codebase to use void* instead of uchar* for keys and data, improving type consistency. The review feedback suggests using static_cast instead of C-style casts for pointer conversions and removing redundant reinterpret_cast operations to improve code readability and safety.
|
Nice!
Could, as a separate PR - prefix this test with: Overall the gemini code assist has some reasonable suggestions. I think not trap future coders, show of the good example, and simplify the merge if the majority of this can be backported to 10.11. There's some features that you've patches that exist in later versions - json_schema, json_array_intersect, hnsw that can be PRs against the versions where they where added (rounded up to currently maintained versions like 11.4, 11.8, 12.3, main) as draft, and we'll wait for the main HASH interface to merge up to those branches before merging. |
gkodinov
left a comment
There was a problem hiding this comment.
Thank you for your contribution! This is a preliminary review.
Please merge all of your 3 commits into a single one.
And there are some further cleanups below to consider.
Also, if you are using any AI tool that requires attribution, please add a "Co-Authored-by:" mention for it in the commit message.
|
(requested reviewers for after the initial drafting and 10.11-rebasing) |
Thanks for your feedback! I will review my changes to make sure they can be backported to 10.11 |
Thank you for your feedback! I will merge my commits into one and attribute AI in my next commit |
FYI: We prefer single squashed commits over multiple commits for various iterations.
It’s probably easier to open separate PRs split from this commit for each base branch. P.S. Whoops, I forgot to switch accounts. |
The HASH interface used uchar* as a generic pointer type for storing and retrieving arbitrary record types. This forced every caller to cast through (uchar*) or reinterpret_cast<const uchar*> when inserting, deleting, or implementing get_key callbacks. Change my_hash_get_key typedef return from const uchar* to const void*, HASH_LINK.data from uchar* to void*, and all function signatures for insert/delete/update/replace/element/search/first/next to use void* for record pointers. Update all ~50 get_key callback implementations to return const void* and remove unnecessary casts. Key byte-buffer parameters (const uchar *key in my_hash_search, my_hash_first, my_hash_next) are left unchanged since they represent actual byte data used for hashing and comparison. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request executes a comprehensive refactoring of the HASH utility and its consumers by transitioning key and record pointers from uchar* to void*. This architectural cleanup spans the entire codebase, including the server core, client libraries, and multiple storage engines like Aria, Spider, and Performance Schema. By standardizing on void*, the PR successfully eliminates a significant amount of legacy casting boilerplate, resulting in cleaner and more maintainable code. I have no feedback to provide.
|
@ParadoxV5 I changed the target branch from @grooverdan
These will be submitted as PRs against their respective branches. @gkodinov I have modified all C-style casts per Gemini's review. I re-requested its review and it looks ok now. Note: I renamed this PR title and my commit to target Thank you all! |
Summary
my_hash_get_keytypedef return type fromconst uchar *toconst void *HASH_LINK.datafromuchar *tovoid *my_hash_insert,my_hash_delete,my_hash_update,my_hash_replace,my_hash_element,my_hash_search,my_hash_first,my_hash_first_from_hash_value, andmy_hash_nextto usevoid *const void *reinterpret_cast<const uchar *>casts at callback return sites and caller insert/delete sitesMotivation
The HASH interface used
uchar *as a generic pointer type for storing and retrieving arbitrary record types. This forced every caller to cast through(uchar *)orreinterpret_cast<const uchar *>when inserting, deleting, or implementing get_key callbacks — adding noise with no type safety benefit.Converting to
void *leverages implicit pointer conversion in C and well-defined static_cast in C++, making the intent clearer at every call site.Key byte-buffer parameters (
const uchar *keyinmy_hash_search,my_hash_first,my_hash_next, and themy_hash_functiontypedef) are leftunchanged since they represent actual byte data used for hashing and comparison.
How can this PR be tested?
No new MTR tests are added since this is a refactor and we only need to make sure all functionalities are unchanged.
MTR test run with these cmd (Need to run as a non-root user as test
roles.set_default_role_invalid_skip_name_resolvewould fail when running as root user):Before rebasing to 10.11
After rebasing to 10.11
I got some tests on main failed due to
mysql_old_passwordnot found or TLS/SSL error. This is probably due to my Docker env usingOpenSSL 3.6.2 7 Apr 2026 (Library: OpenSSL 3.6.2 7 Apr 2026)(which disables legacy TLS), and these shouldn't be caused by my hash changesThe servers were restarted 243 times Spent 730.695 of 176 seconds executing testcases Completed: Failed 9/1106 tests, 99.19% were successful. Failing test(s): main.connect main.ssl_7937 main.ssl_system_ca main.tls_version1 main.tls_version main.change_user main.set_password main.socket_conflictBasing the PR against the correct MariaDB version
Copyright
All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc.