Skip to content

fix(parser): accept GRANT/REVOKE without object type (default TABLE) - #30875

Closed
MatrixAdventurer wants to merge 2 commits into
matrixorigin:mainfrom
MatrixAdventurer:fix/grant-db-star-without-table
Closed

MatrixAdventurer wants to merge 2 commits into
matrixorigin:mainfrom
MatrixAdventurer:fix/grant-db-star-without-table

Conversation

@MatrixAdventurer

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Fixes #30874

What this PR does / why we need it:

Cause. grant_stmt / revoke_stmt in mysql_sql.y require object_type (TABLE|DATABASE|...) after ON, so the MySQL short form GRANT SELECT ON db.* TO u fails with a 1064 syntax error. MySQL's grammar is ON [TABLE|FUNCTION|PROCEDURE] priv_level with TABLE as the default.

Fix. Add one GRANT and one REVOKE alternative without object_type that set ObjType = OBJECT_TYPE_TABLE. The AST is identical to the explicit ON TABLE ... form that already works, so privilege semantics don't change. goyacc reports no new conflicts. mysql_sql.go is regenerated (goyacc -o mysql_sql.go mysql_sql.y + gofmt). Regenerating origin/main's .y with the same command reproduces main's .go exactly, so the large .go diff is table renumbering only.

Evidence.

  • New grant_object_type_opt_test.go: on main, 7 short-form cases (db.*, db.tbl, tbl, *.*, *, REVOKE, REVOKE IF EXISTS) fail with a syntax error. With this PR all 10 cases pass, and each short form formats exactly like its on table ... counterpart. The explicit TABLE/DATABASE/ACCOUNT controls are unchanged.
  • go test ./pkg/sql/parsers/... passes.

Merge danger. Low. This is parser-only: two new grammar alternatives, and existing forms parse the same way.

本操作由 LW 授权的 Grok Bot 智能体执行。

MySQL accepts GRANT priv ON [TABLE] {*|*.*|db.*|db.tbl|tbl}; MO required
the object type keyword, so 'GRANT SELECT ON db.* TO u' was a syntax error.
Add GRANT/REVOKE alternatives without object_type that default to TABLE.

Fixes matrixorigin#30874
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

…hout-table

# Conflicts:
#	pkg/sql/parsers/dialect/mysql/mysql_sql.go
@MatrixAdventurer

Copy link
Copy Markdown
Contributor Author

Merged current main into the branch (ac41291) to clear the conflict. Only mysql_sql.go conflicted; it was regenerated from the merged mysql_sql.y with goyacc (0 conflicts). go test ./pkg/sql/parsers/... passes locally. Ready for review.

本操作由 LW 授权的 Grok Bot 智能体执行。

Copy link
Copy Markdown
Contributor

相关issue将根据优先级计划修复

This branch had an error being deployed

1 failed deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GRANT SELECT ON db.* is rejected without the optional TABLE keyword

3 participants