MYSQL8.0兼容租户执行SQL报错

现在执行一个sql报错,sql如下:
update mon_agent SET car_count = car_count+1 where 1=2 or FIND_IN_SET(agent_id,getParAgentList(1));

说明:getParAgentList是个存储过程,里面会查询mon_agent表,具体定义如下:
CREATE DEFINER = gpsman@% FUNCTION tpss-release.getParAgentList(agentId int(11)) RETURNS varchar(21845)
READS SQL DATA
BEGIN

DECLARE fid varchar(100) default ‘’;

DECLARE str varchar(1000) default agentId;

WHILE agentId is not null do

SET fid =(SELECT parent_id FROM mon_agent where is_delete=0  and agent_id = agentId);   

IF fid is not null THEN   

    SET str = concat(str, ',', fid);   

    SET agentId = fid;   

ELSE   

    SET agentId = fid;   

END IF;   

END WHILE;

return str;

END

报错如下:
SQL 错误 [1442] [HY000]: Can’t update table ‘mon_agent’ in stored function/trigger because it is already used by statement which invoked this stored function/trigger.

但是我在原数据库(MYSQL8.0)执行是不报错的,现在创建的租户是指定兼容MYSQL8.0,sqlmode和原数据库也是一致的。

3 个赞

调用了存储函数或触发器,并且该函数/触发器试图更新与外层 SQL 所操作的相同表 mon_agent,这在 OceanBase 中是被禁止的行为。

这是为了防止 递归更新 或 数据不一致 的情况发生。具体来说,在存储函数或触发器中尝试修改当前正在被外部语句访问的表,会引发“表正在变异(mutating)”的问题。

3 个赞

@论坛小助手

1 个赞

根据您的回复,我的理解是oceanbase 虽然兼容mysql8.0,但是对这种同一表的同时读/写操作的场景是无法兼容的是吗?

1 个赞

需要@论坛小助手,才能回你消息

1 个赞

@辞霜 老师根据您的回复,我的理解是oceanbase 虽然兼容mysql8.0,但是对这种同一表的同时读/写操作的场景是无法兼容的是吗?

1 个赞

可能兼容设计还是存在问题吧

一步步来,可能后面版本就支持了。可以给 OB 提需求,提需求的官方路径是:GitHub - oceanbase/oceanbase: OceanBase is an enterprise distributed relational database with high availability, high performance, horizontal scalability, and compatibility with SQL standards. 里 提 issue 。
论坛里提需求也就看看 :slight_smile: