MDEV-34646 Be more helpful on unknown parameter messages #4303
+792
−27
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.
Description
The previous "unknown variable" error message did not provide details about why the input variable was invalid. For example, entering an incorrect variable name such as innobdb_lock_wait_timeout would produce the following error:
ERROR HY000: Unknown system variable 'innobdb_lock_wait_timeout=1000'
This commits uses Levenshtein algorithm to calculate the closest matching system variable when an invalid name is provided. Levenshtein distance represents the minimum number of single-character edits (insertions, deletions, or replacements) required to transform one string into another, effectively measuring their similarity. More details can be found here:
https://www.geeksforgeeks.org/dsa/introduction-to-levenshtein-distance/
With the improvement, the error message becomes more user-friendly. For example:
ERROR HY000: Unknown system variable 'innobdb_lock_wait_timeout', did you mean 'innodb_lock_wait_timeout'?
This improvement has been applied to all 19 supported languages for system variables.
Since Levenshtein algorithm use O(n^2) space to create matrix. Input variable was truncated to the longest length of options to reduce overusing of space.
Similar changes have also been applied to options when user starts the database with mariadbd.
How can this PR be tested?
Execute the main suite in mysql-test-run.
Basing the PR against the correct MariaDB version
Backward compatibility
This is a new feature introducing more friendly error message without changing existing behaviors. It is compatible with previous versions.
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.