<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 06:17:11 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-70811] SHARDING_FILTER stage missing from db.coll.count({predicate})</title>
                <link>https://jira.mongodb.org/browse/SERVER-70811</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;This bug has different severity depending on the version. The query is &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.coll.count({predicate}) &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;with secondary reads.&lt;/p&gt;

&lt;p&gt;On 4.4, the result is incorrect, and includes orphan documents. A SHARDING_FILTER is missing from the explain plan.&lt;/p&gt;

&lt;p&gt;On 5.0 and 6.0, orphan documents are filtered out and the count is correct, but the SHARDING_FILTER stage is not reported in the explain plan. This makes me think the explain is incorrect, and the stage is actually included.&lt;/p&gt;

&lt;p&gt;Repro script (based on shard_filtering.js):&lt;br/&gt;
```&lt;br/&gt;
 (function() {&lt;br/&gt;
    &quot;use strict&quot;;&lt;/p&gt;

&lt;p&gt;    load(&quot;jstests/libs/analyze_plan.js&quot;);&lt;/p&gt;

&lt;p&gt;    // Deliberately inserts orphans outside of migration.&lt;br/&gt;
    TestData.skipCheckOrphans = true;&lt;br/&gt;
    const st = new ShardingTest({shards: 2, rs: {nodes: 2}});&lt;br/&gt;
    const collName = &quot;test.shardfilter&quot;;&lt;br/&gt;
    const mongosDb = st.s.getDB(&quot;test&quot;);&lt;br/&gt;
    const mongosColl = st.s.getCollection(collName);&lt;/p&gt;

&lt;p&gt;    assert.commandWorked(st.s.adminCommand(&lt;/p&gt;
{enableSharding: &quot;test&quot;}
&lt;p&gt;));&lt;br/&gt;
    st.ensurePrimaryShard(&quot;test&quot;, st.shard1.name);&lt;br/&gt;
    assert.commandWorked(&lt;br/&gt;
        st.s.adminCommand({shardCollection: collName, key: {a: 1, &quot;b.c&quot;: 1, &quot;d.e.f&quot;: 1}}));&lt;/p&gt;

&lt;p&gt;    // Put a chunk with no data onto shard0 in order to make sure that both shards get targeted.&lt;br/&gt;
    assert.commandWorked(st.s.adminCommand({split: collName, middle: {a: 20, &quot;b.c&quot;: 0, &quot;d.e.f&quot;: 0}}));&lt;br/&gt;
    assert.commandWorked(st.s.adminCommand({split: collName, middle: {a: 30, &quot;b.c&quot;: 0, &quot;d.e.f&quot;: 0}}));&lt;br/&gt;
    assert.commandWorked(st.s.adminCommand(&lt;br/&gt;
        {moveChunk: collName, find: &lt;/p&gt;
{a: 25, &quot;b.c&quot;: 0, &quot;d.e.f&quot;: 0}
&lt;p&gt;, to: st.shard0.shardName}));&lt;/p&gt;

&lt;p&gt;    // Shard the collection and insert some docs.&lt;br/&gt;
    const docs = [&lt;br/&gt;
        {_id: 0, a: 1, b: &lt;/p&gt;
{c: 1}
&lt;p&gt;, d: {e: {f: 1}}, g: 100, z: &quot;z&quot;},&lt;br/&gt;
        {_id: 1, a: 1, b: &lt;/p&gt;
{c: 2}
&lt;p&gt;, d: {e: {f: 2}}, g: 100.9, z: &quot;z&quot;},&lt;br/&gt;
        {_id: 2, a: 1, b: &lt;/p&gt;
{c: 3}
&lt;p&gt;, d: {e: {f: 3}}, g: &quot;a&quot;, z: &quot;z&quot;},&lt;br/&gt;
        {_id: 3, a: 1, b: &lt;/p&gt;
{c: 3}
&lt;p&gt;, d: {e: {f: 3}}, g: &lt;span class=&quot;error&quot;&gt;&amp;#91;1, 2, 3&amp;#93;&lt;/span&gt;, z: &quot;z&quot;},&lt;br/&gt;
        {_id: 4, a: &quot;a&quot;, b: &lt;/p&gt;
{c: &quot;b&quot;}
&lt;p&gt;, d: {e: {f: &quot;c&quot;}}, g: null, z: &quot;z&quot;},&lt;br/&gt;
        {_id: 5, a: 1.0, b: &lt;/p&gt;
{c: &quot;b&quot;}
&lt;p&gt;, d: {e: {f: Infinity}}, g: NaN, z: &quot;z&quot;},&lt;br/&gt;
    ];&lt;br/&gt;
    assert.commandWorked(mongosColl.insert(docs));&lt;br/&gt;
    assert.eq(mongosColl.find().itcount(), 6);&lt;/p&gt;

&lt;p&gt;    // Insert some documents with valid partial shard keys to both shards. The versions of these&lt;br/&gt;
    // documents on shard0 are orphans, since all of the data is owned by shard1.&lt;br/&gt;
    const docsWithMissingAndNullKeys = [&lt;br/&gt;
        {_id: 6, a: &quot;missingParts&quot;, z: &quot;z&quot;},&lt;br/&gt;
        {_id: 7, a: null, b: &lt;/p&gt;
{c: 1}
&lt;p&gt;, d: {e: {f: 1}}, z: &quot;z&quot;},&lt;br/&gt;
        {_id: 8, a: &quot;null&quot;, b: &lt;/p&gt;
{c: null}
&lt;p&gt;, d: {e: {f: 1}}, z: &quot;z&quot;},&lt;br/&gt;
        {_id: 9, a: &quot;deepNull&quot;, b: &lt;/p&gt;
{c: 1}
&lt;p&gt;, d: {e: {f: null}}, z: &quot;z&quot;},&lt;br/&gt;
    ];&lt;br/&gt;
    assert.commandWorked(st.shard0.getCollection(collName).insert(docsWithMissingAndNullKeys));&lt;br/&gt;
    assert.commandWorked(st.shard1.getCollection(collName).insert(docsWithMissingAndNullKeys));&lt;/p&gt;

&lt;p&gt;    // Insert orphan docs without missing or null shard keys onto shard0 and test that they get filtered&lt;br/&gt;
    // out.&lt;br/&gt;
    const orphanDocs = [&lt;br/&gt;
        {_id: 10, a: 100, b: &lt;/p&gt;
{c: 10}
&lt;p&gt;, d: {e: {f: 999}}, g: &quot;a&quot;, z: &quot;z&quot;},&lt;br/&gt;
        {_id: 11, a: 101, b: &lt;/p&gt;
{c: 11}
&lt;p&gt;, d: {e: {f: 1000}}, g: &quot;b&quot;, z: &quot;z&quot;}&lt;br/&gt;
    ];&lt;br/&gt;
    assert.commandWorked(st.shard0.getCollection(collName).insert(orphanDocs));&lt;br/&gt;
    assert.eq(mongosColl.find().itcount(), 10);&lt;/p&gt;

&lt;p&gt;    // With primary read pref, count with predicate filters out orphans&lt;br/&gt;
    assert.eq(mongosColl.count(&lt;/p&gt;
{z: &quot;z&quot;}
&lt;p&gt;), 10);&lt;br/&gt;
    // The explain plan includes a sharding filter&lt;br/&gt;
    jsTestLog(mongosColl.explain().count(&lt;/p&gt;
{z: &quot;z&quot;}
&lt;p&gt;));&lt;/p&gt;

&lt;p&gt;    mongosDb.shardfilter.getMongo().setReadPref(&quot;secondary&quot;);&lt;br/&gt;
    // With secondary read pref, count with predicate still filters out orphans&lt;br/&gt;
    assert.eq(mongosColl.count(&lt;/p&gt;
{z: &quot;z&quot;}
&lt;p&gt;), 10);&lt;br/&gt;
    // The following explain doesn&apos;t include a sharding filter&lt;br/&gt;
    jsTestLog(mongosColl.explain().count(&lt;/p&gt;
{z: &quot;z&quot;}
&lt;p&gt;));&lt;/p&gt;

&lt;p&gt;    st.stop();&lt;br/&gt;
})();&lt;br/&gt;
```&lt;/p&gt;</description>
                <environment></environment>
        <key id="2165659">SERVER-70811</key>
            <summary>SHARDING_FILTER stage missing from db.coll.count({predicate})</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="3">Duplicate</resolution>
                                        <assignee username="backlog-query-optimization">Backlog - Query Optimization</assignee>
                                    <reporter username="matt.boros@mongodb.com">Matt Boros</reporter>
                        <labels>
                    </labels>
                <created>Mon, 24 Oct 2022 18:00:19 +0000</created>
                <updated>Mon, 5 Dec 2022 23:35:13 +0000</updated>
                            <resolved>Mon, 24 Oct 2022 18:01:20 +0000</resolved>
                                                                                        <votes>0</votes>
                                    <watches>1</watches>
                                                                                                                <comments>
                            <comment id="4923133" author="JIRAUSER1253388" created="Mon, 24 Oct 2022 18:01:46 +0000"  >&lt;p&gt;Apologies, Jira was acting funny and created two of these tickets.&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10010">
                    <name>Duplicate</name>
                                            <outwardlinks description="duplicates">
                                        <issuelink>
            <issuekey id="2165658">SERVER-70810</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10050" key="com.atlassian.jira.toolkit:comments">
                        <customfieldname># Replies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                <customfield id="customfield_12751" key="com.atlassian.jira.plugin.system.customfieldtypes:multiselect">
                        <customfieldname>Assigned Teams</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="25126"><![CDATA[Query Optimization]]></customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        1 year, 15 weeks, 2 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>alexander.golin@mongodb.com</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            1 year, 15 weeks, 2 days ago
                        </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>backlog-query-optimization</customfieldvalue>
            <customfieldvalue>matt.boros@mongodb.com</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|i1f6y7:</customfieldvalue>

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

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

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