tidb查询结果与筛选不一致问题二

问题
查询:


加上条件查询:t1.change_stock_qty <> 0

版本:mysql 5.7查询结果正常,tidb 4.0 5.0均异常

说明
1.与change_stock_qty类型有关,decimal类型时,结果正常
2.与负号【-】有关,删除-,结果正常
3.与union有关,不进行union,结果正常
4.【t1.change_stock_qty <> 0】中<> 换成>、<、!=、=结果均为空

脚本:

drop table test_eq1;
drop table test_eq2;
create table test_eq1(
	change_stock_qty double(16,4)
);
INSERT INTO `test_eq1`(`change_stock_qty`) VALUES (1);
INSERT INTO `test_eq1`(`change_stock_qty`) VALUES (6);
INSERT INTO `test_eq1`(`change_stock_qty`) VALUES (2);
INSERT INTO `test_eq1`(`change_stock_qty`) VALUES (1);
INSERT INTO `test_eq1`(`change_stock_qty`) VALUES (3);
INSERT INTO `test_eq1`(`change_stock_qty`) VALUES (5);
INSERT INTO `test_eq1`(`change_stock_qty`) VALUES (1);
INSERT INTO `test_eq1`(`change_stock_qty`) VALUES (4);
INSERT INTO `test_eq1`(`change_stock_qty`) VALUES (1);
INSERT INTO `test_eq1`(`change_stock_qty`) VALUES (3);


create table test_eq2(
	change_stock_qty double(16,4)
);

INSERT INTO `test_eq2`(`change_stock_qty`) VALUES (3);
INSERT INTO `test_eq2`(`change_stock_qty`) VALUES (802);
INSERT INTO `test_eq2`(`change_stock_qty`) VALUES (2);
INSERT INTO `test_eq2`(`change_stock_qty`) VALUES (1);
INSERT INTO `test_eq2`(`change_stock_qty`) VALUES (3);
INSERT INTO `test_eq2`(`change_stock_qty`) VALUES (4);
INSERT INTO `test_eq2`(`change_stock_qty`) VALUES (2);
INSERT INTO `test_eq2`(`change_stock_qty`) VALUES (2);
INSERT INTO `test_eq2`(`change_stock_qty`) VALUES (4);
INSERT INTO `test_eq2`(`change_stock_qty`) VALUES (1);



select
	t1.change_stock_qty,
		t1.bill_type
from (	
	select
		9 bill_type,
		-tt1.change_stock_qty change_stock_qty
	from test_eq1 tt1
	union
	select
		10 bill_type,
		tt1.change_stock_qty
	from test_eq2 tt1
) t1
where t1.bill_type = 9
and t1.change_stock_qty <> 0.0;

试了下<>0.0 改为 <> 0.1 就可以正确出结果,应该是 0.0 转换哪里有问题吧,我们先分析下,会尽快答复,多谢。

1 个赞

好的。我们先解决线上问题,不过0.1是有效数据,不能筛选掉

又发现UNION ALL一个问题。
描述:
同一张表关联,字符编码utf8mb4,
select
null name
from t
union
select
name
from t
结果name会乱码,正常查询不乱码

把union 中的null放到下面乱码就正常了

是哪个版本,尝试用 tiup playground nightly 版本测试还有问题么

4.0.12 生产
测试5.0没有这个问题
生产暂时不能直接升级

4.0.13 版本呢,我这里用 4.0.12 没有复现,可以提供下最小复现的步骤么

用客户端查,使用命令行查是没有问题的

CREATE TABLE `t_finance_voucher` (
  `target_org_name` varchar(255) DEFAULT NULL COMMENT '目标机构名称'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=30002 COMMENT='财务凭证表';


INSERT INTO `t_finance_voucher`(`target_org_name`) VALUES (NULL);
INSERT INTO `t_finance_voucher`(`target_org_name`) VALUES (NULL);
INSERT INTO `t_finance_voucher`(`target_org_name`) VALUES ('1号直营店');
INSERT INTO `t_finance_voucher`(`target_org_name`) VALUES ('1号直营店');
INSERT INTO `t_finance_voucher`(`target_org_name`) VALUES ('1号直营店');
INSERT INTO `t_finance_voucher`(`target_org_name`) VALUES ('1号直营店');
INSERT INTO `t_finance_voucher`(`target_org_name`) VALUES ('1号直营店');
INSERT INTO `t_finance_voucher`(`target_org_name`) VALUES ('1号直营店');
INSERT INTO `t_finance_voucher`(`target_org_name`) VALUES ('1号直营店');
INSERT INTO `t_finance_voucher`(`target_org_name`) VALUES ('1号直营店');
INSERT INTO `t_finance_voucher`(`target_org_name`) VALUES (NULL);
INSERT INTO `t_finance_voucher`(`target_org_name`) VALUES (NULL);
INSERT INTO `t_finance_voucher`(`target_org_name`) VALUES ('1号仓库');
INSERT INTO `t_finance_voucher`(`target_org_name`) VALUES ('1号仓库');
INSERT INTO `t_finance_voucher`(`target_org_name`) VALUES ('2号直营店');
INSERT INTO `t_finance_voucher`(`target_org_name`) VALUES ('2号直营店');
INSERT INTO `t_finance_voucher`(`target_org_name`) VALUES ('1号直营店');
INSERT INTO `t_finance_voucher`(`target_org_name`) VALUES ('1号直营店');

SELECT
	NULL AS target_org_name
FROM
	t_finance_voucher a 
	union all
	SELECT
	tfv.target_org_name
FROM
	t_finance_voucher tfv
;

是的,我用命令行查也没有问题,是什么客户端,有选项可以设置字符集吗

navicat 我们这边几个版本都是这样的问题。主要是null放在union上和下返回的结果不一致,tidb返回结果带有编码吗?是不是返回的编码与链接编码不一致导致的?

dbeaver没有问题,可能是navicat客户端本身的问题。:+1: