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

Select query throwing the error "Duplicate variable v already in scope", since an index contains the variable v

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Major
    • 5.5.0
    • 4.6.3, 5.0.0
    • query
    • None
    • Untriaged
    • No

    Description

      "Duplicate variable v already in scope" error thrown when executing a select query. This is because the select query uses 'v' as an alias, when the variable 'v' is already being used in the index.

      We can reproduce this error with travel-sample sample bucket, with the following queries:

      Create an index on scheduled flight IDs and number of stops using the variable 'v':

      CREATE INDEX idx_flight_stops ON `travel-sample` ( stops, DISTINCT ARRAY v.flight FOR v IN schedule END ) WHERE type = "route" ;
      

      Perform the following select query that finds the list of scheduled 'UA' flights that have one or more stops using the alias 'v':

      SELECT * FROM `travel-sample` v
       WHERE type = "route"
       AND stops >=0
       AND ANY v IN schedule SATISFIES v.flight LIKE 'UA%' END;
      

      • The following error is seen on the Query Workbench UI:

      The error is seen even if the select query does not use the index. For example:

      SELECT * FROM `travel-sample` v WHERE type = "route"
      

      Attachments

        Issue Links

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

          Activity

            People

              ajay.bhullar Ajay Bhullar
              James Flather James Flather (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes

                  PagerDuty