Događaji
Izgradite inteligentne aplikacije
M03 17 21 - M03 21 10
Pridružite se seriji susreta kako biste sa kolegama programerima i stručnjacima izgradili skalabilna AI rješenja zasnovana na stvarnim slučajevima korištenja.
Registrirajte seOvaj preglednik više nije podržan.
Nadogradite na Microsoft Edge da iskoristite najnovije osobine, sigurnosna ažuriranja i tehničku podršku.
APPLIES TO:
NoSQL
Važno
Azure Cosmos DB for NoSQL materialized views are currently in preview. You can enable this feature by using the Azure portal and the feature can't be disabled. This preview is provided without a service-level agreement. At this time, we don't recommend that you use materialized views for production workloads. Certain features of this preview might not be supported or might have constrained capabilities. For more information, see the supplemental terms of use for Microsoft Azure previews.
Materialized views are read-only containers that store a persistent copy of data from a source container. These views have their own settings, separate from the source container, such as partition key, indexing policy, Request Unit (RU) limit, and data model, which can be customized by selecting a subset of item properties. Materialized views are automatically kept in sync with the source container using change feed, managed by the materialized views builder. The materialized views builder is dedicated compute provisioned for your Azure Cosmos DB account to maintain views.
Upozorenje
The materialized views feature can't be disabled on an account once enabled, however the materialized views builder and view containers themselves can be deprovisioned.
Applications often need to query data without specifying a partition key. These queries must be executed across all partitions, even if some partitions don't contain data that matches the filter criteria. As a result, queries that don't include the partition key consume more RUs and have higher latency.
With a materialized view, you can:
Materialized views can act as a Global Secondary Index (GSI), enabling efficient querying on properties other than the partition key of the source container. By creating a materialized view with a different partition key, you can achieve a similar effect to a GSI. Once the materialized view is created, queries that would otherwise be cross-partition can be retargeted to the view container, leading to reduced RU consumption and reduced latency.
Azure Cosmos DB materialized views offer the following features:
Creating a materialized view is similar to creating a new container, with requirements to specify the source container and a query defining the view. Each item in the materialized view has a one-to-one mapping to an item in the source container. To maintain this mapping, the id
field in materialized view items is auto populated. The value of id
from the source collection is represented as _id
in the view.
The query used to define a materialized view must adhere to the following constraints:
For example, a valid query could be: SELECT c.userName, c.emailAddress FROM c
, which selects the userName
and emailAddress
properties from the source container c
. This query defines the structure of the materialized view, determining which properties are included in the view. The materialized view source container and definition query can't be changed once created.
Learn how to create materialized views.
Bilješka
Once views are created, if you want to delete the source container, you must first delete all materialized views that are created for it.
The materialized views builder is a dedicated compute layer provisioned for your Azure Cosmos DB account that automatically maintains views defined for source containers. The builder reads from the change feed of the source container and writes changes to the materialized views according to the view definition, keeping them in sync. Updating views is asynchronous and doesn't affect writes to the source container. Updates to the views are eventually consistent with the source container regardless of the consistency level set for the account.
You must provision a materialized views builder for your Azure Cosmos DB account for views to begin populating. The amount of compute provisioned in the builder, including the SKU and the number of nodes, as well as the RUs provisioned on the view container, determine how quickly views are hydrated and synced. The builder can have up to five nodes by default and you can add or remove nodes at any time. Scaling up and down the number of nodes helps control the rate at which views are built.
The materialized views builder is available in the following sizes:
Sku Name | vCPU | Memory |
---|---|---|
D2s | 2 | 8 GB |
D4s | 4 | 16 GB |
D8s | 8 | 32 GB |
D16s | 16 | 64 GB |
Savjet
Once created, you can add or remove builder nodes, but you can't modify the size of the nodes. To change the size of your materialized view builder nodes you can deprovision the builder and provision it again in a different size. Views don't need to be re-created and will catch up to the source once the builder is provisioned again.
For Azure Cosmos DB accounts with a single region, the materialized views builder is provisioned in that region. In a multi-region account with a single write region, the builder is provisioned in the write region and reads change feed from there. In an account with multiple write regions, the builder is provisioned in one of the write regions and reads change feed from the same region it's provisioned in.
Learn how to provision the materialized views builder.
Važno
In the event of a failover for your account, the materialized views builder is deprovisioned and re-provisioned in the new write region.
Manual failovers (change write region operation) are graceful operations, and views are guaranteed to be consistent with the source. However, service managed failovers are not guaranteed to be graceful and can result in inconsistencies between the source and view containers. In such cases, it's recommended to re-build the view containers and fall back to executing cross-partition queries on the source container until the view is updated.
Learn more about service managed failover.
You can monitor the lag in building views and the health of the materialized views builder through Metrics in the Azure portal. To learn about these metrics, see Supported metrics for Microsoft.DocumentDB/DatabaseAccounts.
The MaterializedViewCatchupGapInMinutes metric shows the maximum difference in minutes between data in a source container and a view. While there can be multiple views created in a single account, this metric exposes the highest lag among all views. A high value indicates the builder needs more compute to keep up with the volume of changes to source containers. The RUs provisioned on source and view containers can also affect the rate at which changes are propagated to the view. Check the Total Requests metric and split by StatusCode to determine if there are throttled requests on these containers. Throttled requests have status code 429.
The MaterializedViewsBuilderAverageCPUUsage and MaterializedViewsBuilderAverageMemoryUsage metrics show the average CPU usage and memory consumption across all nodes in the builder. If these metrics are too high, add nodes to scale up the cluster. If these metrics show under-utilization of CPU and memory, remove nodes by scaling down the cluster. For optimal performance, CPU usage should be no higher than 70 percent.
There are a few limitations with the Azure Cosmos DB for NoSQL API materialized view feature while it is in preview:
Događaji
Izgradite inteligentne aplikacije
M03 17 21 - M03 21 10
Pridružite se seriji susreta kako biste sa kolegama programerima i stručnjacima izgradili skalabilna AI rješenja zasnovana na stvarnim slučajevima korištenja.
Registrirajte seObučavanje
Modul
Implement backup and restore for Azure Cosmos DB for NoSQL - Training
Learn how to use the two backup models Azure Cosmos DB provides.
Certifikacija
Microsoft Certified: Azure Cosmos DB Developer Specialty - Certifications
Write efficient queries, create indexing policies, manage, and provision resources in the SQL API and SDK with Microsoft Azure Cosmos DB.
Dokumentacija
Databases, containers, and items - Azure Cosmos DB
Learn about the hierarchy of resources that composes an Azure Cosmos DB account in the service's hierarchical resource model.
How to configure materialized views (preview) - Azure Cosmos DB for NoSQL
Learn how to configure materialized views and use them to avoid expensive cross-partition queries.
Partitioning and horizontal scaling - Azure Cosmos DB
Learn about partitioning, logical, physical partitions in Azure Cosmos DB, best practices when choosing a partition key, and how to manage logical partitions.