-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
sql/handler: referenced_by_foreign_key() returns bool #3530
sql/handler: referenced_by_foreign_key() returns bool #3530
Conversation
I don't understand the buildbot/amd64-debian-11-msan failure and I assume it's not related to this change. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that this code was added a long time ago in e2646f0 as part of an ACID breaking hack that was removed in 1bd681c. The creator of InnoDB preferred C to C++, and in C at that time there was no Boolean data type.
I think that a trivial mechanical change like this had better be applied to the oldest supported major version branch, which currently is 10.5. It would also be good to file an MDEV ticket for this at https://jira.mariadb.org, like our pull request template encourages you to do.
sql/ha_partition.h
Outdated
virtual int get_foreign_key_list(THD *thd, | ||
List<FOREIGN_KEY_INFO> *f_key_list) | ||
virtual uint referenced_by_foreign_key() | ||
virtual bool referenced_by_foreign_key() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It’s nice that you are updating this comment to be consistent with your change. I’d suggest to make it even more consistent, by removing the virtual
and adding override
.
sql/handler.h
Outdated
virtual int | ||
get_parent_foreign_key_list(const THD *thd, List<FOREIGN_KEY_INFO> *f_key_list) | ||
{ return 0; } | ||
virtual uint referenced_by_foreign_key() { return 0;} | ||
virtual bool referenced_by_foreign_key() { return false;} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While you are changing this, I would suggest that you also add const
qualifiers and change also the int
return type to void
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually, I avoid doing two unrelated things in one commit, and I'm not sure if it's possible to add const
in all implementations. But if you say so, I'll amend the commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only InnoDB supports foreign keys, and both member functions are related to that. Actually, also handler::get_foreign_key_list()
should return void
.
More than a decade ago, there was another storage engine PBXT that supported FOREIGN KEY
constraints, but it seems that they did not switch to MariaDB when Oracle changes policies around MySQL.
There is a thin wrapper in Mroonga that would invoke InnoDB, and in fact it does not look like the macro MRN_SET_WRAP_TABLE_KEY
would be const
compatible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the return value of get_foreign_key_list()
is not needed to signal error conditions, why not just return the List<>
from it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking the same, but that collection is actually allocated by the caller, typically from the stack. Only in the rare case that FOREIGN KEY
constraints exist, some heap memory could be allocated and attached to the object. I assume that there are specific reasons why the custom List
template is being used instead of something like std::list
or the C++11 std::forward_list
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But what is really being allocated for List
? It's a trivial class that contains just three fields: two pointers and an integer. Nothing is allocated until something gets pushed to the list (except for 24 bytes of stack space, which is always needed, no matter how you pass it).
For the generated machine code, there's no fundamental difference whether you pass it as a reference parameter or as return value - in both cases, the caller allocates stack space. For the coding style, it makes a big difference because now your List
is truly declared as a return value, and not as some sort of out-parameter kludge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may very well be right. I usually don’t write functions that would return more than would fit in a single register; page_id_t
would be an exception on 32-bit targets. This should be easy to check with https://godbolt.org. Feel free to change the return type. There might be some additional overhead in the Mroonga call wrapper, but that storage engine is hardly maintained or used. Even that overhead should be rather negligible, assuming that the List
is simply copied byte by byte, without any deep-copy constructor.
In https://ci.mariadb.org/50358/logs/amd64-debian-11-msan/var.tar.gz the file
It looks like nothing was happening for almost 4 minutes. The In case you are interested, there are many other builders that for some reason do not report any status to GitHub but are aggregated in the Buildbot grid view. |
6011698
to
23a9d39
Compare
|
Rebased on 10.5 and added @dr-m, do you want me to write a JIRA ticket for this? |
23a9d39
to
e45c915
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, this looks OK to me, with one minor nitpick.
I don’t know if filing a MDEV for this is mandatory.
The method was declared to return an unsigned integer, but it is really a boolean (and used as such by all callers). A secondary change is the addition of "const" and "noexcept" to this method. In ha_mroonga.cpp, I also added "inline" to the two helper methods of referenced_by_foreign_key(). This allows the compiler to flatten the method.
e45c915
to
e1ff5d3
Compare
@MaxKellermann, I understood that it is not needed to file an MDEV for a trivial change like this, which does not need to appear in the release notes. However, it looks like you haven’t signed a contributor agreement or declared that these changes are under the BSD-new license; see the FAQ. |
I did, and the check succeeded on my other PRs. I think this is a bug in the CLA check bot. |
Oh, sorry, I see that the CLA check is actually complaining about myself. I have not signed the CLA but something equivalent. So, this should be ready to merge. |
Description
The method was declared to return an unsigned integer, but it is really a boolean (and used as such by all callers).
Release Notes
No runtime change.
How can this PR be tested?
No runtime change.
Basing the PR against the correct MariaDB version
main
branch.PR quality check