Skip to content
This repository has been archived by the owner on Dec 1, 2022. It is now read-only.

Commit

Permalink
fix filter degradation
Browse files Browse the repository at this point in the history
  • Loading branch information
czpmango committed Jul 12, 2021
1 parent 2fe9721 commit 8ebd772
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/planner/match/WhereClausePlanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ StatusOr<SubPlan> WhereClausePlanner::transform(CypherClauseContextBase* ctx) {
if (wctx->filter) {
SubPlan wherePlan;
auto* newFilter = MatchSolver::doRewrite(wctx->qctx, *wctx->aliasesUsed, wctx->filter);
wherePlan.root = Filter::make(wctx->qctx, nullptr, newFilter, true);
wherePlan.root = Filter::make(wctx->qctx, nullptr, newFilter, needStableFilter_);
wherePlan.tail = wherePlan.root;

return wherePlan;
Expand Down
7 changes: 6 additions & 1 deletion src/planner/match/WhereClausePlanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@ namespace graph {
*/
class WhereClausePlanner final : public CypherClausePlanner {
public:
WhereClausePlanner() = default;
explicit WhereClausePlanner(bool needStableFilter = false)
: needStableFilter_(needStableFilter) {}

StatusOr<SubPlan> transform(CypherClauseContextBase* clauseCtx) override;

private:
// `needStableFilter_=true` only if there is orderBy in withClause(to avoid unstableErase)
bool needStableFilter_{false};
};
} // namespace graph
} // namespace nebula
Expand Down
4 changes: 3 additions & 1 deletion src/planner/match/WithClausePlanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ Status WithClausePlanner::buildWith(WithClauseContext* wctx, SubPlan& subPlan) {
}

if (wctx->where != nullptr) {
auto wherePlan = std::make_unique<WhereClausePlanner>()->transform(wctx->where.get());
bool needStableFilter = wctx->order ? true : false;
auto wherePlan =
std::make_unique<WhereClausePlanner>(needStableFilter)->transform(wctx->where.get());
NG_RETURN_IF_ERROR(wherePlan);
auto plan = std::move(wherePlan).value();
SegmentsConnector::addInput(plan.tail, subPlan.root, true);
Expand Down
1 change: 1 addition & 0 deletions src/planner/plan/Query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ Filter::Filter(QueryContext* qctx, PlanNode* input, Expression* condition, bool
std::unique_ptr<PlanNodeDescription> Filter::explain() const {
auto desc = SingleInputNode::explain();
addDescription("condition", condition_ ? condition_->toString() : "", desc.get());
addDescription("isStable", needStableFilter_ ? "true" : "false", desc.get());
return desc;
}

Expand Down
17 changes: 14 additions & 3 deletions tests/tck/features/match/With.feature
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ Feature: With clause
| "hello" | 1 | 1 |
| "hello" | 2 | 2 |
| "hello" | 3 | 3 |

Scenario: match with return
When executing query:
When profiling query:
"""
MATCH (v:player)
WITH v.age AS age, v AS v, v.name AS name
Expand Down Expand Up @@ -154,6 +152,19 @@ Feature: With clause
| ("Tony Parker" :player{age: 36, name: "Tony Parker"}) | 36 |
| ("Carmelo Anthony" :player{age: 34, name: "Carmelo Anthony"}) | 34 |
| ("LeBron James" :player{age: 34, name: "LeBron James"}) | 34 |
And the execution plan should be:
| id | name | dependencies | operator info |
| 13 | Project | 12 | |
| 12 | Filter | 17 | {"isStable": "true"} |
| 17 | TopN | 9 | |
| 9 | Project | 8 | |
| 8 | Filter | 7 | {"isStable": "false"} |
| 7 | Project | 6 | |
| 6 | Project | 5 | |
| 5 | Filter | 16 | {"isStable": "false"} |
| 16 | GetVertices | 1 | |
| 1 | IndexScan | 0 | |
| 0 | Start | | |

Scenario: with exists
When executing query:
Expand Down

0 comments on commit 8ebd772

Please sign in to comment.