Query for update command shape cannot be canonicalized and optimized

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Duplicate
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Integration
    • ALL
    • Hide

      Add these 2 lines in jstests/noPassthrough/query/queryStats/query_stats_update_key.js

          testDB.runCommand({
              update: coll.getName(),
              updates: [{
                  q: {$or: [{_id: 1.0}, {_id: 1.0}]},
                  u: {foo: "bar"},
              }]
          });
          testDB.adminCommand({aggregate: 1, pipeline: [{"$queryStats": {}}], cursor: {}});
      

      To run the test:

      buildscripts/resmoke.py run --suite no_passthrough --runAllFeatureFlagTests jstests/noPassthrough/query/queryStats/query_stats_update_key.js
      
      Show
      Add these 2 lines in jstests/noPassthrough/query/queryStats/query_stats_update_key.js testDB.runCommand({ update: coll.getName(), updates: [{ q: {$or: [{_id: 1.0}, {_id: 1.0}]}, u: {foo: "bar" }, }] }); testDB.adminCommand({aggregate: 1, pipeline: [{ "$queryStats" : {}}], cursor: {}}); To run the test: buildscripts/resmoke.py run --suite no_passthrough --runAllFeatureFlagTests jstests/noPassthrough/query/queryStats/query_stats_update_key.js
    • 200
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Currently, we use the canonical query from ParsedUpdate to serialize the q with serialization options. However, the match expression (`CanonicalQuery::getPrimaryMatchExpression()`) has been optimized. That leads to problem with parsing. For example:

      • Given a query: {$or: [{_id: 1}, \{_id: 1}]}
      • In ParsedUpdate, it is optimized to {_id: 1}
      • When its debugging format is requests by $queryStats, the optimized query {_id: 1} will not be parsed by ParsedUpdate because ParsedUpdate recognizes it as IDHACK.

      In general, we should not shapify using an optimized match expression. So we should seek solution to obtain an unoptimized match expression when shapifying an update.

      How does find obtain an unoptimized query?

      We could refer to find command shapes to see how it avoid this issue. The steps it takes to shapify a find:

      1. Construct a ParsedFindCommand. This contains an unoptimized MatchExpression.
      2. Use this MatchExpression to shapifying FindCmdShape.
      3. Then, it std::move(ParsedFindCommand) to the constructor of CanonicalQuery
      4. Eventually, the CanonicalQuery takes the ownership of that and generates an optimized MatchExpression. (i.e. an unoptimized MatchExpression no longer exists beyond this point)

      We may follow the approach to break down the parsing of update commands into similar steps such that we can obtain an unoptimized query when registering an request.

            Assignee:
            Chi-I Huang
            Reporter:
            Chi-I Huang
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: