Bug #117040 Inconsistent behavior for the same query on a DATETIME column with and without a PRIMARY KEY constraint.
Submitted: 24 Dec 2024 13:04 Modified: 24 Dec 2024 13:12
Reporter: wang jack Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: DML Severity:S3 (Non-critical)
Version:8.4.3, 8.0.40 OS:Windows (windows 11)
Assigned to: CPU Architecture:x86 (x86_64)

[24 Dec 2024 13:04] wang jack
Description:
I used the same table schema, except for adding and removing the PRIMARY KEY constraint on the column of type DATETIME. 
The results of the same query were inconsistent.

mysql> DROP TABLE IF EXISTS t2;
Query OK, 0 rows affected (0.02 sec)
mysql> CREATE TABLE IF NOT EXISTS t2(
    ->      c1 DATETIME PRIMARY KEY
    -> );
Query OK, 0 rows affected (0.02 sec)
mysql> INSERT INTO t2 VALUES ('0000-00-00 00:00:00');
Query OK, 1 row affected (0.01 sec)
mysql> SELECT TRUE FROM t2 WHERE (t2.c1) IS NULL;
+------+
| TRUE |
+------+
|    1 |
+------+
1 row in set (0.00 sec)

mysql> DROP TABLE IF EXISTS t2;
Query OK, 0 rows affected (0.02 sec)
mysql> CREATE TABLE IF NOT EXISTS t2(
    ->      c1 DATETIME
    -> );
Query OK, 0 rows affected (0.02 sec)
mysql> INSERT INTO t2 VALUES ('0000-00-00 00:00:00');
Query OK, 1 row affected (0.00 sec)
mysql> SELECT TRUE FROM t2 WHERE (t2.c1) IS NULL;
Empty set (0.00 sec)

How to repeat:
set sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';

-- Schema with PRIMARY KEY
DROP TABLE IF EXISTS t2;
CREATE TABLE IF NOT EXISTS t2(
     c1 DATETIME PRIMARY KEY
);
INSERT INTO t2 VALUES ('0000-00-00 00:00:00');

SELECT TRUE FROM t2 WHERE (t2.c1) IS NULL;

-- Schema without PRIMARY KEY
DROP TABLE IF EXISTS t2;
CREATE TABLE IF NOT EXISTS t2(
     c1 DATETIME
);
INSERT INTO t2 VALUES ('0000-00-00 00:00:00');

SELECT TRUE FROM t2 WHERE (t2.c1) IS NULL;
[24 Dec 2024 13:12] MySQL Verification Team
Hello wang jack,

Thank you for the report and test case.

regards,
Umesh