Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove useless inner join for go in simple case
Browse files Browse the repository at this point in the history
jievince committed Aug 19, 2022
1 parent 2b1b733 commit 5b383e4
Showing 3 changed files with 42 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/graph/executor/query/GetDstBySrcExecutor.cpp
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@ folly::Future<Status> GetDstBySrcExecutor::execute() {
auto reqList = std::move(res).value();
if (reqList.empty()) {
DataSet emptyResult;
emptyResult.colNames = gd_->colNames();
return finish(ResultBuilder()
.value(Value(std::move(emptyResult)))
.iter(Iterator::Kind::kSequential)
30 changes: 24 additions & 6 deletions src/graph/planner/ngql/GoPlanner.cpp
Original file line number Diff line number Diff line change
@@ -597,6 +597,10 @@ StatusOr<SubPlan> GoPlanner::transform(AstContext* astCtx) {
goCtx_->joinInput = goCtx_->from.fromType != FromType::kInstantExpr;
goCtx_->joinDst = !goCtx_->exprProps.dstTagProps().empty();
goCtx_->isSimple = isSimpleCase();
if (goCtx_->isSimple) {
// We don't need to do a inner join in such case.
goCtx_->joinInput = false;
}
if (goCtx_->isSimple) {
goCtx_->yieldExpr->columns()[0]->setExpr(InputPropertyExpression::make(qctx->objPool(), kDst));
}
@@ -623,18 +627,32 @@ StatusOr<SubPlan> GoPlanner::transform(AstContext* astCtx) {
}

bool GoPlanner::isSimpleCase() {
if (goCtx_->joinInput || goCtx_->joinDst || goCtx_->filter || !goCtx_->distinct) {
if (goCtx_->joinDst || goCtx_->filter || !goCtx_->distinct) {
return false;
}
if (goCtx_->yieldExpr->columns().size() != 1 ||
goCtx_->yieldExpr->columns()[0]->expr()->kind() != Expression::Kind::kEdgeDst) {
return false;
auto& exprProps = goCtx_->exprProps;
if (!exprProps.srcTagProps().empty()) return false;
if (!exprProps.dstTagProps().empty()) return false;
for (auto& edgeProp : exprProps.edgeProps()) {
auto props = edgeProp.second;
if (props.size() != 1) return false;
if (props.find(kDst) == props.end()) return false;
}

auto expr = static_cast<const EdgeDstIdExpression*>(goCtx_->yieldExpr->columns()[0]->expr());
if (expr->sym() != "*" && goCtx_->over.edgeTypes.size() != 1) {
if (goCtx_->yieldExpr->columns().size() != 1) {
return false;
}
if (goCtx_->yieldExpr->columns()[0]->expr()->kind() != Expression::Kind::kEdgeDst &&
goCtx_->yieldExpr->columns()[0]->expr()->kind() != Expression::Kind::kVarProperty) {
return false;
}
auto* expr = goCtx_->yieldExpr->columns()[0]->expr();
if (expr->kind() == Expression::Kind::kEdgeDst) {
auto dstExpr = static_cast<const EdgeDstIdExpression*>(expr);
if (dstExpr->sym() != "*" && goCtx_->over.edgeTypes.size() != 1) {
return false;
}
}
return true;
}

17 changes: 17 additions & 0 deletions tests/tck/features/go/SimpleCase.feature
Original file line number Diff line number Diff line change
@@ -66,3 +66,20 @@ Feature: Simple case
Then the result should be, in any order, with relax comparison:
| count(*) |
| 28 |
And the execution plan should be:
| id | name | dependencies | operator info |
| 14 | Aggregate | 12 | |
| 12 | Minus | 10,11 | |
| 10 | Project | 13 | |
| 13 | PassThrough | 9 | |
| 9 | Dedup | 8 | |
| 8 | GetDstBySrc | 7 | |
| 7 | Dedup | 6 | |
| 6 | Project | 5 | |
| 5 | DataCollect | 4 | |
| 4 | Loop | 0 | {"loopBody": "3"} |
| 3 | Dedup | 2 | |
| 2 | GetDstBySrc | 1 | |
| 1 | Start | | |
| 0 | Start | | |
| 11 | Project | 13 | |

0 comments on commit 5b383e4

Please sign in to comment.