Broken continuation results with ordered results with recent v3.31.2 change
See original GitHub issueI have confirmed the issue is comming from with the change in v3.31.2. It does not happen in v3.31.1.
When fetching ordered results that cause a continuation token to be returned, the first set of results are returned as normal, but with subsequent fetches, an “odd” filter query is returned with the continuation token, which then when passed into the next query execution causes only 1 record to be returned per call (and very poor performance). So for example, when you have a dataset of 1 million records, and you query with a max page size of 1000, you’d get 1000 records, and then after that 1 record per call. Again, its definitely related to the filter being a part of the continuation token because without it (as it works with the version of the sdk previous to this) the sdk behaves as expected (1000 or max page size results returned per call to cosmos)
SDK Version: v3.31.2
The situation seems to be possibly circumstantial under unknown specific conditions, and I’m not sure which are relevant. Once it happens it consistently happens. The query I’m performing is something like
SELECT VALUE c FROM c WHERE c.DocumentType = @documentType ORDER BY c.DocumentType ASC, c.AuditDate DESC
where AuditDate is a number and DocumentType is a string. The query is cross-partition. The first query returns a continuation result like this:
[{"compositeToken":{"token":"+RID:~MjYdAJoN+QFnBgAAAAAAAA==#RT:1#TRC:1#RTD:NuyR9A/x6vbOO5/KeBRJrwVkdnN9cHNoAPs+J4e/4+f/////4A==#ISV:2#IEO:65567#QCF:8","range":{"min":"","max":"FF"}},"orderByItems":[{"item":"cur|org"},{"item":1673790342}],"rid":"MjYdAJoN+QFnBgAAAAAAAA==","skipCount":0,"filter":"true"}]
but the subseuent ones return one with the following filter
property
[{"compositeToken":{"token":"+RID:~MjYdAJoN+QFwBgAAAAAAAA==#RT:2#TRC:2#RTD:NuyR9A/x6vbOO5/KeBRJrwVkdnN9cHNoAPs+J4f/gSv/////4A==#ISV:2#IEO:65567#QCF:8#FPC:AWwGAAAAAAAAcQYAAAAAAAA=","range":{"min":"","max":"FF"}},"orderByItems":[{"item":"cur|org"},{"item":1673531381}],"rid":"MjYdAJoN+QFwBgAAAAAAAA==","skipCount":0,"filter":"((c.DocumentType > \"cur|org\" OR IS_ARRAY(c.DocumentType) OR IS_OBJECT(c.DocumentType) )) OR ((c.DocumentType = \"cur|org\" ) AND (c.AuditDate <= 1673617781 OR NOT IS_DEFINED(c.AuditDate) OR IS_NULL(c.AuditDate) OR IS_BOOLEAN(c.AuditDate) ))"}]
which only returns one result.
I do have a composite index setup that the query is utilizing, confirmed through IndexMetrics
With the continuation token without a filter:
Index Utilization Information
Utilized Single Indexes
Potential Single Indexes
Utilized Composite Indexes
Index Spec: /DocumentType ASC, /AuditDate DESC
Index Impact Score: High
---
Potential Composite Indexes
With the continuation token with one"
Index Utilization Information
Utilized Single Indexes
Index Spec: /DocumentType/?
Index Impact Score: High
---
Index Spec: /AuditDate/?
Index Impact Score: High
---
Index Spec: /DocumentType/?
Index Impact Score: High
---
Index Spec: /AuditDate/?
Index Impact Score: Low
---
Index Spec: /DocumentType/?
Index Impact Score: High
---
Index Spec: /AuditDate/?
Index Impact Score: High
---
Index Spec: /DocumentType/?
Index Impact Score: High
---
Index Spec: /AuditDate/?
Index Impact Score: High
---
Index Spec: /DocumentType/?
Index Impact Score: High
---
Index Spec: /AuditDate/?
Index Impact Score: High
---
Potential Single Indexes
Utilized Composite Indexes
Index Spec: /DocumentType ASC, /AuditDate ASC
Index Impact Score: High
---
Index Spec: /DocumentType ASC, /AuditDate DESC
Index Impact Score: High
---
Potential Composite Indexes
Issue Analytics
- State:
- Created 8 months ago
- Comments:10 (4 by maintainers)
Top GitHub Comments
Hello @IsaacBoy , thanks for reporting this issue and for sharing the diagnostics. We will change the backend and the continuation token format to accept values so that we can remove these filters from the query. This work is currently scheduled for next month.
Hi @IsaacBoy, I apologize for the delay. We found an issue with our backend implementation and had to make a change in our backend. The backend changes are currently rolling out and there are few more regions to go. I’m hoping to check-in the SDK changes in a week or two if everything goes as planned. Thanks.