0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-27 15:06:34 +01:00
mongodb/jstests/sharding/clustered_coll_scan.js
auto-revert-app[bot] 8dabd67451 Revert "SERVER-92880 Tag more jstests as owned by query (#29090)" (#29523)
GitOrigin-RevId: d5a1fb056144efac5baf4b3c0b4166ac3bc7944e
2024-11-23 09:10:19 +00:00

51 lines
1.6 KiB
JavaScript

/*
* Testing if mongos can deal with clustered collections and the related clustered IDX scan bounds
* (SERVER-83119)
*/
import {assertDropAndRecreateCollection} from "jstests/libs/collection_drop_recreate.js";
import {isClusteredIxscan, isExpress} from "jstests/libs/query/analyze_plan.js";
import {ShardingTest} from "jstests/libs/shardingtest.js";
const st = new ShardingTest({
shards: 2,
mongos: 1,
});
st.s.adminCommand({enableSharding: "test"});
const db = st.getDB("test");
// Create the collection as a clustered collection.
const coll = assertDropAndRecreateCollection(
db, jsTestName(), {clusteredIndex: {key: {_id: 1}, unique: true}});
st.shardColl(coll, {a: 1});
// First of all check that we can execute the query.
assert.commandWorked(coll.insertMany([...Array(10).keys()].map(i => {
return {_id: i, a: i};
})));
{
var explain = coll.find({_id: 2}).explain();
// Make sure that we have Express in the plan.
assert(isExpress(db, explain));
// Make sure that we have a clustered ixscan if Express is ineligible.
var explain = coll.find({_id: 2}, {"foo.bar": 3}).explain();
assert(isClusteredIxscan(db, explain));
assert.commandWorked(
st.getPrimaryShard("test").adminCommand({setParameter: 1, notablescan: 1}));
// Do the same thing only with notablescan enabled.
explain = coll.find({_id: 2}).explain();
assert(isExpress(db, explain));
// Sanity count check.
assert.eq(1, coll.find({_id: 2}).itcount());
}
// Test the same with aggregate.
{
var explain = coll.explain().aggregate([{$match: {_id: 22}}]);
assert(isExpress(db, explain));
}
st.stop();