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

Avoid the extra expression encode decode. #2757

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 6 additions & 6 deletions src/clients/storage/GraphStorageClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ folly::SemiFuture<StorageRpcResponse<cpp2::GetNeighborsResponse>> GraphStorageCl
bool random,
const std::vector<cpp2::OrderBy>& orderBy,
int64_t limit,
std::string filter,
const Expression* filter,
folly::EventBase* evb) {
auto cbStatus = getIdFromRow(space, false);
if (!cbStatus.ok()) {
Expand Down Expand Up @@ -69,8 +69,8 @@ folly::SemiFuture<StorageRpcResponse<cpp2::GetNeighborsResponse>> GraphStorageCl
spec.set_order_by(orderBy);
}
spec.set_limit(limit);
if (filter.size() > 0) {
spec.set_filter(filter);
if (filter != nullptr) {
spec.set_filter(filter->encode());
}
req.set_traverse_spec(std::move(spec));
}
Expand Down Expand Up @@ -167,7 +167,7 @@ folly::SemiFuture<StorageRpcResponse<cpp2::GetPropResponse>> GraphStorageClient:
bool dedup,
const std::vector<cpp2::OrderBy>& orderBy,
int64_t limit,
std::string filter,
const Expression* filter,
folly::EventBase* evb) {
auto cbStatus = getIdFromRow(space, edgeProps != nullptr);
if (!cbStatus.ok()) {
Expand Down Expand Up @@ -202,8 +202,8 @@ folly::SemiFuture<StorageRpcResponse<cpp2::GetPropResponse>> GraphStorageClient:
req.set_order_by(orderBy);
}
req.set_limit(limit);
if (filter.size() > 0) {
req.set_filter(filter);
if (filter != nullptr) {
req.set_filter(filter->encode());
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/clients/storage/GraphStorageClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class GraphStorageClient : public StorageClientBase<cpp2::GraphStorageServiceAsy
bool random = false,
const std::vector<cpp2::OrderBy>& orderBy = std::vector<cpp2::OrderBy>(),
int64_t limit = std::numeric_limits<int64_t>::max(),
std::string filter = std::string(),
const Expression* filter = nullptr,
folly::EventBase* evb = nullptr);

folly::SemiFuture<StorageRpcResponse<cpp2::GetPropResponse>> getProps(
Expand All @@ -59,7 +59,7 @@ class GraphStorageClient : public StorageClientBase<cpp2::GraphStorageServiceAsy
bool dedup = false,
const std::vector<cpp2::OrderBy>& orderBy = std::vector<cpp2::OrderBy>(),
int64_t limit = std::numeric_limits<int64_t>::max(),
std::string filter = std::string(),
const Expression* filter = nullptr,
folly::EventBase* evb = nullptr);

folly::SemiFuture<StorageRpcResponse<cpp2::ExecResponse>> addVertices(
Expand Down
2 changes: 1 addition & 1 deletion src/graph/optimizer/OptimizerUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ void OptimizerUtils::copyIndexScanData(const nebula::graph::IndexScan* from,
to->setDedup(from->dedup());
to->setOrderBy(from->orderBy());
to->setLimit(from->limit());
to->setFilter(from->filter());
to->setFilter(from->filter() == nullptr ? nullptr : from->filter()->clone());
}

} // namespace graph
Expand Down
9 changes: 4 additions & 5 deletions src/graph/optimizer/rule/PushFilterDownGetNbrsRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,10 @@ StatusOr<OptRule::TransformResult> PushFilterDownGetNbrsRule::transform(
newFilterGroupNode = OptGroupNode::create(ctx, newFilter, filterGroupNode->group());
}

auto newGNFilter = condition->encode();
if (!gn->filter().empty()) {
auto filterExpr = Expression::decode(pool, gn->filter());
auto logicExpr = LogicalExpression::makeAnd(pool, condition, filterExpr);
newGNFilter = logicExpr->encode();
auto newGNFilter = condition;
if (gn->filter() != nullptr) {
auto logicExpr = LogicalExpression::makeAnd(pool, condition, gn->filter()->clone());
newGNFilter = logicExpr;
}

auto newGN = static_cast<GetNeighbors *>(gn->clone());
Expand Down
3 changes: 1 addition & 2 deletions src/graph/planner/plan/Query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ std::unique_ptr<PlanNodeDescription> Explore::explain() const {
addDescription("space", folly::to<std::string>(space_), desc.get());
addDescription("dedup", util::toJson(dedup_), desc.get());
addDescription("limit", folly::to<std::string>(limit_), desc.get());
auto filter =
filter_.empty() ? filter_ : Expression::decode(qctx_->objPool(), filter_)->toString();
std::string filter = filter_ == nullptr ? "" : filter_->toString();
addDescription("filter", filter, desc.get());
addDescription("orderBy", folly::toJson(util::toJson(orderBy_)), desc.get());
return desc;
Expand Down
54 changes: 21 additions & 33 deletions src/graph/planner/plan/Query.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,17 @@ class Explore : public SingleInputNode {

int64_t limit() const { return limit_; }

const std::string& filter() const { return filter_; }
const Expression* filter() const { return filter_; }

Expression* filter() { return filter_; }

const std::vector<storage::cpp2::OrderBy>& orderBy() const { return orderBy_; }

void setDedup(bool dedup = true) { dedup_ = dedup; }

void setLimit(int64_t limit) { limit_ = limit; }

void setFilter(std::string filter) { filter_ = std::move(filter); }
void setFilter(Expression* filter) { filter_ = filter; }

void setOrderBy(std::vector<storage::cpp2::OrderBy> orderBy) { orderBy_ = std::move(orderBy); }

Expand All @@ -58,13 +60,13 @@ class Explore : public SingleInputNode {
GraphSpaceID space,
bool dedup,
int64_t limit,
std::string filter,
Expression* filter,
std::vector<storage::cpp2::OrderBy> orderBy)
: SingleInputNode(qctx, kind, input),
space_(space),
dedup_(dedup),
limit_(limit),
filter_(std::move(filter)),
filter_(filter),
orderBy_(std::move(orderBy)) {}

Explore(QueryContext* qctx, Kind kind, PlanNode* input, GraphSpaceID space)
Expand All @@ -76,7 +78,7 @@ class Explore : public SingleInputNode {
GraphSpaceID space_;
bool dedup_{false};
int64_t limit_{std::numeric_limits<int64_t>::max()};
std::string filter_;
Expression* filter_{nullptr};
std::vector<storage::cpp2::OrderBy> orderBy_;
};

Expand Down Expand Up @@ -108,7 +110,7 @@ class GetNeighbors final : public Explore {
bool random = false,
std::vector<storage::cpp2::OrderBy> orderBy = {},
int64_t limit = -1,
std::string filter = "") {
Expression* filter = nullptr) {
auto gn = make(qctx, input, space);
gn->setSrc(src);
gn->setEdgeTypes(std::move(edgeTypes));
Expand All @@ -121,7 +123,7 @@ class GetNeighbors final : public Explore {
gn->setDedup(dedup);
gn->setOrderBy(std::move(orderBy));
gn->setLimit(limit);
gn->setFilter(std::move(filter));
gn->setFilter(filter);
return gn;
}

Expand Down Expand Up @@ -199,7 +201,7 @@ class GetVertices final : public Explore {
bool dedup = false,
std::vector<storage::cpp2::OrderBy> orderBy = {},
int64_t limit = std::numeric_limits<int64_t>::max(),
std::string filter = "") {
Expression* filter = nullptr) {
return qctx->objPool()->add(new GetVertices(qctx,
input,
space,
Expand All @@ -209,7 +211,7 @@ class GetVertices final : public Explore {
dedup,
std::move(orderBy),
limit,
std::move(filter)));
filter));
}

Expression* src() const { return src_; }
Expand Down Expand Up @@ -237,15 +239,8 @@ class GetVertices final : public Explore {
bool dedup,
std::vector<storage::cpp2::OrderBy> orderBy,
int64_t limit,
std::string filter)
: Explore(qctx,
Kind::kGetVertices,
input,
space,
dedup,
limit,
std::move(filter),
std::move(orderBy)),
Expression* filter)
: Explore(qctx, Kind::kGetVertices, input, space, dedup, limit, filter, std::move(orderBy)),
src_(src),
props_(std::move(props)),
exprs_(std::move(exprs)) {}
Expand Down Expand Up @@ -278,7 +273,7 @@ class GetEdges final : public Explore {
bool dedup = false,
int64_t limit = std::numeric_limits<int64_t>::max(),
std::vector<storage::cpp2::OrderBy> orderBy = {},
std::string filter = "") {
Expression* filter = nullptr) {
return qctx->objPool()->add(new GetEdges(qctx,
input,
space,
Expand All @@ -291,7 +286,7 @@ class GetEdges final : public Explore {
dedup,
limit,
std::move(orderBy),
std::move(filter)));
filter));
}

Expression* src() const { return src_; }
Expand Down Expand Up @@ -326,15 +321,8 @@ class GetEdges final : public Explore {
bool dedup,
int64_t limit,
std::vector<storage::cpp2::OrderBy> orderBy,
std::string filter)
: Explore(qctx,
Kind::kGetEdges,
input,
space,
dedup,
limit,
std::move(filter),
std::move(orderBy)),
Expression* filter)
: Explore(qctx, Kind::kGetEdges, input, space, dedup, limit, filter, std::move(orderBy)),
src_(src),
type_(type),
ranking_(ranking),
Expand Down Expand Up @@ -374,7 +362,7 @@ class IndexScan : public Explore {
bool dedup = false,
std::vector<storage::cpp2::OrderBy> orderBy = {},
int64_t limit = std::numeric_limits<int64_t>::max(),
std::string filter = "") {
Expression* filter = nullptr) {
return qctx->objPool()->add(new IndexScan(qctx,
input,
space,
Expand All @@ -386,7 +374,7 @@ class IndexScan : public Explore {
dedup,
std::move(orderBy),
limit,
std::move(filter)));
filter));
}

const std::vector<IndexQueryContext>& queryContext() const { return contexts_; }
Expand Down Expand Up @@ -426,9 +414,9 @@ class IndexScan : public Explore {
bool dedup,
std::vector<storage::cpp2::OrderBy> orderBy,
int64_t limit,
std::string filter,
Expression* filter,
Kind kind = Kind::kIndexScan)
: Explore(qctx, kind, input, space, dedup, limit, std::move(filter), std::move(orderBy)) {
: Explore(qctx, kind, input, space, dedup, limit, filter, std::move(orderBy)) {
contexts_ = std::move(contexts);
returnCols_ = std::move(returnCols);
isEdge_ = isEdge;
Expand Down
Loading