<@U0A71G31CDV> can a materialized view be assigned...
# questions-and-troubleshooting
k
@Rocky can a materialized view be assigned to a colocation group ?
r
Yes, an asynchronous materialized view can be assigned to a colocation group. Starting from StarRocks v3.0, you can specify the
colocate_with
property when creating an asynchronous materialized view. This ensures that the data distribution (bucketing and replica placement) of the materialized view matches other tables or materialized views in the same group, enabling Colocate Joins for better performance. Usage To assign a materialized view to a colocation group, include the
colocate_with
property in the
PROPERTIES
clause:
Copy code
sql
CREATE MATERIALIZED VIEW mv_example
DISTRIBUTED BY HASH(k1) BUCKETS 8
PROPERTIES (
    "colocate_with" = "group_name"
)
AS 
SELECT k1, SUM(v1) FROM base_table GROUP BY k1;
Key Considerations * Requirements: For a materialized view to join a colocation group, it must have the same distribution key types, order, and number of buckets as the other members of the group. * Modifying Existing MVs: You can also add or change the colocation group of an existing materialized view using the
ALTER
statement:
Copy code
sql
    ALTER MATERIALIZED VIEW mv_example SET ("colocate_with" = "new_group_name");
* Synchronous Materialized Views (Rollups): These are technically special indexes attached to a base table. They automatically follow the distribution of the base table. Since v3.2.0, the FE configuration
enable_colocate_mv_index
(enabled by default) ensures that these indexes are colocated with the base table data for faster writes. References • using_starrocks/Colocate_join.md • using_starrocks/Materialized_view-single_table.md • administration/management/FE_configuration.md • best_practices/audit_log_resource_group.md • knowledge/usage/best-practice.md • using_starrocks/async_mv/feature-support-asynchronous-materialized-views.md
👍 1