<@U0A71G31CDV> can I create materialized views int...
# questions-and-troubleshooting
c
@Rocky can I create materialized views into an external catalog?
r
Yes, you can create materialized views into an external catalog in StarRocks, but the behavior and storage location depend on your version and how you define the materialized view (MV). 1. External Catalog-Based Materialized Views (Standard) In this scenario, you create a materialized view on top of tables in an external catalog (such as Hive, Iceberg, Hudi, Paimon, or Delta Lake), but the data is stored inside StarRocks (internal storage). * Supported since: v2.5. * Storage: The precomputed results are stored in the StarRocks
default_catalog
. * Benefit: This is the most common way to accelerate data lake queries by bringing a precomputed snapshot into StarRocks' high-performance engine. * Syntax Example:
Copy code
sql
    CREATE MATERIALIZED VIEW my_mv
    DISTRIBUTED BY HASH(id)
    REFRESH ASYNC EVERY (INTERVAL 1 HOUR)
    AS
    SELECT id, name FROM iceberg_catalog.db.table;
2. External Materialized Views (Storage in the Data Lake) Starting with more recent versions (specifically v3.4 and v3.5), StarRocks introduced "External Materialized Views." These are materialized views where the data is stored directly in the external catalog (e.g., as an Apache Iceberg table) rather than within StarRocks itself. * Supported Catalogs: Primarily Apache Iceberg (v3.4+) and Hive (with write capabilities in v3.3+). * Storage: The precomputed results are stored in your data lake (S3/HDFS) as physical files managed by the external catalog's metadata (like Iceberg). * Purpose: This allows StarRocks to act as a transformation engine for your lakehouse, where the results of the MV can also be consumed by other engines (like Spark or Trino) since the data lives in the open lake format. * Syntax Example:
Copy code
sql
    -- Note the catalog prefix in the MV name
    CREATE MATERIALIZED VIEW iceberg_catalog.target_db.external_mv
    REFRESH ASYNC EVERY (INTERVAL 1 DAY)
    AS
    SELECT ... FROM source_catalog.db.table;
Key Differences & Limitations Feature | Standard MV (Internal Storage) | External MV (Lake Storage) Data Format | StarRocks native format (optimized for SR) | Open formats (e.g., Parquet in Iceberg) Consumption | Only accessible via StarRocks | Accessible by StarRocks, Spark, Trino, etc. Performance | Highest (native indexing/caching) | Slightly lower (network I/O to lake) Rewrite | Transparent query rewrite supported | Rewrite supported (v3.5+) Refresh | Manual, Fixed Interval | Manual, Fixed Interval Note on Refresh: Materialized views based on external tables do not support automatic refresh triggered by data changes in the base table (since external systems don't send "change notifications" to StarRocks). You must use a fixed-interval schedule or manual refresh. For more specific details, you can refer to the StarRocks documentation on Data Lake Acceleration. References • data_source/feature-support-data-lake-analytics.md • data_source/catalog/iceberg/iceberg_catalog.md • using_starrocks/async_mv/use_cases/data_lake_query_acceleration_with_materialized_views.md • data_source/External_table.md