Files
mongo/jstests/core/profile_delete.js
Charlie Swanson 298fc23192 SERVER-63947 Add column store jscore passthrough - plus fixes
Also fixes:
- $where reports depending on a full object, disqualifying it from using
  the column store index.
- projection analysis should not remove a projection if we have some
  match fields that are not needed in the output. This doesn't work yet.
2022-07-27 16:29:59 +00:00

112 lines
3.6 KiB
JavaScript

// @tags: [
// # Asserts on the number of index keys deleted.
// assumes_no_implicit_index_creation,
// does_not_support_stepdowns,
// requires_non_retryable_writes,
// requires_profiling,
// ]
// Confirms that profiled delete execution contains all expected metrics with proper values.
(function() {
"use strict";
load("jstests/libs/clustered_collections/clustered_collection_util.js");
load("jstests/libs/profiler.js"); // For getLatestProfilerEntry.
// Setup test db and collection.
var testDB = db.getSiblingDB("profile_delete");
assert.commandWorked(testDB.dropDatabase());
var coll = testDB.getCollection("test");
testDB.setProfilingLevel(2);
//
// Confirm metrics for single document delete.
//
var i;
for (i = 0; i < 10; ++i) {
assert.commandWorked(coll.insert({a: i, b: i}));
}
assert.commandWorked(coll.createIndex({a: 1}));
assert.commandWorked(
coll.remove({a: {$gte: 2}, b: {$gte: 2}}, {justOne: true, collation: {locale: "fr"}}));
var profileObj = getLatestProfilerEntry(testDB);
const collectionIsClustered = ClusteredCollectionUtil.areAllCollectionsClustered(db.getMongo());
// A clustered collection has no actual index on _id.
let expectedKeysDeleted = collectionIsClustered ? 1 : 2;
assert.eq(profileObj.ns, coll.getFullName(), tojson(profileObj));
assert.eq(profileObj.op, "remove", tojson(profileObj));
assert.eq(profileObj.command.collation, {locale: "fr"}, tojson(profileObj));
assert.eq(profileObj.ndeleted, 1, tojson(profileObj));
assert.eq(profileObj.keysExamined, 1, tojson(profileObj));
assert.eq(profileObj.docsExamined, 1, tojson(profileObj));
assert.eq(profileObj.keysDeleted, expectedKeysDeleted, tojson(profileObj));
assert.eq(profileObj.planSummary, "IXSCAN { a: 1 }", tojson(profileObj));
assert(profileObj.execStats.hasOwnProperty("stage"), tojson(profileObj));
assert(profileObj.hasOwnProperty("millis"), tojson(profileObj));
assert(profileObj.hasOwnProperty("numYield"), tojson(profileObj));
assert(profileObj.hasOwnProperty("locks"), tojson(profileObj));
assert.eq(profileObj.appName, "MongoDB Shell", tojson(profileObj));
//
// Confirm metrics for multiple document delete.
//
coll.drop();
for (i = 0; i < 10; ++i) {
assert.commandWorked(coll.insert({a: i}));
}
assert.commandWorked(coll.remove({a: {$gte: 2}}));
profileObj = getLatestProfilerEntry(testDB);
// A clustered collection has no actual index on _id.
expectedKeysDeleted = collectionIsClustered ? 0 : 8;
assert.eq(profileObj.ndeleted, 8, tojson(profileObj));
assert.eq(profileObj.keysDeleted, expectedKeysDeleted, tojson(profileObj));
assert.eq(profileObj.appName, "MongoDB Shell", tojson(profileObj));
//
// Confirm "fromMultiPlanner" metric.
//
coll.drop();
assert.commandWorked(coll.createIndex({a: 1}));
assert.commandWorked(coll.createIndex({b: 1}));
for (i = 0; i < 5; ++i) {
assert.commandWorked(coll.insert({a: i, b: i}));
}
assert.commandWorked(coll.remove({a: 3, b: 3}));
profileObj = getLatestProfilerEntry(testDB);
assert.eq(profileObj.fromMultiPlanner, true, tojson(profileObj));
assert.eq(profileObj.appName, "MongoDB Shell", tojson(profileObj));
//
// Confirm killing a remove operation will not log 'ndeleted' to the profiler.
//
assert(coll.drop());
for (let i = 0; i < 100; ++i) {
assert.commandWorked(coll.insert({a: 1}));
}
const deleteResult = testDB.runCommand({
delete: coll.getName(),
deletes: [{q: {$where: "sleep(1000);return true", a: 1}, limit: 0}],
maxTimeMS: 1
});
// This command will time out before completing.
assert.commandFailedWithCode(deleteResult, ErrorCodes.MaxTimeMSExpired);
profileObj = getLatestProfilerEntry(testDB);
// 'ndeleted' should not be defined.
assert(!profileObj.hasOwnProperty("ndeleted"), profileObj);
})();