Skip to content

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

chore: consolidate check size and show check warning for large SQL (#9414)

Danny Xu4cd6fc222ffa
diff --git a/backend/api/v1/sql_service.go b/backend/api/v1/sql_service.go
index 104f63bdd5..31028094be 100644
--- a/backend/api/v1/sql_service.go
+++ b/backend/api/v1/sql_service.go
@@ -837,8 +837,8 @@ func (s *SQLService) createExportActivity(ctx context.Context, user *store.UserM
}
func (s *SQLService) Check(ctx context.Context, request *v1pb.CheckRequest) (*v1pb.CheckResponse, error) {
- if len(request.Statement) > common.MaxStatementSizeForSQLReview {
- return nil, status.Errorf(codes.FailedPrecondition, "statement size exceeds maximum allowed size %dKB", common.MaxStatementSizeForSQLReview/1024)
+ if len(request.Statement) > common.MaxSheetCheckSize {
+ return nil, status.Errorf(codes.FailedPrecondition, "statement size exceeds maximum allowed size %dKB", common.MaxSheetCheckSize/1024)
}
instanceID, databaseName, err := common.GetInstanceDatabaseID(request.Database)
diff --git a/backend/common/error.go b/backend/common/error.go
index 575c907bd1..6be17bed33 100644
--- a/backend/common/error.go
+++ b/backend/common/error.go
@@ -19,6 +19,7 @@ const (
NotFound Code = 4
Conflict Code = 5
NotImplemented Code = 6
+ SizeExceeded Code = 7
// 101 ~ 199 db error.
DbConnectionFailure Code = 101
diff --git a/backend/common/util.go b/backend/common/util.go
index 9a797c6939..40d176fb03 100644
--- a/backend/common/util.go
+++ b/backend/common/util.go
@@ -24,14 +24,10 @@ import (
const (
// MaxSheetSize is the maximum size (1M) of a sheet for displaying.
MaxSheetSize = 1024 * 1024
- // MaxSheetSizeForTaskCheck is the maximum size of a sheet for task check to run.
- MaxSheetSizeForTaskCheck = 10 * 1024 * 1024
+ // MaxSheetCheckSize is the maximum size of a sheet for checking changes.
+ MaxSheetCheckSize = 512 * 1024
// MaxSheetSizeForRollback is the maximum size of a sheet for rollback generator to run.
MaxSheetSizeForRollback = 8 * 1024 * 1024
- // MaxSheetSizeForPlanCheckDML is the maximum size of a sheet for plan check to check DML changes.
- MaxSheetSizeForPlanCheckDML = 512 * 1024
- // MaxStatementSizeForSQLReview is the maximum size of the statement to do sql review checks in sql service.
- MaxStatementSizeForSQLReview = 512 * 1024
// ExternalURLPlaceholder is the docs link to configure --external-url.
ExternalURLPlaceholder = "https://www.bytebase.com/docs/get-started/install/external-url"
diff --git a/backend/runner/plancheck/statement_advise_executor.go b/backend/runner/plancheck/statement_advise_executor.go
index b63fb1e5be..dfe76717ee 100644
--- a/backend/runner/plancheck/statement_advise_executor.go
+++ b/backend/runner/plancheck/statement_advise_executor.go
@@ -119,11 +119,11 @@ func (e *StatementAdviseExecutor) runForDatabaseTarget(ctx context.Context, conf
if sheet == nil {
return nil, errors.Errorf("sheet %d not found", sheetUID)
}
- if (sheet.Size > common.MaxSheetSizeForTaskCheck) || (config.ChangeDatabaseType == storepb.PlanCheckRunConfig_DML && sheet.Size > common.MaxSheetSizeForPlanCheckDML) {
+ if sheet.Size > common.MaxSheetCheckSize {
return []*storepb.PlanCheckRunResult_Result{
{
- Status: storepb.PlanCheckRunResult_Result_SUCCESS,
- Code: common.Ok.Int32(),
+ Status: storepb.PlanCheckRunResult_Result_WARNING,
+ Code: common.SizeExceeded.Int32(),
Title: "Large SQL review policy is disabled",
Content: "",
},
@@ -261,11 +261,11 @@ func (e *StatementAdviseExecutor) runForDatabaseGroupTarget(ctx context.Context,
if sheet == nil {
return nil, errors.Errorf("sheet %d not found", sheetUID)
}
- if sheet.Size > common.MaxSheetSizeForTaskCheck {
+ if sheet.Size > common.MaxSheetCheckSize {
return []*storepb.PlanCheckRunResult_Result{
{
- Status: storepb.PlanCheckRunResult_Result_SUCCESS,
- Code: common.Ok.Int32(),
+ Status: storepb.PlanCheckRunResult_Result_WARNING,
+ Code: common.SizeExceeded.Int32(),
Title: "Large SQL review policy is disabled",
Content: "",
},
diff --git a/backend/runner/plancheck/statement_report_executor.go b/backend/runner/plancheck/statement_report_executor.go
index 1bba4f1986..da9b65b870 100644
--- a/backend/runner/plancheck/statement_report_executor.go
+++ b/backend/runner/plancheck/statement_report_executor.go
@@ -97,11 +97,11 @@ func (e *StatementReportExecutor) runForDatabaseTarget(ctx context.Context, conf
if sheet == nil {
return nil, errors.Errorf("sheet %d not found", sheetUID)
}
- if (sheet.Size > common.MaxSheetSizeForTaskCheck) || (config.ChangeDatabaseType == storepb.PlanCheckRunConfig_DML && sheet.Size > common.MaxSheetSizeForPlanCheckDML) {
+ if sheet.Size > common.MaxSheetCheckSize {
return []*storepb.PlanCheckRunResult_Result{
{
- Status: storepb.PlanCheckRunResult_Result_SUCCESS,
- Code: common.Ok.Int32(),
+ Status: storepb.PlanCheckRunResult_Result_WARNING,
+ Code: common.SizeExceeded.Int32(),
Title: "Report for large SQL is not supported",
Content: "",
},
@@ -202,11 +202,11 @@ func (e *StatementReportExecutor) runForDatabaseGroupTarget(ctx context.Context,
if sheet == nil {
return nil, errors.Errorf("sheet %d not found", sheetUID)
}
- if sheet.Size > common.MaxSheetSizeForTaskCheck {
+ if sheet.Size > common.MaxSheetCheckSize {
return []*storepb.PlanCheckRunResult_Result{
{
- Status: storepb.PlanCheckRunResult_Result_SUCCESS,
- Code: common.Ok.Int32(),
+ Status: storepb.PlanCheckRunResult_Result_WARNING,
+ Code: common.SizeExceeded.Int32(),
Title: "Large SQL review policy is disabled",
Content: "",
},
diff --git a/backend/runner/plancheck/statement_type_executor.go b/backend/runner/plancheck/statement_type_executor.go
index 4da4323295..6ac3017236 100644
--- a/backend/runner/plancheck/statement_type_executor.go
+++ b/backend/runner/plancheck/statement_type_executor.go
@@ -97,11 +97,11 @@ func (e *StatementTypeExecutor) runForDatabaseTarget(ctx context.Context, config
if sheet == nil {
return nil, errors.Errorf("sheet %d not found", sheetUID)
}
- if (sheet.Size > common.MaxSheetSizeForTaskCheck) || (config.ChangeDatabaseType == storepb.PlanCheckRunConfig_DML && sheet.Size > common.MaxSheetSizeForPlanCheckDML) {
+ if sheet.Size > common.MaxSheetCheckSize {
return []*storepb.PlanCheckRunResult_Result{
{
- Status: storepb.PlanCheckRunResult_Result_SUCCESS,
- Code: common.Ok.Int32(),
+ Status: storepb.PlanCheckRunResult_Result_WARNING,
+ Code: common.SizeExceeded.Int32(),
Title: "Large SQL review policy is disabled",
Content: "",
},
@@ -205,11 +205,11 @@ func (e *StatementTypeExecutor) runForDatabaseGroupTarget(ctx context.Context, c
if sheet == nil {
return nil, errors.Errorf("sheet %d not found", sheetUID)
}
- if sheet.Size > common.MaxSheetSizeForTaskCheck {
+ if sheet.Size > common.MaxSheetCheckSize {
return []*storepb.PlanCheckRunResult_Result{
{
- Status: storepb.PlanCheckRunResult_Result_SUCCESS,
- Code: common.Ok.Int32(),
+ Status: storepb.PlanCheckRunResult_Result_WARNING,
+ Code: common.SizeExceeded.Int32(),
Title: "Large SQL review policy is disabled",
Content: "",
},
diff --git a/frontend/src/components/SQLCheck/SQLCheckButton.vue b/frontend/src/components/SQLCheck/SQLCheckButton.vue
index b8932092ab..12925d0a19 100644
--- a/frontend/src/components/SQLCheck/SQLCheckButton.vue
+++ b/frontend/src/components/SQLCheck/SQLCheckButton.vue
@@ -90,7 +90,8 @@ const props = withDefaults(
);
const { t } = useI18n();
-const SKIP_CHECK_THRESHOLD = 500000;
+// SKIP_CHECK_THRESHOLD is the MaxSheetCheckSize in the backend.
+const SKIP_CHECK_THRESHOLD = 512 * 1024;
const isRunning = ref(false);
const advices = ref<Advice[]>();
const checkRunCounter = ref(0);