阿里云MySQL8.x数据库"with as"BUG踩坑
项目数据库用的是MySQL8.x, 在本地&测试&预发布都没问题, 但是部署到生产环境出现某个查询SQL报错, 生产环境用的是阿里云的云数据库. 把报错SQL复制下来在本地执行没问题, 在阿里云数据库就报错. 后面排查发现, 阿里云数据库MySQL8.x对with as语法支持有一定问题.

#阿里云数据库MySQL-v8.x BUG说明
WITH 
t1 AS (
	SELECT help_topic_id FROM mysql.help_topic t LIMIT 0,1
),
t2 AS (
	SELECT help_topic_id FROM mysql.help_topic t 
	WHERE NOT EXISTS (select 1 from t1 where t1.help_topic_id=t.help_topic_id)
	LIMIT 1,1
),
t3 AS (
	SELECT help_topic_id FROM mysql.help_topic t 
	WHERE NOT EXISTS (select 1 from t2 where t2.help_topic_id=t.help_topic_id)
	LIMIT 2,1
)
		
#当WITH AS中引用了WITH AS定义的其他临时表, 查询任意一个临时表不报错, 查询一个以上就报错		
select * from t1
union all
select * from t2
union all
select * from t3;

当WITH AS中引用了WITH AS定义的其他临时表, 查询任意一个临时表不报错, 查询一个以上就报错
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

最后也把问题反馈给阿里云技术了, 希望快速修复该BUG.

Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐