Description:
1. create table and insert values
create table t1 (enum_col enum('aaa','bbb','ccc'),datetime_col datetime(6),tinyint_col tinyint);
insert into t1 values ("ccc","9999-12-31 23:59:59.000000",-128);
insert into t1 values (NULL,"1998-09-02 13:20:00.000000",NULL);
2. create list partition table
create table t2 like t1;
insert into t2 select * from t1;
alter table t2 partition by list (weekday(`datetime_col`)) (
PARTITION Holidays VALUES IN (0,6),
PARTITION Single VALUES IN (1,3,5),
PARTITION Multiple VALUES IN (2,4));
3. run query with no-partitioned table t1.(Query results are marked as Result1)
mysql> WITH cte1 AS ( SELECT enum_col, datetime_col FROM t1 ), cte2 AS ( SELECT c1.enum_col, B.datetime_col FROM t1 B LEFT JOIN cte1 c1 ON B.enum_col WHERE c1.datetime_col IS NULL ) SELECT * FROM cte2 GROUP BY 1, 2;
+----------+----------------------------+
| enum_col | datetime_col |
+----------+----------------------------+
| NULL | 1998-09-02 13:20:00.000000 |
+----------+----------------------------+
1 row in set (0.00 sec)
4. run query with list partition table t2.(Query results are marked as Result2)
mysql> WITH cte1 AS ( SELECT enum_col, datetime_col FROM t2 ), cte2 AS ( SELECT c1.enum_col, B.datetime_col FROM t2 B LEFT JOIN cte1 c1 ON B.enum_col WHERE c1.datetime_col IS NULL ) SELECT * FROM cte2 GROUP BY 1, 2;
+----------+----------------------------+
| enum_col | datetime_col |
+----------+----------------------------+
| NULL | 9999-12-31 23:59:59.000000 |
| NULL | 1998-09-02 13:20:00.000000 |
+----------+----------------------------+
2 rows in set (0.01 sec)
5. Result1 is different with Resutl2 and Result2 is incorrect.
How to repeat:
create table t1 (enum_col enum('aaa','bbb','ccc'),datetime_col datetime(6),tinyint_col tinyint);
insert into t1 values ("ccc","9999-12-31 23:59:59.000000",-128);
insert into t1 values (NULL,"1998-09-02 13:20:00.000000",NULL);
create table t2 like t1;
insert into t2 select * from t1;
alter table t2 partition by list (weekday(`datetime_col`)) (
PARTITION Holidays VALUES IN (0,6),
PARTITION Single VALUES IN (1,3,5),
PARTITION Multiple VALUES IN (2,4));
WITH cte1 AS ( SELECT enum_col, datetime_col FROM t1 ), cte2 AS ( SELECT c1.enum_col, B.datetime_col FROM t1 B LEFT JOIN cte1 c1 ON B.enum_col WHERE c1.datetime_col IS NULL ) SELECT * FROM cte2 GROUP BY 1, 2;
WITH cte1 AS ( SELECT enum_col, datetime_col FROM t2 ), cte2 AS ( SELECT c1.enum_col, B.datetime_col FROM t2 B LEFT JOIN cte1 c1 ON B.enum_col WHERE c1.datetime_col IS NULL ) SELECT * FROM cte2 GROUP BY 1, 2;
Suggested fix:
No