Operational Defect Database

BugZero found this defect 73 days ago.

MongoDB | 2602255

Query shape for $documents is unique on each execution

Last update date:

3/14/2024

Affected products:

MongoDB Server

Affected releases:

No affected releases provided.

Fixed releases:

No fixed releases provided.

Description:

Info

When running an aggregation with a $documents stage, the query shape comes from a rewritten query that is unique each time the query runs. The pipeline in the query shape looks like this, with different UUIDs each time the query runs: { "$queue" : "?array" }, { "$project" : { "_id" : true, "03e7f159-305d-4009-9eb8-37f849cb26cb" : "?array" } }, { "$unwind" : { "path" : "$03e7f159-305d-4009-9eb8-37f849cb26cb" } }, { "$replaceRoot" : { "newRoot" : "$03e7f159-305d-4009-9eb8-37f849cb26cb" } } The script below runs such a query twice (run with ./mongo --nodb example.js or using resmoke.py). After running it, search in the output for Query Stats: and notice that there are two entries with distinct query shapes. const options = {setParameter: {internalQueryStatsRateLimit: -1}}; const conn = MongoRunner.runMongod(options); const testDB = conn.getDB("test"); const coll = testDB.coll; assert.commandWorked(coll.insert([{v: 1, y: -3}, {v: 2, y: -2}])); { const pipeline = [ {$documents: [{v:1}, {v:2}]}, {$lookup: { from: coll.getName(), as: "lookedUp", localField: "v", foreignField: "v"} }, ]; const cmd = { aggregate: 1, pipeline: pipeline, cursor: {}, }; // Run twice to see if the query shape differs each time assert.commandWorked(testDB.runCommand(cmd)); assert.commandWorked(testDB.runCommand(cmd)); const result = conn.adminCommand({ aggregate: 1, pipeline: [ {$queryStats: {}}, {$sort: {key: 1}}, {$match: {"key.client.application.name": "MongoDB Shell"}} ], cursor: {} }); assert.commandWorked(result); print("Query Stats: " + tojson(result.cursor.firstBatch)); } MongoRunner.stopMongod(conn);

Top User Comments


Steps to Reproduce


Additional Resources / Links

Share:

BugZero® Risk Score

What's this?

Coming soon

Status

Open

Learn More

Search:

...