<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 02:59:14 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[SERVER-2193] Sparse indexes only support a single field</title>
                <link>https://jira.mongodb.org/browse/SERVER-2193</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;Sparse indexes doesn&apos;t support multiple fields, for compound indexes.&lt;/p&gt;

&lt;p&gt;If any field (in the index def) is missing, the document should not be in the index.&lt;/p&gt;</description>
                <environment></environment>
        <key id="13901">SERVER-2193</key>
            <summary>Sparse indexes only support a single field</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="2">Won&apos;t Fix</resolution>
                                        <assignee username="-1">Unassigned</assignee>
                                    <reporter username="scotthernandez">Scott Hernandez</reporter>
                        <labels>
                    </labels>
                <created>Wed, 8 Dec 2010 16:55:38 +0000</created>
                <updated>Fri, 17 Apr 2015 12:10:11 +0000</updated>
                            <resolved>Sat, 8 Jan 2011 19:02:01 +0000</resolved>
                                                                    <component>Index Maintenance</component>
                                        <votes>4</votes>
                                    <watches>25</watches>
                                                                                                                <comments>
                            <comment id="737435" author="jhaile" created="Thu, 9 Oct 2014 12:44:33 +0000"  >&lt;p&gt;I have the situation where one of my columns is null when I first create it, but may get set to an ID later. And when it&apos;s set to an ID it needs to be unique with another column. &lt;/p&gt;

&lt;p&gt;Unfortunately I can&apos;t enforce this using a unique index because it will fail since many rows may have null in one of the columns. If I were using a regular RDBMS with a sparse unique multi-column index, this would work fine. Unfortunately Mongo has chosen to work in a different way from all of the RDBMS&apos; out there and cannot support this scenario.&lt;/p&gt;

&lt;p&gt;Given that partial indexes are not a quick thing to add and don&apos;t seem like they will be added anytime soon, why is this issue closed? Please reopen and consider implementing this issue.&lt;/p&gt;</comment>
                            <comment id="487798" author="amw" created="Sat, 25 Jan 2014 18:19:22 +0000"  >&lt;p&gt;This feature is really important for unique indexes. Without this you cannot guarantee uniqueness of a field within a category if that field could be left blank. Think {customer_id: 1, external_id: 1} where customer submitting the document can &lt;b&gt;optionally&lt;/b&gt; provide his own external_id that should be unique among his documents. Currently this would generate duplicate key error if he decided not to provide his external_id for multiple documents.&lt;/p&gt;

&lt;p&gt;This feature is popular among RDBMS. Read this quote from MySql documentation:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A UNIQUE index creates a constraint such that all values in the index must be distinct. An error occurs if you try to add a new row with a key value that matches an existing row. For all engines, &lt;b&gt;a UNIQUE index permits multiple NULL values&lt;/b&gt; for columns that can contain NULL.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;&lt;a href=&quot;http://dev.mysql.com/doc/refman/5.7/en/create-index.html&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://dev.mysql.com/doc/refman/5.7/en/create-index.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I know that this could be solved by introducing partial indexes (if they allowed enforcement of uniqueness), but that feature seems a long way to come while I imagine this one could be implemented fairly quickly and painlessly with a special option.&lt;/p&gt;</comment>
                            <comment id="394122" author="kramedt" created="Fri, 2 Aug 2013 01:33:32 +0000"  >&lt;p&gt;Would it make sense to have the logic not be restricted to an &quot;all&quot; or &quot;any&quot; but based on the left most field.   So with an &lt;/p&gt;
{x:1,y:1}
&lt;p&gt; index, the record is included if x is included and not included if x is not included.  The inclusion of y would make no difference.   In that way the db.test.count(&lt;/p&gt;
{x:1}
&lt;p&gt;) could still use the sparse index as could any queries on the leading columns and you don&apos;t have to either put any restrictions on the optimizer using sparse indexes for uncovered queries yet still retain most of the objectives.     Of course the major downside here is only the first field would be considered, which restricts not only the order of the index fields but restricts the number of fields that can be missing in a unique index to just one.   But I would have to imagine in many cases that would be sufficient.   Maybe it could be a third option for sparePolicy.  So something like &quot;all&quot;, &quot;any&quot; or &quot;first&quot;.  Just a thought.   &lt;/p&gt;</comment>
                            <comment id="357068" author="jhn" created="Mon, 10 Jun 2013 19:59:49 +0000"  >&lt;p&gt;Robert, you are so right!&lt;/p&gt;

&lt;p&gt;In the same way that a spares index is disallowed for &lt;tt&gt;$exists: false&lt;/tt&gt; queries, a sparse &quot;include&quot; index should probably be disallowed if not all index fields is present in the query. I don&apos;t understand the query optimizer well enough for trying that out though.&lt;/p&gt;

&lt;p&gt;I guess sparse indexes are tricky when it comes to how they should work in a general way. Should be interesting to see how this is going to be solved for filtered indexes! &lt;/p&gt;</comment>
                            <comment id="355464" author="ireuhon" created="Fri, 7 Jun 2013 18:33:02 +0000"  >&lt;p&gt;Johan, that&apos;s a great idea with sparsePolicy, thanks for making this.&lt;br/&gt;
However, there&apos;s a gotcha:&lt;/p&gt;
&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&amp;gt; db.test.insert({_id: 1, x: 1})&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&amp;gt; db.test.count({x: 1})&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;1&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&amp;gt; db.test.ensureIndex({x: 1, y: 1}, {sparse: true, sparsePolicy: &quot;include&quot;})&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&amp;gt; db.test.count({x: 1})&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;0&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;
&lt;p&gt;Here&apos;s a patch to your test case that covers this: &lt;a href=&quot;http://hastebin.com/qesuvifutu&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://hastebin.com/qesuvifutu&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To make this work properly, I guess, you would also want to adjust the way mongodb chooses indexes while serving a request. In particular, indexes with &lt;tt&gt;sparsePolicy: &quot;include&quot;&lt;/tt&gt; should only be used if request conditions contain all fields covered by the index.&lt;/p&gt;</comment>
                            <comment id="318100" author="jhn" created="Sun, 21 Apr 2013 14:26:27 +0000"  >&lt;p&gt;I know that this issue is closed and I know about the filtered index issue in &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-785&quot; class=&quot;external-link&quot; rel=&quot;nofollow&quot;&gt;https://jira.mongodb.org/browse/SERVER-785&lt;/a&gt; but lets try anyway.&lt;/p&gt;

&lt;p&gt;Support for sparse index with multiple fields is, as far as I can see, implemented in the current code base and has been for a long time (and with written tests). There is a uassert in the code that suppose to prevent a user from creating a sparse index with multiple fields but the implementation of this is wrong so it will never kick in.&lt;/p&gt;

&lt;p&gt;So, if a user creates a sparse index with multiple fields it will work. The semantics for the current implementation is; &quot;exclude a document from the index if &lt;em&gt;all&lt;/em&gt; index fields are &lt;em&gt;missing&lt;/em&gt; from the document&quot;.&lt;/p&gt;

&lt;p&gt;This &quot;mode&quot; of the index might benefit some, but according to many of the wishes in the discussion in this issue and in &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-785&quot; class=&quot;external-link&quot; rel=&quot;nofollow&quot;&gt;https://jira.mongodb.org/browse/SERVER-785&lt;/a&gt; the semantics folks are looking for is; &quot;only include a document in the index if &lt;em&gt;all&lt;/em&gt; index fields are &lt;em&gt;present&lt;/em&gt; in the document&quot;.&lt;/p&gt;

&lt;p&gt;Getting support for this second &quot;mode&quot; of the index is simply a matter of changing &lt;tt&gt;numNotFound == _spec._nFields&lt;/tt&gt; to &lt;tt&gt;numNotFound != 0&lt;/tt&gt; here: &lt;a href=&quot;https://github.com/mongodb/mongo/blob/master/src/mongo/db/indexkey.cpp#L429&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo/blob/master/src/mongo/db/indexkey.cpp#L429&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Provided that I have not missed any complicated corner case regarding this, I have the following suggestions:&lt;/p&gt;

&lt;p&gt;1. Change the documentation so that it is clear that sparse index with multiple fields is supported.&lt;br/&gt;
2. Add a additional config parameter that can be used together with the &lt;tt&gt;sparse: true&lt;/tt&gt; option to flip the behavior of the index according to the second semantics above.&lt;/p&gt;

&lt;p&gt;So, this is basically what is already suggested by @Keith and @Scott above. Nothing new.&lt;/p&gt;

&lt;p&gt;But, since almost all of the coding is already in there this could be in 2.6 with almost no effort.&lt;/p&gt;

&lt;p&gt;Even though you would be able to achieve the same with filtered indexes, that issue is in &quot;Planning Bucket B&quot; so it will be a long time before that will get into the code. In the meantime, a lot of users could benefit from this &quot;simpler&quot; form of filtered indexes, including me.&lt;/p&gt;

&lt;p&gt;You can find the code/patch that does this (with test case) here: &lt;a href=&quot;https://github.com/johanhedin/mongo/commits/SERVER-2193&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/johanhedin/mongo/commits/SERVER-2193&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With this patch you could create a index like this:&lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;db.collection.ensureIndex({ a: 1, b: 1 }, { sparse: &lt;/span&gt;&lt;span style=&quot;color: #006699; font-weight: bold; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;, sparsePolicy: &lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&quot;include&quot;&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; })&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;and only documents where &lt;em&gt;both&lt;/em&gt; &lt;tt&gt;a&lt;/tt&gt; &lt;em&gt;and&lt;/em&gt; &lt;tt&gt;b&lt;/tt&gt; are present will be included in the index. If &lt;tt&gt;sparsePolicy&lt;/tt&gt; is left out (the default) the index will work as before. And of course, the name &lt;tt&gt;sparsePolicy&lt;/tt&gt; is just an suggestion.&lt;/p&gt;

&lt;p&gt;I have only addressed v1 indexes but that same seem to be doable for v0 indexes as well if that is desired.&lt;/p&gt;

&lt;p&gt;I&apos;m happy to create a pull request if this is something you would consider. For my use case, this would be a HUGE improvement since we are starting to scale from hundreds of millions of documents to hundreds of billions of documents and RAM usage for our indexes is a big issue costing a lot of money for hardware that just store &quot;empty&quot; values.&lt;/p&gt;

&lt;p&gt;I can step up and write the documentation for this as well.&lt;/p&gt;</comment>
                            <comment id="298625" author="vinsen.mego@gmail.com" created="Tue, 26 Mar 2013 08:37:57 +0000"  >&lt;p&gt;I would like to vote for this, may be this feature can be reconsidered. Bellow are my case:&lt;br/&gt;
I have a &apos;photo&apos; collection, which only some portion of document has &apos;hashtag&apos; field, and all document has &apos;viewed&apos; field.&lt;br/&gt;
I need to make query like : &lt;br/&gt;
db.photo.find( &lt;/p&gt;
{hashtag:&apos;landscape&apos;}
&lt;p&gt; ).sort(&lt;/p&gt;
{viewed:-1}
&lt;p&gt;).limit(10);&lt;/p&gt;

&lt;p&gt;The collection has 50million documents, bellow are indexes I tried : &lt;br/&gt;
1.  db.photo.ensureIndex( &lt;/p&gt;
{hashtag:1}
&lt;p&gt;, &lt;/p&gt;
{sparse:true}
&lt;p&gt; );&lt;br/&gt;
Index size only 9386048 bytes, the problem is that query only use hashtag index.&lt;/p&gt;

&lt;p&gt;2.  db.photo.ensureIndex( &lt;/p&gt;
{hashtag:1, viewed:-1}
&lt;p&gt;, &lt;/p&gt;
{sparse:true}
&lt;p&gt; );&lt;br/&gt;
Index size became 2048292400 bytes (200 times bigger), which I think it index on all document. &lt;/p&gt;</comment>
                            <comment id="90252" author="eliot" created="Tue, 21 Feb 2012 02:14:42 +0000"  >&lt;p&gt;@roy - a filtered index would cover this case as you can filter otu thigns where song_id was null and then make it unique&lt;/p&gt;</comment>
                            <comment id="90243" author="roysmith" created="Tue, 21 Feb 2012 01:03:23 +0000"  >&lt;p&gt;Here&apos;s a use case (I think) for this.&lt;/p&gt;

&lt;p&gt;I&apos;ve got a collection where every document has song_id and station_id fields.  Some small percentage of the documents also have session_id fields.  I want to make sure that if there is a session_id, the (session_id, song_id, station_id) triple is unique.&lt;/p&gt;

&lt;p&gt;Trying to create the unique sparse index fails:&lt;/p&gt;

&lt;p&gt;&amp;gt; db.song_votes.ensureIndex(&lt;/p&gt;
{session_id:1, station_id:1, song_id:1}
&lt;p&gt;,&lt;/p&gt;
{unique:true, sparse:true}
&lt;p&gt;)&lt;br/&gt;
E11000 duplicate key error index: songza.song_votes.$session_id_1_station_id_1_song_id_1  dup key: { : null, : 1, : 354405 }&lt;/p&gt;

&lt;p&gt;I don&apos;t fully understand the filtered index proposal, so it&apos;s posible that would work for this.&lt;/p&gt;</comment>
                            <comment id="77003" author="eliot" created="Sat, 31 Dec 2011 23:02:24 +0000"  >&lt;p&gt;@thilo - a filtered index would handle this.&lt;br/&gt;
The filter would be parentId not null, and then there would be unique index on the result.&lt;/p&gt;</comment>
                            <comment id="76501" author="thiloplanz" created="Thu, 29 Dec 2011 08:38:30 +0000"  >&lt;p&gt;&quot;It makes more sense to exclude documents from the index if ALL fields in the index are missing.&quot;&lt;/p&gt;

&lt;p&gt;Can we re-open this? Sparse multi-field indexes are not exactly a duplicate of filtered indexes, I think.&lt;/p&gt;

&lt;p&gt;I have the following situation: A file system, every file is a MongoDB document, with parentId and filename. The combination of &lt;/p&gt;
{parentId + filename}
&lt;p&gt; needs to be unique. However, there are also multiple &quot;file system roots&quot;, that do not have a parentId or a filename. Because the unique index cannot be made sparse right now, I cannot have multiple of these roots (my current workaround: leave just the parentId blank, and give them a dummy unique filename).&lt;/p&gt;

&lt;p&gt;Or would filtered indexes cover this? I.e. could I have a filter that says &quot;parentId not null&quot;? In this case, we can leave this one closed (or rather, close it once we do get filtered indexes).&lt;/p&gt;</comment>
                            <comment id="22465" author="scotthernandez" created="Tue, 18 Jan 2011 01:33:40 +0000"  >&lt;p&gt;If we had filtered indexes I don&apos;t think we need sparse indexes, or this; Since we don&apos;t, this is useful.&lt;/p&gt;</comment>
                            <comment id="22464" author="zippy1981" created="Tue, 18 Jan 2011 01:09:19 +0000"  >&lt;p&gt;My gut instinct was to vote on this. However, I don&apos;t see a need for this if I have a filtered index.&lt;/p&gt;

&lt;p&gt;In my case of compound inddex the index was a unique index on &lt;/p&gt;
{documentReference, emailAddress}
&lt;p&gt; in a registration collection. Users that were invited, but not registered did not have the document field filled out.&lt;/p&gt;

&lt;p&gt;Another partial index for the unregistered users could cover them for when I confirm invitees.&lt;/p&gt;</comment>
                            <comment id="22191" author="eliot" created="Sat, 8 Jan 2011 19:02:01 +0000"  >&lt;p&gt;I agree.&lt;br/&gt;
I&apos;m still not sure there are semantics which make sense.&lt;/p&gt;</comment>
                            <comment id="22189" author="keithbranton" created="Sat, 8 Jan 2011 17:30:22 +0000"  >&lt;p&gt;I&apos;ve been thinking about this some more and realize there&apos;s a huge flaw in my earlier ideas. (and I&apos;m now wondering how rdbms&apos; typically handle this - but am struggling to find any implementation details) &lt;/p&gt;

&lt;p&gt;I propose we drop this jira in favor of Scott&apos;s &lt;a href=&quot;http://jira.mongodb.org/browse/SERVER-785&quot; class=&quot;external-link&quot; rel=&quot;nofollow&quot;&gt;http://jira.mongodb.org/browse/SERVER-785&lt;/a&gt; which would seem to cover all the bases nicely.&lt;/p&gt;

&lt;p&gt;I&apos;m moving my vote from here to there.&lt;/p&gt;</comment>
                            <comment id="21208" author="scotthernandez" created="Thu, 9 Dec 2010 00:36:55 +0000"  >&lt;p&gt;I could imagine the sparse options could be &quot;Any&quot;/&quot;All&quot; (not just &quot;true&quot; as it now).&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://jira.mongodb.org/browse/SERVER-785&quot; class=&quot;external-link&quot; rel=&quot;nofollow&quot;&gt;http://jira.mongodb.org/browse/SERVER-785&lt;/a&gt; &amp;#8211; Filtered indexes could address this sparse index needs completely. If the user could specify the rules for inclusion in the index then it is very clear.&lt;/p&gt;

&lt;p&gt;Also, as much as fields should be used in left-to-right order (or combination), it isn&apos;t exactly true. The query optimizer may get smarter and start to choose indexes which don&apos;t fit that rule. Already you can hint and it will use an index where you don&apos;t supply values for the first field in the index.&lt;/p&gt;

&lt;p&gt;I think &quot;sparse&quot; is a misleading name because it doesn&apos;t describe the way in which the index is sparse. &quot;skipDocsWithMissingFields&quot; says more what it does, but isn&apos;t very succinct.&lt;/p&gt;</comment>
                            <comment id="21200" author="keithbranton" created="Wed, 8 Dec 2010 21:47:25 +0000"  >&lt;p&gt;It makes more sense to exclude documents from the index if ALL fields in the index are missing. Compound indexes also serve queries on the first, first+second, etc fields in the index, and so an index on a,b,c should be able to find all the documents where a=1, not only the ones where b and/or c also have values. This is more intuitive, and should be the default behavior.&lt;/p&gt;

&lt;p&gt;That is what &lt;a href=&quot;http://jira.mongodb.org/browse/SERVER-484&quot; class=&quot;external-link&quot; rel=&quot;nofollow&quot;&gt;http://jira.mongodb.org/browse/SERVER-484&lt;/a&gt; suggested and what quite a few voters seem to want.&lt;/p&gt;

&lt;p&gt;I can see Scott&apos;s point too - for polymorphic collections his suggestion really makes a lot of sense.&lt;/p&gt;

&lt;p&gt;Maybe a new option could be passed at index creation time...&lt;/p&gt;

&lt;p&gt;db.people.ensureIndex(&lt;/p&gt;
{title : 1, name : 1}
&lt;p&gt;, &lt;/p&gt;
{sparse : true, sparseIfAnyValueMissing : true}
&lt;p&gt;)&lt;/p&gt;

&lt;p&gt;hopefully someone can think of a better name for that option though &lt;img class=&quot;emoticon&quot; src=&quot;https://jira.mongodb.org/images/icons/emoticons/smile.png&quot; height=&quot;16&quot; width=&quot;16&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/p&gt;</comment>
                            <comment id="21178" author="scotthernandez" created="Wed, 8 Dec 2010 18:17:37 +0000"  >&lt;p&gt;A common use case is where you have multiple document types in a single collection.&lt;/p&gt;

&lt;p&gt;I want to create an index that only applies to one of the documents types (which have certain fields which I want to index).&lt;/p&gt;



&lt;p&gt;I might also want to create an index if the first (N) fields exist, as well. This case might be addressed with filtered/partial index support.&lt;/p&gt;</comment>
                            <comment id="21177" author="eliot" created="Wed, 8 Dec 2010 17:58:43 +0000"  >&lt;p&gt;I thought about that, but I&apos;m not sure those semantics make sense.&lt;/p&gt;

&lt;p&gt;Do you have a use case?&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10010">
                    <name>Duplicate</name>
                                                                <inwardlinks description="is duplicated by">
                                        <issuelink>
            <issuekey id="84364">SERVER-10403</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                        <issuelink>
            <issuekey id="133987">SERVER-13780</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10050" key="com.atlassian.jira.toolkit:comments">
                        <customfieldname># Replies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>19.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Wed, 8 Dec 2010 17:58:43 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        9 years, 18 weeks, 6 days ago
    
                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_18254" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Dependencies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue><![CDATA[]]></customfieldvalue>


                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_10057" key="com.atlassian.jira.toolkit:lastusercommented">
                        <customfieldname>Last comment by Customer</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>true</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_10056" key="com.atlassian.jira.toolkit:lastupdaterorcommenter">
                        <customfieldname>Last commenter</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>marc.schwering</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            9 years, 18 weeks, 6 days ago
                        </customfieldvalues>
                    </customfield>
                                                                                                                        <customfield id="customfield_10000" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Old_Backport</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10000"><![CDATA[No]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10032" key="com.atlassian.jira.plugin.system.customfieldtypes:select">
                        <customfieldname>Operating System</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10026"><![CDATA[ALL]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>amw</customfieldvalue>
            <customfieldvalue>kramedt</customfieldvalue>
            <customfieldvalue>eliot</customfieldvalue>
            <customfieldvalue>jhaile</customfieldvalue>
            <customfieldvalue>jhn</customfieldvalue>
            <customfieldvalue>zippy1981</customfieldvalue>
            <customfieldvalue>keithbranton</customfieldvalue>
            <customfieldvalue>ireuhon</customfieldvalue>
            <customfieldvalue>roysmith</customfieldvalue>
            <customfieldvalue>scotthernandez</customfieldvalue>
            <customfieldvalue>thiloplanz</customfieldvalue>
            <customfieldvalue>vinsen.mego@gmail.com</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrpahr:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hrihgf:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>21480</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_23361" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Requested By</customfieldname>
                        <customfieldvalues>
                                

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            <customfield id="customfield_10053" key="com.atlassian.jira.ext.charting:timeinstatus">
                        <customfieldname>Time In Status</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_22870" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Triagers</customfieldname>
                        <customfieldvalues>
                                

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_14350" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>serverRank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hs7wc7:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                    </customfields>
    </item>
</channel>
</rss>