<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 05:13: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-47330] Extend IDHACK to any unique index where all properties are given as simple &quot;equality&quot; values.</title>
                <link>https://jira.mongodb.org/browse/SERVER-47330</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;The IDHACK is an optimization for &lt;tt&gt;_id&lt;/tt&gt; lookups.  It exploits the fact that &lt;tt&gt;_id&lt;/tt&gt; ~always has a unique index; if the internal find cursor yields a document, there&#8217;s no need to iterate the cursor any more, or make an additional &#8220;step&#8221; in the query planner, which improves performance.  This could be generalized to apply to any unique index where all properties of the index are given as simple equality values.&lt;/p&gt;

&lt;p&gt;For example, given unique index {&lt;tt&gt;foo: 1, bar: 1&lt;/tt&gt;}, a query {&lt;tt&gt;foo: 123, bar: &quot;abc&quot;, baz: {$lt: 789&lt;/tt&gt;}} would be able to use this enhanced IDHACK optimization.&lt;/p&gt;

&lt;p&gt;A much more common case for us would be &lt;tt&gt;$in&lt;/tt&gt; queries on &lt;tt&gt;_id&lt;/tt&gt;, which I suspect is common to many users, since it&apos;s what you&apos;d do to emulate joins.  Today, an &lt;tt&gt;$in&lt;/tt&gt; would require 2x the steps/cursor iterations compared to applying the IDHACK.&lt;/p&gt;</description>
                <environment></environment>
        <key id="1303779">SERVER-47330</key>
            <summary>Extend IDHACK to any unique index where all properties are given as simple &quot;equality&quot; values.</summary>
                <type id="4" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14710&amp;avatarType=issuetype">Improvement</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</priority>
                        <status id="10038" iconUrl="https://jira.mongodb.org/images/icons/subtask.gif" description="">Backlog</status>
                    <statusCategory id="2" key="new" colorName="default"/>
                                    <resolution id="-1">Unresolved</resolution>
                                        <assignee username="backlog-query-optimization">Backlog - Query Optimization</assignee>
                                    <reporter username="bartle">David Bartley</reporter>
                        <labels>
                            <label>qopt-team</label>
                    </labels>
                <created>Fri, 3 Apr 2020 18:42:26 +0000</created>
                <updated>Tue, 6 Dec 2022 02:30:43 +0000</updated>
                                                                                                <votes>0</votes>
                                    <watches>11</watches>
                                                                                                                <comments>
                            <comment id="3031565" author="bartle" created="Wed, 8 Apr 2020 17:58:20 +0000"  >&lt;p&gt;For us it&apos;d be more important for _id $in queries to be optimized.&lt;/p&gt;</comment>
                            <comment id="3030992" author="asya" created="Wed, 8 Apr 2020 14:25:13 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=bartle&quot; class=&quot;user-hover&quot; rel=&quot;bartle&quot;&gt;bartle&lt;/a&gt;&#160;it&apos;s not clear how muxh this would change actual performance.&#160; You can see in&#160;&lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-15802&quot; title=&quot;Query optimizer should always use equality predicate over unique index when possible&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-15802&quot;&gt;&lt;del&gt;SERVER-15802&lt;/del&gt;&lt;/a&gt; back in 2.6/3.0 days we already added an optimization that will always favor unique index when there is an equality predicate on that field.&lt;/p&gt;

&lt;p&gt;This sounds like you&apos;re seeing that but would like to see improvement that would not look at additional keys in this case?&lt;/p&gt;

&lt;p&gt;So you&apos;re looking for&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.foo.find({a:{$in:[5, 10, 20]}}) &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;to examine only 3 keys when there is a unique index on `a` instead of the 6 it would currently examine? We already only examine one key if you query with &lt;tt&gt;a:5&lt;/tt&gt;.&lt;/p&gt;

&lt;p&gt;Note that IDHACK is currently &lt;b&gt;only&lt;/b&gt; applied to equality. If you query with &lt;tt&gt;$in&lt;/tt&gt; against &lt;tt&gt;_id&lt;/tt&gt; and a list of values, we examine 6 keys rather than 3.&lt;/p&gt;

&lt;p&gt;So my two questions are:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;is this ticket to extend IDHACK to non-_id equality queries&lt;/li&gt;
	&lt;li&gt;or is it to apply similar logic to IDHACK to &lt;tt&gt;$in&lt;/tt&gt; queries?&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;For either of these - did you by any chance try the possible code changes and measure how much time/resources would be saved by a typical query?&#160; We don&apos;t have a feel for whether that would be a measurable improvement without actually trying and benchmarking it.&lt;/p&gt;</comment>
                            <comment id="3027506" author="carl.champain" created="Mon, 6 Apr 2020 15:47:03 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=bartle&quot; class=&quot;user-hover&quot; rel=&quot;bartle&quot;&gt;bartle&lt;/a&gt;,&lt;/p&gt;

&lt;p&gt;Thank you for the report. &lt;br/&gt;
We&apos;re passing this ticket along to the appropriate team for additional investigation. Updates will be posted on this ticket as they happen.&lt;/p&gt;

&lt;p&gt;Kind regards,&lt;br/&gt;
Carl&lt;/p&gt;</comment>
                            <comment id="3025761" author="bartle" created="Fri, 3 Apr 2020 18:48:59 +0000"  >&lt;p&gt;Oh, I guess the tile is a bit inaccurate, since it&apos;d apply to simple equality (&lt;tt&gt;foo: 123&lt;/tt&gt;), explicit equality (&lt;tt&gt;foo: {$eq: 123&lt;/tt&gt;}), and &lt;tt&gt;$in&lt;/tt&gt; queries (&lt;tt&gt;foo: {$in: &lt;span class=&quot;error&quot;&gt;&amp;#91;123, 456, 789&amp;#93;&lt;/span&gt;&lt;/tt&gt;}).&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>4.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_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Mon, 6 Apr 2020 15:47:03 +0000</customfieldvalue>

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

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            3 years, 44 weeks ago
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                    <customfield id="customfield_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>asya.kamsky@mongodb.com</customfieldvalue>
            <customfieldvalue>backlog-query-optimization</customfieldvalue>
            <customfieldvalue>carl.champain@mongodb.com</customfieldvalue>
            <customfieldvalue>bartle</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hxdelz:</customfieldvalue>

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

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