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

[BP to 7.2.1 MB-51753/MB-52220] - CTE bindings should detect and mark correlated references

    XMLWordPrintable

Details

    • Untriaged
    • 1
    • Unknown

    Description

      Issue Resolution
      When a WITH clause (common table expression, or CTE) was used inside a subquery, and the WITH clause definition referenced the parent query, and was correlated, the query engine did not properly detect the correlation. This produced an incorrect result from the WITH clause evaluation because the result was not cached correctly. Correlations inside WITH clause definitions are now properly detected.

       

      Repro:

      insert into default values(UUID(), {"arr": [1,2,3], "c2":5});
      insert into default values(UUID(), {"arr": [11,12,13], "c2":5});
       
      create primary index on default;
       
      SELECT  ( WITH a AS (d.arr) SELECT raw c1 FROM a AS c1) AS arr FROM default d WHERE d.c2 = 5;
          "results": [
          {
              "arr": [
                  11,
                  12,
                  13
              ]
          },
          {
              "arr": [
                  11,
                  12,
                  13
              ]
          }
          ],
      
      

      Similar LET clause works as expected:

      SELECT  ( SELECT raw b FROM 1 AS c1 LET b = d.arr) AS arr FROM default d WHERE d.c2 = 5;
          "results": [
          {
              "arr": [
                  [
                      11,
                      12,
                      13
                  ]
              ]
          },
          {
              "arr": [
                  [
                      1,
                      2,
                      3
                  ]
              ]
          }
          ],
      
      

      Similar query with subquery as the binding expression of WITH clause:

      SELECT  ( WITH a AS ((SELECT RAW d.arr)[0]) SELECT raw c1 FROM a AS c1) AS arr FROM default d WHERE d.c2 = 5;
      

      Attachments

        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