SHARE
A "Share" in Databend refers to a feature that enables the sharing of various types of database objects, such as tables, views, and user-defined functions (UDFs), across different tenants.
Sharing data via a share does not involve physically copying or transferring the data to the recipient tenants. Instead, the shared data remains in a read-only state for the recipient tenants. Users belonging to these tenants can only execute queries on the shared data; they are not allowed to perform updates, inserts, or deletions on the shared data.
Getting Started with Share
The section describes how to share data via a share and access the shared data across tenants:
Step 1. Creating a Share
These steps create a share for sharing data with another tenant and grant privileges for the shared data. Perform these steps within the tenant where the data is to be shared.
- Create an empty share using the CREATE SHARE command.
-- Create a share named "myshare"
CREATE SHARE myshare;
- Grant appropriate privileges to the share you created using the GRANT
<privilege>
to SHARE command. Before granting privileges on the objects you want to share, you must grant privileges for the database that contains the objects.
-- Grant the USAGE privilege on the database "db1"
GRANT USAGE ON DATABASE db1 TO SHARE myshare;
-- Grant the SELECT privilege on the table "table1" in the database "db1"
GRANT SELECT ON TABLE db1.table1 TO SHARE myshare;
- Add the tenants you want to share with to the share using the ALTER SHARE command. When sharing data with another organization, you specify the organization by its tenant ID.
-- Add tenant B to the share "myshare"
ALTER SHARE myshare ADD TENANTS = B;
Step 2. Accessing Shared Data
These steps create a share endpoint and a database using the share created in Step 1. Perform these steps within the tenant where you intend to access the shared data.
- Create a SHARE ENDPOINT.
-- Create a share endpoint named "to_share"
CREATE SHARE ENDPOINT to_share URL = 'http://<shared-tenant-endpoint>:<port>' TENANT = <shared-tenant-name>;
- Create a database from the share using the CREATE DATABASE command.
-- Create a database named "db2" using the share "myshare"
CREATE DATABASE db2 FROM SHARE myshare;
- To access the shared data, run a SELECT statement like this:
SELECT * FROM db2.table1 ...
Managing Shares
To manage shares on a tenant, use the following commands: