You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: ydb/docs/en/core/concepts/datamodel/view.md
+20-12Lines changed: 20 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,13 @@
1
1
# View
2
2
3
-
A view is basically a query that is stored in a database which enables you to treat the results of the query as a table. The view itself contains no data. The results of a view are 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 that view. Any changes in the underlying tables are reflected immediately in the view.
4
4
5
5
Views are often used to:
6
6
- hide query complexity,
7
-
- limit access to underlaying data*,
7
+
- limit access to underlying data*,
8
8
- provide a backward compatible interface to emulate a table that used to exist, but whose schema has changed.
9
9
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 select privileges from. See `security_invoker`option description on the [CREATE VIEW](../../yql/reference/syntax/create_view.md) page for details.
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.
11
11
12
12
## Creating a view
13
13
@@ -23,11 +23,21 @@ See [DROP VIEW](../../yql/reference/syntax/drop_view.md).
23
23
24
24
## View invalidation
25
25
26
-
If you drop a table that the view references, the view will become invalid. The queries through it will fail with an error of referencing a table that does not exist. The dependencies of views on the 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 will know that the view's query became invalid only at the moment of its execution. This is going to change in the future releases. We are going to start tracking view's dependencies and the default behavior for dropping a table would be to forbid it if any view is referencing the table.
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 a 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`.
27
31
28
32
## Performance
29
33
30
-
Users might notice a little increase in the compilation time of the queries made using views compared to the compilation time of the same query, where views are substituted by their queries. It happens due to the fact that a statement reading from a view:
34
+
Queries are executed in 2 steps:
35
+
1. compilation,
36
+
2. execution of the compiled code.
37
+
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. It 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.
39
+
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:
31
41
```sql
32
42
SELECT*FROM a_view;
33
43
```
@@ -44,24 +54,22 @@ SELECT * FROM hot_view;
44
54
```
45
55
compilation results will be cached on the {{ ydb-short-name }} server and you will not notice any decrease of performance of queries using views.
46
56
47
-
Execution time of the resulting compiled code for queries using views should always be exactly the same as for the queries directly reading data from the underlying tables.
48
-
49
57
## View redefinition lag
50
58
51
59
### Query compilation cache
52
60
{{ ydb-short-name }} caches query compilation results on the server side for efficiency. For small queries like:
53
61
```sql
54
62
SELECT1;
55
63
```
56
-
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 parameters such as a user SID.
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 info such as a user SID.
57
65
58
-
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 has changed. It happens with a little delay.
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.
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 the future releases.
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.
Copy file name to clipboardExpand all lines: ydb/docs/en/core/yql/reference/yql-core/syntax/create_view.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
CREATE VIEW defines a view of a query.
4
4
5
-
A view is a logical representation of a table formed by the query, specified at the moment of the view's creation. 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 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.
6
6
7
7
## Syntax
8
8
@@ -25,11 +25,11 @@ The SELECT query, which will be used to produce the logical table the view repre
25
25
26
26
This clause specifies optional parameters for a view. The following parameters are supported:
27
27
28
-
*`security_invoker` (Bool)
28
+
*`security_invoker` (Bool) {#security_invoker}
29
29
30
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.
31
31
32
-
## Notes
32
+
## Notes {#notes}
33
33
34
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.
0 commit comments