You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2018/11/14 15:41:32 UTC

[GitHub] dholth opened a new issue #1740: use_index documentation is incorrect

dholth opened a new issue #1740: use_index documentation is incorrect
URL: https://github.com/apache/couchdb/issues/1740
 
 
   I am having some trouble with use_index and partial indexes in CouchDB 2.2.0. This part of the _find documentation is misleading:
   
   > Technically, we don’t need to include the filter on the "status" field in the query selector - the partial index ensures this is always true - but including it makes the intent of the selector clearer and will make it easier to take advantage of future improvements to query planning (e.g. automatic selection of partial indexes).
   
   The documentation should add that an index with fields will never be used unless the selector includes all the fields indexed. ( `"fields": []` works around this problem ). This is different than a typical SQL database that would use an index for queries against any prefix of the list of indexed fields.
   
   I was also confused by using the index's `name` in `use_index`.  Fauxton should put `ddoc` in its example index definitions to make it very clear that the index `name` cannot be used in `use_index` unless it is accompanied by `ddoc`.
   
   Given a design doc like this one,
   
   `{"ddoc": "_design/obsolete-created", "type": "json", "name": "foo-json-index", "def": {"fields": [{"meta.state": "asc"}, {"meta.created": "asc"}], "partial_filter_selector": {"$and": [{"type": "form"}, {"meta.state": "obsolete"}]}}}`
   
   ```
   In [172]: db.explain({"use_index":"obsolete-created", "selector":{"meta.state":"obsolete"}})
   Out[172]: 
   {u'dbname': u'db',
    u'fields': u'all_fields',
    u'index': {u'ddoc': None,
     u'def': {u'fields': [{u'_id': u'asc'}]},
     u'name': u'_all_docs',
     u'type': u'special'},
    u'limit': 25,
    u'mrargs': {u'conflicts': u'undefined',
     u'direction': u'fwd',
     u'end_key': u'<MAX>',
     u'include_docs': True,
     u'reduce': False,
     u'stable': False,
     u'start_key': None,
     u'update': True,
     u'view_type': u'map'},
    u'opts': {u'bookmark': u'nil',
     u'conflicts': False,
     u'execution_stats': False,
     u'fields': u'all_fields',
     u'limit': 25,
     u'r': [49],
     u'skip': 0,
     u'sort': {},
     u'stable': False,
     u'stale': False,
     u'update': True,
     u'use_index': [u'obsolete-created']},
    u'selector': {u'meta.state': {u'$eq': u'obsolete'}},
    u'skip': 0}
   ```
   
   ```
   In [175]: db.explain({"use_index":"obsolete-created", "selector":{"meta.state":"obsolete", "meta.created": "foobar"}})
   Out[175]: 
   {u'dbname': u'db',
    u'fields': u'all_fields',
    u'index': {u'ddoc': u'_design/obsolete-created',
     u'def': {u'fields': [{u'meta.state': u'asc'}, {u'meta.created': u'asc'}],
      u'partial_filter_selector': {u'meta.state': {u'$eq': u'obsolete'}}},
     u'name': u'obsolete-created',
     u'type': u'json'},
    u'limit': 25,
    u'mrargs': {u'conflicts': u'undefined',
     u'direction': u'fwd',
     u'end_key': [u'obsolete', u'foobar', u'<MAX>'],
     u'include_docs': True,
     u'reduce': False,
     u'stable': False,
     u'start_key': [u'obsolete', u'foobar'],
     u'update': True,
     u'view_type': u'map'},
    u'opts': {u'bookmark': u'nil',
     u'conflicts': False,
     u'execution_stats': False,
     u'fields': u'all_fields',
     u'limit': 25,
     u'r': [49],
     u'skip': 0,
     u'sort': {},
     u'stable': False,
     u'stale': False,
     u'update': True,
     u'use_index': [u'obsolete-created']},
    u'selector': {u'$and': [{u'meta.created': {u'$eq': u'foobar'}},
      {u'meta.state': {u'$eq': u'obsolete'}}]},
    u'skip': 0}
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services