Bug #101105 Incorrect grouping by GROUP BY with timezone
Description:
From MySQL 8.0.20 and later version, I can see regression on a select group by sentences would not work correctly when specifying a timezone, the result returns duplicate dates.
Previous releases work fine.
How to repeat:
Prepare environment:
Apply attached SQL file.
Exec query, it's return expected output:
```
mysql> set time_zone = 'UTC';
mysql> select date(from_unixtime(date_received)) as `dt`, count(distinct pid) FROM test2 GROUP by `dt`;
+------------+---------------------+
| dt | count(distinct pid) |
+------------+---------------------+
| 2020-07-30 | 10 |
| 2020-07-31 | 10 |
| 2020-08-01 | 10 |
| 2020-08-02 | 10 |
+------------+---------------------+
4 rows in set (0.00 sec)
```
But when we change timezone and exec this query it's return output with duplicate dates:
```
mysql> set time_zone = 'America/Los_Angeles';
mysql> select date(from_unixtime(date_received)) as `dt`, count(distinct pid) FROM test2 GROUP by `dt`;
+------------+---------------------+
| dt | count(distinct pid) |
+------------+---------------------+
| 2020-07-30 | 3 |
| 2020-07-29 | 2 |
| 2020-07-30 | 2 |
| 2020-07-29 | 1 |
| 2020-07-30 | 1 |
| 2020-07-29 | 1 |
| 2020-07-30 | 1 |
| 2020-07-29 | 1 |
| 2020-07-30 | 1 |
| 2020-07-29 | 2 |
| 2020-07-30 | 7 |
| 2020-07-29 | 3 |
| 2020-07-30 | 2 |
| 2020-07-29 | 10 |
| 2020-07-30 | 1 |
| 2020-07-29 | 6 |
| 2020-07-30 | 1 |
| 2020-07-29 | 10 |
| 2020-07-30 | 10 |
| 2020-07-31 | 2 |
| 2020-07-30 | 1 |
| 2020-07-31 | 1 |
| 2020-07-30 | 1 |
| 2020-07-31 | 2 |
| 2020-07-30 | 2 |
| 2020-07-31 | 2 |
| 2020-07-30 | 2 |
| 2020-07-31 | 1 |
| 2020-07-30 | 1 |
| 2020-07-31 | 2 |
| 2020-07-30 | 1 |
| 2020-07-31 | 2 |
| 2020-07-30 | 10 |
| 2020-07-31 | 10 |
| 2020-08-01 | 4 |
| 2020-07-31 | 2 |
| 2020-08-01 | 1 |
| 2020-07-31 | 1 |
| 2020-08-01 | 5 |
| 2020-07-31 | 1 |
| 2020-08-01 | 1 |
| 2020-07-31 | 2 |
| 2020-08-01 | 2 |
| 2020-07-31 | 10 |
| 2020-08-01 | 1 |
| 2020-07-31 | 10 |
| 2020-08-01 | 10 |
+------------+---------------------+
47 rows in set (0.01 sec)
```
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.058 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.