Uploaded image for project: 'Couchbase Lite'
  1. Couchbase Lite
  2. CBL-671

PredictionValue SCANs table instead of SEARCH indexes

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Major
    • 2.8.0
    • 2.8.0
    • iOS
    • Security Level: Public
    • None

    Description

      How to repro

      • Unit test `testIndexMultiplePredictionValuesUsingValueIndex` - link

      Steps:
      1. Create multiple indexes with prediction value `[[CBLQueryFunction predictionUsingModel: input: ] property: ]`
      2. Query both prediction values ``[[CBLQueryFunction predictionUsingModel: input: ] property: ]``
      3. Query explain shows it scans the full table instead of search both the indexes.

      Expected

      SELECT fl_result(prediction('AggregateModel', dict_of('numbers', fl_value(_doc.body, 'numbers')), '.sum')) AS "s", fl_result(prediction('AggregateModel', dict_of('numbers', fl_value(_doc.body, 'numbers')), '.avg')) AS "a" FROM kv_default AS _doc WHERE (prediction('AggregateModel', dict_of('numbers', fl_value(_doc.body, 'numbers')), '.sum') <= 15 OR prediction('AggregateModel', dict_of('numbers', fl_value(_doc.body, 'numbers')), '.avg') = 8) AND (_doc.flags & 1 = 0)
       
      4|0|0| MULTI-INDEX OR
      5|4|0| INDEX 1
      12|5|0| SEARCH TABLE kv_default AS _doc USING INDEX SumIndex (<expr><?)
      17|4|0| INDEX 2
      23|17|0| SEARCH TABLE kv_default AS _doc USING INDEX AvgIndex (<expr>=?)
       
      {"WHERE":["OR",["<=",["PREDICTION()","AggregateModel",{"numbers":[".numbers"]},".sum"],15],["=",["PREDICTION()","AggregateModel",{"numbers":[".numbers"]},".avg"],8]],"WHAT":[["AS",["PREDICTION()","AggregateModel",{"numbers":[".numbers"]},".sum"],"s"],["AS",["PREDICTION()","AggregateModel",{"numbers":[".numbers"]},".avg"],"a"]]}
      

       

      Actual

      SELECT fl_result(prediction('AggregateModel', dict_of('numbers', fl_value(_doc.body, 'numbers')), '.sum')) AS "s", fl_result(prediction('AggregateModel', dict_of('numbers', fl_value(_doc.body, 'numbers')), '.avg')) AS "a" FROM kv_default AS _doc WHERE (prediction('AggregateModel', dict_of('numbers', fl_value(_doc.body, 'numbers')), '.sum') <= 15 OR prediction('AggregateModel', dict_of('numbers', fl_value(_doc.body, 'numbers')), '.avg') = 8) AND (_doc.flags & 1 = 0)
       
      3|0|0| SCAN TABLE kv_default AS _doc USING INDEX AvgIndex
       
      {"WHERE":["OR",["<=",["PREDICTION()","AggregateModel",{"numbers":[".numbers"]},".sum"],15],["=",["PREDICTION()","AggregateModel",{"numbers":[".numbers"]},".avg"],8]],"WHAT":[["AS",["PREDICTION()","AggregateModel",{"numbers":[".numbers"]},".sum"],"s"],["AS",["PREDICTION()","AggregateModel",{"numbers":[".numbers"]},".avg"],"a"]]}
      

      Attachments

        Issue Links

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

          Activity

            People

              The Lite The Lite
              Jayahari.Vavachan Jay Vavachan
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes

                  PagerDuty