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

[BP to 7.2.1 MB-57240] - Prepared statement may give wrong result in multi-node environment

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Major
    • 7.2.1
    • 7.1.4, 7.2.0
    • query
    • Untriaged
    • 0
    • Yes

    Description

      Issue Resolution
      A Prepared statement might have resulted in an incorrect result in a multi-node environment. For example, a database with two query nodes. Correlated subqueries from an encoded plan are now detected and marked. This ensures correct results are provided.

      Cluster with two query nodes.

      Create bucket shellTest.

      INSERT INTO shellTest (KEY,VALUE) VALUES("test11_withs", {"c11": 1, "c12": 10, "a11": [ 1, 2, 3, 4 ], "type": "left", "test_id": "withs"}), VALUES("test12_withs", {"c11": 2, "c12": 20, "a11": [ 3, 3, 5, 10 ], "type": "left", "test_id": "withs"}), VALUES("test13_withs", {"c11": 3, "c12": 30, "a11": [ 3, 4, 20, 40 ], "type": "left", "test_id": "withs"}), VALUES("test14_withs", {"c11": 4, "c12": 40, "a11": [ 30, 30, 30 ], "type": "left", "test_id": "withs"});
       
      CREATE INDEX st_idx1 on shellTest(c11, c12) WHERE type = "left";
      

      Then on the first query node:

      prepare p1 as SELECT (WITH a AS (s.a11) SELECT RAW c1 FROM a AS c1) AS arr, s.test_id FROM shellTest s WHERE s.c11 IN [1, 2] AND type = "left";
       
      execute p1;
      

      This should produce:

          "results": [
          {
              "arr": [
                  1,
                  2,
                  3,
                  4
              ],
              "test_id": "withs"
          },
          {
              "arr": [
                  3,
                  3,
                  5,
                  10
              ],
              "test_id": "withs"
          }
          ],
      

      which is the correct result.

      Now from the second query node:

      execute p1;
      

      This should produce the same result, however, it produces instead:

          "results": [
          {
              "arr": [
                  1,
                  2,
                  3,
                  4
              ],
              "test_id": "withs"
          },
          {
              "arr": [
                  1,
                  2,
                  3,
                  4
              ],
              "test_id": "withs"
          }
          ],
      

      Attachments

        Issue Links

          Activity

            People

              pierre.regazzoni Pierre Regazzoni
              bingjie.miao Bingjie Miao
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                PagerDuty