Skip to content

Commit 3079f75

Browse files
committed
Review fixes, iteration 1, part 1
1 parent 263f8b5 commit 3079f75

File tree

14 files changed

+172
-207
lines changed

14 files changed

+172
-207
lines changed

ydb/docs/en/core/concepts/datamodel/_includes/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ This section describes the entities that {{ ydb-short-name }} uses within DBs. T
44

55
* [Directory](../dir.md)
66
* [Table](../table.md)
7-
* [Topic](../../topic.md)
87
* [View](../view.md)
8+
* [Topic](../../topic.md)

ydb/docs/en/core/concepts/datamodel/toc_i.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ items:
22
- { name: Overview, href: index.md }
33
- { name: Directory, href: dir.md }
44
- { name: Table, href: table.md }
5+
- { name: View, href: view.md }
56
- { name: Topic, href: ../topic.md }
67
- { name: Secrets, href: secrets.md }
78
- { name: External tables, href: external_table.md }
89
- { name: External data source, href: external_data_source.md }
9-
- { name: View, href: view.md }
Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,32 @@
11
# View
22

3-
A view is a query which is treated as if it was a table storing the results of the query. The view itself contains no data. The content of a view is generated every time you select from that view. Any changes in the underlying tables are reflected immediately in the view.
3+
A view is a query which is treated as if it was a table storing the results of the query. The view itself contains no data. The content of a view is generated every time you `SELECT` from it. Thus, any changes in the underlying tables are reflected immediately in the view.
44

55
Views are often used to:
6-
- hide query complexity,
7-
- limit access to underlying data*,
8-
- provide a backward compatible interface to emulate a table that used to exist, but whose schema has changed.
96

10-
\* The scenario of creating a view to grant other users partial select privileges on a table that has sensitive data is not implemented yet. In {{ ydb-short-name }} view's stored query can only be executed on behalf of the user of the view. A user cannot select from a view that reads from a table that they don't have privileges to select from. See `security_invoker` [option](../../yql/reference/syntax/create_view.md#security_invoker) description on the CREATE VIEW page for details.
7+
- hide query complexity
8+
- limit access to underlying data
9+
- provide a backward-compatible interface to emulate a table that used to exist but whose schema has changed
1110

12-
## Creating a view
11+
{% note warning %}
1312

14-
See [CREATE VIEW](../../yql/reference/syntax/create_view.md).
13+
The scenario of creating a view to grant other users partial `SELECT` privileges on a table that has sensitive data has not been implemented yet. In {{ ydb-short-name }}, the view's stored query can only be executed on behalf of the user querying the view. A user cannot access data from a view that reads from a table that they don't have privileges to `SELECT` from. See the `security_invoker` [option](../../yql/reference/syntax/create_view.md#security_invoker) description on the `CREATE VIEW` page for details.
1514

16-
## Altering a view
17-
18-
See [ALTER VIEW](../../yql/reference/syntax/alter_view.md).
19-
20-
## Dropping a view
21-
22-
See [DROP VIEW](../../yql/reference/syntax/drop_view.md).
15+
{% endnote %}
2316

2417
## View invalidation
2518

26-
If you drop a table that a view references, the view will become invalid. Queries through it will fail with an error, caused by referencing a table that does not exist. To make this view valid again, you need to provide (create or rename, for example) a selectable object (a table or a view) with the same name (and schema if it was specified in the view's query) that the deleted table had. The dependencies of views on tables (and other views) are not tracked in any way at the moment. Select from a view is executed in the same manner as a select from a subquery would: without any prior checks of validity. You would know that the view's query became invalid only at the moment of its execution. This is going to change in future releases. We are going to start tracking view's dependencies and the default behavior would be to forbid dropping a table if it has a view referencing it.
27-
28-
## Query execution context
29-
30-
See [notes](../../yql/reference/syntax/create_view.md#notes) on the CREATE VIEW page. Search by the word `context`.
19+
If you drop a table that a view references, the view will become invalid. Queries against it will fail with an error caused by referencing a table that does not exist. To make the view valid again, you must provide a queriable entity with the same name (by creating or renaming a table or another view). It needs to have a schema compatible with the deleted one. The dependencies of views on tables and other views are not tracked. A `SELECT` from a view is executed like a `SELECT` from a subquery would, without any prior checks of validity. You would know that the view's query became invalid only at the moment of its execution. This approach will change in future releases: {{ ydb-short-name }} will start tracking the view's dependencies, and the default behavior would be to forbid dropping a table if there's a view referencing it.
3120

3221
## Performance
3322

34-
Queries are executed in 2 steps:
35-
1. compilation,
36-
2. execution of the compiled code.
23+
Queries are executed in two steps:
24+
1. compilation
25+
2. execution of the compiled code
3726

38-
The resultant compiled code contains no evidence that the query was made using views, because all the references to views should have been replaced during compilation by the queries that they represent. In practice, it means that there must be no difference in the execution time of the compiled code (step 2) for queries made using views vs. queries directly reading from the underlying tables.
27+
The resulting compiled code contains no evidence that the query was made using views because all the references to views should have been replaced during compilation by the queries that they represent. In practice, there must be no difference in the execution time of the compiled code (step 2) for queries made using views versus queries directly reading from the underlying tables.
3928

40-
However, users might notice a little increase in the compilation time of the queries made using views compared to the compilation time of the same queries written directly. It happens due to the fact that a statement reading from a view:
29+
However, users might notice a little increase in the compilation time of the queries made using views compared to the compilation time of the same queries written directly. It happens because a statement reading from a view:
4130
```sql
4231
SELECT * FROM a_view;
4332
```
@@ -47,23 +36,20 @@ SELECT * FROM (SELECT * FROM underlying_table);
4736
```
4837
but with an additional overhead of loading data from the schema object `a_view`.
4938

50-
Please note that if you execute the same query over and over again like:
39+
Please note that if you execute the same query over and over again, like:
5140
```sql
5241
-- execute multiple times
5342
SELECT * FROM hot_view;
5443
```
55-
compilation results will be cached on the {{ ydb-short-name }} server and you will not notice any difference in performance of queries using views and direct queries.
44+
compilation results will be cached on the {{ ydb-short-name }} server side, and you will not notice any difference in the performance of queries using views and direct queries.
5645

5746
## View redefinition lag
5847

5948
### Query compilation cache
60-
{{ ydb-short-name }} caches query compilation results on the server side for efficiency. For small queries like:
61-
```sql
62-
SELECT 1;
63-
```
64-
compilation can take up to a hundred times more CPU time than the execution. The cache entry is searched by the text of the query and some additional information such as a user SID.
6549

66-
The cache is updated by {{ ydb-short-name }} automatically to stay on track with the changes made to the objects that the query references. However, in the case of views the cache is not updated in the same transaction in which the object's definition changes. It happens with a little delay.
50+
{{ ydb-short-name }} caches query compilation results on the server side for efficiency. For small queries like `SELECT 1;` compilation can take up to a hundred times more CPU time than the execution. The cache entry is searched by the text of the query and some additional information, such as a user SID.
51+
52+
The cache is automatically updated by {{ ydb-short-name }} to stay on track with the changes made to the objects the query references. However, in the case of views, the cache is not updated in the same transaction in which the object's definition changes. It happens with a little delay.
6753

6854
### Problem statement
6955

@@ -81,4 +67,10 @@ DROP VIEW some_view_which_is_going_to_be_redefined;
8167
CREATE VIEW some_view_which_is_going_to_be_redefined ...;
8268
```
8369

84-
The text of the Alice's query does not change, which means that the compilation will happen only once and the results are going to be taken from the cache since then. Bob changes the definition of the view and the cache entry for the Alice's query should theoretically be evicted from the cache in the same transaction, in which the view was redefined. However, this is not the case. The Alice's query will be recompiled with a little delay, which means that for a small period of time Alice's query will produce results inconsistent with the updated definition of the view. This is going to be fixed in future releases.
70+
The text of Alice's query does not change, which means that the compilation will happen only once, and the results are going to be taken from the cache since then. Bob changes the definition of the view, and the cache entry for Alice's query should theoretically be evicted from the cache in the same transaction in which the view was redefined. However, this is not the case. Alice's query will be recompiled with a little delay, which means that for a short period of time, Alice's query will produce results that are inconsistent with the updated definition of the view. This is going to be fixed in future releases.
71+
72+
## See also
73+
74+
* [CREATE VIEW](../../yql/reference/syntax/create_view.md)
75+
* [ALTER VIEW](../../yql/reference/syntax/alter_view.md)
76+
* [DROP VIEW](../../yql/reference/syntax/drop_view.md)
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
# ALTER VIEW
22

3-
ALTER VIEW — change the definition of a view.
3+
`ALTER VIEW` changes the definition of a view.
44

55
This feature is not supported yet. You can redefine a view by dropping it and recreating it with a different query or options values:
66
```sql
77
DROP VIEW redefined_view;
88
CREATE VIEW redefined_view ...;
99
```
10+
This script would not be atomic though.
1011

1112
## See also
1213

13-
[CREATE VIEW](create_view), [DROP VIEW](drop_view)
14+
* [CREATE VIEW](create_view)
15+
* [DROP VIEW](drop_view)
Lines changed: 36 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,81 @@
11
# CREATE VIEW
22

3-
CREATE VIEW defines a view of a query.
3+
`CREATE VIEW` defines a view of a query.
44

5-
A view is a logical representation of a table formed by the specified query. The view does not physically store the table, but runs the query to produce the data whenever the view is selected from.
5+
A view logically represents a table formed by a given query. The view does not physically store the table but executes the query to produce the data whenever the view is accessed.
66

77
## Syntax
88

99
```sql
10-
CREATE VIEW name
11-
[ WITH ( view_option_name [= view_option_value] [, ... ] ) ]
12-
AS query
10+
CREATE VIEW <name>
11+
[ WITH ( <view_option_name> [= <view_option_value>] [, ... ] ) ]
12+
AS <query>
1313
```
1414

1515
### Parameters
1616

17-
* `name`
17+
* `name` - the name of the view to be created. The name must be distinct from the names of all other schema objects.
18+
* `query` - the `SELECT` query, which will be used to produce the logical table the view represents.
1819

19-
The name of the view to be created. The name must be distinct from the name of any other schema object.
20-
* `query`
20+
`WITH ( <view_option_name> [= <view_option_value>] [, ... ] )` specifies optional parameters for a view. The following parameters are supported:
2121

22-
The SELECT query, which will be used to produce the logical table the view represents.
23-
24-
`WITH ( view_option_name [= view_option_value] [, ... ] )`
25-
26-
This clause specifies optional parameters for a view. The following parameters are supported:
27-
28-
* `security_invoker` (Bool) {#security_invoker}
29-
30-
This option causes the underlying base relations to be checked against the privileges of the user of the view rather than the view owner.
22+
* `security_invoker` (Bool) {#security_invoker} causes the underlying base relations to be checked against the privileges of the user of the view rather than the view owner.
3123

3224
## Notes {#notes}
3325

34-
`security_invoker` option must be always 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.
26+
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.
3527

36-
The execution context of the view's query is different from the context of the enclosing SELECT from the view statement. It does not "see" previously defined PRAGMAs like TablePathPrefix, named expressions, etc. Most importantly, users must specify the tables (or views) they select from in the view's query by their schema-qualified names. You can see in the [examples](#examples) that the absolute path like `/domain/database/path/to/underlying_table` is used to specify the table, from which a view selects. The particular context of the view's query compilation might change in next releases.
28+
The execution context of the view's query differs from the context of the enclosing `SELECT`. It does not see previously defined `PRAGMA`s, named expressions, etc. Most importantly, users must specify the tables (or views) they select from in the view's query by their schema-qualified names. You can see in the [examples](#examples) that the absolute path like `/domain/database/path/to/underlying_table` is used to specify the table from which a view reads data. The particular context of the view's query compilation might change in the upcoming releases.
3729

3830
If you wish to specify column names that you would like to see in the output of the view, you might do so by modifying the view's query:
3931
```sql
4032
CREATE VIEW view_with_a_renamed_column WITH (security_invoker = TRUE) AS
41-
SELECT
42-
original_column_name AS custom_column_name
43-
FROM `/domain/database/path/to/underlying_table`;
33+
SELECT
34+
original_column_name AS custom_column_name
35+
FROM `/domain/database/path/to/underlying_table`;
4436
```
4537

46-
Star (`*`) expansion in the view's query happens each time you read from the view. The list of columns returned by the following statement:
38+
Asterisk (`*`) expansion in the view's query happens each time you read from the view. The list of columns returned by the following statement:
4739
```sql
4840
/*
49-
CREATE VIEW view_with_a_star WITH (security_invoker = TRUE) AS
50-
SELECT
51-
*
52-
FROM `/domain/database/path/to/underlying_table`;
41+
CREATE VIEW view_with_an_asterisk WITH (security_invoker = TRUE) AS
42+
SELECT
43+
*
44+
FROM `/domain/database/path/to/underlying_table`;
5345
*/
5446

55-
SELECT * FROM view_with_a_star;
47+
SELECT * FROM view_with_an_asterisk;
5648
```
5749
will change if the list of columns of the `underlying_table` is altered.
5850

5951
## Examples {#examples}
6052

61-
Create a view that will list only recent series from the series table:
53+
Create a view that will list only recent series from the `series` table:
6254

6355
```sql
6456
CREATE VIEW recent_series WITH (security_invoker = TRUE) AS
65-
SELECT
66-
*
67-
FROM `/domain/database/path/to/series`
68-
WHERE
69-
release_date > Date("2020-01-01");
57+
SELECT
58+
*
59+
FROM `/domain/database/path/to/series`
60+
WHERE
61+
release_date > Date("2020-01-01");
7062
```
7163

7264
Create a view that will list the titles of the first episodes of the recent series:
7365

7466
```sql
7567
CREATE VIEW recent_series_first_episodes_titles WITH (security_invoker = TRUE) AS
76-
SELECT
77-
episodes.title AS first_episode
78-
FROM `/domain/database/path/to/recent_series`
79-
AS recent_series
80-
JOIN `/domain/database/path/to/episodes`
81-
AS episodes
82-
ON recent_series.series_id = episodes.series_id
83-
WHERE episodes.season_id = 1 AND episodes.episode_id = 1;
68+
SELECT
69+
episodes.title AS first_episode
70+
FROM `/domain/database/path/to/recent_series`
71+
AS recent_series
72+
JOIN `/domain/database/path/to/episodes`
73+
AS episodes
74+
USING(series_id)
75+
WHERE episodes.season_id = 1 AND episodes.episode_id = 1;
8476
```
8577

8678
## See also
8779

88-
[ALTER VIEW](alter_view), [DROP VIEW](drop_view)
80+
* [ALTER VIEW](alter_view)
81+
* [DROP VIEW](drop_view)
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
# DROP VIEW
22

3-
DROP VIEW drops an existing view.
3+
`DROP VIEW` drops an existing view.
44

55
## Syntax
66

77
```sql
8-
DROP VIEW name
8+
DROP VIEW <name>
99
```
1010

1111
### Parameters
1212

13-
* `name`
14-
15-
The name of the view to be deleted.
13+
* `name` - the name of the view to be deleted.
1614

1715
## Examples
1816

19-
The following command will drop the view named recent_series:
17+
The following command will drop the view named `recent_series`:
2018

2119
```sql
2220
DROP VIEW recent_series;
2321
```
2422

2523
## See also
2624

27-
[CREATE VIEW](create_view), [ALTER VIEW](alter_view)
25+
* [CREATE VIEW](create_view)
26+
* [ALTER VIEW](alter_view)

ydb/docs/en/core/yql/reference/yql-core/syntax/toc_i.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@ items:
55
- { name: ACTION, href: action.md }
66
- { name: ALTER GROUP, href: alter-group.md, when: feature_user_and_group }
77
- { name: ALTER TABLE, href: alter_table.md, when: feature_map_tables }
8+
- { name: ALTER VIEW, href: alter_view.md, when: feature_view }
89
- { name: ALTER TOPIC, href: alter_topic.md, when: feature_topic_control_plane }
910
- { name: ALTER USER, href: alter-user.md, when: feature_user_and_group }
10-
- { name: ALTER VIEW, href: alter_view.md, when: feature_view }
1111
- { name: CREATE GROUP, href: create-group.md, when: feature_user_and_group }
1212
- { name: CREATE TABLE, href: create_table.md }
13+
- { name: CREATE VIEW, href: create_view.md, when: feature_view }
1314
- { name: CREATE TOPIC, href: create_topic.md, when: feature_topic_control_plane }
1415
- { name: CREATE USER, href: create-user.md, when: feature_user_and_group }
15-
- { name: CREATE VIEW, href: create_view.md, when: feature_view }
1616
- { name: DECLARE, href: declare.md }
1717
- { name: DELETE, href: delete.md, when: feature_map_tables }
1818
- { name: DISCARD, href: discard.md }
1919
- { name: DROP GROUP, href: drop-group.md, when: feature_user_and_group }
2020
- { name: DROP TABLE, href: drop_table.md }
21-
- { name: DROP USER, href: drop-user.md, when: feature_user_and_group }
2221
- { name: DROP VIEW, href: drop_view.md, when: feature_view }
22+
- { name: DROP USER, href: drop-user.md, when: feature_user_and_group }
2323
- { name: GROUP BY, href: group_by.md }
2424
- { name: EXPORT and IMPORT, href: export_import.md, when: feature_mapreduce }
2525
- { name: FLATTEN, href: flatten.md }

ydb/docs/ru/core/concepts/datamodel/_includes/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
* [Директории](../dir.md)
66
* [Таблицы](../table.md)
7+
* [Представления (VIEWs)](../view.md)
78
* [Топики](../../topic.md)
89
* [Секреты](../secrets.md)
910
* [Подключения к внешним БД](../external_data_source.md)
1011
* [Внешние источники данных](../external_table.md)
11-
* [Представления (VIEWs)](../view.md)

0 commit comments

Comments
 (0)