Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

带有注释信息的MySQL审核报错 #2962

Closed
iwanghc opened this issue Mar 10, 2025 · 2 comments
Closed

带有注释信息的MySQL审核报错 #2962

iwanghc opened this issue Mar 10, 2025 · 2 comments
Assignees
Labels
bug Something isn't working publish-pre3
Milestone

Comments

@iwanghc
Copy link
Collaborator

iwanghc commented Mar 10, 2025

版本信息(Version)

4.2503-pre1

问题描述(Describe)

当审核的sql最后一行是注释或以注释结尾时,出现报错
期望解决bug的同时能够优化输出的日志,补充在解析哪行或者那条sql时出现的报错。

截图或日志(Log)

Image
Image

如何复现(To Reproduce)

目前已知的注释符:

  • /* xxx */
  • -- xxx
  • # xxx

审核任意其中一条sql:

SELECT * FROM t11;/* xxx */
SELECT * FROM t11;-- xxx
SELECT * FROM t11; # xxx

问题原因

mysql按分号切分sql时,将文本最后一条注释作为sql解析,在获取指纹时发生报错

解决方案

切分sql后判断元素是否为注释,如果不是注释则保留原sql,如果是注释则跳过该元素

变更影响面

受影响的模块或功能

mysql SQL审核

外部引用的潜在问题或风险

版本兼容性

兼容

测试建议

测试多种情况带有注释sql的审核

@iwanghc iwanghc added the bug Something isn't working label Mar 10, 2025
@ColdWaterLW ColdWaterLW added this to the v4.2503.0 milestone Mar 11, 2025
@ColdWaterLW
Copy link
Collaborator

可以考虑提取SQL的时候把注释去掉

@ColdWaterLW ColdWaterLW assigned iwanghc and unassigned ColdWaterLW Mar 11, 2025
@iwanghc iwanghc mentioned this issue Mar 24, 2025
6 tasks
@iwanghc iwanghc changed the title sql审核报错 带有注释信息的sql审核报错 Mar 25, 2025
@iwanghc iwanghc changed the title 带有注释信息的sql审核报错 带有注释信息的MySQL审核报错 Mar 25, 2025
@iwanghc
Copy link
Collaborator Author

iwanghc commented Mar 25, 2025

可以考虑提取SQL的时候把注释去掉

方便用户查找或者阅读sql,审核后保留原始sql,包括sql的注释信息

该issue描述问题在于按结束符切分sql后,如果某个元素是注释则会被当做一个sql解析,从而产生报错
解决点在于切分sql后判断切分后的元素是不是一条注释,如果是则忽略这个元素
SELECT * FROM t11; # xxx
切分后
元素一:
SELECT * FROM t11
元素二:
# xxx
忽略元素二,但是要注意mysql hint和条件注释不应被忽略

@iwanghc iwanghc closed this as completed Mar 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working publish-pre3
Projects
None yet
Development

No branches or pull requests

2 participants