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

Accept both int32/int64 values for int32/int64 QE equality fields in Query Analysis

    • Query Integration

      Proposal

      • Always accept int32 values for an int64 field. Convert the int32 to int64.
      • Sometimes accept int64 values for an int32 field. Convert the int64 to int32 if the int64 is in range of an int32.

      Background & Motivation

      Query Analysis (mongocryptd / crypt_shared) returns an error if the value type being analyzed does not exactly match the bsonType from encryptedFields. Example:

      // run this on mongocryptd:
      db.runCommand({
          "insert": "test",
          "documents": [
              {
                  "_id": 1,
                  "value": NumberInt("123")
              }
          ],
          "$db": "test",
          "encryptionInformation": {
              "type": 1,
              "schema": {
                  "test.test": {
                      "escCollection": "enxcol_.test.esc",
                      "ecocCollection": "enxcol_.test.ecoc",
                      "fields": [
                          {
                              "keyId": UUID("b337ba84-68ec-4df5-b711-6e87bcfb9096"),
                              "path": "value",
                              "bsonType": "long",
                              "queries": {
                                  "queryType": "equality",
                                  "contention": 0
                              }
                          }
                      ]
                  }
              }
          }
      })
      // Results in: MongoServerError: Cannot encrypt element of type int because schema requires that type is one of: [ long ]
      

      This gist includes an example to run against mongocryptd.

      Some driver languages do not have a straightforward way to specify int32 and int64. This is noted in this slack conversation https://mongodb.slack.com/archives/C0406ECL478/p1681098681664019:

      > Does PHP provide a way to specify the numeric type being encoded?
      Not through any user-friendly API. For our internal needs, we reconstruct an Int64 object.

            Assignee:
            backlog-query-integration [DO NOT USE] Backlog - Query Integration
            Reporter:
            kevin.albertson@mongodb.com Kevin Albertson
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated: