Skip to content

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

chore: update omni for oracle parser compatibility (#20539)

rebelicefca0433059d9
diff --git a/backend/plugin/advisor/mysql/rule_function_disallowed_list.go b/backend/plugin/advisor/mysql/rule_function_disallowed_list.go
index 0377a2eab8..eb7da6c7e4 100644
--- a/backend/plugin/advisor/mysql/rule_function_disallowed_list.go
+++ b/backend/plugin/advisor/mysql/rule_function_disallowed_list.go
@@ -134,6 +134,18 @@ func (r *functionDisallowedListOmniRule) checkSelectStmt(n *ast.SelectStmt) {
if n == nil {
return
}
+ for _, cte := range n.CTEs {
+ if cte != nil {
+ r.checkSelectStmt(cte.Select)
+ }
+ }
+ if inner := n.ParenSource; inner != nil {
+ r.checkSelectStmt(inner)
+ }
+ if n.SetOp != ast.SetOpNone {
+ r.checkSelectStmt(n.Left)
+ r.checkSelectStmt(n.Right)
+ }
for _, expr := range n.TargetList {
r.checkExpr(expr)
}
diff --git a/backend/plugin/advisor/mysql/rule_insert_disallow_order_by_rand.go b/backend/plugin/advisor/mysql/rule_insert_disallow_order_by_rand.go
index b101827ce4..e1bbb0327d 100644
--- a/backend/plugin/advisor/mysql/rule_insert_disallow_order_by_rand.go
+++ b/backend/plugin/advisor/mysql/rule_insert_disallow_order_by_rand.go
@@ -74,6 +74,9 @@ func (r *insertDisallowOrderByRandOmniRule) checkSelectForRandOrderBy(sel *ast.S
if sel == nil {
return
}
+ if inner := sel.ParenSource; inner != nil {
+ r.checkSelectForRandOrderBy(inner, text)
+ }
for _, item := range sel.OrderBy {
if r.isRandFunc(item.Expr) {
diff --git a/backend/plugin/advisor/mysql/rule_statement_join_strict_column_attrs.go b/backend/plugin/advisor/mysql/rule_statement_join_strict_column_attrs.go
index 22275a3e2a..342752cb21 100644
--- a/backend/plugin/advisor/mysql/rule_statement_join_strict_column_attrs.go
+++ b/backend/plugin/advisor/mysql/rule_statement_join_strict_column_attrs.go
@@ -80,6 +80,10 @@ func (r *joinStrictColumnAttrsOmniRule) checkSelect(sel *ast.SelectStmt) {
if sel == nil {
return
}
+ if inner := sel.ParenSource; inner != nil {
+ r.checkSelect(inner)
+ return
+ }
if sel.SetOp != ast.SetOpNone {
r.checkSelect(sel.Left)
r.checkSelect(sel.Right)
diff --git a/backend/plugin/advisor/mysql/rule_statement_maximum_join_table_count.go b/backend/plugin/advisor/mysql/rule_statement_maximum_join_table_count.go
index 8f7c1e32e8..e9a8d89058 100644
--- a/backend/plugin/advisor/mysql/rule_statement_maximum_join_table_count.go
+++ b/backend/plugin/advisor/mysql/rule_statement_maximum_join_table_count.go
@@ -68,6 +68,10 @@ func (r *maxJoinTableCountOmniRule) checkSelect(sel *ast.SelectStmt, text string
if sel == nil {
return
}
+ if inner := sel.ParenSource; inner != nil {
+ r.checkSelect(inner, text)
+ return
+ }
if sel.SetOp != ast.SetOpNone {
r.checkSelect(sel.Left, text)
r.checkSelect(sel.Right, text)
diff --git a/backend/plugin/advisor/mysql/rule_statement_maximum_limit_value.go b/backend/plugin/advisor/mysql/rule_statement_maximum_limit_value.go
index 08b7107c6e..e53737dc19 100644
--- a/backend/plugin/advisor/mysql/rule_statement_maximum_limit_value.go
+++ b/backend/plugin/advisor/mysql/rule_statement_maximum_limit_value.go
@@ -70,6 +70,13 @@ func (r *maxLimitValueOmniRule) checkSelectLimit(sel *ast.SelectStmt, _ string)
if sel == nil {
return
}
+ if inner := sel.ParenSource; inner != nil {
+ if sel.Limit != nil {
+ r.checkLimit(sel.Limit)
+ }
+ r.checkSelectLimit(inner, "")
+ return
+ }
if sel.SetOp != ast.SetOpNone {
r.checkSelectLimit(sel.Left, "")
r.checkSelectLimit(sel.Right, "")
diff --git a/backend/plugin/advisor/mysql/rule_statement_where_disallow_using_function.go b/backend/plugin/advisor/mysql/rule_statement_where_disallow_using_function.go
index 8dc2bf5cab..45ed75b148 100644
--- a/backend/plugin/advisor/mysql/rule_statement_where_disallow_using_function.go
+++ b/backend/plugin/advisor/mysql/rule_statement_where_disallow_using_function.go
@@ -161,6 +161,10 @@ func (r *whereDisallowFuncOmniRule) checkSelectInScope(sel *ast.SelectStmt, oute
r.checkSelect(cte.Select)
}
}
+ if inner := sel.ParenSource; inner != nil {
+ r.checkSelectInScope(inner, outer)
+ return
+ }
if sel.SetOp != ast.SetOpNone {
r.checkSelectInScope(sel.Left, outer)
r.checkSelectInScope(sel.Right, outer)
diff --git a/backend/plugin/advisor/mysql/rule_statement_where_maximum_logical_operator_count.go b/backend/plugin/advisor/mysql/rule_statement_where_maximum_logical_operator_count.go
index 79c90a6a7f..f3d099809f 100644
--- a/backend/plugin/advisor/mysql/rule_statement_where_maximum_logical_operator_count.go
+++ b/backend/plugin/advisor/mysql/rule_statement_where_maximum_logical_operator_count.go
@@ -97,6 +97,10 @@ func (r *maxLogicalOperatorOmniRule) checkSelect(sel *ast.SelectStmt, text strin
if sel == nil {
return
}
+ if inner := sel.ParenSource; inner != nil {
+ r.checkSelect(inner, text)
+ return
+ }
if sel.SetOp != ast.SetOpNone {
r.checkSelect(sel.Left, text)
r.checkSelect(sel.Right, text)
diff --git a/backend/plugin/advisor/mysql/rule_stmt_disallow_limit.go b/backend/plugin/advisor/mysql/rule_stmt_disallow_limit.go
index 9b7062fc35..52d7dab6bd 100644
--- a/backend/plugin/advisor/mysql/rule_stmt_disallow_limit.go
+++ b/backend/plugin/advisor/mysql/rule_stmt_disallow_limit.go
@@ -75,11 +75,20 @@ func (r *disallowLimitOmniRule) checkSelectLimit(sel *ast.SelectStmt, text strin
if sel == nil {
return
}
+ if inner := sel.ParenSource; inner != nil {
+ if sel.Limit != nil {
+ r.addLimitAdvice(code.InsertUseLimit, text, sel.Loc)
+ }
+ r.checkSelectLimit(inner, text)
+ return
+ }
if sel.SetOp != ast.SetOpNone {
// Check set operation top-level limit.
if sel.Limit != nil {
r.addLimitAdvice(code.InsertUseLimit, text, sel.Loc)
}
+ r.checkSelectLimit(sel.Left, text)
+ r.checkSelectLimit(sel.Right, text)
return
}
if sel.Limit != nil {
diff --git a/backend/plugin/advisor/mysql/rule_stmt_where_requirement_for_select.go b/backend/plugin/advisor/mysql/rule_stmt_where_requirement_for_select.go
index 8d178cfcdd..492e409e0b 100644
--- a/backend/plugin/advisor/mysql/rule_stmt_where_requirement_for_select.go
+++ b/backend/plugin/advisor/mysql/rule_stmt_where_requirement_for_select.go
@@ -72,6 +72,10 @@ func (r *whereRequirementForSelectOmniRule) checkSelectStmt(sel *ast.SelectStmt,
r.checkSelectStmt(cte.Select, text)
}
}
+ if inner := sel.ParenSource; inner != nil {
+ r.checkSelectStmt(inner, text)
+ return
+ }
// Check set operations (UNION left/right).
if sel.SetOp != ast.SetOpNone {
diff --git a/backend/plugin/advisor/mysql/test/statement_disallow_limit.yaml b/backend/plugin/advisor/mysql/test/statement_disallow_limit.yaml
index 0bc3d19d05..39d567da64 100644
--- a/backend/plugin/advisor/mysql/test/statement_disallow_limit.yaml
+++ b/backend/plugin/advisor/mysql/test/statement_disallow_limit.yaml
@@ -35,6 +35,18 @@
line: 2
column: 0
endposition: null
+- statement: |
+ INSERT INTO tech_book SELECT * FROM tech_book;
+ INSERT INTO tech_book (SELECT * FROM tech_book LIMIT 1);
+ want:
+ - status: 2
+ code: 1103
+ title: STATEMENT_DISALLOW_LIMIT
+ content: LIMIT clause is forbidden in INSERT, UPDATE and DELETE statement, but "INSERT INTO tech_book (SELECT * FROM tech_book LIMIT 1);" uses
+ startposition:
+ line: 2
+ column: 0
+ endposition: null
- statement: |
UPDATE tech_book SET name = 'my name';
UPDATE tech_book SET name = 'my name' LIMIT 10;
diff --git a/backend/plugin/advisor/mysql/test/statement_where_disallow_functions_and_calculations.yaml b/backend/plugin/advisor/mysql/test/statement_where_disallow_functions_and_calculations.yaml
index 238a3371ba..ba7d96cd92 100644
--- a/backend/plugin/advisor/mysql/test/statement_where_disallow_functions_and_calculations.yaml
+++ b/backend/plugin/advisor/mysql/test/statement_where_disallow_functions_and_calculations.yaml
@@ -10,6 +10,18 @@
column: 0
endposition: null
+# Test: Function on indexed column inside a parenthesized query expression should flag.
+- statement: (SELECT * FROM tech_book WHERE UPPER(name) = 'test');
+ want:
+ - status: 2
+ code: 234
+ title: STATEMENT_WHERE_DISALLOW_FUNCTIONS_AND_CALCULATIONS
+ content: "Function \"UPPER\" is applied to indexed column \"name\" in the WHERE clause, which prevents index usage"
+ startposition:
+ line: 1
+ column: 0
+ endposition: null
+
# Test: Calculation on indexed column should flag
- statement: SELECT * FROM tech_book WHERE id + 1 > 5;
want:
diff --git a/backend/plugin/advisor/mysql/test/statement_where_require_select.yaml b/backend/plugin/advisor/mysql/test/statement_where_require_select.yaml
index 8a9e2c20e0..9030549209 100644
--- a/backend/plugin/advisor/mysql/test/statement_where_require_select.yaml
+++ b/backend/plugin/advisor/mysql/test/statement_where_require_select.yaml
@@ -16,6 +16,18 @@
- statement: |
CREATE TABLE book(id INT);
SELECT id FROM book WHERE id > 0;
+- statement: |
+ CREATE TABLE book(id INT);
+ (SELECT id FROM book);
+ want:
+ - status: 2
+ code: 202
+ title: STATEMENT_WHERE_REQUIRE_SELECT
+ content: '"(SELECT id FROM book);" requires WHERE clause'
+ startposition:
+ line: 2
+ column: 0
+ endposition: null
- statement: |
CREATE TABLE book(id INT);
SELECT id
diff --git a/backend/plugin/db/mysql/query_test.go b/backend/plugin/db/mysql/query_test.go
index 77952cd13a..4ef1f81748 100644
--- a/backend/plugin/db/mysql/query_test.go
+++ b/backend/plugin/db/mysql/query_test.go
@@ -71,6 +71,16 @@ func TestGetStatementWithResultLimit(t *testing.T) {
stmt: "SELECT firstName, lastName FROM employees UNION SELECT contactFirstName, contactLastName FROM customers;",
count: 10,
want: "SELECT firstName, lastName FROM employees UNION SELECT contactFirstName, contactLastName FROM customers LIMIT 10;",
+ },
+ {
+ stmt: "(SELECT * FROM t LIMIT 100) LIMIT 20;",
+ count: 10,
+ want: "(SELECT * FROM t LIMIT 100) LIMIT 10;",
+ },
+ {
+ stmt: "(SELECT * FROM t) FOR UPDATE;",
+ count: 10,
+ want: "(SELECT * FROM t) LIMIT 10 FOR UPDATE;",
}, {
stmt: "SELECT customerNumber, checkNumber, amount FROM payments WHERE amount = (SELECT MAX(amount) FROM payments);",
count: 10,
diff --git a/backend/plugin/parser/mysql/query_span_extractor_omni.go b/backend/plugin/parser/mysql/query_span_extractor_omni.go
index b455c437b5..e0c5e71f56 100644
--- a/backend/plugin/parser/mysql/query_span_extractor_omni.go
+++ b/backend/plugin/parser/mysql/query_span_extractor_omni.go
@@ -125,6 +125,15 @@ func (q *omniQuerySpanExtractor) extractOmniSelectStmt(stmt *ast.SelectStmt) (*b
if err := q.processOmniCTEs(stmt.CTEs); err != nil {
return nil, err
}
+ if inner := stmt.ParenSource; inner != nil {
+ return q.extractOmniSelectStmt(inner)
+ }
+ if tableStmt := stmt.TableSource; tableStmt != nil {
+ return q.extractOmniTableStmt(tableStmt)
+ }
+ if valuesStmt := stmt.ValuesSource; valuesStmt != nil {
+ return q.extractOmniValuesStmt(valuesStmt)
+ }
if stmt.SetOp != ast.SetOpNone {
return q.extractOmniSetOp(stmt)
}
@@ -243,10 +252,11 @@ func (q *omniQuerySpanExtractor) extractOmniNonRecursiveCTE(cte *ast.CommonTable
}
func (q *omniQuerySpanExtractor) extractOmniRecursiveCTE(cte *ast.CommonTableExpr) (*base.PseudoTable, error) {
- if cte.Select == nil || cte.Select.SetOp == ast.SetOpNone {
+ selectStmt := ast.UnwrapParenSource(cte.Select)
+ if selectStmt == nil || selectStmt.SetOp == ast.SetOpNone {
return q.extractOmniNonRecursiveCTE(cte)
}
- initialTable, err := q.extractOmniRecursiveCTEAnchor(cte.Select)
+ initialTable, err := q.extractOmniRecursiveCTEAnchor(selectStmt)
if err != nil {
return nil, err
}
@@ -289,6 +299,7 @@ func (q *omniQuerySpanExtractor) extractOmniRecursiveCTE(cte *ast.CommonTableExp
}
func (q *omniQuerySpanExtractor) extractOmniRecursiveCTEAnchor(stmt *ast.SelectStmt) (*base.PseudoTable, error) {
+ stmt = ast.UnwrapParenSource(stmt)
if stmt == nil || stmt.SetOp == ast.SetOpNone {
return q.extractOmniSelectStmt(stmt)
}
@@ -1107,6 +1118,15 @@ func collectOmniAccessTablesFromNode(result base.SourceColumnSet, node ast.Node,
if n.Right != nil {
collectOmniAccessTablesFromNode(result, n.Right, defaultDatabase, normalizeStarRocksCluster)
}
+ if inner := n.ParenSource; inner != nil {
+ collectOmniAccessTablesFromNode(result, inner, defaultDatabase, normalizeStarRocksCluster)
+ }
+ if tableStmt := n.TableSource; tableStmt != nil {
+ collectOmniAccessTablesFromNode(result, tableStmt, defaultDatabase, normalizeStarRocksCluster)
+ }
+ if valuesStmt := n.ValuesSource; valuesStmt != nil {
+ collectOmniAccessTablesFromNode(result, valuesStmt, defaultDatabase, normalizeStarRocksCluster)
+ }
for _, target := range n.TargetList {
collectOmniAccessTablesFromExpr(result, target, defaultDatabase, normalizeStarRocksCluster)
}
diff --git a/go.mod b/go.mod
index 232e459771..63d5c58e34 100644
--- a/go.mod
+++ b/go.mod
@@ -34,7 +34,7 @@ require (
github.com/bmatcuk/doublestar/v4 v4.10.0
github.com/bytebase/gomongo v0.0.0-20260510192859-8526a440b352
github.com/bytebase/lsp-protocol v0.0.0-20250324071136-1586d0c10ff0
- github.com/bytebase/omni v0.0.0-20260605060926-2a62e5b9cf03
+ github.com/bytebase/omni v0.0.0-20260608071738-731478feee32
github.com/caarlos0/env/v11 v11.4.1
github.com/cenkalti/backoff/v5 v5.0.3
github.com/cockroachdb/cockroachdb-parser v0.25.2
diff --git a/go.sum b/go.sum
index 0d5af35b44..7be59585df 100644
--- a/go.sum
+++ b/go.sum
@@ -250,8 +250,8 @@ github.com/bytebase/gomongo v0.0.0-20260510192859-8526a440b352 h1:3sC5pdvJ7bNAhR
github.com/bytebase/gomongo v0.0.0-20260510192859-8526a440b352/go.mod h1:eyWrxE51HCbjGIChvty/mYaNcAroXshnIiR6SIqlxfY=
github.com/bytebase/lsp-protocol v0.0.0-20250324071136-1586d0c10ff0 h1:bJ8NSf2K+pccl5m/wuu97fiYjDwpJH6IzURAq/3XA2U=
github.com/bytebase/lsp-protocol v0.0.0-20250324071136-1586d0c10ff0/go.mod h1:BEWMfiZtqshdmulKJcIsWb45MUaEvDO4CROcgi8dfFg=
-github.com/bytebase/omni v0.0.0-20260605060926-2a62e5b9cf03 h1:mAMVA0S3EEbC+t62NWFNPAau+MwjerE90b9zRfxDPMQ=
-github.com/bytebase/omni v0.0.0-20260605060926-2a62e5b9cf03/go.mod h1:EVG8nQbNPUnUBGKn6J0niSGOs3jgfKo3TciY22R4bfo=
+github.com/bytebase/omni v0.0.0-20260608071738-731478feee32 h1:Ws8/0AvaLfN19AADsQJMuq0mxWW9fLno72HAEdP/R+k=
+github.com/bytebase/omni v0.0.0-20260608071738-731478feee32/go.mod h1:EVG8nQbNPUnUBGKn6J0niSGOs3jgfKo3TciY22R4bfo=
github.com/bytebase/parser v0.0.0-20260417075056-57b6ef7a2640 h1:g4Jed1/Jv/DHBiQmEgN5ILOQDDBjFlG4N4Lp+3B4aYE=
github.com/bytebase/parser v0.0.0-20260417075056-57b6ef7a2640/go.mod h1:jeak/EfutSOAuWKvrFIT2IZunhWprM7oTFBRgZ9RCxo=
github.com/bytebase/pgx/v5 v5.0.0-20250212161523-96ff8aed8767 h1:YuR5G3LcxpO5ScSTA+Kdirxg9RW4TRc/v1t7N2Hfmbw=