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

Sorting on regex field should not depend on the order of regex options

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • Query Optimization

    Description

      The BSON Regex type is sorted as so:

      • Compare the match expression
      • If the match expression is equal, compare the options

      The options comparisons seems to be the reason why some code, sometimes, alphabetize the valid regex options, so the options "xi" are ordered before "ms", because some tools (such as the shell) rewrite the "xi" options to "ix", and therefore sorting before "ms".
      Some code within the server alludes to this to, but does not itself verify, or even guarantee, the order when printing or otherwise exporting such types.

      Besides it being a tad weird to rely on alphabetically ordered options for sorting, I think the server itself should be ordering the options is wants the values if it deems their order to be significant, not relying on the clients doing so:

      > db.regex.insert({reg: new RegExp("hello", "yimg")})
      WriteResult({ "nInserted" : 1 })
      > db.regex.insert({reg: /hello/yimg})
      WriteResult({ "nInserted" : 1 })
      > db.regex.find({reg: {$type: "regex"}}).sort({"reg": 1})
      { "_id" : ObjectId("5825221bad899b26f25b1de7"), "reg" : /hello/gimy }
      { "_id" : ObjectId("5825221fad899b26f25b1de8"), "reg" : /hello/gimy }
      

      Attachments

        Activity

          People

            backlog-query-optimization Backlog - Query Optimization
            bjori Hannes Magnusson
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

            Dates

              Created:
              Updated: