Sql-server – SQL Indexed View for Datamart Reporting with Transactional Replication

data-warehousematerialized-viewperformanceperformance-tuningsql servertransactional-replication

Should Indexed Views be utilized/recommended as method to auto-generate DataMart Reporting tables?

We have a Customer timeline of tables which can be simply joined on CustomerId in each tables.

Indexed views definitely should not be created in high volume OLTP environment database, due to write latency in creating tables. See Brent Ozar Indexed View
Data Modifications
.

However, we want utilize transactional replication of all tables into a separate ReportingDB on another server to create indexed views. This way indexed view will not have any performance reduction on the actual OLTP.

Example OLTP Tables:

  1. Initial Sales tables,
  2. Purchase order tables,
  3. Shipping table, and
  4. Customer Product feedback/Returns table

Best Answer

Yes. It is generally safe, and often useful to create indexed views on subscriber tables in transactional replication.

You may need to drop and recreate the indexed views using custom scripts before and after initializing from a snapshot. See Execute Scripts Before and After the Snapshot Is Applied

You can also use a different indexing scheme on the subscriber (also by using post-snapshot scripts). In particular you can make the subscriber tables Clustered Columnstore tables, or add non-clustered Columnstore indexes on them for reporting.