You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Segment list issues several queries per segment (N+1) for child chunks and attachments #45048
I confirm that I am using English to submit this report, otherwise it will be closed.
Please do not modify this template :) and fill in all the required fields.
1. Is this request related to a challenge you're experiencing? Tell me about your story.
Loading a document's segment list runs a fixed number of queries per segment, so the query count grows linearly with the page size.
For every segment, the list serializer calls get_segment_child_chunks (which loads the segment's Document, then its DatasetProcessRule, then its ChildChunk rows) and get_segment_attachments. All segments on the page belong to the same document, so the document and process rule queries return the same rows every time.
Measured on the unit-test SQLite database with a hierarchical document where every segment has one child chunk and one attachment:
Path
1 segment
20 segments
Console list_segments
7 queries
83 queries
Service API load_segment_details
4 queries
80 queries
At the maximum page size of 100, a hierarchical document issues about 400 extra queries per page.
Service API: load_segment_details → load_segment_detail
Proposal: load a page's child chunks and attachments with a bounded number of queries, the same way #42279 did for the dataset list and load_document_read_batch does for the document list. I have a PR ready for this.
Activity