Skip to content

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

chore: add exceeded commands (#12446)

Danny Xuf8e894388d4c
diff --git a/backend/common/util.go b/backend/common/util.go
index f7b76917cf..a3dcd7a0fb 100644
--- a/backend/common/util.go
+++ b/backend/common/util.go
@@ -28,6 +28,8 @@ const (
// The maximum number of bytes for sql results in response body.
// 100 MB.
MaximumSQLResultSize = 100 * 1024 * 1024
+ // MaximumCommands is the maximum number of commands that can be executed in a single transaction.
+ MaximumCommands = 200
// ExternalURLPlaceholder is the docs link to configure --external-url.
ExternalURLPlaceholder = "https://www.bytebase.com/docs/get-started/install/external-url"
diff --git a/backend/plugin/db/mysql/mysql.go b/backend/plugin/db/mysql/mysql.go
index 94b000f77b..9ab6b68af1 100644
--- a/backend/plugin/db/mysql/mysql.go
+++ b/backend/plugin/db/mysql/mysql.go
@@ -311,6 +311,7 @@ func (d *Driver) Execute(ctx context.Context, statement string, opts db.ExecuteO
var totalCommands int
var commands []base.SingleSQL
var originalIndex []int32
+ oneshot := true
if len(statement) <= common.MaxSheetCheckSize {
singleSQLs, err := mysqlparser.SplitSQL(statement)
if err != nil {
@@ -320,9 +321,13 @@ func (d *Driver) Execute(ctx context.Context, statement string, opts db.ExecuteO
if len(singleSQLs) == 0 {
return 0, nil
}
- totalCommands = len(singleSQLs)
commands = singleSQLs
- } else {
+ totalCommands = len(commands)
+ if totalCommands <= common.MaximumCommands {
+ oneshot = false
+ }
+ }
+ if oneshot {
commands = []base.SingleSQL{
{
Text: statement,
diff --git a/backend/plugin/db/pg/pg.go b/backend/plugin/db/pg/pg.go
index 6d34bcad03..00149e83b6 100644
--- a/backend/plugin/db/pg/pg.go
+++ b/backend/plugin/db/pg/pg.go
@@ -367,6 +367,7 @@ func (driver *Driver) Execute(ctx context.Context, statement string, opts db.Exe
var commands []base.SingleSQL
var originalIndex []int32
var isPlsql bool
+ oneshot := true
if len(statement) <= common.MaxSheetCheckSize {
singleSQLs, err := pgparser.SplitSQL(statement)
if err != nil {
@@ -381,7 +382,11 @@ func (driver *Driver) Execute(ctx context.Context, statement string, opts db.Exe
if len(singleSQLs) == 1 && isPlSQLBlock(singleSQLs[0].Text) {
isPlsql = true
}
- } else {
+ if len(commands) <= common.MaximumCommands {
+ oneshot = false
+ }
+ }
+ if oneshot {
commands = []base.SingleSQL{
{
Text: statement,
diff --git a/backend/plugin/db/redshift/redshift.go b/backend/plugin/db/redshift/redshift.go
index ba7b12bbfb..a9f7827a15 100644
--- a/backend/plugin/db/redshift/redshift.go
+++ b/backend/plugin/db/redshift/redshift.go
@@ -180,13 +180,18 @@ func (driver *Driver) Execute(ctx context.Context, statement string, opts db.Exe
}
var commands []base.SingleSQL
+ oneshot := true
if len(statement) <= common.MaxSheetCheckSize {
singleSQLs, err := pgparser.SplitSQL(statement)
if err != nil {
return 0, err
}
commands = base.FilterEmptySQL(singleSQLs)
- } else {
+ if len(commands) <= common.MaximumCommands {
+ oneshot = false
+ }
+ }
+ if oneshot {
commands = []base.SingleSQL{
{
Text: statement,
diff --git a/backend/plugin/db/risingwave/risingwave.go b/backend/plugin/db/risingwave/risingwave.go
index 20bda64c03..099e2642ad 100644
--- a/backend/plugin/db/risingwave/risingwave.go
+++ b/backend/plugin/db/risingwave/risingwave.go
@@ -245,13 +245,18 @@ func (driver *Driver) Execute(ctx context.Context, statement string, opts db.Exe
}
var commands []base.SingleSQL
+ oneshot := true
if len(statement) <= common.MaxSheetCheckSize {
singleSQLs, err := pgparser.SplitSQL(statement)
if err != nil {
return 0, err
}
commands = base.FilterEmptySQL(singleSQLs)
- } else {
+ if len(commands) <= common.MaximumCommands {
+ oneshot = false
+ }
+ }
+ if oneshot {
commands = []base.SingleSQL{
{
Text: statement,
diff --git a/backend/plugin/db/tidb/tidb.go b/backend/plugin/db/tidb/tidb.go
index daa3653b0f..753932e0c2 100644
--- a/backend/plugin/db/tidb/tidb.go
+++ b/backend/plugin/db/tidb/tidb.go
@@ -192,6 +192,7 @@ func (driver *Driver) Execute(ctx context.Context, statement string, opts db.Exe
var nonTransactionStmts []string
var totalCommands int
var commands []base.SingleSQL
+ oneshot := true
if len(statement) <= common.MaxSheetCheckSize {
singleSQLs, err := tidbparser.SplitSQL(statement)
if err != nil {
@@ -202,19 +203,22 @@ func (driver *Driver) Execute(ctx context.Context, statement string, opts db.Exe
return 0, nil
}
totalCommands = len(singleSQLs)
-
- // Find non-transactional statements.
- // TiDB cannot run create table and create index in a single transaction.
- var remainingSQLs []base.SingleSQL
- for _, singleSQL := range singleSQLs {
- if isNonTransactionStatement(singleSQL.Text) {
- nonTransactionStmts = append(nonTransactionStmts, singleSQL.Text)
- continue
+ if totalCommands <= common.MaximumCommands {
+ oneshot = false
+ // Find non-transactional statements.
+ // TiDB cannot run create table and create index in a single transaction.
+ var remainingSQLs []base.SingleSQL
+ for _, singleSQL := range singleSQLs {
+ if isNonTransactionStatement(singleSQL.Text) {
+ nonTransactionStmts = append(nonTransactionStmts, singleSQL.Text)
+ continue
+ }
+ remainingSQLs = append(remainingSQLs, singleSQL)
}
- remainingSQLs = append(remainingSQLs, singleSQL)
+ commands = remainingSQLs
}
- commands = remainingSQLs
- } else {
+ }
+ if oneshot {
commands = []base.SingleSQL{
{
Text: statement,