Speed of getting data within my blazor or c# application significantly higher than same query in explorer

Ian Christiansen 1 Reputation point


cosmosdb sqlapi

I have the following query in dataexplorer and it takes 40ms. The same query in my application takes up to 20 seconds. Data from the primary and the join are in the same container. Following is the code to get the data. What am i doing wrong please

SELECT c.doctype, c.SecurityId, c.companyName, c.industry, c.sector, c.ticker, c.mic,p.date, p.last, p.high, p.low, p.open, p.volume, p.rTot, p.extracted01, p.extracted02, p.extracted03, p.extracted04, p.extracted05, p.extracted06, p.extracted07, p.extracted08, p.extracted09, p.extracted10 from c join(Select value t from t in c.Pricing where t.date01 >= '2022-07-22' and t.date01 < '2022-07-23') as p WHERE c.doctype='Master'

and the code that is calling this query follows. It gets the data fine, it is just horribly slow. Any help would be appreciated

var queryN = _container.GetItemQueryIterator<ClsCoyAll>(new QueryDefinition(queryS));
var resultsN = new List<ClsCoyAll>();
while (queryN.HasMoreResults)
var response = await queryN.ReadNextAsync();

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
983 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Erland Sommarskog 72,581 Reputation points MVP

    Does the generated query actually have the hardcoded dates? I would expect it to have parameters. And well, it should be parameterised. Inlined parameter values comes with a lot of problems.

  2. Oury Ba-MSFT 10,331 Reputation points Microsoft Employee

    Hi @Ian Christiansen Thank you for posting your question on Microsoft Q&A and for using Azure services.
    As per my understanding you are trying to understand the performance of the slow running query in Data explorer compared to your application.
    You cannot compare Data Explorer as a source of performance. Data Explorer is a different application type, running in another environment.

    If you are looking to understand the performance of your application, you should look into:

    1. https://learn.microsoft.com/en-us/azure/cosmos-db/sql/troubleshoot-dot-net-sdk-slow-request?tabs=cpu-new
    2. https://learn.microsoft.com/en-us/azure/cosmos-db/sql/conceptual-resilient-sdk-applications