Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

small optimization to avoid recompilation #3398

Merged
merged 3 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/graph/optimizer/rule/CollapseProjectRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "graph/optimizer/OptGroup.h"
#include "graph/planner/plan/PlanNode.h"
#include "graph/planner/plan/Query.h"
#include "graph/util/ExpressionUtils.h"

using nebula::graph::PlanNode;
using nebula::graph::QueryContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "graph/optimizer/OptimizerUtils.h"
#include "graph/planner/plan/PlanNode.h"
#include "graph/planner/plan/Scan.h"
#include "graph/util/ExpressionUtils.h"

using nebula::Expression;
using nebula::graph::EdgeIndexFullScan;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "graph/optimizer/rule/IndexScanRule.h"
#include "graph/planner/plan/PlanNode.h"
#include "graph/planner/plan/Scan.h"
#include "graph/util/ExpressionUtils.h"

using nebula::graph::Filter;
using nebula::graph::OptimizerUtils;
Expand Down
1 change: 1 addition & 0 deletions src/graph/optimizer/rule/PushLimitDownGetNeighborsRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "graph/optimizer/OptGroup.h"
#include "graph/planner/plan/PlanNode.h"
#include "graph/planner/plan/Query.h"
#include "graph/util/ExpressionUtils.h"

using nebula::graph::GetNeighbors;
using nebula::graph::Limit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "graph/optimizer/OptGroup.h"
#include "graph/planner/plan/PlanNode.h"
#include "graph/planner/plan/Query.h"
#include "graph/util/ExpressionUtils.h"

using nebula::graph::GetNeighbors;
using nebula::graph::Limit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "graph/optimizer/OptGroup.h"
#include "graph/planner/plan/PlanNode.h"
#include "graph/planner/plan/Query.h"
#include "graph/util/ExpressionUtils.h"

using nebula::graph::GetNeighbors;
using nebula::graph::PlanNode;
Expand Down
26 changes: 26 additions & 0 deletions src/graph/planner/plan/Query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@
#include <folly/json.h>
#include <thrift/lib/cpp/util/EnumUtils.h>

#include "graph/util/ExpressionUtils.h"
#include "graph/util/ToJson.h"

using folly::stringPrintf;

namespace nebula {
namespace graph {

int64_t Explore::limit() const {
QueryExpressionContext ctx;
DCHECK(ExpressionUtils::isEvaluableExpr(limit_));
return DCHECK_NOTNULL(limit_)->eval(ctx).getInt();
}
std::unique_ptr<PlanNodeDescription> Explore::explain() const {
auto desc = SingleInputNode::explain();
addDescription("space", folly::to<std::string>(space_), desc.get());
Expand Down Expand Up @@ -318,6 +324,17 @@ void Sort::cloneMembers(const Sort& p) {
factors_ = std::move(factors);
}

// Get constant count value
int64_t Limit::count() const {
if (count_ == nullptr) {
return -1;
}
DCHECK(ExpressionUtils::isEvaluableExpr(count_));
QueryExpressionContext ctx;
auto s = count_->eval(ctx).getInt();
DCHECK_GE(s, 0);
return s;
}
std::unique_ptr<PlanNodeDescription> Limit::explain() const {
auto desc = SingleInputNode::explain();
addDescription("offset", folly::to<std::string>(offset_), desc.get());
Expand Down Expand Up @@ -364,6 +381,15 @@ void TopN::cloneMembers(const TopN& l) {
count_ = l.count_;
}

// Get constant count
int64_t Sample::count() const {
DCHECK(ExpressionUtils::isEvaluableExpr(count_));
QueryExpressionContext qec;
auto count = count_->eval(qec).getInt();
DCHECK_GE(count, 0);
return count;
}

std::unique_ptr<PlanNodeDescription> Sample::explain() const {
auto desc = SingleInputNode::explain();
addDescription("count", count_->toString(), desc.get());
Expand Down
26 changes: 3 additions & 23 deletions src/graph/planner/plan/Query.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ class Explore : public SingleInputNode {
bool dedup() const { return dedup_; }

// Get the constant limit value
int64_t limit() const {
QueryExpressionContext ctx;
DCHECK(ExpressionUtils::isEvaluableExpr(limit_));
return DCHECK_NOTNULL(limit_)->eval(ctx).getInt();
}
int64_t limit() const;

// Get the limit value in runtime
int64_t limit(QueryExpressionContext& ctx) const {
Expand Down Expand Up @@ -682,17 +678,7 @@ class Limit final : public SingleInputNode {
int64_t offset() const { return offset_; }

// Get constant count value
int64_t count() const {
if (count_ == nullptr) {
return -1;
}
DCHECK(ExpressionUtils::isEvaluableExpr(count_));
QueryExpressionContext ctx;
auto s = count_->eval(ctx).getInt();
DCHECK_GE(s, 0);
return s;
}

int64_t count() const;
// Get count in runtime
int64_t count(QueryExpressionContext& ctx) const {
if (count_ == nullptr) {
Expand Down Expand Up @@ -801,13 +787,7 @@ class Sample final : public SingleInputNode {
}

// Get constant count
int64_t count() const {
DCHECK(ExpressionUtils::isEvaluableExpr(count_));
QueryExpressionContext qec;
auto count = count_->eval(qec).getInt();
DCHECK_GE(count, 0);
return count;
}
int64_t count() const;

// Get Runtime count
int64_t count(QueryExpressionContext& qec) const {
Expand Down
1 change: 1 addition & 0 deletions src/graph/util/FTIndexUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "graph/util/FTIndexUtils.h"

#include "common/expression/Expression.h"
#include "graph/util/ExpressionUtils.h"

DECLARE_uint32(ft_request_retry_times);

Expand Down
1 change: 0 additions & 1 deletion src/graph/util/FTIndexUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "clients/meta/MetaClient.h"
#include "common/base/StatusOr.h"
#include "common/plugin/fulltext/elasticsearch/ESGraphAdapter.h"
#include "graph/util/ExpressionUtils.h"
#include "graph/util/SchemaUtil.h"
#include "parser/MaintainSentences.h"

Expand Down
1 change: 1 addition & 0 deletions src/graph/validator/FindPathValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "graph/planner/plan/Algo.h"
#include "graph/planner/plan/Logic.h"
#include "graph/util/ExpressionUtils.h"
#include "graph/util/ValidateUtil.h"

namespace nebula {
Expand Down
1 change: 1 addition & 0 deletions src/graph/validator/MutateValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "common/expression/LabelAttributeExpression.h"
#include "graph/planner/plan/Mutate.h"
#include "graph/planner/plan/Query.h"
#include "graph/util/ExpressionUtils.h"
#include "graph/util/SchemaUtil.h"
#include "graph/visitor/RewriteSymExprVisitor.h"

Expand Down
2 changes: 2 additions & 0 deletions src/graph/visitor/VidExtractVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include "graph/visitor/VidExtractVisitor.h"

#include "graph/util/ExpressionUtils.h"

namespace nebula {
namespace graph {

Expand Down
4 changes: 1 addition & 3 deletions src/mock/MockCluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ class MockCluster {

void startMeta(const std::string& rootPath, HostAddr addr = HostAddr("127.0.0.1", 0));

void startStorage(HostAddr addr,
const std::string& rootPath,
SchemaVer schemaVerCount = 1);
void startStorage(HostAddr addr, const std::string& rootPath, SchemaVer schemaVerCount = 1);

/**
* Init a meta client connect to current meta server.
Expand Down
11 changes: 11 additions & 0 deletions src/parser/Clauses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,19 @@

#include "parser/Clauses.h"

#include "graph/util/ExpressionUtils.h"

namespace nebula {

bool YieldColumns::hasAgg() const {
for (auto &col : columns_) {
if (graph::ExpressionUtils::findAny(col->expr(), {Expression::Kind::kAggregate})) {
return true;
}
}
return false;
}

std::string StepClause::toString() const {
std::string buf;
buf.reserve(256);
Expand Down
10 changes: 1 addition & 9 deletions src/parser/Clauses.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include "common/base/Base.h"
#include "common/expression/Expression.h"
#include "graph/util/ExpressionUtils.h"
#include "interface/gen-cpp2/storage_types.h"

namespace nebula {
Expand Down Expand Up @@ -275,14 +274,7 @@ class YieldColumns final {

YieldColumn *back() { return columns_.back().get(); }

bool hasAgg() const {
for (auto &col : columns_) {
if (graph::ExpressionUtils::findAny(col->expr(), {Expression::Kind::kAggregate})) {
return true;
}
}
return false;
}
bool hasAgg() const;

private:
std::vector<std::unique_ptr<YieldColumn>> columns_;
Expand Down