Details
-
Bug
-
Resolution: Fixed
-
Major
-
7.6.0, 7.6.2, 7.6.1
-
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
- causes
-
DOC-12319 Sequence examples need to change
-
- Open
-