<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 03:16:27 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-8067] incorrect use of sparse index to sort query results</title>
                <link>https://jira.mongodb.org/browse/SERVER-8067</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;In some cases, sorting a query results in the use of a sparse index, which in turn results in a lesser number of documents being returned than would normally be returned by the query. This strikes me as incorrect.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;Suppose I have a collection &quot;foo&quot; that contains 1000 documents. 750 of those documents include a value for the field &quot;bar&quot;, while the other 250 do not. Suppose I have a sparse index &quot;bar_1&quot; on the field &quot;bar&quot;. The index will contain the 750 documents that have a value for the field.&lt;/p&gt;

&lt;p&gt;The following query results in 1000 documents:&lt;br/&gt;
db.foo.find()&lt;/p&gt;

&lt;p&gt;The following query results in only 750 documents, despite the identical query parameters:&lt;br/&gt;
db.foo.find().sort(&lt;/p&gt;
{ bar: 1 }
&lt;p&gt;)&lt;/p&gt;

&lt;p&gt;&lt;b&gt;I understand why this behaves the way it does&lt;/b&gt;, but in my opinion the behavior is incorrect.&lt;/p&gt;</description>
                <environment></environment>
        <key id="60800">SERVER-8067</key>
            <summary>incorrect use of sparse index to sort query results</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="9">Done</resolution>
                                        <assignee username="benety.goh@mongodb.com">Benety Goh</assignee>
                                    <reporter username="mhurne">Matt Hurne</reporter>
                        <labels>
                            <label>query_triage</label>
                    </labels>
                <created>Thu, 3 Jan 2013 15:29:42 +0000</created>
                <updated>Wed, 28 Oct 2015 04:26:24 +0000</updated>
                            <resolved>Wed, 27 Nov 2013 18:29:20 +0000</resolved>
                                    <version>2.2.2</version>
                                    <fixVersion>2.5.5</fixVersion>
                                    <component>Querying</component>
                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="462773" author="xgen-internal-githook" created="Wed, 27 Nov 2013 18:27:37 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;username&apos;: u&apos;benety&apos;, u&apos;name&apos;: u&apos;Benety Goh&apos;, u&apos;email&apos;: u&apos;benety@mongodb.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-8067&quot; title=&quot;incorrect use of sparse index to sort query results&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-8067&quot;&gt;&lt;del&gt;SERVER-8067&lt;/del&gt;&lt;/a&gt; do not use sparse index to provide sort order&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo/commit/730c2513f4f0af9068ce7ba0852cb63db56d2c99&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo/commit/730c2513f4f0af9068ce7ba0852cb63db56d2c99&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="462293" author="benety.goh" created="Tue, 26 Nov 2013 21:10:31 +0000"  >&lt;p&gt;Documentation at this URL should be updated when this ticket is resolved:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://docs.mongodb.org/manual/core/index-sparse/#sparse-index-on-a-collection-can-results-in-incomplete-results&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://docs.mongodb.org/manual/core/index-sparse/#sparse-index-on-a-collection-can-results-in-incomplete-results&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="230015" author="mhurne" created="Thu, 3 Jan 2013 15:35:20 +0000"  >&lt;p&gt;Related to this is the fact that count() provides an incorrect value when used on queries where the number of documents returned is affected by the sort&apos;s use of a sparse index. Extending the example above, we see:&lt;/p&gt;

&lt;p&gt;db.foo.find().count()&lt;br/&gt;
1000&lt;/p&gt;

&lt;p&gt;db.foo.find().sort(&lt;/p&gt;
{ bar: 1 }
&lt;p&gt;).count()&lt;br/&gt;
1000&lt;/p&gt;

&lt;p&gt;The latter shouldn&apos;t be allowed at all, but if it is, the count() should be 750.&lt;/p&gt;</comment>
                            <comment id="230009" author="mhurne" created="Thu, 3 Jan 2013 15:31:40 +0000"  >&lt;p&gt;One solution would be to refuse to execute a query where the sort&apos;s use of a spare index would result in a different number of results than the unsorted query. Certainly there are cases where the query itself might use the sparse index in a way that would allow the sort to occur without affecting the number of results; such queries should be allowed.&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10010">
                    <name>Duplicate</name>
                                                                <inwardlinks description="is duplicated by">
                                        <issuelink>
            <issuekey id="130444">SERVER-13549</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                        <issuelink>
            <issuekey id="97080">SERVER-11568</issuekey>
        </issuelink>
                            </outwardlinks>
                                                                <inwardlinks description="is related to">
                                                        </inwardlinks>
                                    </issuelinktype>
                    </issuelinks>
                <attachments>
                            <attachment id="34476" name="server8067.js" size="374" author="benety.goh@mongodb.com" created="Tue, 26 Nov 2013 17:33:43 +0000"/>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10050" key="com.atlassian.jira.toolkit:comments">
                        <customfieldname># Replies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>4.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_10011" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Backwards Compatibility</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10012"><![CDATA[Major Change]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                            <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Tue, 26 Nov 2013 17:40:54 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        10 years, 12 weeks 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>dan@mongodb.com</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            10 years, 12 weeks 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>benety.goh@mongodb.com</customfieldvalue>
            <customfieldvalue>xgen-internal-githook</customfieldvalue>
            <customfieldvalue>mhurne</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrncz3:</customfieldvalue>

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

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>38247</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_10166" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Tests Written</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10154"><![CDATA[Complete]]></customfieldvalue>

                        </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|hszv5r:</customfieldvalue>

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