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

sql/handler: referenced_by_foreign_key() returns bool #3530

Merged
merged 3 commits into from
Sep 30, 2024

Conversation

MaxKellermann
Copy link
Contributor

  • The Jira issue number for this PR is: MDEV-______

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

  • This is a new feature or a refactoring, and the PR is based against the main branch.
  • This is a bug fix, and the PR is based against the earliest maintained branch in which the bug can be reproduced.

PR quality check

  • I checked the CODING_STANDARDS.md file and my PR conforms to this where appropriate.
  • For any trivial modifications to the PR, I am ok with the reviewer making the changes themselves.

@MaxKellermann
Copy link
Contributor Author

I don't understand the buildbot/amd64-debian-11-msan failure and I assume it's not related to this change.

Copy link
Contributor

@dr-m dr-m left a 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.

Comment on lines 1466 to 1468
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()
Copy link
Contributor

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
Comment on lines 4552 to 4555
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;}
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@dr-m
Copy link
Contributor

dr-m commented Sep 20, 2024

I don't understand the buildbot/amd64-debian-11-msan failure and I assume it's not related to this change.

In https://ci.mariadb.org/50358/logs/amd64-debian-11-msan/var.tar.gz the file mysql-test/var/35/log/mysqld.1.errcontains the following, which looks like there was a hang.

2024-09-20  7:46:59 0 [Note] Plugin 'parsec' is disabled.
2024-09-20  7:46:59 0 [Note] Plugin 'wsrep_provider' is disabled.
2024-09-20  7:46:59 0 [Warning] /home/buildbot/amd64-debian-11-msan/build/sql/mariadbd: unknown option '--loose-pam-debug'
2024-09-20  7:46:59 0 [Warning] /home/buildbot/amd64-debian-11-msan/build/sql/mariadbd: unknown option '--loose-aria'
2024-09-20  7:46:59 0 [Warning] /home/buildbot/amd64-debian-11-msan/build/sql/mariadbd: unknown option '--loose-enable-named-pipe'
CURRENT_TEST: perfschema.table_lock_aggregate_hist_2u_3t
$ /home/buildbot/amd64-debian-11-msan/build/sql/mariadbd --defaults-group-suffix=.1 --defaults-file=/home/buildbot/amd64-debian-11-msan/build/mysql-test/var/35/my.cnf --log-output=file --core-file --loose-debug-sync-timeout=300
2024-09-20  7:50:20 0 [Warning] Could not increase number of max_open_files to more than 1024 (request: 32310)

It looks like nothing was happening for almost 4 minutes. The mariadbd process was killed and a new one (for a different test) started. Unfortunately, the mtr test driver does not always produce core dumps or stack traces for hangs. Maybe @vuvova can comment on that. In any case, it definitely is unrelated to your change.

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.

@CLAassistant
Copy link

CLAassistant commented Sep 23, 2024

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ MaxKellermann
❌ dr-m
You have signed the CLA already but the status is still pending? Let us recheck it.

@MaxKellermann MaxKellermann changed the base branch from main to 10.5 September 23, 2024 07:04
@MaxKellermann
Copy link
Contributor Author

Rebased on 10.5 and added const & noexcept.
I think changing other methods to return List<> (or change the unnecessary return value to void) is out of this PR's scope.

@dr-m, do you want me to write a JIRA ticket for this?

Copy link
Contributor

@dr-m dr-m left a 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.

storage/innobase/handler/ha_innodb.cc Outdated Show resolved Hide resolved
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.
@dr-m dr-m enabled auto-merge (rebase) September 30, 2024 06:04
@dr-m dr-m disabled auto-merge September 30, 2024 06:43
@dr-m
Copy link
Contributor

dr-m commented Sep 30, 2024

@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.

@MaxKellermann
Copy link
Contributor Author

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.

@dr-m dr-m enabled auto-merge (rebase) September 30, 2024 13:07
@dr-m
Copy link
Contributor

dr-m commented Sep 30, 2024

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.

@dr-m dr-m merged commit 45298b7 into MariaDB:10.5 Sep 30, 2024
8 of 11 checks passed
@MaxKellermann MaxKellermann deleted the bool_referenced_by_foreign_key branch October 1, 2024 06:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants