Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added info on table naming rules #11319

Merged
merged 11 commits into from
Feb 10, 2025
8 changes: 0 additions & 8 deletions ydb/docs/en/core/concepts/datamodel/_includes/index.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## Database object naming rules {#object-naming-rules}

Every [scheme object](../../../concepts/glossary.md#scheme-object) in {{ ydb-short-name }} has a name. In YQL statements, object names are specified by identifiers that can be enclosed in backticks or not. For more information on identifiers, refer to [{#T}](../../../yql/reference/syntax/lexer.md#keywords-and-ids).

Scheme object names in {{ ydb-short-name }} must meet the following requirements:

- Object names can include the following characters:
- uppercase latin characters
- lowercase latin characters
- digits
- special characters: `.`, `-`, and `_`.
- Object name length must not exceed 255 characters.
- Objects cannot be created in folders, which names start with a dot, such as `.sys`, `.medatata`, `.sys_health`.

## Column naming rules {#column-naming-rules}

Column names in {{ ydb-short-name }} must meet the following requirements:

- Column names can include the following characters:
- uppercase latin characters
- lowercase latin characters
- digits
- special characters: `-` and `_`.
- Column names must not start with the system prefix `__ydb_`.
2 changes: 1 addition & 1 deletion ydb/docs/en/core/concepts/datamodel/_includes/table.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ At the moment, not all functionality of column-oriented tables is implemented. T
* Adding data to column-oriented tables using the SQL INSERT statement.
* Deleting data from column-oriented tables using the SQL DELETE statement. In fact, deletion is only possible after the TTL data retention time has expired.

## Partitioning of a column-oriented table {#olap-tables-partitioning}
### Partitioning column-oriented tables {#olap-tables-partitioning}

Unlike row-oriented {{ ydb-short-name }} tables, you cannot partition column-oriented tables by primary keys but only by specially designated partitioning keys. Partitioning keys constitute a subset of the table's primary keys.

Expand Down
22 changes: 21 additions & 1 deletion ydb/docs/en/core/concepts/datamodel/index.md
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
{% include [index.md](_includes/index.md) %}
# Data model and schema

This section describes the entities that {{ ydb-short-name }} uses within DBs. The {{ ydb-short-name }} core lets you flexibly implement various storage primitives, so new entities may appear in the future.

{{ ydb-short-name }} is a relational database where the data is stored in [tables](table.md) with each table consisting of rows and columns. Database objects in {{ ydb-short-name }} can be organized into a hierarchy of [folders](dir.md).

* [Folder](dir.md)
* [Table](table.md)

{% if feature_view %}
* [View](view.md)
{% endif %}

* [Topic](../topic.md)
* [Secret](secrets.md)
* [External table](external_table.md)
* [External data source](external_data_source.md)

[Scheme objects](../../concepts/glossary.md#scheme-object) in {{ ydb-short-name }} all follow the same naming rules described in the section below. However, requirements for column names are slightly different.

{% include [object naming rules](./_includes/object-naming-rules.md) %}
10 changes: 10 additions & 0 deletions ydb/docs/en/core/yql/reference/syntax/alter_table/rename.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@
ALTER TABLE old_table_name RENAME TO new_table_name;
```

{% if oss == true and backend_name == "YDB" %}

{% cut "See table and column naming rules" %}

{% include [table naming rules](../../../../concepts/datamodel/_includes/object-naming-rules.md) %}

{% endcut %}

{% endif %}

If a table with the new name already exists, an error will be returned. The ability to transactionally replace a table under load is supported by specialized methods in CLI and SDK.

{% note warning %}
Expand Down
2 changes: 2 additions & 0 deletions ydb/docs/en/core/yql/reference/syntax/create-topic.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ CREATE TOPIC topic_path (
All the parameters except the topic name are optional. By default, a topic is created without consumers. All
the omitted settings are also set by default (both for the topic and its consumers).

{% include [object naming rules](../../../concepts/datamodel/_includes/object-naming-rules.md#object-naming-rules) %}

## Examples

Creating a topic without consumers with default settings:
Expand Down
2 changes: 2 additions & 0 deletions ydb/docs/en/core/yql/reference/syntax/create-view.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ AS <query>

* `security_invoker` (Bool) causes the underlying base relations to be checked against the privileges of the user of the view rather than the view owner. {#security_invoker}

{% include [object naming rules](../../../concepts/datamodel/_includes/object-naming-rules.md#object-naming-rules) %}

## Notes {#notes}

The `security_invoker` option must always be set to true because the default behavior for views is to execute the query on behalf of the view's creator, which is not supported yet.
Expand Down
7 changes: 5 additions & 2 deletions ydb/docs/en/core/yql/reference/syntax/create_table/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ The invocation of `CREATE TABLE` creates {% if concept_table %}a [table]({{ conc

{% if oss == true and backend_name == "YDB" %}


{% if feature_olap_tables %}

{{ ydb-short-name }} supports two types of tables:
Expand All @@ -59,7 +60,9 @@ By default, if the `STORE` parameter is not specified, a row-oriented table is c

{% endif %}

### Examples of table creation {#examples-tables-creation}
{% include [table naming rules](../../../../concepts/datamodel/_includes/object-naming-rules.md) %}

## Examples of table creation {#examples-tables-creation}

{% list tabs %}

Expand Down Expand Up @@ -213,7 +216,7 @@ Specifying a `PRIMARY KEY` with a non-empty list of columns is mandatory. These

{% endif %}

#### Example
### Example

```yql
CREATE TABLE <table_name> (
Expand Down
15 changes: 0 additions & 15 deletions ydb/docs/ru/core/concepts/datamodel/_includes/index.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
## Правила наименования схемных объектов {#object-naming-rules}

У каждого [схемного объекта](../../../concepts/glossary.md#scheme-object) базы данных в {{ ydb-short-name }} есть имя. В YQL-выражениях имена схемных объектов указываются с помощью идентификаторов, заключённых в обратные кавычки (`` ` ``) или без этих символов. Для более подробной информации об идентификаторах, см. [{#T}](../../../yql/reference/syntax/lexer.md#keywords-and-ids).

Имена схемных объектов в {{ ydb-short-name }} должны соответствовать следующим требованиям:

- Имя объекта может состоять из следующих символов:
- прописные латинские буквы;
- строчные латинские буквы;
- цифры;
- специальные символы: `.`, `-` и `_`.
- Длина имени объекта не должна превышать 255 символов.
- Объекты не должны создаваться в папках, имена которых начинаются с точки, таких как `.sys`, `.medatata`, `.sys_health`.

## Правила наименования колонок {#column-naming-rules}

Имена колонок в {{ ydb-short-name }} должны соответствовать следующим требованиям:

- Имя колонки может состоять из следующих символов:
- прописные латинские буквы;
- строчные латинские буквы;
- цифры;
- специальные символы: `-` и `_`.
- Длина имени колонки не должна превышать 255 символов.
- Имя колонки не должно начинаться с системного префикса `__ydb_`.
22 changes: 21 additions & 1 deletion ydb/docs/ru/core/concepts/datamodel/index.md
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
{% include [index.md](_includes/index.md) %}
# Модель данных и схема

В разделе собраны описания сущностей, которыми оперирует {{ ydb-short-name }} в рамках БД. Ядро {{ ydb-short-name }} позволяет гибко реализовывать различные примитивы хранения, поэтому возможно появление в будущем новых сущностей.

{{ ydb-short-name }} – это реляционная база данных, в которой данные хранятся в таблицах, состоящих из рядов и колонок. Объекты баз данных {{ ydb-short-name }} могут быть организованы в иерархию директорий.

* [Директории](dir.md)
* [Таблицы](table.md)

{% if feature_view %}
* [Представления (VIEW)](view.md)
{% endif %}

* [Топики](../topic.md)
* [Секреты](secrets.md)
* [Подключения к внешним БД](external_data_source.md)
* [Внешние источники данных](external_table.md)

Все [схемные объекты](../../concepts/glossary.md#scheme-object) в {{ ydb-short-name }} имеют одинаковые требования к своим наименованиям. Но правила наименования колонок немного отличаются от правил для схемных объектов.

{% include [object naming rules](./_includes/object-naming-rules.md) %}
12 changes: 11 additions & 1 deletion ydb/docs/ru/core/yql/reference/syntax/alter_table/rename.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@
ALTER TABLE old_table_name RENAME TO new_table_name;
```

{% if oss == true and backend_name == "YDB" %}

{% cut "См. правила наименования таблиц и колонок" %}

{% include [table naming rules](../../../../concepts/datamodel/_includes/object-naming-rules.md) %}

{% endcut %}

{% endif %}

Если таблица с новым именем существует, будет возвращена ошибка. Возможность транзакционной подмены таблицы под нагрузкой поддерживается специализированными методами в CLI и SDK.

{% note warning %}
Expand All @@ -22,4 +32,4 @@ ALTER TABLE old_table_name RENAME TO new_table_name;

```yql
ALTER TABLE `table1` RENAME TO `/backup/table1`;
```
```
2 changes: 2 additions & 0 deletions ydb/docs/ru/core/yql/reference/syntax/create-topic.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ CREATE TOPIC topic_path (

{% endif %}

{% include [object naming rules](../../../concepts/datamodel/_includes/object-naming-rules.md#object-naming-rules) %}

Следующая команда создаст топик без читателей с настройками по умолчанию:

```yql
Expand Down
4 changes: 3 additions & 1 deletion ydb/docs/ru/core/yql/reference/syntax/create-view.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ AS <запрос>

* `security_invoker` (Bool) - опция, при включении которой запрос, хранящийся в представлении, будет исполнен от имени пользователя, читающего из представления, а не от имени создателя представления. {#security_invoker}

{% include [object naming rules](../../../concepts/datamodel/_includes/object-naming-rules.md#object-naming-rules) %}

## Замечания

`security_invoker` опция должна быть всегда выставлена в `TRUE`, потому что поведением по умолчанию для представления является исполнение сохранённого запроса от имени создателя представления, но эта возможность на данный момент не реализована в {{ ydb-short-name }}.
Expand Down Expand Up @@ -80,4 +82,4 @@ WHERE episodes.season_id = 1 AND episodes.episode_id = 1;
## См. также

* [ALTER VIEW](alter-view.md)
* [DROP VIEW](drop-view.md)
* [DROP VIEW](drop-view.md)
10 changes: 6 additions & 4 deletions ydb/docs/ru/core/yql/reference/syntax/create_table/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ WITH (

{% endif %}

### Примеры создания таблиц
{% include [table naming rules](../../../../concepts/datamodel/_includes/object-naming-rules.md) %}

## Примеры создания таблиц

{% list tabs %}

Expand Down Expand Up @@ -95,15 +97,15 @@ WITH (
{% if feature_column_container_type == true %}

Для неключевых колонок допускаются любые типы данных{% if feature_serial %} , кроме [серийных](../../types/serial.md) {% endif %}, для ключевых - только [примитивные](../../types/primitive.md){% if feature_serial %} и [серийные](../../types/serial.md){% endif %}. При указании сложных типов (например, `List<String>`) тип заключается в двойные кавычки.

{% else %}

{% if feature_serial %}

Для ключевых колонок допускаются только [примитивные](../../types/primitive.md) и [серийные](../../types/serial.md) типы данных, для неключевых колонок допускаются только [примитивные](../../types/primitive.md).

{% else %}

Для ключевых и неключевых колонок допускаются только [примитивные](../../types/primitive.md) типы данных.

{% endif %}
Expand Down Expand Up @@ -183,7 +185,7 @@ WITH (
AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = 10
);
```

Такой код создаст колоночную таблицу с 10-ю партициями. С полным списком опций партиционирования колоночных таблиц можно ознакомиться в разделе [{#T}](../../../../concepts/datamodel/table.md#olap-tables-partitioning) статьи [{#T}](../../../../concepts/datamodel/table.md).


Expand Down