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
, navigate to the folder dashboard and select Managed Service for YDB. - Select the database to create a table in.
- Navigate 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
NULLvalue. - 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-oriented and column-oriented tables in a database.
Document table
Note
Document tables are only available in Managed Service for YDB serverless mode.
- In the management console
, navigate to the folder dashboard 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
NULLvalue. - Partition key: Simple primary key that consists of one attribute. YDB uses the partitioning key value as an input for the internal hashing function. The result of the hash function calculation decides the partition the element will be stored in.
- Sort key. The primary key can be composite and consist of a partitioning key and a sorting key. All elements with the same partitioning key will be stored together, sorted based on the sorting key. If a document table features a partitioning key and a sorting key, any two elements may contain the same partitioning key value but must contain different sorting key values.
- Click Create table.
To learn how to create a document table using Terraform, see Creating document tables in a database.
Сolumn-oriented table
- In the management console
, navigate to the folder dashboard and select Managed Service for YDB. - Select the database to create a table in.
- Navigate 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:
Column table.
- Add columns:
-
Column Name. Must be unique within the table.
-
Column data Type.
-
Primary key. Specify whether the column is part of the primary key. A primary index is automatically created based on the primary key.
Note
The order of columns in the primary key depends on the order of columns in the table being created.
-
NOT NULL constraint. Specify whether the column may contain the
NULLvalue.
-
- Configure the table TTL parameters:
- Column. Select the column whose value will be used to calculate the lifetime of the rows.
- Lifetime. Specify the lifetime of the table rows.
- Unit. Select a unit of measurement for the table row lifetime you specified.
- Configure partitioning:
- Partition key: Specify a column to partition the table by.
- Partition count: Specify the number of partitions for the table.
- Click Create table.
To create column-oriented tables, you can also use the CREATE TABLE
To learn how to create a column-oriented table using Terraform, see Creating row-oriented and column-oriented 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
, navigate to the folder dashboard 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
NULLvalue.
- 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-oriented and column-oriented 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
, navigate to the folder dashboard 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
Column-oriented table
-
In the management console
, navigate to the folder dashboard and select Managed Service for YDB. -
Select the database to update a table in.
-
Find the table in the list and select
→ Edit.Make the required updates in the table structure. Available actions:
- 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
NULLvalue.
- To delete non-key columns from the table, click
in the appropriate row. You cannot delete columns that make up a primary key. - Configure the table TTL parameters:
- Column. Select the column whose value will be used to calculate the lifetime of the rows.
- Lifetime. Specify the lifetime of the table rows.
- Unit. Select a unit of measurement for the table row lifetime you specified.
- Add new columns to the table and specify their parameters:
-
Click Alter table.
To update column-oriented tables, you can also use the ALTER TABLE
See Creating row-oriented and column-oriented tables in a database for the description of the table entities that you can change using Terraform.
Note
Updating the store and partition_by parameters of the column-oriented table will result in recreating the table.
Deleting a table
Row-oriented table
- In the management console
, navigate to the folder dashboard 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
, navigate to the folder dashboard 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.
Column-oriented table
- In the management console
, navigate to the folder dashboard 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 column-oriented table, delete the yandex_ydb_table resource.
To delete tables, you can also use the DROP TABLE
Creating and deleting directories
- In the management console
, navigate to the folder dashboard 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.