Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-5477

when sharded, no need to merge groups if $group _id is the shard key or original document _id

    XMLWordPrintableJSON

Details

    • Query Optimization
    • Fully Compatible
    • QuInt 8 08/28/15, Query 2019-06-17, Query 2019-07-01, Query 2019-07-15, Query 2019-07-29, Query 2019-08-12

    Description

      Copied from SERVER-4961:

      On sharded environment, using early grouping, besides the use of an index, it would be nice that we be able to avoid the mongos regrouping process.

      I'll try to explain that:

        * result_node1: [
           {
             id: "value1",
             totalcount: 50
           },
           {
             id: "value2",
             totalcount: 100
           },
         ]
       * result_node2: [
           {
             id: "value1",
             totalcount: 60
           }
         ]
      

      The real results(after mongos regroup) must looks like:

       [
           {
             id: "value1",
             totalcount: 110
           },
           {
             id: "value2",
             totalcount: 100
           },
       ]
      

      But, in some cases, mongos regrouping process is nonsense since the grouping key is same as sharding key. So, never got same group key from different shards.

      So, the prior example, now looks like:

        * result_node1: [
           {
             id: "value1",
             totalcount: 110
           }
         ]
       * result_node2: [
           {
             id: "value2",
             totalcount: 100
           }
         ]
      

      The real results must looks like:

       [
           {
             id: "value1",
             totalcount: 110
           },
           {
             id: "value2",
             totalcount: 100
           },
       ]
      

      So, the point is mongos regrouping process is a waste of time when you group using same key as sharding key.

      Attachments

        Issue Links

          Activity

            People

              backlog-query-optimization Backlog - Query Optimization
              dan@mongodb.com Daniel Pasette (Inactive)
              Votes:
              11 Vote for this issue
              Watchers:
              20 Start watching this issue

              Dates

                Created:
                Updated: