Data Branch Privilege Model¶
Every DATA BRANCH command in MatrixOne now requires specific, operation-scoped privileges on both the source and target objects. This page documents the privilege requirements for each branch operation, the error messages users may encounter, and the protected database mechanism.
Description¶
MatrixOne enforces fine-grained privilege checks for all DATA BRANCH SQL commands. Each operation type requires specific object-level privileges on the source and target tables or databases. The privilege model also includes cross-account cloning restrictions, system database protection, and a protected-database mechanism that prevents accidental drops.
Syntax¶
The privilege model is enforced through standard SQL GRANT and REVOKE statements. Below are the privilege patterns required for each DATA BRANCH operation.
DATA BRANCH CREATE TABLE¶
GRANT SELECT ON TABLE <source_db>.<source_table> TO <role>;
GRANT CREATE TABLE ON DATABASE <target_db> TO <role>;
DATA BRANCH CREATE DATABASE¶
GRANT SELECT ON TABLE <source_db>.<source_table> TO <role>;
GRANT CREATE DATABASE ON ACCOUNT * TO <role>;
DATA BRANCH DIFF¶
GRANT SELECT ON TABLE <db>.<target_table> TO <role>;
GRANT SELECT ON TABLE <db>.<base_table> TO <role>;
DATA BRANCH MERGE¶
GRANT SELECT ON TABLE <db>.<source_table> TO <role>;
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE <db>.<destination_table> TO <role>;
DATA BRANCH PICK¶
GRANT SELECT ON TABLE <db>.<source_table> TO <role>;
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE <db>.<destination_table> TO <role>;
GRANT SELECT ON TABLE <db>.<keys_table> TO <role>;
DATA BRANCH DELETE TABLE¶
GRANT DROP TABLE ON DATABASE <db> TO <role>;
DATA BRANCH DELETE DATABASE¶
GRANT DROP DATABASE ON ACCOUNT * TO <role>;
Arguments¶
Privilege |
Scope |
Description |
|---|---|---|
|
Table |
Allows reading rows from the specified table. Required on source tables for all branch read operations and on both sides for DIFF, MERGE, and PICK. |
|
Database |
Allows creating new tables in the specified database. Required on the target database for |
|
Account |
Allows creating new databases in the account. Required for |
|
Table |
Allows inserting new rows into the specified table. Required on the destination table for |
|
Table |
Allows modifying existing rows in the specified table. Required on the destination table for |
|
Table |
Allows deleting rows from the specified table. Required on the destination table for |
|
Database |
Allows dropping tables in the specified database. Required for |
|
Database |
Allows dropping objects in the specified database. Satisfies the requirement for |
|
Account |
Allows dropping databases in the account. Required for |
|
Database |
Grants all database-level privileges. Satisfies requirements for |
|
Database |
Grants ownership-level privileges on a database. Satisfies requirements for |
|
Account |
Grants all account-level privileges. Satisfies |
Privilege Requirements by Operation¶
DATA BRANCH CREATE TABLE¶
Creates a branch table from a source table.
Object |
Required Privileges |
|---|---|
Source table |
|
Destination database |
One of: |
Cross-account clones require a snapshot. Only sys accounts can clone to another account.
DATA BRANCH CREATE DATABASE¶
Creates a branch database from a source database.
Object |
Required Privileges |
|---|---|
Each source table |
|
Destination |
|
DATA BRANCH DELETE TABLE¶
Deletes a branch table. The target must be an active branch table (created by a prior DATA BRANCH CREATE TABLE).
Object |
Required Privileges |
|---|---|
Target database |
One of: |
For non-system databases, table ownership also satisfies the requirement.
DATA BRANCH DELETE DATABASE¶
Deletes a branch database. All tables in the target database must be active branch tables.
Object |
Required Privileges |
|---|---|
Account |
One of: |
For non-system databases, database ownership also satisfies the requirement.
DATA BRANCH DIFF¶
Compares two tables and outputs the differences.
Object |
Required Privileges |
|---|---|
Target table |
|
Base table |
|
DATA BRANCH MERGE¶
Merges changes from a source table into a destination table.
Object |
Required Privileges |
|---|---|
Source table |
|
Destination table |
|
DATA BRANCH PICK¶
Copies selected rows from a source table into a destination table by primary key.
Object |
Required Privileges |
|---|---|
Source table |
|
Destination table |
|
KEYS subquery tables |
|
Cross-Account Cloning Restrictions¶
Cloning a table or database from one account to another requires a snapshot (
{snapshot = '<name>'}or{timestamp = <expr>}).Only
sysaccount users can clone to another account.COPY GRANTScannot be used withTO ACCOUNT.
System Database Protection¶
Non-sys accounts cannot clone data from system databases (mo_catalog, system, information_schema). No account can clone data into system databases.
Protected Databases¶
MatrixOne supports a protected_databases system variable that marks specified databases as protected from accidental drops.
SET GLOBAL protected_databases = 'db1,db2';
When a database is listed in protected_databases:
DROP DATABASEon the protected database is rejected, even for users withDatabaseAllandDatabaseOwnershipprivileges.All other operations (SELECT, INSERT, UPDATE, DELETE, CREATE TABLE, ALTER TABLE, CREATE VIEW) on the protected database continue to work normally.
Only users with the ability to set global variables can modify
protected_databases.
REPLACE INTO DELETE Privilege¶
When REPLACE INTO encounters a unique-key conflict, it internally performs a DELETE of the conflicting row. Users must hold DELETE privilege in addition to SELECT and INSERT for REPLACE INTO to succeed on conflict paths. Pure-insert paths (no conflict, such as NULL unique values) succeed without DELETE privilege.
Examples¶
The following examples demonstrate how privileges interact with DATA BRANCH operations. All statements combine into a single runnable script that can be executed against an empty MatrixOne instance.
DROP DATABASE IF EXISTS dbbranchpriv;
CREATE DATABASE dbbranchpriv;
USE dbbranchpriv;
-- Create source table and data for branch operations
CREATE TABLE src_t(a INT PRIMARY KEY, b VARCHAR(20));
INSERT INTO src_t VALUES (1, 'one'), (2, 'two');
-- Create target table for DIFF operations
CREATE TABLE target_t(a INT PRIMARY KEY, b VARCHAR(20));
INSERT INTO target_t VALUES (1, 10), (3, 30);
-- Create a snapshot for table-level branch operations
CREATE SNAPSHOT sp_t FOR TABLE dbbranchpriv src_t;
-- Create a role with SELECT on source and CREATE TABLE on database
CREATE ROLE r_branch;
GRANT SELECT ON TABLE dbbranchpriv.src_t TO r_branch;
GRANT CREATE TABLE ON DATABASE dbbranchpriv TO r_branch;
CREATE USER u_branch IDENTIFIED BY '111' DEFAULT ROLE r_branch;
-- DATA BRANCH CREATE TABLE: creates a branch table from the source snapshot
DATA BRANCH CREATE TABLE dbbranchpriv.branch_t FROM dbbranchpriv.src_t{snapshot="sp_t"};
-- Verify the branch table contains source data
SELECT COUNT(*) FROM dbbranchpriv.branch_t;
-- DATA BRANCH DIFF: compares two tables and outputs the differences
DATA BRANCH DIFF dbbranchpriv.target_t AGAINST dbbranchpriv.src_t OUTPUT COUNT;
-- Error case: DATA BRANCH DELETE TABLE fails when the target is not a branch-created table
-- Expected-Success: false
DATA BRANCH DELETE TABLE dbbranchpriv.target_t;
-- Cleanup
DROP SNAPSHOT sp_t;
DROP USER u_branch;
DROP ROLE r_branch;
DROP DATABASE IF EXISTS dbbranchpriv;
Error Messages¶
Error |
Cause |
|---|---|
|
Missing required privilege for the attempted branch operation |
|
Non-sys account attempting to clone from |
|
Attempting to clone into a system database |
|
DELETE target is not a branch-created table |
|
DELETE target database has no active branch tables |
|
Combining COPY GRANTS with cross-account clone |
|
Cross-account clone without a snapshot |
Usage Notes¶
Privilege checks are skipped for internal system users and when
SkipCheckPrivilegeis enabled.DATA BRANCH CREATE DATABASEresolves source tables during privilege checking to ensure the same object set is authorized and executed.For
DATA BRANCH DELETE TABLEandDELETE DATABASE, the system validates that the target objects are active branch objects (tracked inmo_catalog.mo_branch_metadata).Branch operations that require multiple privileges check each independently; missing any one privilege causes the entire statement to fail.