aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormzinal <zinal@ydb.tech>2023-07-19 17:09:57 +0300
committermzinal <zinal@ydb.tech>2023-07-19 17:09:57 +0300
commit29ab18afdb3aca70fc943207733eba6959b38392 (patch)
tree5ece16bcdc299583ac750f10a172763c57e7d712
parentd34037f1ebac7a9b3d7669010224c828ed89c5aa (diff)
downloadydb-29ab18afdb3aca70fc943207733eba6959b38392.tar.gz
better paging sample in docs
-rw-r--r--ydb/docs/en/core/best_practices/_includes/paging.md27
-rw-r--r--ydb/docs/ru/core/best_practices/_includes/paging.md26
2 files changed, 12 insertions, 41 deletions
diff --git a/ydb/docs/en/core/best_practices/_includes/paging.md b/ydb/docs/en/core/best_practices/_includes/paging.md
index 29a9ced506..dd8f5067c3 100644
--- a/ydb/docs/en/core/best_practices/_includes/paging.md
+++ b/ydb/docs/en/core/best_practices/_includes/paging.md
@@ -28,28 +28,14 @@ DECLARE $limit AS Uint64;
DECLARE $lastCity AS Utf8;
DECLARE $lastNumber AS Uint32;
-$part1 = (
- SELECT * FROM schools
- WHERE city = $lastCity AND number > $lastNumber
- ORDER BY city, number LIMIT $limit
-);
-
-$part2 = (
- SELECT * FROM schools
- WHERE city > $lastCity
- ORDER BY city, number LIMIT $limit
-);
-
-$union = (
- SELECT * FROM $part1
- UNION ALL
- SELECT * FROM $part2
-);
-
-SELECT * FROM $union
-ORDER BY city, number LIMIT $limit;
+SELECT * FROM schools
+WHERE (city, number) > ($lastCity, $lastNumber)
+ORDER BY city, number
+LIMIT $limit;
```
+In the query example shown above, the `WHERE` clause uses a tuple comparison to select the next set of rows. Tuples are compared element by element from left to right, so the order of the fields in the tuple must match the order of the fields in the primary key to avoid table full scan.
+
{% note warning "NULL value in key column" %}
In {{ ydb-short-name }}, all columns, including key ones, may have a NULL value. Despite this, using NULL as key column values is highly discouraged, since the SQL standard doesn't allow NULL to be compared. As a result, concise SQL statements with simple comparison operators won't work correctly. Instead, you'll have to use cumbersome statements with IS NULL/IS NOT NULL expressions.
@@ -65,4 +51,3 @@ In {{ ydb-short-name }}, all columns, including key ones, may have a NULL value.
* [Java](https://github.com/yandex-cloud/ydb-java-sdk/tree/master/examples/ydb-cookbook/src/main/java/com/yandex/ydb/examples/pagination)
* [Python](https://github.com/ydb-platform/ydb-python-sdk/tree/main/examples/pagination)
* [Go](https://github.com/ydb-platform/ydb-go-examples/tree/master/pagination)
-
diff --git a/ydb/docs/ru/core/best_practices/_includes/paging.md b/ydb/docs/ru/core/best_practices/_includes/paging.md
index c03e3149bf..7bc5847acf 100644
--- a/ydb/docs/ru/core/best_practices/_includes/paging.md
+++ b/ydb/docs/ru/core/best_practices/_includes/paging.md
@@ -28,28 +28,14 @@ DECLARE $limit AS Uint64;
DECLARE $lastCity AS Utf8;
DECLARE $lastNumber AS Uint32;
-$part1 = (
- SELECT * FROM schools
- WHERE city = $lastCity AND number > $lastNumber
- ORDER BY city, number LIMIT $limit
-);
-
-$part2 = (
- SELECT * FROM schools
- WHERE city > $lastCity
- ORDER BY city, number LIMIT $limit
-);
-
-$union = (
- SELECT * FROM $part1
- UNION ALL
- SELECT * FROM $part2
-);
-
-SELECT * FROM $union
-ORDER BY city, number LIMIT $limit;
+SELECT * FROM schools
+WHERE (city, number) > ($lastCity, $lastNumber)
+ORDER BY city, number
+LIMIT $limit;
```
+В примере запроса, приведенном выше, в операторе `WHERE` применено сравнение кортежей для отбора очередного множества строк. Сравнение кортежей выполняется поэлементно слева направо, поэтому порядок указания полей в кортеже должен совпадать с порядком указания полей в первичном ключе, чтобы избежать полного сканирования таблицы при выполнении запроса.
+
{% note warning "Значение NULL в ключевой колонке" %}
В {{ ydb-short-name }} все колонки, включая ключевые, могут иметь значение NULL. Несмотря на это использование NULL в качестве значений в ключевых колонках крайне не рекомендуется, так как по SQL стандарту NULL нельзя сравнивать. Как следствие, лаконичные SQL конструкции с простыми операторами сравнения будут работать некорректно. Вместо них придется использовать громоздкие конструкции с IS NULL/IS NOT NULL выражениями.