diff --git a/docs/en/sql-reference/statements/create/view.md b/docs/en/sql-reference/statements/create/view.md index 3544ad93aa5..1d6621ff67d 100644 --- a/docs/en/sql-reference/statements/create/view.md +++ b/docs/en/sql-reference/statements/create/view.md @@ -74,30 +74,17 @@ There isn’t a separate query for deleting views. To delete a view, use [DROP T CREATE LIVE VIEW [IF NOT EXISTS] [db.]table_name [WITH [TIMEOUT [value_in_sec] [AND]] [REFRESH [value_in_sec]]] AS SELECT ... ``` -Live views store result of the corresponding [SELECT](../../../sql-reference/statements/select/index.md) query -and are updated any time the result of the query changes. Query result as well as partial result -needed to combine with new data are stored in memory providing increased performance -for repeated queries. Live views can provide push notifications -when query result changes using the [WATCH](../../../sql-reference/statements/watch.md) query. +Live views store result of the corresponding [SELECT](../../../sql-reference/statements/select/index.md) query and are updated any time the result of the query changes. Query result as well as partial result needed to combine with new data are stored in memory providing increased performance +for repeated queries. Live views can provide push notifications when query result changes using the [WATCH](../../../sql-reference/statements/watch.md) query. Live views are triggered by insert into the innermost table specified in the query. -!!! info "Note" - [Table function](../../../sql-reference/table-functions/index.md) is not supported as the innermost table. +Live views work similarly to how a query in a distributed table works. But instead of combining partial results from different servers they combine partial result from current data with partial result from the new data. When a live view query includes a subquery then the cached partial result is only stored for the innermost subquery. !!! info "Note" - Tables that do not have inserts such as a [dictionary](../../../sql-reference/dictionaries/index.md) - or a [system table](../../../operations/system-tables/index.md) - will not trigger a live view. See [WITH REFRESH](#live-view-with-refresh) to enable periodic - updates of a live view. - -Live views work similarly to how a query in a distributed table works. But instead of combining partial results -from different servers they combine partial result from current data with partial result from the new data. -When a live view query includes a subquery then the cached partial result is only stored for the innermost subquery. - -!!! info "Note" - Only queries where one can combine partial result from the old data plus partial result from the new data will work. - Live view will not work for queries that require the complete data set to compute the final result. + - [Table function](../../../sql-reference/table-functions/index.md) is not supported as the innermost table. + - Tables that do not have inserts such as a [dictionary](../../../sql-reference/dictionaries/index.md) or a [system table](../../../operations/system-tables/index.md) will not trigger a live view. See [WITH REFRESH](#live-view-with-refresh) to enable periodic updates of a live view. + - Only queries where one can combine partial result from the old data plus partial result from the new data will work. Live view will not work for queries that require the complete data set to compute the final result. You can watch for changes in the live view query result using the [WATCH](../../../sql-reference/statements/watch.md) query @@ -111,9 +98,7 @@ or add [EVENTS](../../../sql-reference/statements/watch.md#events-clause) clause WATCH [db.]live_view EVENTS ``` -You can execute [SELECT](../../../sql-reference/statements/select/index.md) query on a live view -in the same way as for any regular view or a table. If the query result is cached -it will return the result immediately without running the stored query on the underlying tables. +You can execute [SELECT](../../../sql-reference/statements/select/index.md) query on a live view in the same way as for any regular view or a table. If the query result is cached it will return the result immediately without running the stored query on the underlying tables. ```sql SELECT * FROM [db.]live_view WHERE ... @@ -125,9 +110,7 @@ You can force live view refresh using the `ALTER LIVE VIEW [db.]table_name REFRE ### With Timeout {#live-view-with-timeout} -When a live view is create with a `WITH TIMEOUT` clause then the live view will be dropped automatically after the specified -number of seconds elapse since the end of the last [WATCH](../../../sql-reference/statements/watch.md) query -that was watching the live view. +When a live view is create with a `WITH TIMEOUT` clause then the live view will be dropped automatically after the specified number of seconds elapse since the end of the last [WATCH](../../../sql-reference/statements/watch.md) query that was watching the live view. ```sql CREATE LIVE VIEW [db.]table_name WITH TIMEOUT [value_in_sec] AS SELECT ... @@ -137,8 +120,7 @@ If the timeout value is not specified then the value specified by the `temporary ### With Refresh {#live-view-with-refresh} -When a live view is created with a `WITH REFRESH` clause then it will be automatically refreshed -after the specified number of seconds elapse since the last refresh or trigger. +When a live view is created with a `WITH REFRESH` clause then it will be automatically refreshed after the specified number of seconds elapse since the last refresh or trigger. ```sql CREATE LIVE VIEW [db.]table_name WITH REFRESH [value_in_sec] AS SELECT ... diff --git a/docs/en/sql-reference/statements/watch.md b/docs/en/sql-reference/statements/watch.md index 480841cf1b9..10d2a2715fb 100644 --- a/docs/en/sql-reference/statements/watch.md +++ b/docs/en/sql-reference/statements/watch.md @@ -17,9 +17,7 @@ WATCH [db.]live_view [FORMAT format] ``` -The `WATCH` query performs continuous data retrieval from a [live view](./create/view.md#live-view) table. -Unless the `LIMIT` clause is specified it provides an infinite stream of query results -from a live view. +The `WATCH` query performs continuous data retrieval from a [live view](./create/view.md#live-view) table. Unless the `LIMIT` clause is specified it provides an infinite stream of query results from a live view. ```sql WATCH [db.]live_view @@ -27,8 +25,7 @@ WATCH [db.]live_view The virtual `_version` column in the query result indicates the current result version. -By default, the requested data is returned to the client, while in conjunction with [INSERT INTO](../../sql-reference/statements/insert-into.md) -it can be forwarded to a different table. +By default, the requested data is returned to the client, while in conjunction with [INSERT INTO](../../sql-reference/statements/insert-into.md) it can be forwarded to a different table. ```sql INSERT INTO [db.]table WATCH [db.]live_view ... @@ -36,9 +33,7 @@ INSERT INTO [db.]table WATCH [db.]live_view ... ## EVENTS Clause {#events-clause} -The `EVENTS` clause can be used to obtain a short form of the `WATCH` query -where instead of the query result you will just get the latest query -result version. +The `EVENTS` clause can be used to obtain a short form of the `WATCH` query where instead of the query result you will just get the latest query result version. ```sql WATCH [db.]live_view EVENTS LIMIT 1 @@ -46,14 +41,10 @@ WATCH [db.]live_view EVENTS LIMIT 1 ## LIMIT Clause {#limit-clause} -The `LIMIT n` clause species the number of updates the `WATCH` query should wait -for before terminating. By default there is no limit on the number of updates and therefore -the query will not terminate. The value of `0` -indicates that the `WATCH` query should not wait for any new query results -and therefore will return immediately once query is evaluated. +The `LIMIT n` clause species the number of updates the `WATCH` query should wait for before terminating. By default there is no limit on the number of updates and therefore the query will not terminate. The value of `0` indicates that the `WATCH` query should not wait for any new query results and therefore will return immediately once query is evaluated. ```sql -WATCH [db.]live_view LIMIT 1 +WATCH [db.]live_view LIMIT 2 ``` ## FORMAT Clause {#format-clause} @@ -61,8 +52,5 @@ WATCH [db.]live_view LIMIT 1 The `FORMAT` clause works the same way as for the [SELECT](./select/index.md#format-clause). !!! info "Note" - The [JSONEachRowWithProgress](../../interfaces/formats/#jsoneachrowwithprogress) format should be used when watching [live view](./create/view.md#live-view) - tables over the HTTP interface. The progress messages will be added to the output - to keep the long-lived HTTP connection alive until the query result changes. - The interval between progress messages is controlled using the [live_view_heartbeat_interval](./create/view.md#live-view-settings) setting. + The [JSONEachRowWithProgress](../../interfaces/formats/#jsoneachrowwithprogress) format should be used when watching [live view](./create/view.md#live-view) tables over the HTTP interface. The progress messages will be added to the output to keep the long-lived HTTP connection alive until the query result changes. The interval between progress messages is controlled using the [live_view_heartbeat_interval](./create/view.md#live-view-settings) setting.