Skip to content

Commit 1e12209

Browse files
authored
updated (#1982)
1 parent f382ffa commit 1e12209

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

docs/en/guides/56-security/access-control/01-privileges.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,16 @@ Please note that you can use the [USE DATABASE](/sql/sql-commands/ddl/database/d
170170

171171
| Privilege | Description |
172172
|:----------|:-----------------------------------------------------------------------------------------------------------------|
173-
| Alter | Renames a database. |
173+
| ALTER | Renames a database. |
174174
| CREATE | Creates a database. |
175175
| DROP | Drops or undrops a database. Restores the recent version of a dropped database. |
176176
| SELECT | SHOW CREATE a database. |
177177
| OWNERSHIP | Grants full control over a database. Only a single role can hold this privilege on a specific object at a time. |
178+
| USAGE | Allows entering a database using `USE <database>`, without granting access to any contained objects. |
178179

179180
> Note:
180181
>
181-
> 1. If a role own a database, this role can access all tables under this database.
182+
> 1. If a role owns a database, the role can access all the tables in the database.
182183
183184

184185
### Session Policy Privileges

docs/en/sql-reference/10-sql-commands/00-ddl/00-database/ddl-use-database.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
title: USE DATABASE
33
sidebar_position: 3
44
---
5+
import FunctionDescription from '@site/src/components/FunctionDescription';
6+
7+
<FunctionDescription description="Introduced or updated: v1.2.721"/>
58

69
Selects a database for the current session. This statement allows you to specify and switch to a different database. Once you set the current database using this command, it remains the same until the end of the session unless you choose to change it.
710

@@ -11,6 +14,22 @@ Selects a database for the current session. This statement allows you to specify
1114
USE <database_name>
1215
```
1316

17+
## Important Notes
18+
19+
In some cases, executing `USE <database>` can be slow—for example, when the user has ownership of only a subset of tables, and Databend needs to scan metadata to determine access rights.
20+
21+
To improve the performance of the `USE <database>` statement—especially in databases with many tables or complex permissions—you can grant the `USAGE` privilege on the database to a role, and then assign that role to users.
22+
23+
```sql
24+
-- Grant USAGE privilege on the database to a role
25+
GRANT USAGE ON <database_name>.* TO ROLE <role_name>;
26+
27+
-- Assign the role to a user
28+
GRANT ROLE <role_name> TO <user_name>;
29+
```
30+
31+
The `USAGE` privilege allows users to enter the database but does not grant visibility or access to any tables. Users still need appropriate table-level privileges such as `SELECT` or `OWNERSHIP` to see or query tables.
32+
1433
## Examples
1534

1635
```sql

0 commit comments

Comments
 (0)