1
0
mirror of https://github.com/MariaDB/server.git synced 2026-01-06 05:22:24 +03:00
Files
mariadb/sql
Monty 16258677b3 MDEV-6768 Wrong result with aggregate with join with no result set
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.

What happens in the 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. However fields are not set
to NULL.

The used fix is to produce NULL-complemented records for constant tables
as well. Also, reset the constant table's records back in case we're
in a subquery which may get re-executed.
An alternative fix would have item->no_rows_in_result() also work
with Item_field objects.

There is some other issues with the code:
- 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.
- unclear_tables() does not correctly restore status to what is
  was before clear_tables().

Main bug fix was to always use a table_map argument to clear_tables() and
always use join->clear() and clear_tables() together with unclear_tables().

Other 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 code 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.

Reviewer: Sergei Petrunia <sergey@mariadb.com>
2023-05-22 17:15:46 +03:00
..
2023-02-10 12:02:11 +02:00
2020-04-08 14:51:14 +04:00
2022-09-05 13:28:56 +03:00
2023-01-27 13:54:14 +01:00
2020-08-03 14:44:06 +02:00
2021-04-20 12:30:09 +03:00
2022-03-23 10:47:27 +11:00
2023-04-03 09:34:26 +02:00
2020-06-10 07:43:18 +03:00
2020-08-04 17:24:15 +02:00
2023-01-27 13:54:14 +01:00
2020-08-03 14:44:06 +02:00
2023-02-10 12:02:11 +02:00
2021-04-22 08:25:40 +03:00
2022-04-21 15:33:50 +03:00
2022-09-26 13:34:38 +03:00
2021-06-21 14:22:22 +03:00
2022-09-05 13:28:56 +03:00
2020-08-03 14:44:06 +02:00
2020-07-15 14:51:22 +03:00
2023-02-10 12:02:11 +02:00
2022-09-26 13:34:38 +03:00
2023-02-10 12:02:11 +02:00
2023-01-27 13:54:14 +01:00
2020-10-30 11:15:30 +02:00
2023-02-10 12:02:11 +02:00
2023-02-10 12:02:11 +02:00
2023-02-10 12:02:11 +02:00
2023-02-10 12:02:11 +02:00
2023-02-10 12:02:11 +02:00
2023-02-10 12:02:11 +02:00
2023-02-10 12:02:11 +02:00
2021-03-31 11:05:21 +03:00
2023-01-27 13:54:14 +01:00
2023-02-10 12:02:11 +02:00
2023-02-10 12:02:11 +02:00
2021-10-28 08:48:36 +03:00
2020-10-30 11:15:30 +02:00
2021-10-13 12:03:32 +03:00
2020-08-01 14:42:51 +03:00
2020-08-04 17:24:15 +02:00
2020-11-03 16:24:47 +02:00
2021-07-02 13:02:26 +03:00
2022-09-05 13:28:56 +03:00
2020-09-04 18:44:44 +03:00
2023-04-27 09:39:53 +03:00
2023-02-10 12:02:11 +02:00
2023-02-10 12:02:11 +02:00
2023-02-10 12:02:11 +02:00
2020-11-02 15:48:47 +02:00
2021-04-21 07:25:48 +03:00
2020-11-03 14:49:17 +02:00
2021-11-16 14:26:13 +02:00
2023-02-10 12:02:11 +02:00
2023-04-27 09:39:53 +03:00
2022-09-26 13:34:38 +03:00
2020-05-30 11:04:27 +03:00
2023-04-24 12:43:47 +02:00
2023-02-10 12:02:11 +02:00
2023-05-03 15:53:14 +02:00
2022-06-09 12:22:55 +03:00
2020-04-08 10:36:41 +03:00
2022-10-02 14:38:13 +02:00
2022-12-13 14:39:18 +02:00
2023-02-10 12:02:11 +02:00
2022-10-25 11:26:37 +03:00
2022-02-01 20:33:04 +01:00
2023-02-10 12:02:11 +02:00
2022-09-26 13:34:38 +03:00
2020-08-10 21:38:55 +03:00
2022-02-01 20:33:04 +01:00
2020-09-03 09:26:54 +03:00
2022-05-09 22:04:06 +02:00
2023-02-10 12:02:11 +02:00
2023-02-10 12:02:11 +02:00
2021-10-21 15:26:25 +03:00
2021-10-21 14:57:00 +03:00
2023-02-10 12:02:11 +02:00
2020-10-30 11:15:30 +02:00
2023-02-10 12:02:11 +02:00
2023-02-10 12:02:11 +02:00
2023-05-02 10:09:27 +02:00
2022-05-09 22:04:06 +02:00
2023-02-10 12:02:11 +02:00
2022-09-20 13:17:02 +03:00
2023-02-10 12:02:11 +02:00
2022-12-13 14:39:18 +02:00
2023-02-10 12:02:11 +02:00
2023-02-10 12:02:11 +02:00
2023-01-28 18:22:55 +01:00
2023-01-27 13:54:14 +01:00
2023-02-10 12:02:11 +02:00
2022-10-05 10:09:49 +03:00
2022-09-20 13:17:02 +03:00
2021-08-18 18:22:35 +03:00
2023-02-10 12:02:11 +02:00
2022-09-26 13:34:38 +03:00
2023-02-10 12:02:11 +02:00
2022-08-02 16:35:15 +10:00
2023-02-10 12:02:11 +02:00
2023-02-10 12:02:11 +02:00
2023-01-03 17:08:42 +02:00
2022-11-30 13:10:52 +02:00
2023-01-28 18:22:55 +01:00
2023-01-28 18:22:55 +01:00
2023-02-10 12:02:11 +02:00
2023-04-24 12:43:47 +02:00
2021-06-30 18:41:46 +03:00
2023-02-10 12:02:11 +02:00
2023-02-10 12:02:11 +02:00
2022-05-09 22:04:06 +02:00
2021-01-06 10:53:00 +01:00
2023-05-04 18:19:47 +02:00
2023-01-13 10:18:30 +02:00
2023-01-28 18:22:55 +01:00
2022-05-09 22:04:06 +02:00
2021-03-05 12:54:43 +02:00
2022-09-05 13:28:56 +03:00
2023-01-27 13:54:14 +01:00
2023-02-10 12:02:11 +02:00
2023-02-10 12:02:11 +02:00
2022-09-05 13:28:56 +03:00
2022-09-05 13:28:56 +03:00
2021-04-20 12:30:09 +03:00
2023-02-10 12:02:11 +02:00
2021-02-23 09:25:57 +01:00
2023-04-24 12:43:47 +02:00
2023-01-27 13:54:14 +01:00
2022-10-25 11:26:37 +03:00
2020-07-31 18:09:08 +03:00
2022-10-02 14:38:13 +02:00
2021-09-17 19:57:13 +03:00
2022-11-08 17:01:28 +02:00
2021-04-21 09:01:01 +03:00
2022-09-26 13:34:38 +03:00
2020-10-22 13:27:18 +03:00
2023-02-10 12:02:11 +02:00
2022-08-10 12:24:31 +02:00
2023-04-27 09:39:53 +03:00
2022-02-01 20:33:04 +01:00
2023-05-04 18:19:47 +02:00
2023-02-10 12:02:11 +02:00
2023-02-10 12:02:11 +02:00
2021-07-02 13:02:26 +03:00
2023-02-10 12:02:11 +02:00
2023-02-10 12:02:11 +02:00
2020-06-14 10:13:53 +03:00
2020-06-14 10:13:53 +03:00
2022-03-29 12:59:18 +03:00
2023-01-03 17:08:42 +02:00
2023-02-10 12:02:11 +02:00
2020-07-15 09:49:48 +02:00
2020-12-01 14:55:46 +02:00
2022-09-05 13:28:56 +03:00
2020-11-11 07:37:05 +02:00
2022-11-30 13:10:52 +02:00
2023-01-27 13:54:14 +01:00
2022-06-27 10:14:37 +03:00
2020-08-26 12:02:07 +03:00
2022-04-21 11:33:59 +03:00
2022-11-30 13:10:52 +02:00
2021-04-08 07:47:49 +03:00