After adding the index, they "materialize"?

If so, how does the view update? For example, the query began to return additional rows. Are they re-created according to a schedule?

Does it make a difference to use indexed views on frequently changing data or data that rarely changes?

    1 answer 1

    After adding the index, they "materialize"?

    Exactly. Adding a unique clustered index materializes the data returned by the view into that clustered index (that is, essentially into a separate table).

    If so, how does the view update? For example, the query began to return additional rows. Are they re-created according to a schedule?

    Updating of the materialized view occurs synchronously with the change of data in the tables on which it is based, and incrementally (the indexes of the views are not rebuilt completely each time when the data is changed, but supplemented or modified).

    Imagine that there is a regular table with an additional index. If you add rows to the table, the index will be updated in accordance with the data table. The mechanism for updating data of a materialized view is similar to the mechanism for updating data in an index from the data in a table.

    therefore

    Does it make a difference to use indexed views on frequently changing data or data that rarely changes?

    Yes, the use of indexed views on frequently changing data is usually less desirable than on rarely changing ones, since having an indexed view will slow down changing this data.

    A sufficiently large number of special requirements and constraints that the representation must satisfy in order to materialize it (binding to the scheme, requirements of determinism, impossibility to use non-additive aggregating functions) is associated with the implementation of the materialized representations as an index and the incrementality of updating data in them.

    • When sampling will not be performed an expensive query that builds this view, and the data will be selected as fast as if it is a regular table? - iluxa1810
    • @ iluxa1810, yes, it will be like a sample from a table (index). Depending on the version of SqlServer (2016SP1 or earlier) and edition (Express / Standard / Enterprise), it may or may not be necessary to specify the NOEXPAND prompt ( SELECT * FROM View WITH (NOEXPAND) so that the data is taken from the index and the view is not expanded. - i -one