Contrib Fake PR: Implement Bug#106645: Slow query log is not logging database/schema name.#11
Draft
jfg956 wants to merge 1 commit intomysql-8.4.0_for_fake_prsfrom
Draft
Conversation
Owner
Author
Examples of Logs with and without the feature enabled |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds database / schema in the slow query log file, implementing the feature request Bug#106645: Slow query log is not logging database/schema name.
In case, at the same time as merging this contribution, it makes sense to fix Bug#115203, this PR also includes a commented fix for that bug (Empty "use ;" on replica in slow query log file).
This is a "Contrib Fake PR". It is there so people can comment on this work in case it needs adjustments. This has be contributed on 2024-07-12 as a patch file in Bug#106645. More about this in the RFC blog post, section Fake PRs and my Way of Working on MySQL Contributions.
This PR merges on 8.4.0, and the corresponding patch file applies on 8.4.1 and 9.0.0. It does not apply on 8.0.38, but the commit of this PR can be cherry-picked in a branch from the 8.0.38 tag. The mtr tests of this work pass in all of 8.0.38, 8.4.0, 8.4.1 and 9.0.0.
For implementing database / schema in the slow query log file, this PR introduces a new global variable:
log_slow_extra_db. It isONby default, and can be set toOFFto keep the current 9.0, 8.4 and 8.0 behavior (in case of changing the format of the slow query log file breaks tooling parsing the file). This variable should eventually be deprecated to reduce code complexity (I have chosen not to introduce it as deprecated, if Oracle prefers that and notifies me, I will update the PR).Ideally, in addition to being included in a next Innovation Release, this would be back-ported in 8.4 and 8.0. For back-porting, the default value of the global variable
log_slow_extra_dbshould be set tofalseto avoid a breaking change.Note that with
log_slow_extra_db = ON, alluse ...are removed from the slow query log file.Also note that with
log_slow_extra_db = ON, there is a minor change in the format of theUser@Hostline of the slow query log file. Before, it was# User@Host: %s Id: %s, withId: %sbeing a%5u. Withlog_slow_extra_db = ON, it is# User@Host: %s Id: %lu Db: %swhich is consistent with the wayThread_idis logged withlog_slow_extra. It looks like the right time to improve on the formatting of this line (adding a new field and this change being behind a feature-flag), but Oracle can revert this if they do not like it (I can adapt the PR if they ask me to).Examples of logs with and without the feature enabled in the 1st PR comment.
This PR also includes the three mtr tests below. The first two are for testing this new feature, and the last one, for adding a missing test on an existing feature (
log_slow_extra). The third test is inspired from the second, and even if this test is not directly related to this work, adding it looked like the right thing to do (and it was easy).There is a limit to this implementation, inherited from Bug#115526: Invalid multi-line "use" in slow query log file with multi-line schema. When logging a slow query in a multi-line schema, the
Dbfield is on two lines (see example in 1st PR comment). It could be escaped, but depending on how the existing bug will be fixed, this might need a rework. So I am leaving this to be addressed at the same time as Bug#115526. Also, IMHO, someone using a multi-line schema is looking for trouble, so ¯_(ツ)_/¯.While doing this work, I "played with fire" and tried improving the implementation of the function
File_query_log::write_slow. This led to four improvements, which I isolated in four different commits in the Work Branch. I will let Oracle decide if these should be included or reverted (I can adapt the PR if they ask me to).buff_lenforadministrator commandDb, makeIdformat consistent withThread_id(already mentioned above)buff_lenendclearer with better assignmentsMore JFG development notes: