【 TiDB 使用环境】
测试环境版本是:5.7.25-TiDB-v4.0.6,生产环境版本是:5.7.25-TiDB-v4.0.7
补充一点:测试环境 安装的时候 默认没有启用 新的排序规则(Collation),生产环境安装的时候故意开启了新的排序规则。
【概述】 场景 + 问题概述
同一个sql,测试环境和生产环境数据一样,测试环境能查出结果,生产环境查不出结果,初步排查是因为在生产环境join关联不到。关联字段加个trim(也就是:ON trim(a.digit_identity) = trim(b.channelname))可以关联查询出来,但是加trim性能太差。尝试trim之后更新字段的方式,还是join不到。sql如下:
SELECT
b.time,
b.channelvalue,
a.id AS “id”,
a.equipment_code AS “equipmentCode”,
a.digit_name AS “digitName”,
a.digit_identity AS “digitIdentity”,
a.data_type AS “dataType”,
a.value_upperlimit AS “valueUpperlimit”,
a.value_lowerlimit AS “valueLowerlimit”,
a.digit_type_id AS “digitTypeId”,
a.digit_type_name AS “digitTypeName”,
a.energy_type_id AS “energyTypeId”,
a.energy_type_name AS “energyTypeName”,
a.description AS “description”,
a.create_by AS “createBy.id”,
a.create_date AS “createDate”,
a.update_by AS “updateBy.id”,
a.update_date AS “updateDate”,
a.del_flag AS “delFlag”,
a.unit_id AS “unitId”,
a.unit AS “unit”,
a.fault_def_id AS “faultDefId”,
a.fault_def_name AS “faultDefName”,
a.is_monitored AS “isMonitored”,
a.icon_url AS “iconUrl”,
a.is_trend_monitored AS “isTrendMonitored”,
a.is_data_distribute AS “isDataDistribute”,
a.plc_datatype AS “plcDatatype”,
a.plc_address AS “plcAddress”,
a.plc_bit AS “plcBit”,
a.data_source AS “dataSource”,
a.formula_str AS “formulaStr”,
a.parent_identity AS “parentIdentity”,
a.parent_identity_full AS “parentIdentityFull”,
a.gateway_identity_id AS “gatewayIdentityId”
FROM
t_equipment_digit a
JOIN eventlog b ON a.digit_identity = b.channelname
WHERE
a.del_flag = 0
AND a.equipment_code = ‘GANTEN(JX)-DPLZ2’
AND a.digit_type_id = ‘8d2b235e-ba55-11e8-816f-000c291a2998’
ORDER BY
b.time DESC
LIMIT 1;