<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 05:04:47 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-44032] Mongodb Count is slow</title>
                <link>https://jira.mongodb.org/browse/SERVER-44032</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;Hi,&lt;br/&gt;
I am trying to improve count using covered queries but its taking ~5sec to return the response.&lt;/p&gt;

&lt;p&gt;Is this behavior expected or there is something I can do to improve this.&lt;/p&gt;

&lt;p&gt;Please find details below-&lt;/p&gt;

&lt;p&gt;There is collection with 6 million records&lt;/p&gt;

&lt;p&gt;consider each document to be something like this&lt;/p&gt;

{

&quot;_id&quot;: &quot;523453252&quot;,
&quot;type&quot;: &quot;test&quot;

}

&lt;p&gt;i have a single field index on &quot;type&quot;&lt;/p&gt;

&lt;p&gt;&#160;when I execute following command&lt;br/&gt;
db.test.explain(&quot;executionStats&quot;).find({type:{$in:&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;quot;test&amp;quot;,&amp;quot;test1&amp;quot;,&amp;quot;test2&amp;quot;&amp;#93;&lt;/span&gt;}},{type:1,_id:0}).count()&lt;/p&gt;

&lt;p&gt;the number of keys examined are ~5.9 million&lt;br/&gt;
number of docs examined are 0&lt;br/&gt;
even though there are no docs examined i.e nothing is loaded from disk&lt;br/&gt;
and the query is using only index the count is taking ~5sec&lt;br/&gt;
Please let me know if there is anything that can be done to improve count response time.&lt;/p&gt;</description>
                <environment></environment>
        <key id="970620">SERVER-44032</key>
            <summary>Mongodb Count is slow</summary>
                <type id="6" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14720&amp;avatarType=issuetype">Question</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="3">Duplicate</resolution>
                                        <assignee username="eric.sedor@mongodb.com">Eric Sedor</assignee>
                                    <reporter username="virinchisamineni@gmail.com">virinchi samineni</reporter>
                        <labels>
                    </labels>
                <created>Tue, 15 Oct 2019 19:57:35 +0000</created>
                <updated>Fri, 6 Dec 2019 22:45:54 +0000</updated>
                            <resolved>Fri, 6 Dec 2019 22:45:30 +0000</resolved>
                                    <version>4.2.0</version>
                                                                        <votes>0</votes>
                                    <watches>4</watches>
                                                                                                                <comments>
                            <comment id="2590869" author="eric.sedor" created="Fri, 6 Dec 2019 22:45:13 +0000"  >&lt;p&gt;Hi,&lt;/p&gt;

&lt;p&gt;We haven&#8217;t heard back from you for some time, so I&#8217;m going to close this issue as a duplicate of &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-17266&quot; title=&quot;count command performance optimization should support more complex queries&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-17266&quot;&gt;SERVER-17266&lt;/a&gt;. If this is still an issue for you, please provide additional information and we will reopen the ticket.&lt;/p&gt;

&lt;p&gt;Sincerely,&lt;br/&gt;
Eric&lt;/p&gt;</comment>
                            <comment id="2521814" author="eric.sedor" created="Thu, 7 Nov 2019 00:35:06 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=virinchisamineni%40gmail.com&quot; class=&quot;user-hover&quot; rel=&quot;virinchisamineni@gmail.com&quot;&gt;virinchisamineni@gmail.com&lt;/a&gt;,&lt;/p&gt;

&lt;p&gt;Are you are able to provide an exact command and explain() results via the MongoDB shell? We would still need that information to diagnose this issue as something other than &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-17266&quot; title=&quot;count command performance optimization should support more complex queries&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-17266&quot;&gt;SERVER-17266&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Gratefully,&lt;br/&gt;
Eric&lt;/p&gt;</comment>
                            <comment id="2501814" author="eric.sedor" created="Fri, 25 Oct 2019 21:13:05 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=virinchisamineni%40gmail.com&quot; class=&quot;user-hover&quot; rel=&quot;virinchisamineni@gmail.com&quot;&gt;virinchisamineni@gmail.com&lt;/a&gt;,&lt;/p&gt;

&lt;p&gt;Just to keep in mind, we are still continuing with the assumption that this is a duplicate of &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-17266&quot; title=&quot;count command performance optimization should support more complex queries&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-17266&quot;&gt;SERVER-17266&lt;/a&gt;, and our workaround suggestion continues to be to issue separate queries for each $in clause.&lt;/p&gt;

&lt;p&gt;If you would like to continue trying to confirm this fully, we would need to see the explain plan generated in the &lt;a href=&quot;https://docs.mongodb.com/manual/mongo/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;mongodb shell&lt;/a&gt;. Please C&amp;amp;P both the command and the output. Screenshots make it very difficult for us to communicate about specific details.&lt;/p&gt;

&lt;p&gt;Gratefully,&lt;br/&gt;
Eric&lt;/p&gt;</comment>
                            <comment id="2499788" author="virinchisamineni@gmail.com" created="Thu, 24 Oct 2019 19:33:46 +0000"  >&lt;p&gt;hi&#160;@&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=eric.sedor&quot; class=&quot;user-hover&quot; rel=&quot;eric.sedor&quot;&gt;eric.sedor&lt;/a&gt;&lt;br/&gt;
 please find screen shot below and no problem with going back and forth&#160;&lt;br/&gt;
 I want understand how the system works.&lt;/p&gt;

&lt;p&gt;I don&apos;t see COUNT_STAGE now either&lt;/p&gt;

&lt;p&gt;&lt;span class=&quot;image-wrap&quot; style=&quot;&quot;&gt;&lt;img src=&quot;https://jira.mongodb.org/secure/attachment/235245/235245_scr1.png&quot; width=&quot;100%&quot; style=&quot;border: 0px solid black&quot; /&gt;&lt;/span&gt;&lt;/p&gt;</comment>
                            <comment id="2499485" author="eric.sedor" created="Thu, 24 Oct 2019 16:46:03 +0000"  >&lt;p&gt;Thanks &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=virinchisamineni%40gmail.com&quot; class=&quot;user-hover&quot; rel=&quot;virinchisamineni@gmail.com&quot;&gt;virinchisamineni@gmail.com&lt;/a&gt; and sorry for the back and forth here. I do see .count() is included in what you ran but it really seems like the count portion of this operation is not reaching explain().&lt;/p&gt;

&lt;p&gt;Can you try this form please, and paste the explain results?&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.test.explain(&quot;executionStats&quot;).count({applicationType:{$in:[&quot;test&quot;,&quot;test1&quot;,&quot;test2&quot;]}})&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;</comment>
                            <comment id="2498568" author="virinchisamineni@gmail.com" created="Thu, 24 Oct 2019 04:49:20 +0000"  >&lt;p&gt;Hi @&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=eric.sedor&quot; class=&quot;user-hover&quot; rel=&quot;eric.sedor&quot;&gt;eric.sedor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yes &quot;applicationType&quot; is equivalent to &quot;type&quot; provided in description. I just wanted to convey the problem i was facing. here is screen shot for command I ran.&lt;/p&gt;

&lt;p&gt;&lt;span class=&quot;image-wrap&quot; style=&quot;&quot;&gt;&lt;img src=&quot;https://jira.mongodb.org/secure/attachment/235172/235172_scrnsht.png&quot; width=&quot;100%&quot; style=&quot;border: 0px solid black&quot; /&gt;&lt;/span&gt;&lt;/p&gt;</comment>
                            <comment id="2497754" author="eric.sedor" created="Wed, 23 Oct 2019 16:28:13 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=virinchisamineni%40gmail.com&quot; class=&quot;user-hover&quot; rel=&quot;virinchisamineni@gmail.com&quot;&gt;virinchisamineni@gmail.com&lt;/a&gt;: this query looks to be on &lt;tt&gt;applicationType&lt;/tt&gt; instead of &lt;tt&gt;type&lt;/tt&gt; as initially provided in the description, and I&apos;m a bit surprised there is no COUNT stage at all. Can you please provide the exact command you run to produce that explain output? It will help us dispel confusion while interpreting the explain plan. Thanks!&lt;/p&gt;</comment>
                            <comment id="2496874" author="virinchisamineni@gmail.com" created="Wed, 23 Oct 2019 01:58:06 +0000"  >&lt;p&gt;Hi&#160;@&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=eric.sedor&quot; class=&quot;user-hover&quot; rel=&quot;eric.sedor&quot;&gt;eric.sedor&lt;/a&gt;&#160;&lt;br/&gt;
 Please find below the output above command&lt;br/&gt;
 {&lt;br/&gt;
 &quot;queryPlanner&quot;: {&lt;br/&gt;
 &quot;plannerVersion&quot;: 1,&lt;br/&gt;
 &quot;namespace&quot;: &quot;demoapp.test&quot;,&lt;br/&gt;
 &quot;indexFilterSet&quot;: false,&lt;br/&gt;
 &quot;parsedQuery&quot;: {&lt;br/&gt;
 &quot;applicationType&quot;:&lt;/p&gt;

{ &quot;$in&quot;: [ &quot;test&quot;, &quot;test1&quot;, &quot;test2&quot; ] }

&lt;p&gt;},&lt;br/&gt;
 &quot;queryHash&quot;: &quot;612B6DDB&quot;,&lt;br/&gt;
 &quot;planCacheKey&quot;: &quot;75C11F3B&quot;,&lt;br/&gt;
 &quot;winningPlan&quot;: {&lt;br/&gt;
 &quot;stage&quot;: &quot;IXSCAN&quot;,&lt;br/&gt;
 &quot;keyPattern&quot;:&lt;/p&gt;

{ &quot;applicationType&quot;: -1 }

&lt;p&gt;,&lt;br/&gt;
 &quot;indexName&quot;: &quot;applicationType_-1&quot;,&lt;br/&gt;
 &quot;isMultiKey&quot;: false,&lt;br/&gt;
 &quot;multiKeyPaths&quot;:&lt;/p&gt;

{ &quot;applicationType&quot;: [ ] }

&lt;p&gt;,&lt;br/&gt;
 &quot;isUnique&quot;: false,&lt;br/&gt;
 &quot;isSparse&quot;: false,&lt;br/&gt;
 &quot;isPartial&quot;: false,&lt;br/&gt;
 &quot;indexVersion&quot;: 2,&lt;br/&gt;
 &quot;direction&quot;: &quot;forward&quot;,&lt;br/&gt;
 &quot;indexBounds&quot;:&lt;/p&gt;

{ &quot;applicationType&quot;: [ &quot;[\&quot;test2\&quot;, \&quot;test2\&quot;]&quot;, &quot;[\&quot;test1\&quot;, \&quot;test1\&quot;]&quot;, &quot;[\&quot;test\&quot;, \&quot;test\&quot;]&quot; ] }

&lt;p&gt;},&lt;br/&gt;
 &quot;rejectedPlans&quot;: [&lt;br/&gt;
 {&lt;br/&gt;
 &quot;stage&quot;: &quot;IXSCAN&quot;,&lt;br/&gt;
 &quot;keyPattern&quot;:&lt;/p&gt;

{ &quot;applicationType&quot;: 1, &quot;classification&quot;: 1 }

&lt;p&gt;,&lt;br/&gt;
 &quot;indexName&quot;: &quot;applicationType_1_classification_1&quot;,&lt;br/&gt;
 &quot;isMultiKey&quot;: false,&lt;br/&gt;
 &quot;multiKeyPaths&quot;:&lt;/p&gt;

{ &quot;applicationType&quot;: [ ], &quot;classification&quot;: [ ] }

&lt;p&gt;,&lt;br/&gt;
 &quot;isUnique&quot;: false,&lt;br/&gt;
 &quot;isSparse&quot;: false,&lt;br/&gt;
 &quot;isPartial&quot;: false,&lt;br/&gt;
 &quot;indexVersion&quot;: 2,&lt;br/&gt;
 &quot;direction&quot;: &quot;forward&quot;,&lt;br/&gt;
 &quot;indexBounds&quot;:&lt;/p&gt;

{ &quot;applicationType&quot;: [ &quot;[\&quot;test\&quot;, \&quot;test\&quot;]&quot;, &quot;[\&quot;test1\&quot;, \&quot;test1\&quot;]&quot;, &quot;[\&quot;test2\&quot;, \&quot;test2\&quot;]&quot; ], &quot;classification&quot;: [ &quot;[MinKey, MaxKey]&quot; ] }

&lt;p&gt;},&lt;br/&gt;
 {&lt;br/&gt;
 &quot;stage&quot;: &quot;IXSCAN&quot;,&lt;br/&gt;
 &quot;keyPattern&quot;:&lt;/p&gt;

{ &quot;applicationType&quot;: 1, &quot;classification&quot;: 1, &quot;isBundleListed&quot;: 1 }

&lt;p&gt;,&lt;br/&gt;
 &quot;indexName&quot;: &quot;applicationType_1_classification_1_isBundleListed_1&quot;,&lt;br/&gt;
 &quot;isMultiKey&quot;: false,&lt;br/&gt;
 &quot;multiKeyPaths&quot;:&lt;/p&gt;

{ &quot;applicationType&quot;: [ ], &quot;classification&quot;: [ ], &quot;isBundleListed&quot;: [ ] }

&lt;p&gt;,&lt;br/&gt;
 &quot;isUnique&quot;: false,&lt;br/&gt;
 &quot;isSparse&quot;: false,&lt;br/&gt;
 &quot;isPartial&quot;: false,&lt;br/&gt;
 &quot;indexVersion&quot;: 2,&lt;br/&gt;
 &quot;direction&quot;: &quot;forward&quot;,&lt;br/&gt;
 &quot;indexBounds&quot;:&lt;/p&gt;

{ &quot;applicationType&quot;: [ &quot;[\&quot;test\&quot;, \&quot;test\&quot;]&quot;, &quot;[\&quot;test1\&quot;, \&quot;test1\&quot;]&quot;, &quot;[\&quot;test2\&quot;, \&quot;test2\&quot;]&quot; ], &quot;classification&quot;: [ &quot;[MinKey, MaxKey]&quot; ], &quot;isBundleListed&quot;: [ &quot;[MinKey, MaxKey]&quot; ] }

&lt;p&gt;},&lt;br/&gt;
 {&lt;br/&gt;
 &quot;stage&quot;: &quot;IXSCAN&quot;,&lt;br/&gt;
 &quot;keyPattern&quot;:&lt;/p&gt;

{ &quot;applicationType&quot;: 1, &quot;classification&quot;: 1, &quot;publicationDate&quot;: -1, &quot;isBundleListed&quot;: 1 }

&lt;p&gt;,&lt;br/&gt;
 &quot;indexName&quot;: &quot;applicationType_1_classification_1_publicationDate_-1_isBundleListed_1&quot;,&lt;br/&gt;
 &quot;isMultiKey&quot;: false,&lt;br/&gt;
 &quot;multiKeyPaths&quot;:&lt;/p&gt;

{ &quot;applicationType&quot;: [ ], &quot;classification&quot;: [ ], &quot;publicationDate&quot;: [ ], &quot;isBundleListed&quot;: [ ] }

&lt;p&gt;,&lt;br/&gt;
 &quot;isUnique&quot;: false,&lt;br/&gt;
 &quot;isSparse&quot;: false,&lt;br/&gt;
 &quot;isPartial&quot;: false,&lt;br/&gt;
 &quot;indexVersion&quot;: 2,&lt;br/&gt;
 &quot;direction&quot;: &quot;forward&quot;,&lt;br/&gt;
 &quot;indexBounds&quot;:&lt;/p&gt;

{ &quot;applicationType&quot;: [ &quot;[\&quot;test\&quot;, \&quot;test\&quot;]&quot;, &quot;[\&quot;test1\&quot;, \&quot;test1\&quot;]&quot;, &quot;[\&quot;test2\&quot;, \&quot;test2\&quot;]&quot; ], &quot;classification&quot;: [ &quot;[MinKey, MaxKey]&quot; ], &quot;publicationDate&quot;: [ &quot;[MaxKey, MinKey]&quot; ], &quot;isBundleListed&quot;: [ &quot;[MinKey, MaxKey]&quot; ] }

&lt;p&gt;}&lt;br/&gt;
 ]&lt;br/&gt;
 },&lt;br/&gt;
 &quot;executionStats&quot;: {&lt;br/&gt;
 &quot;executionSuccess&quot;: true,&lt;br/&gt;
 &quot;nReturned&quot;: 6122209,&lt;br/&gt;
 &quot;executionTimeMillis&quot;: 4144,&lt;br/&gt;
 &quot;totalKeysExamined&quot;: 6122211,&lt;br/&gt;
 &quot;totalDocsExamined&quot;: 0,&lt;br/&gt;
 &quot;executionStages&quot;: {&lt;br/&gt;
 &quot;stage&quot;: &quot;IXSCAN&quot;,&lt;br/&gt;
 &quot;nReturned&quot;: 6122209,&lt;br/&gt;
 &quot;executionTimeMillisEstimate&quot;: 102,&lt;br/&gt;
 &quot;works&quot;: 6122212,&lt;br/&gt;
 &quot;advanced&quot;: 6122209,&lt;br/&gt;
 &quot;needTime&quot;: 2,&lt;br/&gt;
 &quot;needYield&quot;: 0,&lt;br/&gt;
 &quot;saveState&quot;: 47833,&lt;br/&gt;
 &quot;restoreState&quot;: 47833,&lt;br/&gt;
 &quot;isEOF&quot;: 1,&lt;br/&gt;
 &quot;keyPattern&quot;:&lt;/p&gt;

{ &quot;applicationType&quot;: -1 }

&lt;p&gt;,&lt;br/&gt;
 &quot;indexName&quot;: &quot;applicationType_-1&quot;,&lt;br/&gt;
 &quot;isMultiKey&quot;: false,&lt;br/&gt;
 &quot;multiKeyPaths&quot;:&lt;/p&gt;

{ &quot;applicationType&quot;: [ ] }

&lt;p&gt;,&lt;br/&gt;
 &quot;isUnique&quot;: false,&lt;br/&gt;
 &quot;isSparse&quot;: false,&lt;br/&gt;
 &quot;isPartial&quot;: false,&lt;br/&gt;
 &quot;indexVersion&quot;: 2,&lt;br/&gt;
 &quot;direction&quot;: &quot;forward&quot;,&lt;br/&gt;
 &quot;indexBounds&quot;:&lt;/p&gt;

{ &quot;applicationType&quot;: [ &quot;[\&quot;test2\&quot;, \&quot;test2\&quot;]&quot;, &quot;[\&quot;test1\&quot;, \&quot;test1\&quot;]&quot;, &quot;[\&quot;test\&quot;, \&quot;test\&quot;]&quot; ] }

&lt;p&gt;,&lt;br/&gt;
 &quot;keysExamined&quot;: 6122211,&lt;br/&gt;
 &quot;seeks&quot;: 3,&lt;br/&gt;
 &quot;dupsTested&quot;: 0,&lt;br/&gt;
 &quot;dupsDropped&quot;: 0&lt;br/&gt;
 }&lt;br/&gt;
 },&lt;br/&gt;
 &quot;ok&quot;: 1,&lt;br/&gt;
 &quot;$clusterTime&quot;: {&lt;br/&gt;
 &quot;clusterTime&quot;: Timestamp(1571795638,&lt;br/&gt;
 1),&lt;br/&gt;
 &quot;signature&quot;:&lt;/p&gt;

{ &quot;hash&quot;: BinData(0, &quot;AAAAAAAAAAAAAAAAAAAAAAAAAAA=&quot;), &quot;keyId&quot;: 0 }

&lt;p&gt;},&lt;br/&gt;
 &quot;operationTime&quot;: Timestamp(1571795638,&lt;br/&gt;
 1)&lt;br/&gt;
 }&lt;/p&gt;</comment>
                            <comment id="2496807" author="eric.sedor" created="Tue, 22 Oct 2019 23:48:00 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=virinchisamineni%40gmail.com&quot; class=&quot;user-hover&quot; rel=&quot;virinchisamineni@gmail.com&quot;&gt;virinchisamineni@gmail.com&lt;/a&gt;,&lt;/p&gt;

&lt;p&gt;To be clear: Yes, the delay is due to the current implementation of count.&lt;/p&gt;

&lt;p&gt;And yes, the current workaround for this is to issue separate queries. This does impose the network cost you as you say, but depending on the size of the collection, that could still be faster than issuing one query of $ins, and less disruptive of the working set. That means other operations won&apos;t be as impacted by the count operations either, so there could be indirect benefits for other ops.&lt;/p&gt;

&lt;p&gt;I believe Asya is correct that this is a duplicate of &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-17266&quot; title=&quot;count command performance optimization should support more complex queries&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-17266&quot;&gt;SERVER-17266&lt;/a&gt;. But for completeness, can you please provide the output of:&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.test.explain(&quot;executionStats&quot;).find({type:{$in:[&quot;test&quot;,&quot;test1&quot;,&quot;test2&quot;]}},{type:1,_id:0}).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;Gratefully,&lt;br/&gt;
Eric&lt;/p&gt;


</comment>
                            <comment id="2492126" author="asya" created="Mon, 21 Oct 2019 09:18:59 +0000"  >&lt;p&gt;This appears to be duplicate of &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-17266&quot; title=&quot;count command performance optimization should support more complex queries&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-17266&quot;&gt;SERVER-17266&lt;/a&gt; (and a few related tickets).  The issue is that faster COUNT_SCAN can only be used if the index is &lt;b&gt;not&lt;/b&gt; multiKey.  I&apos;ve reopened the other ticket and scheduled it for triage, this one should be marked as a duplicate of it.&lt;/p&gt;</comment>
                            <comment id="2490872" author="virinchisamineni@gmail.com" created="Fri, 18 Oct 2019 22:21:47 +0000"  >&lt;p&gt;Hi Eric,&lt;/p&gt;

&lt;p&gt;Thanks for the update.&lt;/p&gt;

&lt;p&gt;Are you suggesting that rather than using $in operator&#160;&lt;br/&gt;
&#160;I should be querying the database 3 times(one for each type )&lt;br/&gt;
and then combine counts for each of them.&lt;/p&gt;

&lt;p&gt;If that&apos;s the case won&apos;t I be facing network latency as i am issuing 3 separate queries as opposed to one.&lt;/p&gt;

&lt;p&gt;I want to understand if there is a possibility of reducing 5 sec to 1~2 sec&lt;br/&gt;
and also I would like to know whether 5 sec is&#160; happening&#160; due to how count is implemented in mongodb or any other issue.&lt;/p&gt;</comment>
                            <comment id="2487765" author="eric.sedor" created="Thu, 17 Oct 2019 22:10:21 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=virinchisamineni%40gmail.com&quot; class=&quot;user-hover&quot; rel=&quot;virinchisamineni@gmail.com&quot;&gt;virinchisamineni@gmail.com&lt;/a&gt;,&lt;/p&gt;

&lt;p&gt;It looks like you are experiencing known behavior with how &lt;a href=&quot;https://docs.mongodb.com/manual/reference/method/db.collection.count/#index-use&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;count is currently able to use indexes&lt;/a&gt;. For this specific operation, you should be able to issue queries for each &lt;tt&gt;type&lt;/tt&gt; separately (rather than using &lt;tt&gt;$in&lt;/tt&gt;. Each individual count request should be able to use only the index because each operation would access a &quot;contiguous&quot; range of index keys.&lt;/p&gt;

&lt;p&gt;That said, I am looking into whether or not a jira ticket exists to change this behavior, and will update you. Thanks in advance for your patience.&lt;/p&gt;

&lt;p&gt;Sincerely,&lt;br/&gt;
Eric&lt;/p&gt;</comment>
                            <comment id="2486139" author="virinchisamineni@gmail.com" created="Thu, 17 Oct 2019 02:46:18 +0000"  >&lt;p&gt;Hi ,&lt;br/&gt;
Any update on this. &lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10010">
                    <name>Duplicate</name>
                                            <outwardlinks description="duplicates">
                                        <issuelink>
            <issuekey id="183854">SERVER-17266</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                    </issuelinks>
                <attachments>
                            <attachment id="235245" name="scr1.png" size="209038" author="virinchisamineni@gmail.com" created="Thu, 24 Oct 2019 19:33:05 +0000"/>
                            <attachment id="235172" name="scrnsht.png" size="215090" author="virinchisamineni@gmail.com" created="Thu, 24 Oct 2019 04:48:21 +0000"/>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10050" key="com.atlassian.jira.toolkit:comments">
                        <customfieldname># Replies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>13.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Thu, 17 Oct 2019 22:10:21 +0000</customfieldvalue>

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

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            4 years, 9 weeks, 5 days ago
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                    <customfield id="customfield_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>asya.kamsky@mongodb.com</customfieldvalue>
            <customfieldvalue>eric.sedor@mongodb.com</customfieldvalue>
            <customfieldvalue>virinchisamineni@gmail.com</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hvxnzz:</customfieldvalue>

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

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>9223372036854775807</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>
                                    <customfieldvalue><![CDATA[eric.sedor@mongodb.com]]></customfieldvalue>
    

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

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