<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 02:58:22 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-1896] limit() clause is not being pushed down to the shard for evaluation, causing more documents to be returned than are needed</title>
                <link>https://jira.mongodb.org/browse/SERVER-1896</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;Problem:&lt;br/&gt;
It appears that the limit() clause is not being pushed down to the shard server for evaluation, since the explain() indicates more documents returned than the limit.&lt;/p&gt;

&lt;p&gt;For example, given the shard key &quot;x&quot; has values 0-100 and the split is at 50. Given the query&lt;/p&gt;

&lt;p&gt;db.test20101005.find( {x : { $lt : 60}} ).sort( &lt;/p&gt;
{ x:-1}
&lt;p&gt; ).limit(1).explain()&lt;/p&gt;

&lt;p&gt;produces&lt;/p&gt;

&lt;p&gt;&amp;gt; db.test20101005.find( {x : { $lt : 60}} ).sort( &lt;/p&gt;
{ x:-1}
&lt;p&gt; ).limit(1).explain()&lt;br/&gt;
{&lt;br/&gt;
	&quot;clusteredType&quot; : &quot;ParallelSort&quot;,&lt;br/&gt;
	&quot;shards&quot; : {&lt;br/&gt;
		&quot;10.195.79.0:27000&quot; : [&lt;br/&gt;
			{&lt;br/&gt;
				&quot;cursor&quot; : &quot;BtreeCursor x_1 reverse&quot;,&lt;br/&gt;
				&quot;nscanned&quot; : 50,&lt;br/&gt;
				&quot;nscannedObjects&quot; : 50,&lt;br/&gt;
				&quot;n&quot; : 50,&lt;br/&gt;
				&quot;millis&quot; : 0,&lt;br/&gt;
				&quot;nYields&quot; : 0,&lt;br/&gt;
				&quot;nChunkSkips&quot; : 0,&lt;br/&gt;
				&quot;indexBounds&quot; : &lt;/p&gt;
{
					&quot;x&quot; : [
						[
							60,
							-1.7976931348623157e+308
						]
					]
				}
&lt;p&gt;			}&lt;br/&gt;
		],&lt;br/&gt;
		&quot;10.203.83.53:27000&quot; : [&lt;br/&gt;
			{&lt;br/&gt;
				&quot;cursor&quot; : &quot;BtreeCursor x_1 reverse&quot;,&lt;br/&gt;
				&quot;nscanned&quot; : 10,&lt;br/&gt;
				&quot;nscannedObjects&quot; : 10,&lt;br/&gt;
				&quot;n&quot; : 10,&lt;br/&gt;
				&quot;millis&quot; : 0,&lt;br/&gt;
				&quot;nYields&quot; : 0,&lt;br/&gt;
				&quot;nChunkSkips&quot; : 0,&lt;br/&gt;
				&quot;indexBounds&quot; : &lt;/p&gt;
{
					&quot;x&quot; : [
						[
							60,
							-1.7976931348623157e+308
						]
					]
				}
&lt;p&gt;			}&lt;br/&gt;
		]&lt;br/&gt;
	},&lt;br/&gt;
	&quot;n&quot; : 60,&lt;br/&gt;
	&quot;nChunkSkips&quot; : 0,&lt;br/&gt;
	&quot;nYields&quot; : 0,&lt;br/&gt;
	&quot;nscanned&quot; : 60,&lt;br/&gt;
	&quot;nscannedObjects&quot; : 60,&lt;br/&gt;
	&quot;millisTotal&quot; : 0,&lt;br/&gt;
	&quot;millisAvg&quot; : 0,&lt;br/&gt;
	&quot;numQueries&quot; : 2,&lt;br/&gt;
	&quot;numShards&quot; : 2&lt;br/&gt;
}&lt;/p&gt;

&lt;p&gt;The value of &quot;n&quot; indicates that shard0000 returns 50 documents, and shard0001 returns 10 before the final sort &amp;amp; limit is applied by the mongos.&lt;/p&gt;

&lt;p&gt;Reproduce:&lt;br/&gt;
&amp;gt; for (i=0; i &amp;lt; 100; i++) { db.test20101005.insert(&lt;/p&gt;
{ x: i}
&lt;p&gt;); }&lt;br/&gt;
&amp;gt; db.test20101005.ensureIndex(&lt;/p&gt;
{x:1}
&lt;p&gt;)&lt;br/&gt;
&amp;gt; use admin&lt;br/&gt;
switched to db admin&lt;br/&gt;
&amp;gt; db.runCommand( &lt;/p&gt;
{ enablesharding : &quot;test&quot;}
&lt;p&gt; )    &lt;/p&gt;
{ &quot;ok&quot; : 1 }
&lt;p&gt;&amp;gt; db.runCommand( { shardcollection : &quot;test.test20101005&quot;, key : &lt;/p&gt;
{ x : 1 }
&lt;p&gt; } )&lt;/p&gt;
{ &quot;collectionsharded&quot; : &quot;test.test20101005&quot;, &quot;ok&quot; : 1 }
&lt;p&gt;&amp;gt; db.runCommand( { split : &quot;test.test20101005&quot;, middle : { x : 50 }} ); &lt;/p&gt;
{ &quot;ok&quot; : 1 }
&lt;p&gt;&amp;gt; db.runCommand( { moveChunk: &quot;test.test20101005&quot;, find : &lt;/p&gt;
{ x : 51}
&lt;p&gt;, to : &quot;shard0001&quot; })&lt;/p&gt;
{ &quot;millis&quot; : 2413, &quot;ok&quot; : 1 }
&lt;p&gt;&amp;gt; use test&lt;br/&gt;
switched to db test&lt;br/&gt;
&amp;gt; db.test20101005.find( {x : { $lt : 60}} ).sort( &lt;/p&gt;
{ x:-1}
&lt;p&gt; ).limit(1).explain()&lt;br/&gt;
{&lt;br/&gt;
	&quot;clusteredType&quot; : &quot;ParallelSort&quot;,&lt;br/&gt;
	&quot;shards&quot; : {&lt;br/&gt;
		&quot;10.195.79.0:27000&quot; : [&lt;br/&gt;
			{&lt;br/&gt;
				&quot;cursor&quot; : &quot;BtreeCursor x_1 reverse&quot;,&lt;br/&gt;
				&quot;nscanned&quot; : 50,&lt;br/&gt;
				&quot;nscannedObjects&quot; : 50,&lt;br/&gt;
				&quot;n&quot; : 50,&lt;br/&gt;
				&quot;millis&quot; : 0,&lt;br/&gt;
				&quot;nYields&quot; : 0,&lt;br/&gt;
				&quot;nChunkSkips&quot; : 0,&lt;br/&gt;
				&quot;indexBounds&quot; : &lt;/p&gt;
{
					&quot;x&quot; : [
						[
							60,
							-1.7976931348623157e+308
						]
					]
				}
&lt;p&gt;			}&lt;br/&gt;
		],&lt;br/&gt;
		&quot;10.203.83.53:27000&quot; : [&lt;br/&gt;
			{&lt;br/&gt;
				&quot;cursor&quot; : &quot;BtreeCursor x_1 reverse&quot;,&lt;br/&gt;
				&quot;nscanned&quot; : 10,&lt;br/&gt;
				&quot;nscannedObjects&quot; : 10,&lt;br/&gt;
				&quot;n&quot; : 10,&lt;br/&gt;
				&quot;millis&quot; : 0,&lt;br/&gt;
				&quot;nYields&quot; : 0,&lt;br/&gt;
				&quot;nChunkSkips&quot; : 0,&lt;br/&gt;
				&quot;indexBounds&quot; : &lt;/p&gt;
{
					&quot;x&quot; : [
						[
							60,
							-1.7976931348623157e+308
						]
					]
				}
&lt;p&gt;			}&lt;br/&gt;
		]&lt;br/&gt;
	},&lt;br/&gt;
	&quot;n&quot; : 60,&lt;br/&gt;
	&quot;nChunkSkips&quot; : 0,&lt;br/&gt;
	&quot;nYields&quot; : 0,&lt;br/&gt;
	&quot;nscanned&quot; : 60,&lt;br/&gt;
	&quot;nscannedObjects&quot; : 60,&lt;br/&gt;
	&quot;millisTotal&quot; : 0,&lt;br/&gt;
	&quot;millisAvg&quot; : 0,&lt;br/&gt;
	&quot;numQueries&quot; : 2,&lt;br/&gt;
	&quot;numShards&quot; : 2&lt;br/&gt;
}&lt;/p&gt;

&lt;p&gt;Solution:&lt;br/&gt;
Certainly in this case, the sort and limit could be applied to the data set returned by each shard. The final sort and limit will still need to happen in the mongos.&lt;/p&gt;

&lt;p&gt;Business Case:&lt;br/&gt;
Performance.&lt;/p&gt;</description>
                <environment>1.7.2-pre-&lt;br/&gt;
</environment>
        <key id="13262">SERVER-1896</key>
            <summary>limit() clause is not being pushed down to the shard for evaluation, causing more documents to be returned than are needed</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="eliot">Eliot Horowitz</assignee>
                                    <reporter username="alvin">Alvin Richards</reporter>
                        <labels>
                    </labels>
                <created>Tue, 5 Oct 2010 19:40:34 +0000</created>
                <updated>Tue, 12 Jul 2016 00:20:13 +0000</updated>
                            <resolved>Wed, 10 Nov 2010 21:22:41 +0000</resolved>
                                    <version>1.7.0</version>
                                    <fixVersion>1.7.3</fixVersion>
                                                        <votes>2</votes>
                                    <watches>3</watches>
                                                                                                                <comments>
                            <comment id="20221" author="eliot" created="Wed, 10 Nov 2010 21:22:41 +0000"  >&lt;p&gt;Note: as far as I can tell this is just an explain() issue, not a normal query issue.&lt;br/&gt;
If you think its on normal queries as well - please open a different case.&lt;/p&gt;</comment>
                            <comment id="20220" author="auto" created="Wed, 10 Nov 2010 21:22:26 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;login&apos;: &apos;erh&apos;, &apos;name&apos;: &apos;Eliot Horowitz&apos;, &apos;email&apos;: &apos;eliot@10gen.com&apos;}
&lt;p&gt;Message: fix limit on explain &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-1896&quot; title=&quot;limit() clause is not being pushed down to the shard for evaluation, causing more documents to be returned than are needed&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-1896&quot;&gt;&lt;del&gt;SERVER-1896&lt;/del&gt;&lt;/a&gt;&lt;br/&gt;
/mongodb/mongo/commit/af8370b1e2ff5681858b855f0cb816e9197b1230&lt;/p&gt;</comment>
                            <comment id="19340" author="digal" created="Tue, 19 Oct 2010 10:08:03 +0000"  >&lt;p&gt;As I can see in our test environment, this also seem to affect 1.6.3 (debian mongodb-stable 20101018).&lt;/p&gt;


&lt;p&gt;&amp;gt; db.related.find(&lt;/p&gt;
{&quot;user.old_pk&quot; : 902}
&lt;p&gt;).limit(1).explain()&lt;br/&gt;
{&lt;br/&gt;
	&quot;clusteredType&quot; : &quot;SerialServer&quot;,&lt;br/&gt;
	&quot;shards&quot; : {&lt;br/&gt;
		&quot;192.168.4.204:27017&quot; : [&lt;br/&gt;
			{&lt;br/&gt;
				&quot;cursor&quot; : &quot;BtreeCursor user.old_pk_1_posted_-1&quot;,&lt;br/&gt;
				&quot;nscanned&quot; : 1205,&lt;br/&gt;
				&quot;nscannedObjects&quot; : 1205,&lt;br/&gt;
				&quot;n&quot; : 1205,&lt;br/&gt;
				&quot;millis&quot; : 4,&lt;br/&gt;
				&quot;indexBounds&quot; : {&lt;br/&gt;
					&quot;user.old_pk&quot; : [&lt;br/&gt;
						[&lt;br/&gt;
							902,&lt;br/&gt;
							902&lt;br/&gt;
						]&lt;br/&gt;
					],&lt;br/&gt;
					&quot;posted&quot; : [&lt;br/&gt;
						[&lt;br/&gt;
							&lt;/p&gt;
{
								&quot;$maxElement&quot; : 1
							}
&lt;p&gt;,&lt;/p&gt;
							{
								&quot;$minElement&quot; : 1
							}
&lt;p&gt;						]&lt;br/&gt;
					]&lt;br/&gt;
				}&lt;br/&gt;
			}&lt;br/&gt;
		]&lt;br/&gt;
	},&lt;br/&gt;
	&quot;nscanned&quot; : 1205,&lt;br/&gt;
	&quot;nscannedObjects&quot; : 1205,&lt;br/&gt;
	&quot;n&quot; : 1205,&lt;br/&gt;
	&quot;millisTotal&quot; : 4,&lt;br/&gt;
	&quot;millisAvg&quot; : 4,&lt;br/&gt;
	&quot;numQueries&quot; : 1,&lt;br/&gt;
	&quot;numShards&quot; : 1&lt;br/&gt;
}&lt;/p&gt;</comment>
                            <comment id="18961" author="alvin" created="Wed, 6 Oct 2010 20:12:45 +0000"  >&lt;p&gt;Added jstest/sharding/limit_push.js.&lt;/p&gt;

&lt;p&gt;Execution is commented out, so you will need to uncomment in order to get the test to fail.&lt;/p&gt;

&lt;p&gt;Per the update above, on a non-sharded system, n=1. It appears at least from the explain output that each shard is return n &amp;gt; 1.&lt;/p&gt;</comment>
                            <comment id="18960" author="auto" created="Wed, 6 Oct 2010 20:09:43 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;login&apos;: &apos;alvin10gen&apos;, &apos;name&apos;: &apos;Alvin Richards&apos;, &apos;email&apos;: &apos;alvin@10gen.com&apos;}
&lt;p&gt;Message: Added jstest for &lt;a href=&quot;http://jira.mongodb.org/browse/SERVER-1896&quot; class=&quot;external-link&quot; rel=&quot;nofollow&quot;&gt;http://jira.mongodb.org/browse/SERVER-1896&lt;/a&gt;&lt;br/&gt;
&lt;a href=&quot;http://github.com/mongodb/mongo/commit/ddb16cb7e47806406592a49155e223f5132fd993&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://github.com/mongodb/mongo/commit/ddb16cb7e47806406592a49155e223f5132fd993&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="18954" author="alvin" created="Wed, 6 Oct 2010 14:47:44 +0000"  >&lt;p&gt;confirmed on a non-shared system that &quot;n&quot; is 1 as you would expect (see below). Will write a js test for this&lt;/p&gt;

&lt;p&gt;&amp;gt; db.test20101005.find( {x : { $lt : 60}} ).sort( &lt;/p&gt;
{ x:-1}
&lt;p&gt; ).limit(1).explain() &lt;br/&gt;
{&lt;br/&gt;
	&quot;cursor&quot; : &quot;BtreeCursor x_1 reverse&quot;,&lt;br/&gt;
	&quot;nscanned&quot; : 1,&lt;br/&gt;
	&quot;nscannedObjects&quot; : 1,&lt;br/&gt;
	&quot;n&quot; : 1,&lt;br/&gt;
	&quot;millis&quot; : 0,&lt;br/&gt;
	&quot;nYields&quot; : 0,&lt;br/&gt;
	&quot;nChunkSkips&quot; : 0,&lt;br/&gt;
	&quot;indexBounds&quot; : &lt;/p&gt;
{
		&quot;x&quot; : [
			[
				60,
				-1.7976931348623157e+308
			]
		]
	}
&lt;p&gt;}&lt;/p&gt;</comment>
                            <comment id="18944" author="eliot" created="Wed, 6 Oct 2010 01:39:16 +0000"  >&lt;p&gt;Yes - please attach a full example w/o sharding with asserts (in js  test style)&lt;/p&gt;</comment>
                            <comment id="18936" author="eliot" created="Tue, 5 Oct 2010 21:54:27 +0000"  >&lt;p&gt;pretty sure that&apos;s notmal behavior when using limit(1)&lt;br/&gt;
try it without sharding&lt;br/&gt;
kristina knows all about this.&lt;br/&gt;
try against a mongod.&lt;br/&gt;
assuming i&apos;m right - please close the case&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10050" key="com.atlassian.jira.toolkit:comments">
                        <customfieldname># Replies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>8.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Tue, 5 Oct 2010 21:54:27 +0000</customfieldvalue>

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

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            13 years, 15 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>alvin</customfieldvalue>
            <customfieldvalue>auto</customfieldvalue>
            <customfieldvalue>eliot</customfieldvalue>
            <customfieldvalue>digal</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrpdrj:</customfieldvalue>

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

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>21870</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|ht0hdz:</customfieldvalue>

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