Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-8346

Allow Query Hints by Index Name

      Support Query Hinting by Index Name in the Mongo shell, as addressed in RUBY-493:

      db.coll.ensureIndex({ k: 1 }, { name: "mySortKey" }); 
      db.coll.save({ k: 1, v: "someValue" }); 
      // ... insert more documents 
      db.coll.find().hint("mySortKey"); 
      

      I noticed an old ticket (SERVER-8) about removing index names as redundant. I don't know if that's still intended, and I do appreciate the necessity of simplicity. At the same time, I want to defend index names as an important means of hiding implementation details.

      Sure, developers "should" normally know the structure of the indices they're using. However, in some cases we might just be using an index to ensure quick sorting on an abstract property, regardless of which document fields that property happens to cover. Query hints are a key area to realize the value of index names, because symbolic names can allow developers to vary index definition in response to "schema" adjustments (albeit Mongo is NoSQL, we still have pseudo-schemas) without impacting the optimization of downstream queries. And, given that field names are often optimized to a fine point just to reduce storage size (see SERVER-863), the field structure of an index tends to be far less meaningful than its name.

      Indices are the pith of queries, and index names are the closest Mongo has to named views. Let's take them to the next level and allow hinting on index names!

            Assignee:
            Unassigned Unassigned
            Reporter:
            rubytuesdaydono Reuben Garrett
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: