Compare commits

...

1 Commits

Author SHA1 Message Date
Ruslan Abdulkhalikov
76287d314b SERVER-56932 failed optimizer error to have a specific code 2021-10-08 09:12:55 -07:00
5 changed files with 54 additions and 14 deletions

View File

@@ -0,0 +1,29 @@
// Tests that checks if optimization errors raised with a specific code
// @tags: [
// requires_fcv_51
// ]
(function() {
"use strict";
const coll = db.getCollection(jsTestName());
coll.drop();
// Forcing optimizer only failure (empty collection, $project will never execute)
assert.throwsWithCode(() => db.nonexistent.aggregate([
{$project:
{dt1:
{$map:
{
input: "$a",
as: "b",
in: {
$toDate: {
$dayOfYear: {
date: new Date("2019-04-08T11:48:29.394Z"),
timezone: "Australia/Melbourne"
}
}
}}}}}]), 5693200);
})();

View File

@@ -198,14 +198,6 @@ boost::intrusive_ptr<DocumentSourceSort> createMetadataSortForReorder(
maxMemoryUsageBytes);
}
// Optimize the section of the pipeline before the $_internalUnpackBucket stage.
void optimizePrefix(Pipeline::SourceContainer::iterator itr, Pipeline::SourceContainer* container) {
auto prefix = Pipeline::SourceContainer(container->begin(), itr);
Pipeline::optimizeContainer(&prefix);
container->erase(container->begin(), itr);
container->splice(itr, prefix);
}
// Returns whether 'field' depends on a pushed down $addFields or computed $project.
bool fieldIsComputed(BucketSpec spec, std::string field) {
return std::any_of(

View File

@@ -6463,8 +6463,12 @@ boost::intrusive_ptr<Expression> ExpressionConvert::optimize() {
// and _onNull values could still be legally folded if those values are not needed. Support for
// that case would add more complexity than it's worth, though.
if (ExpressionConstant::allNullOrConstant({_input, _to, _onError, _onNull})) {
return ExpressionConstant::create(
getExpressionContext(), evaluate(Document{}, &(getExpressionContext()->variables)));
try {
return ExpressionConstant::create(
getExpressionContext(), evaluate(Document{}, &(getExpressionContext()->variables)));
} catch (DBException& ex) {
uasserted(5693200, str::stream() << "Failed to optimize pipeline :: " + ex.reason());
}
}
return this;

View File

@@ -26,20 +26,16 @@
* exception statement from all source files in the program, then also delete
* it in the license file.
*/
#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kDefault
#include "mongo/db/pipeline/pipeline.h"
#include "mongo/logv2/log.h"
#include <algorithm>
#include "mongo/base/error_codes.h"
#include "mongo/db/bson/dotted_path_support.h"
#include "mongo/db/exec/document_value/document.h"
#include "mongo/db/jsobj.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/pipeline/accumulator.h"
#include "mongo/db/pipeline/document_source.h"
#include "mongo/db/pipeline/document_source_match.h"
#include "mongo/db/pipeline/document_source_merge.h"
@@ -50,6 +46,8 @@
#include "mongo/db/storage/storage_options.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/str.h"
#include <algorithm>
namespace mongo {
@@ -669,6 +667,18 @@ std::unique_ptr<Pipeline, PipelineDeleter> Pipeline::makePipeline(
return pipeline;
}
std::ostream& operator<<(std::ostream& os, const Pipeline& pipeline) {
vector<Value> serializedSources;
for (auto&& source : pipeline.getSources()) {
source->serializeToArray(serializedSources, explain::VerbosityEnum::kQueryPlanner);
}
for (auto stage : serializedSources) {
os << stage << " ";
}
return os;
}
Pipeline::SourceContainer::iterator Pipeline::optimizeEndOfPipeline(
Pipeline::SourceContainer::iterator itr, Pipeline::SourceContainer* container) {
// We must create a new SourceContainer representing the subsection of the pipeline we wish to

View File

@@ -449,4 +449,9 @@ private:
bool _dismissed = false;
};
/**
* Print operator useful for diagnostics
*/
std::ostream& operator<<(std::ostream& os, const Pipeline& pipeline);
} // namespace mongo