(function() {
|
"use strict";
|
|
load("./measure-time.js");
|
|
load("jstests/libs/sbe_util.js"); // For "checkSBEEnabled.""
|
|
const REPEAT = 5;
|
const MEASURE_PERF = false;
|
|
const columnstoreEnabled =
|
checkSBEEnabled(db, ["featureFlagColumnstoreIndexes", "featureFlagSbeFull"]);
|
if (!columnstoreEnabled) {
|
jsTestLog("Columnstore index is NOT active.");
|
return;
|
} else {
|
jsTestLog("Columnstore index is active.");
|
}
|
|
let currIndexes = db.order_lineitem.getIndexes()
|
assert.eq(currIndexes.length, 2);
|
assert(currIndexes[0].name == "_id_" || currIndexes[1].name == "_id_");
|
assert(currIndexes[0].name == "$**_columnstore" || currIndexes[1].name == "$**_columnstore");
|
|
const queries = {
|
"ssb.Q2.2": {
|
"pipeline": [
|
{
|
$match: {
|
'part.p_brand':
|
{$in: ['Brand#21', 'Brand#22', 'Brand#15', 'Brand#41', 'Brand#41']}
|
}
|
},
|
{
|
$lookup: {
|
from: 'supplier',
|
localField: 'l_suppkey',
|
foreignField: 's_suppkey',
|
'as': 'supplier'
|
}
|
},
|
{$match: {'supplier.nation.region.r_name': 'ASIA'}},
|
{$addFields: {supplier: {$first: '$supplier'}}},
|
{
|
$group: {
|
_id: {order_year: {$year: '$order.o_orderdate'}, brand: '$part.p_brand'},
|
revenue: {$sum: {$multiply: ['$l_extendedprice', '$l_discount']}}
|
}
|
}
|
]
|
},
|
"ssb.Q4.1": {
|
"pipeline": [
|
{$match: {'part.p_mfgr': {$in: ['Manufacturer#1', 'Manufacturer#2']}}},
|
{
|
$lookup: {
|
from: 'supplier',
|
localField: 'l_suppkey',
|
foreignField: 's_suppkey',
|
'as': 'supplier'
|
}
|
},
|
{$addFields: {supplier: {$first: '$supplier'}}},
|
{$match: {'supplier.nation.region.r_name': 'AMERICA'}},
|
{
|
$lookup: {
|
from: 'customer',
|
localField: 'order.o_custkey',
|
foreignField: 'c_custkey',
|
'as': 'customer'
|
}
|
},
|
{$addFields: {customer: {$first: '$customer'}}},
|
{$match: {'customer.nation.region.r_name': 'AMERICA'}},
|
{
|
$group: {
|
_id: {
|
order_year: {$year: '$order.o_orderdate'},
|
c_nation: '$customer.nation.n_name'
|
},
|
revenue: {
|
$sum: {
|
$subtract: [
|
'$l_extendedprice',
|
{$multiply: ['$l_extendedprice', '$l_discount']}
|
]
|
}
|
}
|
}
|
},
|
{$addFields: {order_year: '$_id.order_year', customer_nation: '$_id.c_nation'}}
|
]
|
},
|
};
|
|
for (const [qName, qAgg] of Object.entries(queries)) {
|
print("--------------------------------------------------------------------------------------");
|
jsTestLog(`Handling ${qName}:`);
|
print(`${qName}.pipeline:`)
|
printjson(qAgg.pipeline)
|
if (qAgg.options) {
|
print(`${qName}.options:`)
|
printjson(qAgg.options)
|
}
|
let explain = qAgg.options ? db.order_lineitem.explain().aggregate(qAgg.pipeline, qAgg.options)
|
: db.order_lineitem.explain().aggregate(qAgg.pipeline);
|
print(`${qName} uses COLUMN_SCAN? ` + JSON.stringify(explain).includes('COLUMN_SCAN'));
|
printjson(explain);
|
if (MEASURE_PERF) {
|
let durations = [];
|
for (let i = 0; i < REPEAT; ++i) {
|
jsTestLog(`${qName} iteration ${i}`);
|
const dur = qAgg.options
|
? measureTime(() => db.order_lineitem.aggregate(qAgg.pipeline, qAgg.options))
|
: measureTime(() => db.order_lineitem.aggregate(qAgg.pipeline));
|
jsTestLog(`${qName} took ${dur}ms`);
|
durations.push(dur);
|
}
|
jsTestLog(`experiment,${qName},${durations}`);
|
}
|
}
|
})();
|