Skip to content

Instantly share code, notes, and snippets.

@spetrunia
Created April 4, 2023 11:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spetrunia/8ed17ea6e2880245b7ea2affc601662b to your computer and use it in GitHub Desktop.
Save spetrunia/8ed17ea6e2880245b7ea2affc601662b to your computer and use it in GitHub Desktop.
> commit a49d2e4bc62507496b85c3499a423b5b4e321354
> Author: Monty <monty@mariadb.org>
> Date: Fri Mar 31 19:35:04 2023 +0300
>
> MDEV-6768 Wrong result with aggregate with join with no result set
>
> What happens is that end_send_group() is called with a const row but
> without any rows matching the WHERE clause.
> This last part is shown by 'join->first_record' not being set.
>
> This causes item->no_rows_in_result() to be called for all items to reset
> all sum functions to their initial state.
The above doesn't describe what the bug was about, does it?
The problem was as follows:
When a query does implicit grouping and join operation produces an empty
result set, a NULL-complemented row combination is generated.
However, constant table fields still show non-NULL values.
Fix the code to produce NULL-complemented records for constant tables as well.
(And also, reset the constant table's records back in case we're in a subquery
which may get re-executed).
>
> There is some other issues with the code:
> - Item_field::no_rows_in_result_set() does not do anything, which causes
> the fields in constants rows read from tables to be returned in the
> result set.
It is called no_rows_in_result(). And we do not consider this to be a problem...
> - join->no_rows_in_result_called is used but never set.
> - Tables that are used with group functions are not properly marked as
> maybe_null, which is required if the table rows should be regarded as
> null-complemented (not existing).
> - The code that tries to detect if mixed_implicit_grouping should be set
> didn't take into account all usage of fields and sum functions.
> - Item_func::restore_to_before_no_rows_in_result() called the wrong
> function.
> - join->clear() does not use a table_map argument to clear_tables()
> which caused it to ignore constant tables.
> - join->unclear() does not correctly restore status to what is
> was before join->clear()
There is/was no join->unclear(). You've meant unclear_tables()?
> Fixed by always use a table_map argument to clear_tables() and always use
> join->clear() and join->unclear() together.
same as above, no join->unclear(). unclear_tables() ?
>
> Other bug fixes:
"More comments" and "Changed return_zero_rows() are technically not "bug fixes".
Please change "bug fixes" to "fixes".
> - Fixed Item_func::restore_to_before_no_rows_in_result()
> - Set 'join->no_rows_in_result_called' when no_rows_in_result_set()
> is called.
> - Removed not used argument from setup_end_select_func().
> - More comments
> - Ensure that end_send_group() modifies the same fields as are in the
> result set.
> - Changed return_zero_rows() to use pointers instead of references,
> similar to the rest of the code.
>
>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment