Uploaded image for project: 'Couchbase Server'
  1. Couchbase Server
  2. MB-44912

Document incorrectly updates

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: Cheshire-Cat, 6.6.1
    • Fix Version/s: 6.6.2, 7.0.0
    • Component/s: query
    • Triage:
      Untriaged
    • Story Points:
      1
    • Is this a Regression?:
      Unknown

      Description

      DELETE FROM default;
      INSERT INTO default VALUES ("meta:app_uuid_0:e:1", { "app_s": {}}), VALUES ("meta:app_uuid_1:e:1", { "app_s": {}});
       
      MERGE INTO `default` as t USING (SELECT v.* FROM [ {"country_code": "gb", "key_id": "meta:app_uuid_0:e:1"}, { "country_code": "fr", "key_id": "meta:app_uuid_1:e:1"} ] AS v) AS d ON d.key_id = META(t).id
      WHEN MATCHED THEN UPDATE SET
      t.app_s.[d.country_code] = {},
      t.app_s.[d.country_code].[d.key_id] = "xyz";
       
      SELECT META(d).id, d.* FROM default AS d;
      {
          "requestID": "72896913-03be-40ca-9098-6bf0ef00dd25",
          "signature": {
              "*": "*",
              "id": "json"
          },
          "results": [
          {
              "app_s": {
                  "gb": {
                      "meta:app_uuid_0:e:1": "xyz",
                      "meta:app_uuid_1:e:1": "xyz"
                  }
              },
              "id": "meta:app_uuid_0:e:1"
          },
          {
              "app_s": {
                  "fr": {
                      "meta:app_uuid_0:e:1": "xyz",
                      "meta:app_uuid_1:e:1": "xyz"
                  }
              },
              "id": "meta:app_uuid_1:e:1"
          }
          ],
          "status": "success",
          "metrics": {
              "elapsedTime": "14.918115ms",
              "executionTime": "14.845052ms",
              "resultCount": 2,
              "resultSize": 396
          }
      }
      

      The above output in correct. The following one is the right one.

       
          {
              "app_s": {
                  "gb": {
                      "meta:app_uuid_0:e:1": "xyz"
                  }
              },
              "id": "meta:app_uuid_0:e:1"
          },
          {
              "app_s": {
                  "fr": {
                      "meta:app_uuid_1:e:1": "xyz"
                  }
              },
              "id": "meta:app_uuid_1:e:1"
          }
          
      

      The problem is t.app_s.[d.country_code] = {},
      right side is objectConstruct constant. During evaluation it returns from https://github.com/couchbase/query/blob/master/expression/cons_object.go#L51
      The value is assigned to left side and later modified. each iteration of UPDATE updates same value and this makes all documents update in correctly.
      Same thing can happen ARRAY construct, UPDATE statement.

      https://forums.couchbase.com/t/merge-into-seems-to-not-work-correctly/29779/3

      This can cause concurrent access of map too

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

          Hide
          build-team Couchbase Build Team added a comment -

          Build couchbase-server-7.0.0-4715 contains query commit d9ef2e8 with commit message:
          MB-44912 Always evaluate values in SET path.

          Show
          build-team Couchbase Build Team added a comment - Build couchbase-server-7.0.0-4715 contains query commit d9ef2e8 with commit message: MB-44912 Always evaluate values in SET path.
          Hide
          build-team Couchbase Build Team added a comment -

          Build couchbase-server-6.6.2-9571 contains query commit a9e23b3 with commit message:
          MB-44912 Always evaluate values in SET path.

          Show
          build-team Couchbase Build Team added a comment - Build couchbase-server-6.6.2-9571 contains query commit a9e23b3 with commit message: MB-44912 Always evaluate values in SET path.
          Hide
          pierre.regazzoni Pierre Regazzoni added a comment -

          Verified on 6.6.2-9571 and 7.0.0-4715

          cbq> SELECT META(d).id, d.* FROM default AS d;
          {
              "requestID": "c478efc0-2ab7-493d-b090-8a9097ce7749",
              "signature": {
                  "*": "*",
                  "id": "json"
              },
              "results": [
              {
                  "app_s": {
                      "gb": {
                          "meta:app_uuid_0:e:1": "xyz"
                      }
                  },
                  "id": "meta:app_uuid_0:e:1"
              },
              {
                  "app_s": {
                      "fr": {
                          "meta:app_uuid_1:e:1": "xyz"
                      }
                  },
                  "id": "meta:app_uuid_1:e:1"
              }
              ],
              "status": "success",
              "metrics": {
                  "elapsedTime": "3.67169ms",
                  "executionTime": "3.483832ms",
                  "resultCount": 2,
                  "resultSize": 304
              }
          } 

          Show
          pierre.regazzoni Pierre Regazzoni added a comment - Verified on 6.6.2-9571 and 7.0.0-4715 cbq> SELECT META(d).id, d.* FROM default AS d; {     "requestID" : "c478efc0-2ab7-493d-b090-8a9097ce7749" ,     "signature" : {         "*" : "*" ,         "id" : "json"     },     "results" : [     {         "app_s" : {             "gb" : {                 "meta:app_uuid_0:e:1" : "xyz"             }         },         "id" : "meta:app_uuid_0:e:1"     },     {         "app_s" : {             "fr" : {                 "meta:app_uuid_1:e:1" : "xyz"             }         },         "id" : "meta:app_uuid_1:e:1"     }     ],     "status" : "success" ,     "metrics" : {         "elapsedTime" : "3.67169ms" ,         "executionTime" : "3.483832ms" ,         "resultCount" : 2 ,         "resultSize" : 304     } }

            People

            Assignee:
            pierre.regazzoni Pierre Regazzoni
            Reporter:
            Sitaram.Vemulapalli Sitaram Vemulapalli
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes

                  PagerDuty