Details

    • Type: New Feature New Feature
    • Status: Open Open
    • Priority: Major - P3 Major - P3
    • Resolution: Unresolved
    • Affects Version/s: planned but not scheduled
    • Fix Version/s: Planning Bucket C
    • Component/s: Indexing
    • Labels:
      None
    • Backport:
      No
    • # Replies:
      26
    • Last comment by Customer:
      true

      Description

      Support filtered indexes where only some values are indexed. These are also called partial indexes.

      For more informations here is wikipedia:
      http://en.wikipedia.org/wiki/Partial_index

        Issue Links

          Activity

          Hide
          Johan Hedin
          added a comment -

          Oleg, I have one collection with one type of documents. It's just that the documents are a bit dynamic in their structure. Thus, some keys are only present in some documents.

          Sparse indexes would do the trick for me if they just allowed compound indexes...

          Show
          Johan Hedin
          added a comment - Oleg, I have one collection with one type of documents. It's just that the documents are a bit dynamic in their structure. Thus, some keys are only present in some documents. Sparse indexes would do the trick for me if they just allowed compound indexes...
          Hide
          Oleg
          added a comment -

          > Sparse indexes would do the trick for me if they just allowed compound indexes...

          You can try make this like:

          { index_field:"field1+field2" }

          , or { index_field:

          { field1:"value", field2:"value" }

          }

          Show
          Oleg
          added a comment - > Sparse indexes would do the trick for me if they just allowed compound indexes... You can try make this like: { index_field:"field1+field2" } , or { index_field: { field1:"value", field2:"value" } }
          Hide
          Dwayne Bull
          added a comment -

          Just checking in and adding my vote, is there any progress on this?

          Show
          Dwayne Bull
          added a comment - Just checking in and adding my vote, is there any progress on this?
          Hide
          Shane R. Spencer
          added a comment -

          Posting here in the wake of SERVER-2193.

          I'm trying to evaluate a use case I run into a lot where I have large or sharded databases and rely on compound indexes to get me access to content without post-filtering.

          db.places.ensureIndex({
              level: 1,
              continent: 1,
              country: 1,
              state: 1,
              needsfixup: 1
          }, {
              sparse: 1
          })
          

          If needsfixup doesn't exist, I'm still adding a lot of documents to the index because the others do.

          I'd rather be able to establish an index as:

          db.places.ensureIndex({
              level: 1,
              continent: 1,
              country: 1,
              state: 1,
              needsfixup: 1
          }, {
              sparse: {
                  needsfixup: 1
              }
          })
          

          Where this key is required to be there or no index is made for those documents.

          I'm not sure how a more general approach will get this done.

          Show
          Shane R. Spencer
          added a comment - Posting here in the wake of SERVER-2193 . I'm trying to evaluate a use case I run into a lot where I have large or sharded databases and rely on compound indexes to get me access to content without post-filtering. db.places.ensureIndex({ level: 1, continent: 1, country: 1, state: 1, needsfixup: 1 }, { sparse: 1 }) If needsfixup doesn't exist, I'm still adding a lot of documents to the index because the others do. I'd rather be able to establish an index as: db.places.ensureIndex({ level: 1, continent: 1, country: 1, state: 1, needsfixup: 1 }, { sparse: { needsfixup: 1 } }) Where this key is required to be there or no index is made for those documents. I'm not sure how a more general approach will get this done.
          Hide
          Glenn Maynard
          added a comment - - edited

          I'd recommend allowing a query as the sparse argument, for example:

          db.users.ensureIndex({
              _id: 1
          }, {
              query: {
                  role: { $in: ["admin", "moderator"] }
              }
          });
          

          to create an index of users whose role is "admin" or "moderator". Shane's example above would become query: { needsfixup: {$exists: true} }.

          Selecting these indexes automatically may be logic that Mongo doesn't have yet (eg. determining that a query is a superset of another: 'role:

          { $in: ["admin", "moderator"] }

          ' is a superset of "role: 'admin'"), but they can be selected via hint().

          The index specifier itself couldn't be used as the identifier for these indexes, since you could have multiple indexes with the same fields but different queries. Encoding the whole query into the default index name would probably be a mess, so this type of index may want to require an explicit name.

          This would also give the ability to create a sparse index that excludes null values, which is requested a lot.

          Show
          Glenn Maynard
          added a comment - - edited I'd recommend allowing a query as the sparse argument, for example: db.users.ensureIndex({ _id: 1 }, { query: { role: { $in: ["admin", "moderator"] } } }); to create an index of users whose role is "admin" or "moderator". Shane's example above would become query: { needsfixup: {$exists: true} }. Selecting these indexes automatically may be logic that Mongo doesn't have yet (eg. determining that a query is a superset of another: 'role: { $in: ["admin", "moderator"] } ' is a superset of "role: 'admin'"), but they can be selected via hint(). The index specifier itself couldn't be used as the identifier for these indexes, since you could have multiple indexes with the same fields but different queries. Encoding the whole query into the default index name would probably be a mess, so this type of index may want to require an explicit name. This would also give the ability to create a sparse index that excludes null values, which is requested a lot.

            People

            • Votes:
              129 Vote for this issue
              Watchers:
              104 Start watching this issue

              Dates

              • Created:
                Updated:
                Days since reply:
                33 weeks, 6 days ago
                Date of 1st Reply: