Uploaded image for project: 'Mender'
  1. Mender
  2. MEN-5443

[deployments] avoid "SCAN AND SORT" in deployments/next

    XMLWordPrintable

    Details

      Description

      The deployments service is querying the deployments collection as follows:

       

      "winningPlan" : {
              "stage" : "SORT",
              "sortPattern" : {
                      "created" : 1
              },
              "memLimit" : 104857600,
              "type" : "simple",
              "inputStage" : {
                      "stage" : "FETCH",
                      "filter" : {
                              "created" : {
                                      "$gt" : ISODate("2021-12-13T12:00:51.788Z")
                              }
                      },
                      "inputStage" : {
                              "stage" : "IXSCAN",
                              "keyPattern" : {
                                      "status" : 1
                              },
                              "indexName" : "deploymentStatus",
                              "isMultiKey" : false,
                              "multiKeyPaths" : {
                                      "status" : [ ]
                              },
                              "isUnique" : false,
                              "isSparse" : false,
                              "isPartial" : false,
                              "indexVersion" : 2,
                              "direction" : "forward",
                              "indexBounds" : {
                                      "status" : [
                                              "[MinKey, \"finished\")",
                                              "(\"finished\", MaxKey]"
                                      ]
                              }
                      }
              }
      },
      

      The query was:

      "$and" : [
              {
                      "created" : {
                              "$gt" : ISODate("2021-12-13T12:00:51.788Z")
                      }
              },
              {
                      "status" : {
                              "$not" : {
                                      "$eq" : "finished"
                              }
                      }
              }
      ]
      

      The results are sorted by the "created" field.

      Proposed solution:

      • Create a partial index on "created" filtering by status in ("pending", "inprogress") 

       

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              tranchitella Fabio Tranchitella
              Reporter:
              tranchitella Fabio Tranchitella
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: