max_rows rewrites the offset of `LIMIT offset, count` on MySQL/MariaDB/SQLite

未关闭 适合新手
#536 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
mariadb, mysql, sql, sqlite, typescript
领域
backend, databases

调研方向

从 src/utils/sql-row-limiter.ts 中的 findTopLevelLimit 开始;issue 指出它会将 LIMIT 后的第一个数字读取为行数。检查现有的行数限制器测试,并为 SQLite 和 MySQL 上的 LIMIT offset, count 和 LIMIT count OFFSET offset 都添加测试覆盖。完成标准是保留 offset、将返回的行数限制为 max_rows,并在适用时报告截断。

由索引模型根据 Issue 内容生成。

描述

With max_rows set on a tool, a query in the LIMIT offset, count form gets a different page of rows, or more rows than the cap.

[[sources]]
id = "lite"
dsn = "sqlite:///w/t.db"

[[tools]]
name = "execute_sql"
source = "lite"
max_rows = 5

Table t(id) with ids 1..300, on v2.0.0 (main c3b3fc7):

query sqlite3 dbhub
select id from t order by id limit 100, 3 101, 102, 103 7, 8, 9
select id from t order by id limit 3, 10 4 .. 13 4 .. 13 (10 rows, over max_rows = 5, not marked truncated)
select id from t order by id limit 3 offset 100 101, 102, 103 101, 102, 103

Same on MySQL 8. No error in either case, so the agent works with the wrong rows.

findTopLevelLimit in src/utils/sql-row-limiter.ts reads the first number after LIMIT as the row count, but in LIMIT a, b that is the offset. The limiter then replaces it with min(a, max_rows + 1) (100 becomes 6), and when a is already under the cap it leaves the query alone, so b is never capped.

#444 had a fix for this and was closed with a request to open an issue first; I didn't find one, so here it is. I can send a PR that caps the second operand of LIMIT a, b and keeps the offset, if that's the direction you want.

主要语言
TypeScript
星标
3.9k
派生
338
平均合并
6 小时 35 分钟
30 天内合并 PR
37

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

bytebase/dbhub 的其他 Issue

查看 bytebase/dbhub 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。