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

Query with order and subquery without order gives wrong results

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Major
    • 4.5.0
    • 4.5.0
    • query
    • None
    • Untriaged
    • Unknown

    Description

       
      Post from :
      http://stackoverflow.com/questions/36063384/couchbase-order-by-retuning-null-results
       
       
      create primary index on default;
       
      insert into default values("c001", {
              "p_brand1": "MFGR#1121",
              "lineorder": [{
                          "lo_revenue": 4282453,
                          "orderdate": [{ "d_year": 1992}],
                          "supplier": [{ "s_region": "AMERICA" }]
                      }] });
       
       
      SELECT l.lo_revenue as revenue, o.d_year, p.p_brand1 from (SELECT p_brand1, lineorder from default where p_brand1='MFGR#1121') as p UNNEST p.lineorder l UNNEST l.supplier s UNNEST l.orderdate o where s.s_region='AMERICA' order by o.d_year;
       
       
      Above query returns empty result set. If you remove order by it works fine.
       
      explain SELECT l.lo_revenue as revenue, o.d_year, p.p_brand1 from (SELECT p_brand1, lineorder from default where p_brand1='MFGR#1121') as p UNNEST p.lineorder l UNNEST l.supplier s UNNEST l.orderdate o where s.s_region='AMERICA' order by o.d_year;
      {
          "requestID": "05334684-cc17-4cf0-9364-5f107b48dde4",
          "signature": "json",
          "results": [
              {
                  "plan": {
                      "#operator": "Sequence",
                      "~children": [
                          {
                              "#operator": "Sequence",
                              "~children": [
                                  {
                                      "#operator": "Sequence",
                                      "~children": [
                                          {
                                              "#operator": "PrimaryScan",
                                              "index": "#primary",
                                              "keyspace": "default",
                                              "namespace": "default",
                                              "using": "gsi"
                                          },
                                          {
                                              "#operator": "Parallel",
                                              "~child": {
                                                  "#operator": "Sequence",
                                                  "~children": [
                                                      {
                                                          "#operator": "Fetch",
                                                          "keyspace": "default",
                                                          "namespace": "default"
                                                      },
                                                      {
                                                          "#operator": "Filter",
                                                          "condition": "((`default`.`p_brand1`) = \"MFGR#1121\")"
                                                      },
                                                      {
                                                          "#operator": "InitialProject",
                                                          "result_terms": [
                                                              {
                                                                  "expr": "(`default`.`p_brand1`)"
                                                              },
                                                              {
                                                                  "expr": "(`default`.`lineorder`)"
                                                              }
                                                          ]
                                                      }
                                                  ]
                                              }
                                          }
                                      ]
                                  },
                                  {
                                      "#operator": "Alias",
                                      "as": "p"
                                  },
                                  {
                                      "#operator": "Parallel",
                                      "~child": {
                                          "#operator": "Sequence",
                                          "~children": [
                                              {
                                                  "#operator": "Unnest",
                                                  "as": "l",
                                                  "expr": "(`p`.`lineorder`)"
                                              },
                                              {
                                                  "#operator": "Unnest",
                                                  "as": "s",
                                                  "expr": "(`l`.`supplier`)"
                                              },
                                              {
                                                  "#operator": "Unnest",
                                                  "as": "o",
                                                  "expr": "(`l`.`orderdate`)"
                                              },
                                              {
                                                  "#operator": "Filter",
                                                  "condition": "((`s`.`s_region`) = \"AMERICA\")"
                                              },
                                              {
                                                  "#operator": "InitialProject",
                                                  "result_terms": [
                                                      {
                                                          "as": "revenue",
                                                          "expr": "(`l`.`lo_revenue`)"
                                                      },
                                                      {
                                                          "expr": "(`o`.`d_year`)"
                                                      },
                                                      {
                                                          "expr": "(`p`.`p_brand1`)"
                                                      }
                                                  ]
                                              }
                                          ]
                                      }
                                  }
                              ]
                          },
                          {
                              "#operator": "Order",
                              "sort_terms": [
                                  {
                                      "expr": "(`o`.`d_year`)"
                                  }
                              ]
                          },
                          {
                              "#operator": "FinalProject"
                          }
                      ]
                  },
                  "text": "SELECT l.lo_revenue as revenue, o.d_year, p.p_brand1 from (SELECT p_brand1, lineorder from default where p_brand1='MFGR#1121') as p UNNEST p.lineorder l UNNEST l.supplier s UNNEST l.orderdate o where s.s_region='AMERICA' order by o.d_year"
              }
          ],
          "status": "success",
          "metrics": {
              "elapsedTime": "1.747152ms",
              "executionTime": "1.723018ms",
              "resultCount": 1,
              "resultSize": 5717
          }
      }
       
      
      

      Attachments

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

        Activity

          People

            Sitaram.Vemulapalli Sitaram Vemulapalli
            Sitaram.Vemulapalli Sitaram Vemulapalli
            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