diff options
author | samontea <merciers.merciers@gmail.com> | 2021-11-16 14:54:47 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-12-14 22:02:37 +0000 |
commit | 8fb1d8039361bcbf3a0ab77127cc6712783485ca (patch) | |
tree | 2681117e701eaffd05e48ea49f4f444044a320a5 /jstests/core | |
parent | 56d055c507a94a70e31a014142934060b76710ed (diff) | |
download | mongo-8fb1d8039361bcbf3a0ab77127cc6712783485ca.tar.gz |
SERVER-60672 Simpler pushdown when timeseries collection has no mixed-schema buckets
Diffstat (limited to 'jstests/core')
-rw-r--r-- | jstests/core/timeseries/timeseries_find.js | 93 |
1 files changed, 46 insertions, 47 deletions
diff --git a/jstests/core/timeseries/timeseries_find.js b/jstests/core/timeseries/timeseries_find.js index a32264f4e17..283b951bd9f 100644 --- a/jstests/core/timeseries/timeseries_find.js +++ b/jstests/core/timeseries/timeseries_find.js @@ -8,23 +8,21 @@ * requires_timeseries, * # Required because of deficiencies in the burnin multiversion system. * requires_fcv_51, - * # Tenant migration may cause they test case to fail as it could lead to bucket splitting. - * tenant_migration_incompatible, * ] */ (function() { "use strict"; +load("jstests/libs/fixture_helpers.js"); // For FixtureHelpers.isMongos(). + const timeFieldName = "time"; /* * Creates a collection, populates it with `docs`, runs the `query` and ensures that the result set - * is equal to `results`. Also checks that the bounds at `path` formed by the min & max of the - * control values for the path `path` are equal to `bounds`. In order to do this we assert that only - * one bucket was created. + * is equal to `results`. */ -function runTest(docs, query, results, path, bounds) { +function runTest(docs, query, results) { // Setup our DB & our collections. const tsColl = db.getCollection(jsTestName()); tsColl.drop(); @@ -35,40 +33,59 @@ function runTest(docs, query, results, path, bounds) { // Construct our pipelines for later use. const pipeline = [{$match: query}, {$sort: {_id: 1}}, {$project: {_id: 0, time: 0}}]; - const controlPipeline = - [{$project: {_id: 0, value: [`$control.min.${path}`, `$control.max.${path}`]}}]; // Populate the collection with documents. docs.forEach(d => tsColl.insert(Object.assign({[timeFieldName]: new Date("2021-01-01")}, d))); // Check that the result is in the result set. assert.docEq(tsColl.aggregate(pipeline).toArray(), results); - const buckets = bucketColl.aggregate(controlPipeline).toArray(); + + // Ensure $type operator was not used. + const explain = tsColl.explain().aggregate(pipeline); + const noTypeExpression = (obj) => { + if (typeof obj === 'object' && obj != null) { + assert(!Object.keys(obj).includes("$type")); + for (const [k, v] of Object.entries(obj)) + noTypeExpression(v); + } else if (Array.isArray(obj)) { + for (const member of obj) { + noTypeExpression(obj); + } + } + }; + if (!FixtureHelpers.isMongos(db)) { + assert(Array.isArray(explain.stages), explain); + noTypeExpression(explain.stages); + } else { + if (explain.splitPipeline) { + assert(Array.isArray(explain.splitPipeline), explain); + noTypeExpression(explain.splitPipeline); + } else if (explain.stages) { + assert(Array.isArray(explain.stages), explain); + noTypeExpression(explain.stages); + } else { + const firstShardName = Object.getOwnPropertyNames(explain.shards)[0]; + const firstShard = explain.shards[firstShardName]; + assert(Array.isArray(firstShard.stages)); + noTypeExpression(firstShard.stages); + } + } } // 'a.b' is missing in the bounds even though it appears in the events. -runTest([{a: 1}, {a: {b: 3}}, {a: new Date("2021-01-01")}], - {"a.b": {$gt: 2}}, - [{a: {b: 3}}], - "a", - [1, new Date("2021-01-01")]); +runTest([{a: 1}, {a: {b: 3}}, {a: new Date("2021-01-01")}], {"a.b": {$gt: 2}}, [{a: {b: 3}}]); // 'a.b' is missing in the bounds even though it appears in the events. The bounds it is missing // in are arrays on both sides. -runTest([{a: [1]}, {a: [{b: 3}]}, {a: [new Date("2021-01-01")]}], - {"a.b": {$gt: 2}}, - [{a: [{b: 3}]}], - "a", - [[1], [new Date("2021-01-01")]]); +runTest( + [{a: [1]}, {a: [{b: 3}]}, {a: [new Date("2021-01-01")]}], {"a.b": {$gt: 2}}, [{a: [{b: 3}]}]); // 'a.b' appears in the bounds which are arrays. But it doesn't appear not in every pair of bounds. // And the relevant value of 'a.b' does not appear in the bounds despite being present in the // events. runTest([{a: [1]}, {a: [{b: 3}]}, {a: [new Date("2021-01-01"), {b: 1}]}], {"a.b": {$gt: 2}}, - [{a: [{b: 3}]}], - "a", - [[1, {b: 1}], [new Date("2021-01-01"), {b: 1}]]); + [{a: [{b: 3}]}]); // 'a.b' appears in the bounds but not the relevant side of the bounds. runTest( @@ -77,9 +94,7 @@ runTest( {a: {b: 1}}, ], {"a.b": {$lt: 2}}, - [{a: {b: 1}}], - "a", - [1, {b: 1}]); + [{a: {b: 1}}]); // We query the upper bound for 'a.b', but 'a.b' only appears in the lower bound. runTest( @@ -88,9 +103,7 @@ runTest( {a: {b: [1, 2]}}, ], {"a.b": {$gte: 3}}, - [{a: {b: 3}}], - "a.b", - [3, [1, 2]]); + [{a: {b: 3}}]); // We query the lower bound for 'a.b', but 'a.b' only appears in the upper bound. runTest( @@ -99,16 +112,12 @@ runTest( {a: {b: [1, 2]}}, ], {"a.b": {$lte: 3}}, - [{a: {b: [1, 2]}}], - "a.b", - [4, [1, 2]]); + [{a: {b: [1, 2]}}]); // 'a.b' appears in the bounds but the matching values appear in neither side of the bounds. runTest([{a: {b: 3}}, {a: {b: [1, 2]}}, {a: new Date("2021-01-01")}], {"a.b": {$eq: 2}}, - [{a: {b: [1, 2]}}], - "a", - [{b: 3}, new Date("2021-01-01")]); + [{a: {b: [1, 2]}}]); // 'a.0' doesn't appear in the bounds. runTest( @@ -120,20 +129,10 @@ runTest( {a: true} ], {"a.0": {$gte: ""}}, - [{a: ["ya", {"b": "/lc/"}, 0.9999999701976788, 0.3044235921021081]}], - "a", - [1.7881393632457332e-7, true]); + [{a: ["ya", {"b": "/lc/"}, 0.9999999701976788, 0.3044235921021081]}]); // We test arrays wrapping objects and objects wrapping arrays as different ways of achieving // multiple bounds on 'a.b'. -runTest([{a: {b: [3, 4]}}, {a: [{b: 1}, {b: 2}]}], - {"a.b": {$lt: 2}}, - [{a: [{b: 1}, {b: 2}]}], - "a", - [{b: [3, 4]}, [{b: 1}, {b: 2}]]); -runTest([{a: {b: [3, 4]}}, {a: [{b: 1}, {b: 2}]}], - {"a.b": {$gte: 3}}, - [{a: {b: [3, 4]}}], - "a", - [{b: [3, 4]}, [{b: 1}, {b: 2}]]); +runTest([{a: {b: [3, 4]}}, {a: [{b: 1}, {b: 2}]}], {"a.b": {$lt: 2}}, [{a: [{b: 1}, {b: 2}]}]); +runTest([{a: {b: [3, 4]}}, {a: [{b: 1}, {b: 2}]}], {"a.b": {$gte: 3}}, [{a: {b: [3, 4]}}]); })(); |