Skip to content

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

feat(sql-review): disallow cross-db queries (#12126)

Azusaineb2bc0125127
diff --git a/backend/plugin/advisor/advisor.go b/backend/plugin/advisor/advisor.go
index eda9aa46ef..15b08a7840 100644
--- a/backend/plugin/advisor/advisor.go
+++ b/backend/plugin/advisor/advisor.go
@@ -615,6 +615,9 @@ const (
// MSSQLProcedureDisallowCreateOrAlter restricts the creation of procedures.
MSSQLProcedureDisallowCreateOrAlter Type = "bb.plugin.advisor.mssql.procedure.disallow-create-or-alter"
+
+ // MSSQLStatementDisallowCrossDBQueries prohibits cross database queries.
+ MSSQLStatementDisallowCrossDBQueries Type = "bb.plugin.advisor.mssql.statement.disallow-cross-db-queries"
)
// Advice is the result of an advisor.
@@ -656,7 +659,7 @@ type Context struct {
Driver *sql.DB
Context context.Context
- // CurrentDatabase is the current database. Special for Snowflake.
+ // CurrentDatabase is the current database.
CurrentDatabase string
// Statement is the original statement of AST, it is used for some PostgreSQL
// advisors which need to check the token stream.
diff --git a/backend/plugin/advisor/code.go b/backend/plugin/advisor/code.go
index d85c979fc5..3d2e906083 100644
--- a/backend/plugin/advisor/code.go
+++ b/backend/plugin/advisor/code.go
@@ -57,6 +57,7 @@ const (
StatementNonTransactional Code = 230
StatementAddColumnWithPosition Code = 231
StatementOfflineDDL Code = 232
+ StatementDisallowCrossDBQueries Code = 233
// 301 ~ 399 naming error code
// 301 table naming advisor error code.
diff --git a/backend/plugin/advisor/config/sql-review.dev.yaml b/backend/plugin/advisor/config/sql-review.dev.yaml
index a60df11056..3b5d43af84 100644
--- a/backend/plugin/advisor/config/sql-review.dev.yaml
+++ b/backend/plugin/advisor/config/sql-review.dev.yaml
@@ -106,6 +106,8 @@ ruleList:
level: WARNING
- type: statement.prior-backup-check
level: ERROR
+ - type: statement.disallow-cross-db-queries
+ level: WARNING
- type: naming.fully-qualified
level: WARNING
- type: naming.table
diff --git a/backend/plugin/advisor/config/sql-review.prod.yaml b/backend/plugin/advisor/config/sql-review.prod.yaml
index 1f9750c9ee..3e2c423f3b 100644
--- a/backend/plugin/advisor/config/sql-review.prod.yaml
+++ b/backend/plugin/advisor/config/sql-review.prod.yaml
@@ -118,6 +118,8 @@ ruleList:
level: WARNING
- type: statement.disallow-offline-ddl
level: WARNING
+ - type: statement.disallow-cross-db-queries
+ level: WARNING
- type: naming.fully-qualified
level: WARNING
- type: naming.table
diff --git a/backend/plugin/advisor/mssql/advisor_statement_disallow_cross_db_queries.go b/backend/plugin/advisor/mssql/advisor_statement_disallow_cross_db_queries.go
new file mode 100644
index 0000000000..0ceb79b80e
--- /dev/null
+++ b/backend/plugin/advisor/mssql/advisor_statement_disallow_cross_db_queries.go
@@ -0,0 +1,82 @@
+package mssql
+
+import (
+ "fmt"
+ "strings"
+
+ "github.com/antlr4-go/antlr/v4"
+ parser "github.com/bytebase/tsql-parser"
+ "github.com/pkg/errors"
+
+ "github.com/bytebase/bytebase/backend/plugin/advisor"
+ "github.com/bytebase/bytebase/backend/plugin/parser/tsql"
+ "github.com/bytebase/bytebase/proto/generated-go/store"
+)
+
+func init() {
+ advisor.Register(store.Engine_MSSQL, advisor.MSSQLStatementDisallowCrossDBQueries, &DisallowCrossDBQueriesAdvisor{})
+}
+
+type DisallowCrossDBQueriesAdvisor struct{}
+
+type DisallowCrossDBQueriesChecker struct {
+ *parser.BaseTSqlParserListener
+ curDB string
+ level advisor.Status
+ title string
+ adviceList []advisor.Advice
+}
+
+func (*DisallowCrossDBQueriesAdvisor) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {
+ tree, ok := ctx.AST.(antlr.Tree)
+ if !ok {
+ return nil, errors.Errorf("failed to convert to Tree")
+ }
+
+ level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)
+ if err != nil {
+ return nil, err
+ }
+
+ checker := &DisallowCrossDBQueriesChecker{
+ level: level,
+ title: ctx.Rule.Type,
+ curDB: ctx.CurrentDatabase,
+ }
+
+ antlr.ParseTreeWalkerDefault.Walk(checker, tree)
+
+ if len(checker.adviceList) == 0 {
+ checker.adviceList = append(checker.adviceList, advisor.Advice{
+ Status: advisor.Success,
+ Code: advisor.Ok,
+ Title: "OK",
+ Content: "",
+ })
+ }
+
+ return checker.adviceList, nil
+}
+
+func (checker *DisallowCrossDBQueriesChecker) EnterTable_source_item(ctx *parser.Table_source_itemContext) {
+ if fullTblnameCtx := ctx.Full_table_name(); fullTblnameCtx != nil {
+ // Case insensitive.
+ if fullTblName, err := tsql.NormalizeFullTableName(fullTblnameCtx); err == nil && fullTblName.Database != "" && !strings.EqualFold(fullTblName.Database, checker.curDB) {
+ checker.adviceList = append(checker.adviceList, advisor.Advice{
+ Status: checker.level,
+ Code: advisor.StatementDisallowCrossDBQueries,
+ Title: checker.title,
+ Content: fmt.Sprintf("Cross database queries (target databse: '%s', current database: '%s') are prohibited", fullTblName.Database, checker.curDB),
+ Line: ctx.GetStart().GetLine(),
+ })
+ }
+ // Ignore internal error...
+ }
+}
+
+func (checker *DisallowCrossDBQueriesChecker) EnterUse_statement(ctx *parser.Use_statementContext) {
+ if newDB := ctx.GetDatabase(); newDB != nil {
+ _, lowercaceDBName := tsql.NormalizeTSQLIdentifier(newDB)
+ checker.curDB = lowercaceDBName
+ }
+}
diff --git a/backend/plugin/advisor/mssql/mssql_rules_test.go b/backend/plugin/advisor/mssql/mssql_rules_test.go
index 6ce85412d9..378f257f12 100644
--- a/backend/plugin/advisor/mssql/mssql_rules_test.go
+++ b/backend/plugin/advisor/mssql/mssql_rules_test.go
@@ -27,9 +27,17 @@ func TestMSSQLRules(t *testing.T) {
advisor.SchemaRuleColumnTypeDisallowList,
advisor.SchemaRuleFunctionDisallowCreate,
advisor.SchemaRuleProcedureDisallowCreate,
+ advisor.SchemaRuleStatementDisallowCrossDBQueries,
}
for _, rule := range mssqlRules {
- advisor.RunSQLReviewRuleTest(t, rule, storepb.Engine_MSSQL, nil, false /* record */)
+ _, needMockData := advisorNeedMockData[rule]
+ advisor.RunSQLReviewRuleTest(t, rule, storepb.Engine_MSSQL, needMockData, false /* record */)
}
}
+
+// Add SQL review type here if you need metadata for test.
+var advisorNeedMockData = map[advisor.SQLReviewRuleType]bool{
+ advisor.SchemaRuleStatementDisallowCrossDBQueries: true,
+ advisor.SchemaRuleSchemaBackwardCompatibility: true,
+}
diff --git a/backend/plugin/advisor/mssql/test/schema_backward_compatibility.yaml b/backend/plugin/advisor/mssql/test/schema_backward_compatibility.yaml
index e5607d4cb0..366cf766e9 100644
--- a/backend/plugin/advisor/mssql/test/schema_backward_compatibility.yaml
+++ b/backend/plugin/advisor/mssql/test/schema_backward_compatibility.yaml
@@ -3,7 +3,7 @@
- status: WARN
code: 112
title: schema.backward-compatibility
- content: Drop table TEST_DB.dbo.MyTable may cause incompatibility with the existing data and code
+ content: Drop table master.dbo.MyTable may cause incompatibility with the existing data and code
line: 1
column: 0
details: ""
@@ -23,7 +23,7 @@
- status: WARN
code: 112
title: schema.backward-compatibility
- content: Drop schema TEST_DB.myschema may cause incompatibility with the existing data and code
+ content: Drop schema master.myschema may cause incompatibility with the existing data and code
line: 1
column: 0
details: ""
diff --git a/backend/plugin/advisor/mssql/test/statement_disallow_cross_db_queries.yaml b/backend/plugin/advisor/mssql/test/statement_disallow_cross_db_queries.yaml
new file mode 100644
index 0000000000..90c25dbadd
--- /dev/null
+++ b/backend/plugin/advisor/mssql/test/statement_disallow_cross_db_queries.yaml
@@ -0,0 +1,27 @@
+# case insensitive.
+- statement: |-
+ SELECT * FROM MASTER.dbo.pokes;
+ want:
+ - status: SUCCESS
+ code: 0
+ title: OK
+- statement: |-
+ WITH foo1 AS (SELECT * FROM master2.dbo.tech_book)
+ SELECT * FROM master.dbo.pokes;
+ CREATE TABLE pokes (foo int);
+ want:
+ - status: WARN
+ code: 233
+ title: statement.disallow-cross-db-queries
+ content: "Cross database queries (target databse: 'master2', current database: 'master') are prohibited"
+ line: 1
+# Testing with database switching.
+- statement: |-
+ USE master2;
+ SELECT * FROM master.dbo.pokes;
+ want:
+ - status: WARN
+ code: 233
+ title: statement.disallow-cross-db-queries
+ content: "Cross database queries (target databse: 'master', current database: 'master2') are prohibited"
+ line: 2
diff --git a/backend/plugin/advisor/mysql/mysql_rules_test.go b/backend/plugin/advisor/mysql/mysql_rules_test.go
index 1e06d878b9..2e6dffb1b7 100644
--- a/backend/plugin/advisor/mysql/mysql_rules_test.go
+++ b/backend/plugin/advisor/mysql/mysql_rules_test.go
@@ -160,6 +160,6 @@ func TestMySQLRules(t *testing.T) {
}
for _, rule := range mysqlRules {
- advisor.RunSQLReviewRuleTest(t, rule, storepb.Engine_MYSQL, nil, false /* record */)
+ advisor.RunSQLReviewRuleTest(t, rule, storepb.Engine_MYSQL, false, false /* record */)
}
}
diff --git a/backend/plugin/advisor/oracle/oracle_rules_test.go b/backend/plugin/advisor/oracle/oracle_rules_test.go
index bd156b65a5..e52d8ddaf2 100644
--- a/backend/plugin/advisor/oracle/oracle_rules_test.go
+++ b/backend/plugin/advisor/oracle/oracle_rules_test.go
@@ -31,6 +31,6 @@ func TestOracleRules(t *testing.T) {
}
for _, rule := range oracleRules {
- advisor.RunSQLReviewRuleTest(t, rule, storepb.Engine_ORACLE, nil, false /* record */)
+ advisor.RunSQLReviewRuleTest(t, rule, storepb.Engine_ORACLE, false, false /* record */)
}
}
diff --git a/backend/plugin/advisor/pg/pg_rules_test.go b/backend/plugin/advisor/pg/pg_rules_test.go
index fedec7b948..676459993a 100644
--- a/backend/plugin/advisor/pg/pg_rules_test.go
+++ b/backend/plugin/advisor/pg/pg_rules_test.go
@@ -58,11 +58,8 @@ func TestPostgreSQLRules(t *testing.T) {
}
for _, rule := range pgRules {
- var dbSchemaMetadata *storepb.DatabaseSchemaMetadata
- if _, needMockData := advisorNeedMockData[rule]; needMockData {
- dbSchemaMetadata = getMockDBSChemaData()
- }
- advisor.RunSQLReviewRuleTest(t, rule, storepb.Engine_POSTGRES, dbSchemaMetadata, false /* record */)
+ _, needMetaData := advisorNeedMockData[rule]
+ advisor.RunSQLReviewRuleTest(t, rule, storepb.Engine_POSTGRES, needMetaData, false /* record */)
}
}
@@ -70,26 +67,3 @@ func TestPostgreSQLRules(t *testing.T) {
var advisorNeedMockData = map[advisor.SQLReviewRuleType]bool{
advisor.SchemaRuleFullyQualifiedObjectName: true,
}
-
-func getMockDBSChemaData() *storepb.DatabaseSchemaMetadata {
- return &storepb.DatabaseSchemaMetadata{
- Name: "TEST_DB",
- Schemas: []*storepb.SchemaMetadata{
- {
- Name: "public",
- Tables: []*storepb.TableMetadata{
- {Name: "pokes"},
- {Name: "pokesv1"},
- {Name: "pokesv2"},
- {Name: "pokesv3"},
- },
- ExternalTables: []*storepb.ExternalTableMetadata{
- {Name: "pokesv4"},
- {Name: "pokesv5"},
- {Name: "pokesv6"},
- {Name: "pokesv7"},
- },
- },
- },
- }
-}
diff --git a/backend/plugin/advisor/pg/test/naming_fully_qualified.yaml b/backend/plugin/advisor/pg/test/naming_fully_qualified.yaml
index 92aac7f299..deeb60a5e9 100644
--- a/backend/plugin/advisor/pg/test/naming_fully_qualified.yaml
+++ b/backend/plugin/advisor/pg/test/naming_fully_qualified.yaml
@@ -13,7 +13,7 @@
- statement: |-
CREATE SEQUENCE public.seq;
CREATE SEQUENCE seq;
- DROP SEQUENCE public.seq
+ DROP SEQUENCE public.seq
want:
- status: WARN
code: 310
@@ -76,19 +76,19 @@
- statement: |-
CREATE TABLE public.pokes (foo int);
- SELECT * FROM (SELECT (foo) FROM pokes) AS foo;
+ SELECT * FROM (SELECT (id) FROM tech_book) AS foo;
want:
- status: WARN
code: 310
title: naming.fully-qualified
- content: "unqualified object name: 'pokes'"
+ content: "unqualified object name: 'tech_book'"
line: 2
- statement: |-
CREATE TABLE public.pokes (foo int);
- WITH foo1 AS (SELECT * FROM public.pokes)
+ WITH foo1 AS (SELECT * FROM public.tech_book)
SELECT * FROM foo1;
want:
- status: SUCCESS
code: 0
- title: OK
\ No newline at end of file
+ title: OK
diff --git a/backend/plugin/advisor/snowflake/snowflake_rules_test.go b/backend/plugin/advisor/snowflake/snowflake_rules_test.go
index 985e23bfda..102e16bad2 100644
--- a/backend/plugin/advisor/snowflake/snowflake_rules_test.go
+++ b/backend/plugin/advisor/snowflake/snowflake_rules_test.go
@@ -26,6 +26,6 @@ func TestSnowflakeRules(t *testing.T) {
}
for _, rule := range snowflakeRules {
- advisor.RunSQLReviewRuleTest(t, rule, storepb.Engine_SNOWFLAKE, nil, false /* record */)
+ advisor.RunSQLReviewRuleTest(t, rule, storepb.Engine_SNOWFLAKE, false, false /* record */)
}
}
diff --git a/backend/plugin/advisor/sql_review.go b/backend/plugin/advisor/sql_review.go
index e88849be90..3717a9930c 100644
--- a/backend/plugin/advisor/sql_review.go
+++ b/backend/plugin/advisor/sql_review.go
@@ -100,7 +100,6 @@ const (
SchemaRuleStatementAddCheckNotValid = "statement.add-check-not-valid"
// SchemaRuleStatementAddFKNotValid require add foreign key not valid.
SchemaRuleStatementAddFKNotValid = "statement.add-foreign-key-not-valid"
-
// SchemaRuleStatementDisallowAddNotNull disallow to add NOT NULL.
SchemaRuleStatementDisallowAddNotNull = "statement.disallow-add-not-null"
// SchemaRuleStatementDisallowAddColumn disallow to add column.
@@ -139,7 +138,8 @@ const (
SchemaRuleStatementAddColumnWithoutPosition = "statement.add-column-without-position"
// SchemaRuleStatementDisallowOfflineDDL disallow offline ddl.
SchemaRuleStatementDisallowOfflineDDL = "statement.disallow-offline-ddl"
-
+ // SchemaRuleStatementDisallowCrossDBQueries disallow cross database queries.
+ SchemaRuleStatementDisallowCrossDBQueries = "statement.disallow-cross-db-queries"
// SchemaRuleTableRequirePK require the table to have a primary key.
SchemaRuleTableRequirePK SQLReviewRuleType = "table.require-pk"
// SchemaRuleTableNoFK require the table disallow the foreign key.
@@ -1668,6 +1668,10 @@ func getAdvisorTypeByRule(ruleType SQLReviewRuleType, engine storepb.Engine) (Ty
if engine == storepb.Engine_MYSQL {
return MySQLStatementJoinStrictColumnAttrs, nil
}
+ case SchemaRuleStatementDisallowCrossDBQueries:
+ if engine == storepb.Engine_MSSQL {
+ return MSSQLStatementDisallowCrossDBQueries, nil
+ }
case SchemaRuleCommentLength:
if engine == storepb.Engine_POSTGRES {
return PostgreSQLCommentConvention, nil
diff --git a/backend/plugin/advisor/tidb/tidb_rules_test.go b/backend/plugin/advisor/tidb/tidb_rules_test.go
index e11a1d14c1..f70b421668 100644
--- a/backend/plugin/advisor/tidb/tidb_rules_test.go
+++ b/backend/plugin/advisor/tidb/tidb_rules_test.go
@@ -114,6 +114,6 @@ func TestTiDBRules(t *testing.T) {
}
for _, rule := range tidbRules {
- advisor.RunSQLReviewRuleTest(t, rule, storepb.Engine_TIDB, nil, false /* record */)
+ advisor.RunSQLReviewRuleTest(t, rule, storepb.Engine_TIDB, false, false /* record */)
}
}
diff --git a/backend/plugin/advisor/utils_for_tests.go b/backend/plugin/advisor/utils_for_tests.go
index a9d9a0ec38..71cc217f14 100644
--- a/backend/plugin/advisor/utils_for_tests.go
+++ b/backend/plugin/advisor/utils_for_tests.go
@@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"encoding/json"
+ "fmt"
"io"
"os"
"path/filepath"
@@ -117,6 +118,19 @@ var (
},
},
}
+ MockMSSQLDatabase = &storepb.DatabaseSchemaMetadata{
+ Name: "master",
+ Schemas: []*storepb.SchemaMetadata{
+ {
+ Name: "dbo",
+ Tables: []*storepb.TableMetadata{
+ {Name: "pokes"},
+ {Name: "pokes2"},
+ {Name: "pokes3"},
+ },
+ },
+ },
+ }
)
// TestCase is the data struct for test.
@@ -134,7 +148,7 @@ func (c *testCatalog) GetFinder() *catalog.Finder {
}
// RunSQLReviewRuleTest helps to test the SQL review rule.
-func RunSQLReviewRuleTest(t *testing.T, rule SQLReviewRuleType, dbType storepb.Engine, schemaMetadata *storepb.DatabaseSchemaMetadata, record bool) {
+func RunSQLReviewRuleTest(t *testing.T, rule SQLReviewRuleType, dbType storepb.Engine, needMetaData bool, record bool) {
var tests []TestCase
fileName := strings.Map(func(r rune) rune {
@@ -156,6 +170,21 @@ func RunSQLReviewRuleTest(t *testing.T, rule SQLReviewRuleType, dbType storepb.E
require.NoError(t, err, rule)
for i, tc := range tests {
+ // Add engine types here for mocked database metadata.
+ var schemaMetadata *storepb.DatabaseSchemaMetadata
+ curDB := "TEST_DB"
+ if needMetaData {
+ switch dbType {
+ case storepb.Engine_POSTGRES:
+ schemaMetadata = MockPostgreSQLDatabase
+ case storepb.Engine_MSSQL:
+ curDB = "master"
+ schemaMetadata = MockMSSQLDatabase
+ default:
+ panic(fmt.Sprintf("%s doesn't have mocked metadata support", storepb.Engine_name[int32(dbType)]))
+ }
+ }
+
database := MockMySQLDatabase
if dbType == storepb.Engine_POSTGRES {
database = MockPostgreSQLDatabase
@@ -180,7 +209,7 @@ func RunSQLReviewRuleTest(t *testing.T, rule SQLReviewRuleType, dbType storepb.E
Catalog: &testCatalog{finder: finder},
Driver: nil,
Context: context.Background(),
- CurrentDatabase: "TEST_DB",
+ CurrentDatabase: curDB,
DBSchema: schemaMetadata,
}
@@ -367,7 +396,8 @@ func SetDefaultSQLReviewRulePayload(ruleTp SQLReviewRuleType, dbType storepb.Eng
SchemaRuleStatementDisallowMixDDLDML,
SchemaRuleStatementPriorBackupCheck,
SchemaRuleStatementJoinStrictColumnAttrs,
- SchemaRuleTableDisallowSetCharset:
+ SchemaRuleTableDisallowSetCharset,
+ SchemaRuleStatementDisallowCrossDBQueries:
case SchemaRuleTableDropNamingConvention:
payload, err = json.Marshal(NamingRulePayload{
Format: "_delete$",
diff --git a/frontend/src/locales/sql-review/en-US.json b/frontend/src/locales/sql-review/en-US.json
index 989d806c32..7f10f2b45f 100644
--- a/frontend/src/locales/sql-review/en-US.json
+++ b/frontend/src/locales/sql-review/en-US.json
@@ -516,6 +516,10 @@
"title": "Disallow Offline DDL",
"description": "To prevent database changes from impacting your business, avoid using Offline DDL."
},
+ "statement-disallow-cross-db-queries": {
+ "title": "Disallow cross database queries",
+ "description": "Cross-database queries increase system coupling and can lead to efficiency issues. Suggested error level: Warning"
+ },
"schema-backward-compatibility": {
"title": "Check application backward compatibility",
"description": "Some changes may affect running applications, such as modifying the name of database object, adding new constraints, etc. This rule can avoid careless changes that lead to the failure of existing application. Suggestion error level: Warning"
diff --git a/frontend/src/locales/sql-review/es-ES.json b/frontend/src/locales/sql-review/es-ES.json
index 46f5637e04..c81b69ebf8 100644
--- a/frontend/src/locales/sql-review/es-ES.json
+++ b/frontend/src/locales/sql-review/es-ES.json
@@ -516,6 +516,10 @@
"title": "Prohibir DDL sin conexión",
"description": "Para evitar que los cambios en la base de datos afecten su negocio, por favor evite usar DDL sin conexión."
},
+ "statement-disallow-cross-db-queries": {
+ "title": "Prohibir consultas entre bases de datos",
+ "description": "Las consultas entre bases de datos aumentan el acoplamiento del sistema y pueden llevar a problemas de eficiencia. Nivel de error sugerido: Advertencia"
+ },
"schema-backward-compatibility": {
"title": "Comprobación de la compatibilidad con versiones anteriores de la aplicación",
"description": "Algunos cambios pueden afectar las aplicaciones en ejecución, como modificar el nombre del objeto de la base de datos, agregar nuevas restricciones, etc. Esta regla puede evitar cambios descuidados que lleven al fallo de la aplicación existente. Nivel de error sugerido: Advertencia"
@@ -652,4 +656,4 @@
"warning": "Advertencia",
"disabled": "Deshabilitado"
}
-}
\ No newline at end of file
+}
diff --git a/frontend/src/locales/sql-review/ja-JP.json b/frontend/src/locales/sql-review/ja-JP.json
index a31ac3fd05..ecad055e8b 100644
--- a/frontend/src/locales/sql-review/ja-JP.json
+++ b/frontend/src/locales/sql-review/ja-JP.json
@@ -516,6 +516,10 @@
"title": "オフラインDDLを禁止",
"description": "データベースの変更がビジネスに影響するのを防ぐために、オフラインDDLの使用を避けてください。"
},
+ "statement-disallow-cross-db-queries": {
+ "title": "データベース間のクエリを禁止する",
+ "description": "データベース間のクエリはシステムの結合度を高め、効率性に問題を引き起こす可能性があります。推奨されるエラーレベル:警告"
+ },
"schema-backward-compatibility": {
"title": "アプリケーションの後方互換性を確認する",
"description": "一部の変更は実行中のアプリケーションに影響を与える可能性があります。データベースオブジェクトの名前の変更や新しい制約の追加などが該当します。このルールにより、既存のアプリケーションの障害を防ぐことができます。提案されるエラーレベル:警告"
@@ -652,4 +656,4 @@
"warning": "警告",
"disabled": "無効化"
}
-}
\ No newline at end of file
+}
diff --git a/frontend/src/locales/sql-review/zh-CN.json b/frontend/src/locales/sql-review/zh-CN.json
index 3d7522f38e..f702359735 100644
--- a/frontend/src/locales/sql-review/zh-CN.json
+++ b/frontend/src/locales/sql-review/zh-CN.json
@@ -644,6 +644,10 @@
"statement-non-transactional": {
"title": "检测并报告非事务性语句",
"description": ""
+ },
+ "statement-disallow-cross-db-queries": {
+ "title": "禁止跨数据库查询",
+ "description": "跨数据库查询会增加系统的耦合性,并可能导致效率问题。建议的错误级别:警告"
}
},
"level": {
@@ -652,4 +656,4 @@
"warning": "警告",
"disabled": "禁用"
}
-}
\ No newline at end of file
+}
diff --git a/frontend/src/types/sql-review-schema.yaml b/frontend/src/types/sql-review-schema.yaml
index 83191b27f9..85ddb70c4c 100644
--- a/frontend/src/types/sql-review-schema.yaml
+++ b/frontend/src/types/sql-review-schema.yaml
@@ -352,6 +352,10 @@ ruleList:
category: STATEMENT
engineList:
- OCEANBASE
+ - type: statement.disallow-cross-db-queries
+ category: STATEMENT
+ engineList:
+ - MSSQL
- type: naming.fully-qualified
category: NAMING
engineList: