简体   繁体   English

从 Cosmos DB 获取详细信息的更快查询

[英]Faster Query to fetch details from Cosmos DB

I am fetching the list of persons from Cosmos DB using a LINQ expression mentioned below from an array( String[] getPersons ) as input.我使用下面提到的 LINQ 表达式从数组( String[] getPersons )作为输入从 Cosmos DB 中获取人员列表。

var container = db.GetContainer(containerId);
var q = container.GetItemLinqQueryable<Person>();
var iterator = q.Where(p => getPersons.Contains(p.Name)).ToFeedIterator();
var results = await iterator.ReadNextAsync();

I could able to get result but it is taking more time( >15 sec ) to retrieve data( more than 1K records ) from CosmosDB.我可以得到结果,但从 CosmosDB 检索数据(超过 1K 条记录)需要更多时间( >15 秒)。 I need to get the data with in < 1 sec .我需要在< 1 sec内获取数据。 Is there any way to optimise the above query to achieve this?有没有办法优化上述查询来实现这一点?

There could be multiple things that you can do but my intuition thinks this is not an SDK issue but one of design.您可以做很多事情,但我的直觉认为这不是 SDK 问题,而是设计问题之一。

Is the partition key person name?是分区键人名吗? If not then you are running a cross-partition query which will never scale.如果不是,那么您正在运行一个永远不会扩展的跨分区查询。 In fact, your performance will worsen as you add more data.事实上,随着您添加更多数据,您的性能会变差。

I suggest taking a look at Choosing a Partition key to learn more about how to create a database that can scale easily.我建议查看选择分区键以了解有关如何创建可轻松扩展的数据库的更多信息。

Also, if you're new to this type of database, this article is super helpful too, How to model and partition data on Azure Cosmos DB using a real-world example此外,如果您不熟悉这种类型的数据库,这篇文章也非常有帮助, How to model and partition data on Azure Cosmos DB using a real-world example

Once you have a design that can scale where queries are answered from a single (or a bounded set of) partitions, your query performance will drastically increase.一旦您的设计可以扩展从单个(或一组有界)分区回答查询的位置,您的查询性能将大大提高。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM