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

Multiple increments for sequences used in VALUES clauses.

    XMLWordPrintable

Details

    • Untriaged
    • 0
    • Unknown

    Description

      Currently evaluation of the key, value and option elements of a VALUES clause are performed independently so sequence generation is not correctly shared.  Furthermore, within any element, sequence generation is not cached.  This means every execution of NEXTVAL generates a new value when it really should be generating a single value per VALUES clause.

      e.g.

       

      cbq> INSERT INTO default
         2 VALUES(to_string(NEXTVAL FOR default.s1.q1),{"a":NEXTVAL FOR default.s1.q1,"b":NEXTVAL FOR default.s1.q1});
      ...
      cbq> SELECT meta().id, * FROM default;
      ...
          "results": [
          {
              "id": "0",
              "default": {
                  "a": 2,
                  "b": 1
              }
          }
          ],

       

      • All are new values
      • Within the "value", "b" may be generated before "a" (not strictly predictable since the elements are generated via map iteration)

      We do indicate this here: https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/sequenceops.html#examples  (example 3)

      You can workaround this using PREVVAL after the "key" has been generated, i.e.

      INSERT INTO default
      VALUES(to_string(NEXTVAL FOR default.s1.q1),{"a":PREVVAL FOR default.s1.q1,"b":PREVVAL FOR default.s1.q1});

      but this won't work well for a contented sequence (as all refer to the global value, rather than a document/clause specific value).

      For standards compliance I believe we should be generating a single value per sequence per VALUES clause.

       

       

      Attachments

        Issue Links

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

          Activity

            People

              pierre.regazzoni Pierre Regazzoni
              Donald.haggart Donald Haggart
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes

                  PagerDuty