- General questions about YDB
- What is YDB?
- What features does YDB provide?
- What consistency model does YDB use?
- How do I design a primary key?
- How do I evenly distribute load across table partitions?
- Can I use NULL in a key column?
- Is there an optimal size of a database row?
- How are secondary indexes used in YDB?
- How is paginated output performed?
- How do I efficiently upload large amounts of data to YDB?
- How do I delete expired data?
General questions about YDB
What is YDB?
YDB is a distributed fault-tolerant SQL DBMS. YDB provides high availability and scalability while simultaneously ensuring strict consistency and ACID transaction support. Queries are made using an SQL dialect (YQL).
YDB is a fully managed database. DB instances are created through the YDB database management service.
What features does YDB provide?
YDB provides high availability and data security through synchronous replication in three availability zones. YDB also ensures even load distribution across available hardware resources. This means you don’t need to order resources, YDB automatically provisions and releases resources based on the user load.
What consistency model does YDB use?
To read data, YDB uses a model of strict data consistency.
How do I design a primary key?
To design a primary key properly, follow the rules below.
Avoid situations where the main load falls on a single partition of a table. With even load distribution, it’s easier to achieve high overall performance.
This rule implies that you shouldn’t use a monotonically increasing sequence, such as timestamp, as a table’s primary key.
The fewer table partitions a query uses, the faster it runs. For greater performance, follow the one query — one partition rule.
Avoid situations where a small part of the DB is under much heavier load than the rest of the DB.
For more information, see Schema design.
How do I evenly distribute load across table partitions?
You can use the following techniques to distribute the load evenly across table partitions and increase overall DB performance.
- To avoid using uniformly increasing primary key values, you can:
- Change the order of its components.
- use a hash of the key column values as the primary key.
- Reduce the number of partitions used in a single query.
For more information, see Schema design.
Can I use NULL in a key column?
In YDB, all columns, including key ones, may contain a NULL
value, but we don’t recommend using NULL
as values in key columns.
Per the SQL standard (ISO/IEC 9075), you can’t compare NULL
with other values. Therefore, the use of concise SQL statements with simple comparison operators may result in rows containing NULL being skipped during filtering, for example.
Is there an optimal size of a database row?
To achieve high performance, we don’t recommend writing rows larger than 8 MB and key columns larger than 2 KB to the DB.
For more information about limits, see Database limits.
How are secondary indexes used in YDB?
Secondary indexes in YDB are global and can be non-unique.
For more information, see Secondary indexes.
How is paginated output performed?
To organize paginated output, we recommend selecting data sorted by primary key sequentially, limiting the number of rows with the LIMIT
keyword. We do not recommend using the OFFSET
keyword to solve this problem.
For more information, see Paginated output.
How do I efficiently upload large amounts of data to YDB?
To increase upload speed for large amounts of data, follow the recommendations below:
- When creating a table, explicitly specify the required number of partitions or their boundaries. This will help you effectively use system bandwidth as soon as you start uploading data by avoiding unnecessary re-partitioning of the table.
- Don’t insert data in separate transactions for each row. It’s more efficient to insert multiple rows at once (batch inserts). This reduces the overhead on the transaction mechanism itself.
- In addition to the previous step, within each transaction (batch), insert rows from the primary key-sorted set of data to minimize the number of partitions that the transaction affects.
- Avoid writing data sequentially in ascending or descending order of the primary key value to evenly distribute the load across all table partitions.
For more detail, see Uploading large volumes of data.
How do I delete expired data?
To effectively remove expired data, we recommend using TTL.