{
    "@context": "https://schema.org",
    "@type": "DefinedTerm",
    "@id": "https://hostdir.net/glossary/materialized-view",
    "name": "Materialized View",
    "description": "A database object that stores the precomputed result of a query as a table, refreshed periodically or on demand to improve read performance and reduce computational overhead.",
    "url": "https://hostdir.net/glossary/materialized-view",
    "inDefinedTermSet": "https://hostdir.net/glossary",
    "termCode": "materialized-view",
    "mainEntityOfPage": "https://hostdir.net/glossary/materialized-view",
    "license": "https://creativecommons.org/licenses/by/4.0/",
    "_hostdir": {
        "kind": "glossary-term",
        "slug": "materialized-view",
        "canonical": "https://hostdir.net/glossary/materialized-view",
        "term": "Materialized View",
        "category": "Databases",
        "category_slug": "databases",
        "summary": "A database object that stores the precomputed result of a query as a table, refreshed periodically or on demand to improve read performance and reduce computational overhead.",
        "definition": "A materialized view is a database object that contains the results of a query, stored physically on disk like a table. Unlike a standard (virtual) view, which executes its defining query every time it is accessed, a materialized view holds a snapshot of the data at the time of the last refresh. This precomputation trades storage space and refresh cost for significantly faster read queries.\n\nMaterialized views are common in data warehouses, reporting systems, and any environment where aggregate queries over large datasets must return quickly. The underlying query can involve joins, aggregations, and complex filtering. The database system stores the result set, and the materialized view can be indexed like a regular table. The data in a materialized view becomes stale over time because it does not reflect every subsequent change to the base tables. Administrators must refresh it either on a schedule (for example, nightly), on demand via a manual command, or incrementally using a mechanism such as a materialized view log (Oracle) or a refresh materialized view concurrently in PostgreSQL.\n\nDatabase platforms differ in how they implement materialized views. Oracle, PostgreSQL, Snowflake, BigQuery, and Amazon Redshift all support some form of materialized view, but the syntax for refresh strategies, query rewrite, and concurrency varies. In systems that support automatic query rewrite, the optimizer can transparently substitute a materialized view for part of a query even if the query does not explicitly reference the view, as long as the view covers the needed data. This makes materialized views a powerful tool for performance tuning without rewriting application queries.",
        "examples": "A retail company runs a nightly data warehouse load. They create a materialized view that sums daily sales by product category from a fact table with millions of rows. Each morning, the dashboard queries only the materialized view, which has a few hundred rows instead of scanning the entire fact table. The view is refreshed after the nightly load completes, so the dashboard always sees the previous day's totals.",
        "key_facts": [
            "Stores query results as a physical table, unlike a virtual view which executes each time.",
            "Requires explicit or scheduled refresh to stay synchronized with base tables.",
            "Can be indexed to improve access speed beyond the base query benefit.",
            "Supports query rewrite in some databases for transparent optimization.",
            "Common in data warehousing for pre-aggregated report tables."
        ],
        "related_terms": [
            "View",
            "Index",
            "Query Rewrite",
            "Data Warehouse",
            "ETL",
            "Snapshot"
        ],
        "references": [
            {
                "title": "PostgreSQL Documentation: Materialized Views",
                "url": "https://www.postgresql.org/docs/current/rules-materializedviews.html"
            },
            {
                "title": "Oracle Database: Materialized View Concepts",
                "url": "https://docs.oracle.com/en/database/oracle/oracle-database/19/dwhsg/basic-materialized-views.html"
            },
            {
                "title": "MySQL 8.0: No materialized views, but workarounds",
                "url": "https://dev.mysql.com/doc/refman/8.0/en/create-table.html"
            }
        ],
        "word_count": 260,
        "license": "CC BY 4.0",
        "license_url": "https://creativecommons.org/licenses/by/4.0/",
        "attribution": "HostDir Glossary — https://hostdir.net/glossary/materialized-view"
    }
}