spring-boot项目中,oceanbase集群数据库执行sql报错java.sql.SQLException: Internal error

【 使用环境 】生产环境
【 使用版本 】版本 5.7.25-OceanBase_CE-v4.3.3.0,集群部署
spring boot中jdbc使用 mysql-connector-j-8.0.33.jar驱动,
替换为官网推荐的mysql-connector-java-5.1.47.jar,两个驱动问题一样。
【问题描述】
(1)初始报错报错

Error querying database. Cause: java.sql.SQLException: Internal error

The error may exist in com/suninfo/userasset/mapper/asset/MonitorItcompMapper.xml

The error may involve com.suninfo.userasset.mapper.asset.MonitorItcompMapper.countItcompGroupbycitype-Inline

The error occurred while setting parameters

SQL: SELECT t1.citypeUuid AS name,count(t1.uuid) as value FROM t_monitor_itcomp t1 WHERE t1.citypeUuid is not null AND t1.status != 4 AND FIND_IN_SET(?, t1.module_codes) > 0 AND EXISTS (SELECT asset_uuid FROM (SELECT DISTINCT asset_uuid FROM t_asset_usedepart_rel WHERE usedepart_uuid IN ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? ) ) AS ud WHERE ud.asset_uuid = t1.uuid) and t1.citypeUuid IN ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? ) GROUP BY t1.citypeUuid

Cause: java.sql.SQLException: Internal error

========================Exception End=============================
(2)去除t1.citypeUuid的查询条件后不报错,如下
SELECT t1.citypeUuid AS name,count(t1.uuid) as value FROM t_monitor_itcomp t1 WHERE t1.citypeUuid is not null AND t1.status != 4 AND FIND_IN_SET(?, t1.module_codes) > 0 AND EXISTS (SELECT asset_uuid FROM (SELECT DISTINCT asset_uuid FROM t_asset_usedepart_rel WHERE usedepart_uuid IN ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? ) ) AS ud WHERE ud.asset_uuid = t1.uuid)
(3)根据业务修改sql后不报错
select
t1.citypeUuid as name,
count(t1.uuid) as value
from
t_monitor_itcomp t1
inner join t_cmdb_citype as t3 on
t1.citypeUuid = t3.uuid
inner join (
select
distinct asset_uuid
from
t_asset_usedepart_rel
where
usedepart_uuid in ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? ) ) as t4 on
t1.uuid = t4.asset_uuid
where
t1.status != 4
and FIND_IN_SET(‘3’, t1.module_codes) > 0
and FIND_IN_SET(‘3’, t3.module_codes) > 0
group by
t1.citypeUuid
原始sql如(1)为什么报错,针对单个sql长度有限制吗,in参数的长度有要求吗?
sql中uuid每个都是32位。
已针对数据库做了如下参数调整:
“ALTER SYSTEM SET enable_record_trace_log=false;”
“SET GLOBAL ob_query_timeout = 600000000;”
“SET GLOBAL ob_sql_work_area_percentage=30;”
“ALTER SYSTEM SET enable_sql_audit=false;”
“ALTER SYSTEM SET enable_perf_event=false;”
“ALTER SYSTEM SET syslog_level=‘ERROR’;”
“SET GLOBAL ob_query_timeout=600000000;”
“SET GLOBAL ob_sql_work_area_percentage=30;”
“ALTER SYSTEM SET _preserve_order_for_pagination=true;”
“SET GLOBAL ob_enable_sql_audit=false;”
“SET GLOBAL max_allowed_packet=67108864;”
“ALTER proxyconfig SET proxy_mem_limited=‘6G’;”
“ALTER proxyconfig SET enable_compression_protocol=false;”

2 个赞
ALTER SYSTEM SET syslog_level='WDIAG';

调整下日志级别,麻烦复现下,发下包含报错时间的observer.log

另外OceanBase_CE-v4.3.3.0版本不是LTS版本,不建议使用,建议使用4.3.5最新BP

生产环境上已将sql替换成第三种,不允许回退了,但是测试环境上无法复现

为何不适用OB官网提供的驱动呢?毕竟OB不是用的mysql源码只是借鉴,底层还是有很多不一样的,用官方的驱动适配性更好些吧

MySQL租户,建议使用原生MySQL驱动 :sweat_smile:

看报错是出现在 setting parameters 阶段,setting parameters 我理解是 orm 框架做的,还没到 OB 执行这边。
有条件的话可以抓下生产上 spring-boot 到 OB 之间的包,看 OB 是否返回了报错

这种情况下用哪种驱动更好?

建议使用OB的驱动

时间原因,现在不能替换ob的驱动。
麻烦你看下我初始描述的,第一次sql执行报错,第二次中去掉citypeUuid查询条件后执行正常了,第三次将citypeUuid条件按照业务修改为find_in_set也执行正常。
请问是和执行语句的长度,sql的复杂度有关吗?能否通过配置参数临时修改?

原SQL直接在数据里面执行有试过吗?报错吗?

试过的,后台直接用mysql命令连接,执行原sql不报错。

spring boot中这个报错是偶尔报错 还是一直报错?
原SQL直接在数据里面执行一直不报错吗?

看这个SQL条件 citypeUuid中的in 参数 不是很多,远达不到限制,

测试环境上数据量比生产环境数据量多,但是不报错。
生产环境上也是运行一段时间后报错的,报错后在后台执行一直不报错,但是页面上操作必现。

那和 “执行语句的长度,sql的复杂度” 没有关系,看起来和传入的参数有关系,需要看下observer.log是否有相关记录,也可能sql还没到数据层