<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:12:22 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[DOCS-15241] [SERVER] Constant folding not commutative</title>
                <link>https://jira.mongodb.org/browse/DOCS-15241</link>
                <project id="10380" key="DOCS">Documentation</project>
                    <description>&lt;p&gt;Original title: &lt;span class=&quot;error&quot;&gt;&amp;#91;SERVER&amp;#93;&lt;/span&gt; Investigate changes in &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-63099&quot; title=&quot;Constant folding should not assume arithmetic is associative or commutative in the general case&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-63099&quot;&gt;&lt;del&gt;SERVER-63099&lt;/del&gt;&lt;/a&gt;: Constant folding should not assume arithmetic is associative or commutative in the general case&lt;/p&gt;

&lt;p&gt;------&lt;/p&gt;

    &lt;div class=&quot;panel&quot; style=&quot;background-color: #c2d2c2;border-width: 1px;&quot;&gt;&lt;div class=&quot;panelHeader&quot; style=&quot;border-bottom-width: 1px;background-color: #239eb0;&quot;&gt;&lt;b&gt;Original Downstream Change Summary&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;    Users with queries that multiply or add many constants together along with some fieldpaths in an aggregation pipeline using the $add and $multiply expressions may find that their queries become slower after &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-63099&quot; title=&quot;Constant folding should not assume arithmetic is associative or commutative in the general case&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-63099&quot;&gt;&lt;del&gt;SERVER-63099&lt;/del&gt;&lt;/a&gt; if their fieldpaths are at the beginning of the argument list. See JIRA comments on this ticket for examples. &lt;/p&gt;

&lt;p&gt;After &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-63099&quot; title=&quot;Constant folding should not assume arithmetic is associative or commutative in the general case&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-63099&quot;&gt;&lt;del&gt;SERVER-63099&lt;/del&gt;&lt;/a&gt; is merged, users will be able to speed up their queries back to pre-fix performance by moving any fieldpath references to the end of the list of arguments. For example, $multiply: &lt;span class=&quot;error&quot;&gt;&amp;#91;1, &amp;quot;$v&amp;quot;, 2, &amp;quot;$w&amp;quot;, 3, 4&amp;#93;&lt;/span&gt; can be rewritten to $multiply: &lt;span class=&quot;error&quot;&gt;&amp;#91;1, 2, 3, 4, &amp;quot;$v&amp;quot;, &amp;quot;$w&amp;quot;&amp;#93;&lt;/span&gt; to speed the query up again. &lt;/p&gt;

&lt;p&gt;The fact that addition and multiplication with these expressions is now defined to be left-to-right associative should be reflected in the documentation for $add and $multiply.&lt;/p&gt;
&lt;h2&gt;&lt;a name=&quot;DescriptionofLinkedTicket&quot;&gt;&lt;/a&gt;Description of Linked Ticket&lt;/h2&gt;
&lt;p&gt;    Currently, arithmetic aggregation expressions like &lt;a href=&quot;https://github.com/10gen/mongo/blob/f27135ef2b94b67806614cea3e72216187897e7e/src/mongo/db/pipeline/expression.h?plain=1#L2115&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;$multiply are marked as associative and commutative&lt;/a&gt; which allows the &lt;a href=&quot;https://github.com/10gen/mongo/blob/f27135ef2b94b67806614cea3e72216187897e7e/src/mongo/db/pipeline/expression.cpp?plain=1#L3645&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;constant folding optimization&lt;/a&gt; to rearrange constants to combine as many of them as possible during optimization.&lt;/p&gt;

&lt;p&gt;There are three reasons this is not a valid optimization in general:&lt;/p&gt;

&lt;p&gt;1. For integers, this is not a safe optimization due to overflow. For example, &lt;tt&gt;1073741824*-1*2 == -2147483648&lt;/tt&gt;, but &lt;tt&gt;1073741824*2*-1&lt;/tt&gt; overflows.&lt;/p&gt;

&lt;p&gt;2. Floating point arithmetic is not generally associative. See &lt;a href=&quot;https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;this paper&lt;/a&gt;, specifically:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Due to roundoff errors, the associative laws of algebra do not necessarily hold for floating-point numbers. For example, the expression (x+y)&lt;ins&gt;z has a totally different answer than x&lt;/ins&gt;(y+z) when x = 1030, y = -1030 and z = 1 (it is 1 in the former case, 0 in the latter). The importance of preserving parentheses cannot be overemphasized. &lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;3. Type coercions occur when performing an operation on multiple types. For example, &lt;tt&gt;1 + 0.5 + 2&lt;/tt&gt; will convert 1 from an integer to a float before adding it to 0.5. These type coercions are dependent on the order of operations and could change the result. See the &quot;steps to reproduce&quot; section for an example with `NumberDecimal`.&lt;/p&gt;

&lt;p&gt;Because we can&apos;t know if a fieldpath will resolve to a specific number type or a value within a specific range, we cannot rule out any kind of overflow or type coercion.&lt;/p&gt;

&lt;p&gt;So far I have only looked in to ExpressionMultiply, but ExpressionAdd and other arithmetic operations should be investigated to make sure they respect type coercions and overflow when constant folding.&lt;/p&gt;
</description>
                <environment></environment>
        <key id="2024768">DOCS-15241</key>
            <summary>[SERVER] Constant folding not commutative</summary>
                <type id="3" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14718&amp;avatarType=issuetype">Task</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="13201">Fixed</resolution>
                                        <assignee username="dave.cuthbert@mongodb.com">Dave Cuthbert</assignee>
                                    <reporter username="backlog-server-pm">Backlog - Core Eng Program Management Team</reporter>
                        <labels>
                    </labels>
                <created>Wed, 13 Apr 2022 20:23:25 +0000</created>
                <updated>Mon, 13 Nov 2023 17:42:42 +0000</updated>
                            <resolved>Wed, 8 Feb 2023 17:31:57 +0000</resolved>
                                                    <fixVersion>6.1.0-rc0</fixVersion>
                    <fixVersion>Server_Docs_20231030</fixVersion>
                    <fixVersion>Server_Docs_20231106</fixVersion>
                    <fixVersion>Server_Docs_20231105</fixVersion>
                    <fixVersion>Server_Docs_20231113</fixVersion>
                                    <component>manual</component>
                    <component>Server</component>
                        <due></due>
                            <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="4670505" author="edu.bot" created="Mon, 11 Jul 2022 14:19:55 +0000"  >&lt;p&gt;&lt;em&gt;Fix Version updated for upstream &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-63099&quot; title=&quot;Constant folding should not assume arithmetic is associative or commutative in the general case&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-63099&quot;&gt;&lt;del&gt;SERVER-63099&lt;/del&gt;&lt;/a&gt;:&lt;/em&gt; &lt;br/&gt;
6.1.0-rc0&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10320">
                    <name>Documented</name>
                                            <outwardlinks description="documents">
                                        <issuelink>
            <issuekey id="1973256">SERVER-63099</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_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Mon, 11 Jul 2022 14:19:55 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        1 year, 30 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_17052" key="com.atlassian.jira.plugin.system.customfieldtypes:textarea">
                        <customfieldname>Downstream Changes Summary</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Users with queries that multiply or add many constants together along with some fieldpaths in an aggregation pipeline using the $add and $multiply expressions may find that their queries become slower after &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-63099&quot; title=&quot;Constant folding should not assume arithmetic is associative or commutative in the general case&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-63099&quot;&gt;&lt;strike&gt;SERVER-63099&lt;/strike&gt;&lt;/a&gt; if their fieldpaths are at the beginning of the argument list. See JIRA comments on this ticket for examples. &lt;br/&gt;
&lt;br/&gt;
After &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-63099&quot; title=&quot;Constant folding should not assume arithmetic is associative or commutative in the general case&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-63099&quot;&gt;&lt;strike&gt;SERVER-63099&lt;/strike&gt;&lt;/a&gt; is merged, users will be able to speed up their queries back to pre-fix performance by moving any fieldpath references to the end of the list of arguments. For example, $multiply: [1, &amp;quot;$v&amp;quot;, 2, &amp;quot;$w&amp;quot;, 3, 4] can be rewritten to $multiply: [1, 2, 3, 4, &amp;quot;$v&amp;quot;, &amp;quot;$w&amp;quot;] to speed the query up again. &lt;br/&gt;
&lt;br/&gt;
The fact that addition and multiplication with these expressions is now defined to be left-to-right associative should be reflected in the documentation for $add and $multiply.</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                        <customfield id="customfield_10857" key="com.pyxis.greenhopper.jira:gh-epic-link">
                        <customfieldname>Epic Link</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>DOCSP-11701</customfieldvalue>
                        </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>emet.ozar@mongodb.com</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            1 year, 30 weeks, 2 days ago
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                            <customfield id="customfield_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>backlog-server-pm</customfieldvalue>
            <customfieldvalue>dave.cuthbert@mongodb.com</customfieldvalue>
            <customfieldvalue>edu.bot</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|i0r5gn:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|i0a420:</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_10557" key="com.pyxis.greenhopper.jira:gh-sprint">
                        <customfieldname>Sprint</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue id="6124">ServerDocs2022: Apr26 - May3</customfieldvalue>
    <customfieldvalue id="6127">ServerDocs2022: Jun1 - Jun14</customfieldvalue>
    <customfieldvalue id="6128">ServerDocs2022: Jun14 - Jun28</customfieldvalue>
    <customfieldvalue id="6226">ServerDocs2022: May3-May10</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_14350" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>serverRank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|i0qrlz:</customfieldvalue>

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