Datetime字段为null时使用is null查不到数据

为提高效率,提问时请提供以下信息,问题描述清晰可优先响应。

  • 【TiDB 版本】:v4.0.4
  • 【问题描述】:

背景:Mysql中字段类型为Datetime,通过数据同步工具(阿里云DTS)至Tidb,Tidb中字段类型也为Datetime。
我们发现当Mysql中,数据字段为NULL时,Binlog同步中语句也为NULL。但是到了Tidb中,可能变成了’00-00-00 00:00:00’,造成数据查询中使用IS NULL 条件查询不出,我们使用’00-00-00 00:00:00’查出了数据。我们发现IS NULL做条件时和使用’00-00-00 00:00:00’时EXPLAIN执行计划也不一样,截图已附。我们想了解一下Tidb中是如何处理Datetime和如何处理Datetime为空的。

  1. 我测试了下插入datetime 为null时,查询结果也是 null
    image
  2. 请问您 tidb 中datetime 列表中定义是什么? 有没有默认 null 值转换?
  3. 听其他用户说 DTS 会自动把 null 转换为 0 ,麻烦和阿里官方确认下,多谢。

rg.springframework.dao.TransientDataAccessResourceException: Error attempting to get column ‘add_time’ from result set. Cause: java.sql.SQLException: Value ‘0000-00-00 00:00:00’ can not be represented as java.sql.Timestamp ; Value ‘0000-00-00 00:00:00’ can not be represented as java.sql.Timestamp; nested exception is java.sql.SQLException: Value ‘0000-00-00 00:00:00’ can not be represented as java.sql.Timestamp at

我们java代码里看到这个,是不是说明现在在tidb里值就是 ‘0000-00-00 00:00:00’

从这里看应该是的,不识别 0000-00-00 00:00:00 ,说明存放的是这些值