Skip to content

[Question] sql 最后如果有 注释 -- 那么设置的查询总条数限制就失效了 #1263

Open

Description

@xiaoxiaoadmin

描述问题
sql 最后如果有 注释 -- 那么设置的查询总条数限制就失效了

复现
重现该行为的步骤:

  1. 设置查询总条数为1000
  2. 找一个条数大于1000的表 A 执行查询 select * form A --
  3. 会查询出所有的数据,如果给了导出权限,应该可以导出所有

期望的结果
即使sql最后加了 -- 也不要把平台拼接的limit给注释掉
其实执行 select * form A -- where 也是一样的效果

Activity

  1. Issues-translate-bot commented on Apr 9, 2026

    @Issues-translate-bot

    Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


    Title: [Question] If there is a comment at the end of the sql -- then the limit on the total number of queries set will be invalid.

    Describe the problem
    If there is a comment at the end of sql -- then the limit on the total number of queries set will be invalid.

    Recurrence
    Steps to reproduce the behavior:

    1. Set the total number of queries to 1000
    2. Find a table A with more than 1000 entries and execute the query select * form A --
    3. All data will be queried. If export permission is given, all data should be exported.

    Desired results
    Even if -- is added to the sql at the end, do not comment out the limit for platform splicing.
    In fact, executing select * form A -- where has the same effect.

  2. dosubot commented on Apr 9, 2026

    @dosubot

    Hi @xiaoxiaoadmin! I'm Dosu and I’m helping the Yearning team.

    这个问题确认存在。根源在于 Yearning 在将 SQL 发送给 RPC 引擎执行前,没有对 SQL 中的注释进行清理,导致 RPC 引擎拼接的 LIMIT 子句被 -- 注释掉。

    执行流程大致是:

    1. 用户提交 SELECT * FROM A --
    2. 主应用将 SQL 和配置的 limit 值通过 RPC 发送给引擎服务 [1]
    3. 引擎在 SQL 末尾拼接 LIMIT 1000,变成 SELECT * FROM A -- LIMIT 1000
    4. -- 之后的内容被数据库当作注释,LIMIT 失效

    值得注意的是,Yearning 代码中其实已经有注释剥离的正则逻辑(支持 -- 单行注释和 /* */ 多行注释),但目前只在 GetFingerprint() 中用于 SQL 指纹提取和 AI 建议功能 [2],并没有应用在查询执行路径上。

    可能的修复方向:

    • 在主应用侧:将 SQL 发送给 RPC 引擎前,复用 GetFingerprint() 中的注释剥离逻辑清理 SQL
    • 在 RPC 引擎侧:在拼接 LIMIT 前先移除尾部注释
    • 或者更稳妥地:解析 SQL 结构后将 LIMIT 插入到注释之前

    /* */ 块注释理论上也有类似的绕过风险。

    To reply, just mention @dosu.


    Docs are dead. Just use Dosu.

    Leave Feedback Ask Dosu about Yearning Share Dosu with your team

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions