Skip to content

[Bug][Compatibility]: GRANT ... ON TABLE <view> is silently accepted but never grants access (non-MySQL ON VIEW required) #30887

Closed as not planned

Description

@XuPeng-SH

Summary

GRANT SELECT ON TABLE <db>.<view> — the MySQL form — is accepted silently but grants nothing. The user still gets 20101 do not have privilege to execute the statement. Access only works after the non-MySQL GRANT SELECT ON VIEW <db>.<view>.

MySQL (8.0/8.3) has no VIEW object type in GRANT: GRANT SELECT ON db.v TO u works for a view. So a MySQL-compatible grant script produces a silent no-op on a security-relevant statement.

Repro (fresh main@3ad9adbb4c, single-node)

create database if not exists vg;
use vg;
create table s(a int primary key, b int);
insert into s values (1,10);
create view vs as select a,b from s;

create role vg_role;
grant connect on account * to vg_role;
grant select on table vg.s to vg_role;
grant select on table vg.vs to vg_role;          -- MySQL form: accepted, no error
create user vg_u identified by 'Pwd123!@#' default role vg_role;
grant vg_role to vg_u;

Then, as vg_u:

set role vg_role;
select count(*) from vg.s;   -- works: 1        (base table privilege is effective)
select * from vg.vs;         -- ERROR 20101 (HY000): internal error: do not have privilege to execute the statement

Adding the non-MySQL form fixes it immediately:

grant select on view vg.vs to vg_role;   -- as admin
-- as vg_u again
set role vg_role;
select * from vg.vs;        -- a  b
                            -- 1  10

Expected

Either of:

  1. GRANT ... ON TABLE <view> should grant access to the view (MySQL behaviour), or
  2. it should be rejected with a clear error (e.g. "object is a view, use ON VIEW"), instead of succeeding and doing nothing.

Evidence / classification

  • Reproduced identically on main@3ad9adbb4c and on the window base 7b911aea68 (differential run with two local builds) → pre-existing, not introduced by the recent commits.
  • Same user/role can read the base table in the failing state, so this is not a general privilege setup error.

Code pointers

  • pkg/frontend/authenticate.go:9772 and :9804 — the privilege path branches on astObjType == tree.OBJECT_TYPE_VIEW / checkPrivilegeObjectTypeAndPrivilegeLevel(..., tree.OBJECT_TYPE_VIEW, ...).
  • pkg/sql/parsers/dialect/mysql/mysql_sql.y:2660 vs :2676 — TABLE and VIEW map to different object types, so ON TABLE <view> records a table privilege that the view check never reads.

Related to the view-authorization work in #30799 / 6495ce9 (preserve view authorization across index joins and replacement), which is why this is routed to that author rather than left unassigned.

Activity

  1. added
    kind/bug
    on Oct 22, 2026
  2. XuPeng-SH commented on Oct 26, 2026

    @XuPeng-SH
    ContributorAuthor

    Duplicate of #30626 — merged into the consolidated privilege-enforcement tracking table in #30626. Original reproduction remains in this issue.

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

Metadata

Metadata

Assignees

Labels

kind/bugneeds-triage

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions