Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: mysql limit (#13537)

Danny Xu5f34c2836256
diff --git a/backend/plugin/db/mysql/query.go b/backend/plugin/db/mysql/query.go
index 943a726892..5555e96df1 100644
--- a/backend/plugin/db/mysql/query.go
+++ b/backend/plugin/db/mysql/query.go
@@ -62,6 +62,7 @@ func (r *mysqlRewriter) EnterQueryExpression(ctx *mysql.QueryExpressionContext)
r.outerMostQuery = false
if ctx.LimitClause() != nil {
// limit clause already exists.
+ r.rewriter.ReplaceDefault(ctx.LimitClause().GetStart().GetTokenIndex(), ctx.LimitClause().GetStop().GetTokenIndex(), fmt.Sprintf("LIMIT %d", r.limitCount))
return
}
diff --git a/backend/plugin/db/mysql/query_test.go b/backend/plugin/db/mysql/query_test.go
index 720647ee29..d1ecfa4cfc 100644
--- a/backend/plugin/db/mysql/query_test.go
+++ b/backend/plugin/db/mysql/query_test.go
@@ -20,7 +20,12 @@ func TestGetStatementWithResultLimitOfMySQL(t *testing.T) {
{
stmt: "SELECT * FROM t LIMIT 5;",
count: 10,
- want: "SELECT * FROM t LIMIT 5;",
+ want: "SELECT * FROM t LIMIT 10;",
+ },
+ {
+ stmt: "SELECT * FROM t LIMIT 123;",
+ count: 10,
+ want: "SELECT * FROM t LIMIT 10;",
},
{
stmt: "SELECT * FROM t2 JOIN t1 ON t2.c2 = t1.c2 where t2.c2 > 10;",