From f12dc69aa63e58fab88222f182b8921e90f4921b Mon Sep 17 00:00:00 2001 From: henrinikku Date: Fri, 27 Oct 2023 10:53:10 +0000 Subject: [PATCH] Add benchmarks for single predicate collscan shortcut --- testcases/simple_query.js | 84 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/testcases/simple_query.js b/testcases/simple_query.js index c1936288..5d1cf8f2 100644 --- a/testcases/simple_query.js +++ b/testcases/simple_query.js @@ -55,6 +55,90 @@ if (typeof(tests) !== "object") { op: {op: "find", query: {nonexistent: 5}} }); + /** + * Setup: Create a large collection of large documents. + * + * Test: Query for a document that doesn't exist. Scans all documents using a collection scan + * and returns no documents. + */ + for (const [n, title] of [[10000, "10K"], [100000, "100K"]]) { + addQueryTestCase({ + name: "NoMatchLarge" + title, + tags: ["regression"], + nDocs: n, + docs: largeDoc, + op: {op: "find", query: {nonexistent: 5}} + }); + } + + /** + * Setup: Create a collection of documents with ObjectID '_id' and 'a' fields. + * + * Test: Query with an equality predicate matches returns every other document. Scans all documents using a collection scan. + */ + for (const [n, title] of [[100, "100"], [10000, "10K"], [100000, "100K"]]) { + addQueryTestCase({ + name: "HalfMatchEqInt" + title, + tags: ["regression"], + nDocs: n, + docs: function(i) { + return {a: i % 2}; + }, + op: {op: "find", query: {a: 0}} + }); + } + + /** + * Setup: Create a collection of documents with ObjectID '_id' and 'a' fields. + * + * Test: Query with a $lt predicate that matches every other document. Scans all documents using a collection scan. + */ + for (const [n, title] of [[100, "100"], [10000, "10K"], [100000, "100K"]]) { + addQueryTestCase({ + name: "HalfMatchLtInt" + title, + tags: ["regression"], + nDocs: n, + docs: function(i) { + return {a: i % 2}; + }, + op: {op: "find", query: {a: {$lt: 1}}} + }); + } + + /** + * Setup: Create a collection of documents with ObjectID '_id' and 'a' fields. + * + * Test: Query with an equality predicate that matches every other document. Scans all documents using a collection scan. + */ + for (const [n, title] of [[100, "100"], [10000, "10K"], [100000, "100K"]]) { + addQueryTestCase({ + name: "HalfMatchEqNaN" + title, + tags: ["regression"], + nDocs: n, + docs: function(i) { + return {a: (i % 2 == 0 ? NaN : 0)}; + }, + op: {op: "find", query: {a: NaN}} + }); + } + + /** + * Setup: Create a collection of documents with ObjectID '_id' and 'a' fields. + * + * Test: Query with a $lt predicate that matches every other document. Scans all documents using a collection scan. + */ + for (const [n, title] of [[100, "100"], [10000, "10K"], [100000, "100K"]]) { + addQueryTestCase({ + name: "HalfMatchLteNaN" + title, + tags: ["regression"], + nDocs: n, + docs: function(i) { + return {a: (i % 2 == 0 ? NaN : 0)}; + }, + op: {op: "find", query: {a: {$lte: NaN}}} + }); + } + /** * Setup: Create a collection of documents with only an integer _id field. *