Skip to content

V2规则:禁止WHERE子句中条件字段与值的数据类型不一致,误触发 #3049

@winfredLIN

Description

@winfredLIN

版本信息(Version)

版本:4.2502.0

问题描述与复现流程

  1. 建表
create table
  t1 (id bigint unsigned NOT NULL, name varchar(100));
  1. 使用SQL基于带有V2规则禁止WHERE子句中条件字段与值的数据类型不一致的规则模板审核
update t1
set
  name = 'jack'
where
  id = 2838923;
  1. 规则误触发

Image

问题原因

结论:在判断SQL中常量值类型的时候,值类型取值错误
具体原因:

  1. 在判断值的类型的时候,使用类型转换存在转换不准确,以及类型覆盖不全的问题
case types.KindInt64, types.KindUint64:
        return mysql.TypeLong, nil

Image
2. 在判断的时候严格要求类型枚举值相等,和1中产生矛盾
Image

解决方案

建议对值类型的数据,直接使用解析出的类型
Image

变更影响面

受影响的模块或功能

外部引用的潜在问题或风险

版本兼容性

测试建议

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions