Managing tables and directories
This section describes how to manage row-oriented and document tables as well as directories using the cloud management console or Terraform.
The following operations are possible:
To work with tables and directories, you will need a database.
Creating a table
You can create a row-oriented table or a document table.
Row-oriented table
- In the management console
, go to the folder page and select Managed Service for YDB. - Select the database to create a table in.
- Go to the Navigation tab.
- Choose Create → Table on the right side of the page.
- Configure the table settings:
- Table Name. Must be unique within the database.
- Table type:
Row table
.
- Add columns:
- Column Name. Must be unique within the table.
- Column data Type. Regardless of the data type, each column may contain a
NULL
value. - Primary key. Specify whether the column is part of the primary key. Primary indexes are automatically created based on the primary key.
- If necessary, set up secondary indexes
:- Secondary index Name. Must be unique within the table.
- Key: One or more columns that make up a key for creating a secondary index.
- Configure the partitioning
policy:None
: The table is not partitioned.Evenly
: The entire range of values of Uint32 or Uint64 key columns (from 0 to the maximum value) is split into same-length intervals. When using this policy, set the number of intervals in the Count field.Explicitly
: Allows you to explicitly specify values for keys that will act as boundaries for initial table partitioning. To add another boundary value, click Add split point.
- Configure automatic partitioning:
- By size: If enabled, a partition is split into two when a certain data size is reached.
- By load: If enabled, a partition is split into two if it is under high loads for a certain period of time (uses a lot of CPU time).
- Configure advanced table settings:
- Auto-partitioning by size in MB: Threshold data size at which auto partitioning by size is triggered.
- Minimum number of partitions: Number of partitions in the table below which no partition merge by size or load is performed.
- Maximum number of partitions: Number of partitions in the table above which no splitting by size or load is performed.
- Bloom filter for primary key: If enabled, YDB uses a Bloom filter
to search data by key. In some cases, it can speed up key reads.
- Click Create table.
To create row-oriented tables, you can also use the CREATE TABLE
To learn how to create a row-oriented table using Terraform, see Creating row tables in a database.
Document table
Note
Document tables are only available in Managed Service for YDB serverless mode.
- In the management console
, go to the folder page and select Managed Service for YDB. - Select the database to create a table in.
- Choose Create → Table on the right side of the page.
- Configure the table settings:
- Table Name. Must be unique within the database.
- Table type:
Document table
.
- Add columns:
- Column Name. Must be unique within the table.
- Column data Type. Regardless of the data type, each column may contain a
NULL
value. - Partition key: Simple primary key that consists of one attribute. YDB uses the partition key value as an input for the internal hashing function. The result of calculating the hash function determines the partition where the item will be stored.
- Sort key. A primary key can be composite and consist of a partition key and a sort key. All items with the same partition key will be stored together, in sorted order by the sort key value. If a partition key and a sort key are specified in a document table, two elements may contain the same value for the partition key but must contain different values for the sort key.
- Click Create table.
To learn how to create a document table using Terraform, see Creating document tables in a database.
Changing the table structure
Row-oriented table
In the YDB cloud console, you can add non-key columns to a table and change its automatic partitioning settings.
- In the management console
, go to the folder page and select Managed Service for YDB. - Select the database to update a table in.
- Find the table in the list and select
→ Edit. - Add new columns to the table and specify their parameters:
- Column Name. Must be unique within the table.
- Column data Type. Regardless of the data type, each column may contain a
NULL
value.
- To delete non-key columns from the table, click
in the appropriate line. You cannot delete columns that make up a primary key. - Configure automatic partitioning:
- By size: If enabled, a partition is split into two when a certain data size is reached.
- By load: If enabled, a partition is split into two if it is under high loads for a certain period of time (uses a lot of CPU time).
- Configure advanced table settings:
- Auto-partitioning by size in MB: Threshold data size at which auto partitioning by size is triggered.
- Minimum number of partitions: Number of partitions in the table below which no partition merge by size or load is performed.
- Maximum number of partitions: Number of partitions in the table above which no splitting by size or load is performed.
- Bloom filter for primary key: If enabled, YDB uses a Bloom filter
to search data by key. In some cases, it can speed up key reads.
- Click Alter table.
See Creating row tables in a database for the description of the table entities that you can change using Terraform.
Document table
Note
Currently, only adding new rows to a table is supported, while the preview is disabled in the management console.
- In the management console
, go to the folder page and select Managed Service for YDB. - Select the database to update a table in.
- Find the table in the list and click it.
- Click Add row.
- Enter the values for the columns listed in the form, then click Add.
See Creating document tables in a database for the description of the table entities that you can change using Terraform.
To edit row-oriented tables, you can also use the ALTER TABLE
Deleting a table
Row-oriented table
- In the management console
, go to the folder page and select Managed Service for YDB. - Select the database to delete a table from.
- Find the table in the list and select
→ Delete. - Confirm the deletion.
To delete a row-oriented table, delete the yandex_ydb_table
resource.
Document table
- In the management console
, go to the folder page and select Managed Service for YDB. - Go to the database to delete a document table from.
- Select a document table from the list of tables, then click
→ Delete. - Confirm the deletion.
To delete a document table, delete the aws_dynamodb_table
resource.
To delete row-oriented tables, you can also use the DROP TABLE
Creating and deleting directories
- In the management console
, go to the folder page and select Managed Service for YDB. - Select the database to create a directory in.
- Choose Create → Directory on the right side of the page.
- Enter the directory name and click Create directory.