<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 03:00:52 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-2677] Allow count to work with query hints</title>
                <link>https://jira.mongodb.org/browse/SERVER-2677</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;Add ability to hint count commands.&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;// using explicit command form&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;db.runCommand({count:&apos;test&apos;, query:{f:1}, hint:&apos;_id_&apos;})&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;&amp;nbsp;&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;// using shell helper&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;db.test.find({f:1}).hint(&apos;x_1&apos;).count()&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;If there is no predicate for the query given to the count command, the hint will be ignored and the result will be pulled directly from the collection metadata.&lt;/p&gt;</description>
                <environment>Redhat 6.0</environment>
        <key id="14991">SERVER-2677</key>
            <summary>Allow count to work with query hints</summary>
                <type id="4" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14710&amp;avatarType=issuetype">Improvement</type>
                                            <priority id="4" iconUrl="https://jira.mongodb.org/images/icons/priorities/minor.svg">Minor - P4</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="dan@mongodb.com">Daniel Pasette</assignee>
                                    <reporter username="realzyy">Yunyang Zhang</reporter>
                        <labels>
                    </labels>
                <created>Fri, 4 Mar 2011 08:58:26 +0000</created>
                <updated>Tue, 27 Oct 2015 14:57:43 +0000</updated>
                            <resolved>Thu, 16 Jan 2014 22:27:25 +0000</resolved>
                                    <version>1.8.0-rc0</version>
                                    <fixVersion>2.5.5</fixVersion>
                                                        <votes>20</votes>
                                    <watches>16</watches>
                                                                                                                <comments>
                            <comment id="483401" author="xgen-internal-githook" created="Thu, 16 Jan 2014 22:26:58 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;username&apos;: u&apos;monkey101&apos;, u&apos;name&apos;: u&apos;Dan Pasette&apos;, u&apos;email&apos;: u&apos;dan@10gen.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-2677&quot; title=&quot;Allow count to work with query hints&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-2677&quot;&gt;&lt;del&gt;SERVER-2677&lt;/del&gt;&lt;/a&gt; Allow hint to work with the count command.&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo/commit/2bea8060ce966275cd1424e18157ca790af34636&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo/commit/2bea8060ce966275cd1424e18157ca790af34636&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="481480" author="jake@about.me" created="Tue, 14 Jan 2014 02:06:40 +0000"  >&lt;p&gt;Not entirely sure that&apos;s accurate - we had very fast .count() before we changed our indexes, likewise a fast .explain(), but now .count() is super slow (90 seconds or more), and .explain() with a hint is still 17 seconds. We added a compound index to actually match the queries we&apos;re doing more closely - dropping one that isn&apos;t used, yet it slowed down.&lt;/p&gt;

&lt;p&gt;Not entirely sure what&apos;s going on there. We&apos;ve had to resort to not counting and just doing a boolean check (for pagination). &lt;img class=&quot;emoticon&quot; src=&quot;https://jira.mongodb.org/images/icons/emoticons/sad.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="481460" author="antoine" created="Tue, 14 Jan 2014 01:27:48 +0000"  >&lt;p&gt;In itself, explain does not do that much more work than a count(), for example it will properly do covered only index if it is possible.&lt;br/&gt;
It is an ugly workaround API wise, but as far as what the db does it should not be bad, at least it&apos;s much better than doing a table scan or wrong index scan.&lt;br/&gt;
A lot of the hinting and query optimizing has been completely revamped in 2.6, so that&apos;s also something to watch for.&lt;/p&gt;</comment>
                            <comment id="481451" author="jake@about.me" created="Tue, 14 Jan 2014 01:08:53 +0000"  >&lt;p&gt;This is nuts. Just ran into this today. Leveraging compound indexes great, except when the query optimizer totally ignores your compound index in favor of less optimized indexes.&lt;/p&gt;

&lt;p&gt;Count doesn&apos;t support $hint or .hint()? This is killing one of our applications. .explain() is an absolutely terrible work-around.&lt;/p&gt;

&lt;p&gt;Any chance we can get priority bumped on this?&lt;/p&gt;</comment>
                            <comment id="450020" author="christopher.price@mtvn.com" created="Fri, 1 Nov 2013 12:19:03 +0000"  >&lt;p&gt;Additional note: in most of my examples where mongodb has chosen a less than ideal index, the mongo team has recommended using $hint.  So support for $hint on count operations is the only way for us to follow your own advice.  &lt;/p&gt;</comment>
                            <comment id="450019" author="christopher.price@mtvn.com" created="Fri, 1 Nov 2013 12:16:11 +0000"  >&lt;p&gt;I have had several problems where mongo picks a less than ideal index for find and count operations.  I proposed using explain on all of my operations to prevent bad query plans from being cached and it was strongly discouraged by the mongo team.  I don&apos;t think that using explain on application queries in a production system is a very good (nor scalable) option.  &lt;/p&gt;</comment>
                            <comment id="449831" author="antoine" created="Thu, 31 Oct 2013 21:58:46 +0000"  >&lt;p&gt;A current workaround would be to actually use &quot;n&quot; from find().hint().explain() instead of doing the count.&lt;br/&gt;
If count is picking the wrong index, this count be many times faster.&lt;/p&gt;</comment>
                            <comment id="42776" author="eliot" created="Mon, 18 Jul 2011 13:10:13 +0000"  >&lt;p&gt;@kushal, those results are not going to be correct.&lt;/p&gt;</comment>
                            <comment id="42772" author="krave" created="Mon, 18 Jul 2011 12:52:05 +0000"  >&lt;p&gt;Hinting seems to work for fetching results&lt;/p&gt;


&lt;p&gt;&amp;gt; db.usertodos.find({&apos;u&apos;:2102,&apos;wtd&apos;:true,&apos;latlng&apos;:{&apos;$within&apos;:{$center:[&lt;span class=&quot;error&quot;&gt;&amp;#91;40.7, -74&amp;#93;&lt;/span&gt;, 0.1185]}}}).hint(&lt;/p&gt;
{u:1}
&lt;p&gt;).explain()                                                                                 &lt;br/&gt;
{&lt;br/&gt;
	&quot;cursor&quot; : &quot;BtreeCursor u_1&quot;,&lt;br/&gt;
	&quot;nscanned&quot; : 198,&lt;br/&gt;
	&quot;nscannedObjects&quot; : 198,&lt;br/&gt;
	&quot;n&quot; : 85,&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;isMultiKey&quot; : false,&lt;br/&gt;
	&quot;indexOnly&quot; : false,&lt;br/&gt;
	&quot;indexBounds&quot; : &lt;/p&gt;
{
		&quot;u&quot; : [
			[
				2102,
				2102
			]
		]
	}
&lt;p&gt;}&lt;/p&gt;</comment>
                            <comment id="42737" author="eliot" created="Mon, 18 Jul 2011 02:38:31 +0000"  >&lt;p&gt;Right now you have to use the 2d index with any $within type query.&lt;br/&gt;
So hinting to something else is not supported.&lt;/p&gt;

&lt;p&gt;That would definitely be a separate issue.&lt;/p&gt;</comment>
                            <comment id="42728" author="krave" created="Mon, 18 Jul 2011 00:56:01 +0000"  >&lt;p&gt;One case we&apos;ve run into is that Mongo insists on using a 2d index if there&apos;s any geo restriction in the query (should this be a separate bug?). As a result, if we don&apos;t have or shouldn&apos;t use the 2d index, we need to hint our way out of this. See below. I suppose I can work around by doing the lat lng query as less than, greater than, but it makes me feel yucky to do so. &lt;/p&gt;

&lt;p&gt;&amp;gt; db.usertodos.find({&apos;u&apos;:2102,&apos;wtd&apos;:true,&apos;latlng&apos;:{&apos;$within&apos;:{$center:[&lt;span class=&quot;error&quot;&gt;&amp;#91;40.7, -74&amp;#93;&lt;/span&gt;, 0.1185]}}}).hint(&lt;/p&gt;
{u:1}
&lt;p&gt;).count()&lt;br/&gt;
Mon Jul 18 00:51:27 uncaught exception: count failed: {&lt;br/&gt;
	&quot;errmsg&quot; : &quot;exception: can&apos;t find special index: 2d for: { u: 2102.0, wtd: true, latlng: { $within: &lt;/p&gt;
{ $center: [ [ 40.7, -74.0 ], 0.1185 ] }
&lt;p&gt; } }&quot;,&lt;br/&gt;
	&quot;code&quot; : 13038,&lt;br/&gt;
	&quot;ok&quot; : 0&lt;br/&gt;
}&lt;/p&gt;</comment>
                            <comment id="42679" author="eliot" created="Sun, 17 Jul 2011 01:47:15 +0000"  >&lt;p&gt;@boris - what&apos;s the case where you need hint?  We see that very rarely.&lt;/p&gt;</comment>
                            <comment id="42406" author="borisman" created="Thu, 14 Jul 2011 20:28:22 +0000"  >&lt;p&gt;Guys, this bug renders count() unusable for most practical reasons. It NEEDS to be fixed.&lt;/p&gt;</comment>
                            <comment id="38745" author="tdemille" created="Wed, 22 Jun 2011 15:50:31 +0000"  >&lt;p&gt;I know this issue only has two votes but this is somewhat critical (at least for me &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;  ) as we do about 7 counts for every find, thus 7 out of 8 queries can&apos;t use hints right now&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10011">
                    <name>Depends</name>
                                                                <inwardlinks description="is depended on by">
                                        <issuelink>
            <issuekey id="150787">JAVA-1344</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                            <issuelinktype id="10010">
                    <name>Duplicate</name>
                                                                <inwardlinks description="is duplicated by">
                                        <issuelink>
            <issuekey id="89461">SERVER-10749</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                        <issuelink>
            <issuekey id="12729">SERVER-1599</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="129110">DOCS-3066</issuekey>
        </issuelink>
                            </outwardlinks>
                                                                <inwardlinks description="is related to">
                                        <issuelink>
            <issuekey id="51122">SERVER-7105</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="151064">SERVER-14799</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10050" key="com.atlassian.jira.toolkit:comments">
                        <customfieldname># Replies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>14.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_10011" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Backwards Compatibility</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10038"><![CDATA[Fully Compatible]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                            <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Wed, 22 Jun 2011 15:50:31 +0000</customfieldvalue>

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

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            10 years, 4 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_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>antoine</customfieldvalue>
            <customfieldvalue>borisman</customfieldvalue>
            <customfieldvalue>christopher.price@mtvn.com</customfieldvalue>
            <customfieldvalue>dan@mongodb.com</customfieldvalue>
            <customfieldvalue>eliot</customfieldvalue>
            <customfieldvalue>xgen-internal-githook</customfieldvalue>
            <customfieldvalue>jake@about.me</customfieldvalue>
            <customfieldvalue>krave</customfieldvalue>
            <customfieldvalue>tdemille</customfieldvalue>
            <customfieldvalue>realzyy</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrp4n3:</customfieldvalue>

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

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

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