I am having a cosmos collection having somewhere aroung 28000 documents and i am using CreateDocumentQuery on DocumentClient with a where condition on properties of type 'T'. With different types of usage mentioned below i am getting very drastic difference of time latency in getting results.
Case 1:
var docs2 =
_documentClient.CreateDocumentQuery<HeartRateDayRecordIdentifierData>(collectionUri).Where(x =>
x.SubjectDeviceInformation.StudyId == "TestStudy"
&& x.SubjectDeviceInformation.SiteId == "Site_._Street_23"
&& x.SubjectDeviceInformation.SubjectId == "Subject3"
&& x.SubjectDeviceInformation.DeviceId == "Device1"
&& x.DaySplit == "20181112").AsEnumerable().FirstOrDefault();
Case 2: It is the same code and condition but this time, i am using function variable to decalre the where condition.
Func<HeartRateDayRecordIdentifierData, bool> searchOptions = x =>
x.SubjectDeviceInformation.StudyId == "TestStudy"
&& x.SubjectDeviceInformation.SiteId == "Site_._Street_23"
&& x.SubjectDeviceInformation.SubjectId == "Subject3"
&& x.SubjectDeviceInformation.DeviceId == "Device1"
&& x.DaySplit == "20181112";
var docs1 = _documentClient.CreateDocumentQuery<HeartRateDayRecordIdentifierData>(collectionUri)
.Where(searchOptions).AsEnumerable().FirstOrDefault();
Case 1 which is having inline where condition is returning the results in timespan of less than a second where as in Case 2 the result is taking around 20-30 seconds which seems a bit odd. I don't understand what's the difference between having an inline where condition and passing where condition as varaible.
If anybody interestd in sample cosmos document:
{
"id": "TestStudy_Site_._Street_21_Subject1_Device1_20181217",
"AssemblyVersion": "1.2.3.0",
"DataItemId": "20181217/TestStudy_Site_._Street_21_Subject1_Device1_20181217",
"MessageType": "HeartRateDayDocumentIdentifier",
"TimeStamp": "2018-12-14T00:00:00",
"DaySplit": "20181217",
"SubjectDeviceInformation": {
"SubjectId": "Subject1",
"DeviceId": "Device1",
"StudyId": "TestStudy",
"SiteId": "Site_._Street_21"
}
}
and Here is the model used to deserialize the document: internal class HeartRateDayRecordIdentifierData { public string id { get; set; }
public string AssemblyVersion { get; set; }
public string DataItemId { get; set; }
public string MessageType { get; set; }
public DateTime TimeStamp { get; set; }
public string DaySplit { get; set; }
public SubjectDeviceInformation SubjectDeviceInformation { get; set; }
}
internal class SubjectDeviceInformation
{
public string SubjectId { get; set; }
public string DeviceId { get; set; }
public string StudyId { get; set; }
public string SiteId { get; set; }
}
Any suggestions on anything wrong i am doing here.