[SERVER-79267] Complete explain response for search cursor stage Created: 24/Jul/23  Updated: 06/Nov/23  Resolved: 06/Nov/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 7.2.0-rc0

Type: Task Priority: Major - P3
Reporter: Prithwish Dan (Inactive) Assignee: Zixuan Zhuang
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-82236 Update search test case for new expla... Closed
Assigned Teams:
Query Execution
Backwards Compatibility: Fully Compatible
Sprint: QE 2023-10-16, QE 2023-10-30, QE 2023-11-13
Participants:

 Description   

Need to consider how to handle incorporating the mongot cursor's explain response in the search cursor stage's explain.

https://github.com/10gen/mongot/blob/master/docs/protocol/search.md#explain-information

{
  explainVersion: '1',
  stages: [
    {
      '$_internalSearchMongotRemote': {
          mongotQuery: { query: 'cakes', path: 'title' },
          explain: {
             path: 'writer',
             type: 'xxx',
             analyzer: 'lucence',
             args: 'xxx",
             stats: {
                context: ...
                match: ...
                score: ... 
             }         
         }
      },
      nReturned: Long("0"),
      executionTimeMillisEstimate: Long("1")
    },
    {
      '$_internalSearchIdLookup': {},
      nReturned: Long("0"),
      executionTimeMillisEstimate: Long("1")
    }
  ],
...
} 

 

 _explainResponse = mongot_cursor::getExplainResponse(_expCtx, _searchQuery, _taskExecutor.get());



 Comments   
Comment by Githook User [ 06/Nov/23 ]

Author:

{'name': 'zixuan zhuang', 'email': 'zixuan.zhuang@mongodb.com', 'username': 'leozzx'}

Message: SERVER-79267 Support search explain
Branch: master
https://github.com/mongodb/mongo/commit/3bcb9438f948920aad16ffde8c7f29334d1b8b2f

Comment by Zixuan Zhuang [ 11/Oct/23 ]

After the update, we will have three possible explain output format:

1. the query is purely executed in SBE engine

{
  explainVersion: '2',
  queryPlanner: {
    namespace: 'test.search',
    indexFilterSet: false,
    parsedQuery: {},
    ....,
    winningPlan: {
      queryPlan: { stage: 'SEARCH', planNodeId: 1 },
      slotBasedPlan: {
        slots: '....',
        stages: '....'
      },
      remotePlans: [{
        id: 1,
        mongotQuery: { query: 'cakes', path: 'title' },
        explain: {profession: 'writer'}
      }]
     },
    rejectedPlans: []
  },
  command: {
    ....
  },
  serverInfo: {
    ....
  },
  serverParameters: {
    ....
  },
  ok: 1
} 

2. the query is executed in hybrid engines (one or more stages in pipeline is not compatible with SBE)

{
  explainVersion: '2',
  stages: [
    {
      '$cursor': {
        queryPlanner: {
          namespace: 'test.search',
          indexFilterSet: false,
          parsedQuery: {},
          ....
          winningPlan: {
            queryPlan: { stage: 'SEARCH', planNodeId: 1 },
            slotBasedPlan: {
              slots: '....',
              stages: '....'
            },
            remotePlans: [{
              id: 1,
              mongotQuery: { query: 'cakes', path: 'title' },
              explain: {profession: 'writer'}
            }]
         },
         rejectedPlans: []
       }
      }
    },
    { '$project': { _id: false } }
  ],
  serverInfo: {
    ....
  },
  serverParameters: {
    ....
  },
  command: {
    ....
  },
  ok: 1
} 

3. the query is executed in classic engine (SBE is turned off). This is same with current format.

{
  explainVersion: '1',
  stages: [
    {
      '$_internalSearchMongotRemote': {
        mongotQuery: { query: 'cakes', path: 'title' },
        explain: { profession: 'writer' }
      }
    },
    { '$_internalSearchIdLookup': {} }
  ],
  serverInfo: {
    ....
  },
  serverParameters: {
    ....
  },
  command: {
    ....
  },
  ok: 1
} 

Comment by Zixuan Zhuang [ 29/Sep/23 ]

Search explain format:

winningPlan: {
      queryPlan: { stage: 'SEARCH', planNodeId: 1 },
      slotBasedPlan: {
        slots: '$$RESULT=s6 env: { s1 = 0 (searchCursorId), s2 = [{"_id" : 6, "score" : 0.123}] (searchFirstBatch), s3 = {"query" : "cakes", "path" : "title", "returnStoredSource" : true} (searchQuery), s4 = Nothing (searchLimit), s5 = Nothing (searchProtocolVersion) }',
        stages: '[1] search_cursor s6 [s8, s9, s10, s11] [] s1 s2 s4 s7 remotePlanId=1
      }
      remotePlans: [{
        id: 1,
        explain: {profession: 'writer'}
      }]
    } 

Generated at Thu Feb 08 06:40:32 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.