Make ASTSelectQuery::formatImpl() more robust #46889
Merged
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.
Fixes #45204
The problem is that
ASTSelectQuery::group_by_with_grouping_sets == true
should implyASTSelectQuery::groupBy()
but sometimes this wasn't the case. I added a sanity check a few months ago but had no idea how the AST became corrupt.All crashes/exceptions were during AST fuzzing. Looking at Client/QueryFuzzer.cpp, there is a very small chance to run into the issue. In detail:
In
QueryFuzzer::fuzz()
, we find that the AST is aASTSelectQuery
andgroupBy()
returns true.With small probability, we do
select->group_by_with_grouping_sets = !select->group_by_with_grouping_sets;
where the (default false)group_by_with_grouping_sets
flips true.With small probability, we change the expression type in the following WHERE or PREWHERE if-branches.
This situation is illegal. One possibility is changing the fuzzing code to not generate it. The fuzzing code is however generic, and doesn't really care about such details. Therefore, instead add an (theoretically unnecessary) extra check to
ASTSelectQuery::formatImpl()
for robustness.Changelog category (leave one):